blob: fb3917776eb3157b43be22e0662dc7ce26f9ae91 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
Tony Barbourae58dba2016-12-13 16:30:36 -0700175 found_expected = true;
176 m_msgFound = VK_TRUE;
177 m_failure_message_strings.insert(errorString);
Karl Schultz05cc4e32016-10-12 13:25:23 -0600178 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600179 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600180 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600181 m_msgFound = VK_TRUE;
182 result = VK_TRUE;
183 // We only want one match for each expected error so remove from set here
184 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600185 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600186 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600187 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600188 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600189 for (auto desired_id : m_desired_message_ids) {
190 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
191 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
192 // Return true to avoid calling layers/driver with this error.
193 result = VK_TRUE;
194 } else if (desired_id == message_code) {
195 // Double-check that the string matches the error enum
196 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
197 found_expected = true;
198 result = VK_TRUE;
199 m_msgFound = VK_TRUE;
200 m_desired_message_ids.erase(desired_id);
201 break;
202 } else {
203 // Treat this message as a regular unexpected error, but print a warning jic
204 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
205 errorString.c_str(), desired_id, validation_error_map[desired_id]);
206 }
207 }
208 }
209
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600210 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200211 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600212 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600213 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600214 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600215 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600216 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217
Karl Schultz6addd812016-02-02 17:17:23 -0700218 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600219
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600220 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
221
Karl Schultz6addd812016-02-02 17:17:23 -0700222 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600223
Karl Schultz6addd812016-02-02 17:17:23 -0700224 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600225
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600227 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600228 if (otherMsgs.size()) {
229 cout << "Other error messages logged for this test were:" << endl;
230 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
231 cout << " " << *iter << endl;
232 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600233 }
234 }
235
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600236 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200237
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600238 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
239 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
240 m_msgFlags = message_flag_mask;
241 // Match ANY message matching specified type
242 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200243 }
244
245 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600246 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200247 if (!DesiredMsgFound()) {
248 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600249 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600250 FAIL() << "Did not receive expected error '" << desired_msg << "'";
251 }
Tony Barbour59b42282016-11-03 13:31:28 -0600252 for (auto desired_id : m_desired_message_ids) {
253 FAIL() << "Did not receive expected error '" << desired_id << "'";
254 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200255 }
256 }
257
258 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600259 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200260 if (DesiredMsgFound()) {
261 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600262 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600263 FAIL() << "Expected to succeed but got error: " << msg;
264 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200265 }
266 }
267
Karl Schultz6addd812016-02-02 17:17:23 -0700268 private:
269 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600270 std::unordered_set<uint32_t>m_desired_message_ids;
271 std::unordered_set<string> m_desired_message_strings;
272 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700273 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600274 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700275 bool *m_bailout;
276 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600277};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500278
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600279static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
280 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
281 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600282 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
283 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600284 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600285 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600286 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600287}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500288
Karl Schultz6addd812016-02-02 17:17:23 -0700289class VkLayerTest : public VkRenderFramework {
290 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800291 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
292 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
294 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700295 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600296 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
297 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700298 }
Tony Barbour300a6082015-04-07 13:44:53 -0600299
Tony Barbourfe3351b2015-07-28 10:17:20 -0600300 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600301 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800302 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
304 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700305 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600306 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700307 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600308 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700309 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600310 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
311 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
312 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700313 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
314 }
315 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
316 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
317 }
318
319 protected:
320 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600321 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600322
323 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600324 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600325 std::vector<const char *> instance_extension_names;
326 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600327
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700328 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600329 /*
330 * Since CreateDbgMsgCallback is an instance level extension call
331 * any extension / layer that utilizes that feature also needs
332 * to be enabled at create instance time.
333 */
Karl Schultz6addd812016-02-02 17:17:23 -0700334 // Use Threading layer first to protect others from
335 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700336 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600337 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800338 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700339 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800340 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600341 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700342 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600343
Ian Elliott2c1daf52016-05-12 09:41:46 -0600344 if (m_enableWSI) {
345 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
346 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
347#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
348#if defined(VK_USE_PLATFORM_ANDROID_KHR)
349 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_ANDROID_KHR
351#if defined(VK_USE_PLATFORM_MIR_KHR)
352 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_MIR_KHR
354#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
355 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WAYLAND_KHR
357#if defined(VK_USE_PLATFORM_WIN32_KHR)
358 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
359#endif // VK_USE_PLATFORM_WIN32_KHR
360#endif // NEED_TO_TEST_THIS_ON_PLATFORM
361#if defined(VK_USE_PLATFORM_XCB_KHR)
362 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
363#elif defined(VK_USE_PLATFORM_XLIB_KHR)
364 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
365#endif // VK_USE_PLATFORM_XLIB_KHR
366 }
367
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600368 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800370 this->app_info.pApplicationName = "layer_tests";
371 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600372 this->app_info.pEngineName = "unittest";
373 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600374 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600375
Tony Barbour15524c32015-04-29 17:34:29 -0600376 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600377 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600378 }
379
380 virtual void TearDown() {
381 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600382 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600383 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600384 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600385
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600386 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600387};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500388
Karl Schultz6addd812016-02-02 17:17:23 -0700389VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600390 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600391
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800392 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600393
394 /*
395 * For render test all drawing happens in a single render pass
396 * on a single command buffer.
397 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200398 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800399 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600400 }
401
402 return result;
403}
404
Karl Schultz6addd812016-02-02 17:17:23 -0700405VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600406 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600407
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200408 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200410 }
Tony Barbour300a6082015-04-07 13:44:53 -0600411
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800412 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600413
414 return result;
415}
416
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600417void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418 // Create identity matrix
419 int i;
420 struct vktriangle_vs_uniform data;
421
422 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700423 glm::mat4 View = glm::mat4(1.0f);
424 glm::mat4 Model = glm::mat4(1.0f);
425 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500426 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700427 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500428
429 memcpy(&data.mvp, &MVP[0][0], matrixSize);
430
Karl Schultz6addd812016-02-02 17:17:23 -0700431 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600432 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 };
434
Karl Schultz6addd812016-02-02 17:17:23 -0700435 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500436 data.position[i][0] = tri_data[i].posX;
437 data.position[i][1] = tri_data[i].posY;
438 data.position[i][2] = tri_data[i].posZ;
439 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700440 data.color[i][0] = tri_data[i].r;
441 data.color[i][1] = tri_data[i].g;
442 data.color[i][2] = tri_data[i].b;
443 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444 }
445
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500446 ASSERT_NO_FATAL_FAILURE(InitViewport());
447
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200448 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
449 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
Karl Schultz6addd812016-02-02 17:17:23 -0700451 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600452 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453
454 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800455 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500456 pipelineobj.AddShader(&vs);
457 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600458 if (failMask & BsoFailLineWidth) {
459 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600460 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600461 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600462 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
463 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600464 }
465 if (failMask & BsoFailDepthBias) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600470 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600471 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700473 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700474 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600475 if (failMask & BsoFailViewport) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
477 }
478 if (failMask & BsoFailScissor) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
480 }
481 if (failMask & BsoFailBlend) {
482 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600483 VkPipelineColorBlendAttachmentState att_state = {};
484 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
485 att_state.blendEnable = VK_TRUE;
486 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600487 }
488 if (failMask & BsoFailDepthBounds) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
490 }
491 if (failMask & BsoFailStencilReadMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
493 }
494 if (failMask & BsoFailStencilWriteMask) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
496 }
497 if (failMask & BsoFailStencilReference) {
498 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
499 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600502 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600505 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500506
Tony Barbourfe3351b2015-07-28 10:17:20 -0600507 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508
509 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600510 if (failMask & BsoFailIndexBuffer) {
511 // Use DrawIndexed w/o an index buffer bound
512 DrawIndexed(3, 1, 0, 0, 0);
513 } else {
514 Draw(3, 1, 0, 0);
515 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
Mark Muellerd4914412016-06-13 17:52:06 -0600517 if (failMask & BsoFailCmdClearAttachments) {
518 VkClearAttachment color_attachment = {};
519 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
520 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
521 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
522
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600523 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600524 }
525
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500526 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600527 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500528
Tony Barbourfe3351b2015-07-28 10:17:20 -0600529 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500530}
531
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
533 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500536 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600537 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538 }
539
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800540 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700541 // Make sure depthWriteEnable is set so that Depth fail test will work
542 // correctly
543 // Make sure stencilTestEnable is set so that Stencil fail test will work
544 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600545 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800546 stencil.failOp = VK_STENCIL_OP_KEEP;
547 stencil.passOp = VK_STENCIL_OP_KEEP;
548 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
549 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600550
551 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
552 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600553 ds_ci.pNext = NULL;
554 ds_ci.depthTestEnable = VK_FALSE;
555 ds_ci.depthWriteEnable = VK_TRUE;
556 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
557 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600558 if (failMask & BsoFailDepthBounds) {
559 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600560 ds_ci.maxDepthBounds = 0.0f;
561 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600562 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600563 ds_ci.stencilTestEnable = VK_TRUE;
564 ds_ci.front = stencil;
565 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600566
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600567 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600568 pipelineobj.SetViewport(m_viewports);
569 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600571 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600572 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800573 commandBuffer->BindPipeline(pipelineobj);
574 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500575}
576
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600577class VkPositiveLayerTest : public VkLayerTest {
578 public:
579 protected:
580};
581
Ian Elliott2c1daf52016-05-12 09:41:46 -0600582class VkWsiEnabledLayerTest : public VkLayerTest {
583 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600584 protected:
585 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600586};
587
Mark Muellerdfe37552016-07-07 14:47:42 -0600588class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600589 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600590 enum eTestEnFlags {
591 eDoubleDelete,
592 eInvalidDeviceOffset,
593 eInvalidMemoryOffset,
594 eBindNullBuffer,
595 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600596 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600597 };
598
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600599 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600600
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
602 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600603 return true;
604 }
605 VkDeviceSize offset_limit = 0;
606 if (eInvalidMemoryOffset == aTestFlag) {
607 VkBuffer vulkanBuffer;
608 VkBufferCreateInfo buffer_create_info = {};
609 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
610 buffer_create_info.size = 32;
611 buffer_create_info.usage = aBufferUsage;
612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600614 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600615
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600617 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
618 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
620 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600621 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600622 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600623 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 }
626 if (eOffsetAlignment < offset_limit) {
627 return true;
628 }
629 return false;
630 }
631
632 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
634 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600635
636 if (eBindNullBuffer == aTestFlag) {
637 VulkanMemory = 0;
638 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
639 } else {
640 VkBufferCreateInfo buffer_create_info = {};
641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
642 buffer_create_info.size = 32;
643 buffer_create_info.usage = aBufferUsage;
644
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600645 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600646
647 CreateCurrent = true;
648
649 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600650 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600651
652 VkMemoryAllocateInfo memory_allocate_info = {};
653 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
654 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600655 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
656 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 if (!pass) {
658 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
659 return;
660 }
661
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600663 AllocateCurrent = true;
664 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600665 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
666 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600667 BoundCurrent = true;
668
669 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
670 }
671 }
672
673 ~VkBufferTest() {
674 if (CreateCurrent) {
675 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
676 }
677 if (AllocateCurrent) {
678 if (InvalidDeleteEn) {
679 union {
680 VkDeviceMemory device_memory;
681 unsigned long long index_access;
682 } bad_index;
683
684 bad_index.device_memory = VulkanMemory;
685 bad_index.index_access++;
686
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600687 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600688 }
689 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
690 }
691 }
692
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600693 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600694
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600695 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600696
697 void TestDoubleDestroy() {
698 // Destroy the buffer but leave the flag set, which will cause
699 // the buffer to be destroyed again in the destructor.
700 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
701 }
702
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600703 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600704 bool AllocateCurrent;
705 bool BoundCurrent;
706 bool CreateCurrent;
707 bool InvalidDeleteEn;
708
709 VkBuffer VulkanBuffer;
710 VkDevice VulkanDevice;
711 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600712};
713
714class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 public:
716 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600717 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600720 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
721 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600722 BindIdGenerator++; // NB: This can wrap w/misuse
723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
725 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600726
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600727 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
728 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
729 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
730 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
731 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600732
733 unsigned i = 0;
734 do {
735 VertexInputAttributeDescription[i].binding = BindId;
736 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
738 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600739 i++;
740 } while (AttributeCount < i);
741
742 i = 0;
743 do {
744 VertexInputBindingDescription[i].binding = BindId;
745 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600746 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600747 i++;
748 } while (BindingCount < i);
749 }
750
751 ~VkVerticesObj() {
752 if (VertexInputAttributeDescription) {
753 delete[] VertexInputAttributeDescription;
754 }
755 if (VertexInputBindingDescription) {
756 delete[] VertexInputBindingDescription;
757 }
758 }
759
760 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600761 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
762 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600763 return true;
764 }
765
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600766 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600767 VkDeviceSize *offsetList;
768 unsigned offsetCount;
769
770 if (aOffsetCount) {
771 offsetList = aOffsetList;
772 offsetCount = aOffsetCount;
773 } else {
774 offsetList = new VkDeviceSize[1]();
775 offsetCount = 1;
776 }
777
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600778 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600779 BoundCurrent = true;
780
781 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600782 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600783 }
784 }
785
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600786 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600787 static uint32_t BindIdGenerator;
788
789 bool BoundCurrent;
790 unsigned AttributeCount;
791 unsigned BindingCount;
792 uint32_t BindId;
793
794 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
795 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
796 VkVertexInputBindingDescription *VertexInputBindingDescription;
797 VkConstantBufferObj VulkanMemoryBuffer;
798};
799
800uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500801// ********************************************************************************************************************
802// ********************************************************************************************************************
803// ********************************************************************************************************************
804// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600805#if PARAMETER_VALIDATION_TESTS
806TEST_F(VkLayerTest, RequiredParameter) {
807 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
808 "pointer, array, and array count parameters");
809
810 ASSERT_NO_FATAL_FAILURE(InitState());
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600813 // Specify NULL for a pointer to a handle
814 // Expected to trigger an error with
815 // parameter_validation::validate_required_pointer
816 vkGetPhysicalDeviceFeatures(gpu(), NULL);
817 m_errorMonitor->VerifyFound();
818
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
820 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 // Specify NULL for pointer to array count
822 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600823 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 m_errorMonitor->VerifyFound();
825
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600827 // Specify 0 for a required array count
828 // Expected to trigger an error with parameter_validation::validate_array
829 VkViewport view_port = {};
830 m_commandBuffer->SetViewport(0, 0, &view_port);
831 m_errorMonitor->VerifyFound();
832
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 // Specify NULL for a required array
835 // Expected to trigger an error with parameter_validation::validate_array
836 m_commandBuffer->SetViewport(0, 1, NULL);
837 m_errorMonitor->VerifyFound();
838
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600840 // Specify VK_NULL_HANDLE for a required handle
841 // Expected to trigger an error with
842 // parameter_validation::validate_required_handle
843 vkUnmapMemory(device(), VK_NULL_HANDLE);
844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
847 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600848 // Specify VK_NULL_HANDLE for a required handle array entry
849 // Expected to trigger an error with
850 // parameter_validation::validate_required_handle_array
851 VkFence fence = VK_NULL_HANDLE;
852 vkResetFences(device(), 1, &fence);
853 m_errorMonitor->VerifyFound();
854
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600856 // Specify NULL for a required struct pointer
857 // Expected to trigger an error with
858 // parameter_validation::validate_struct_type
859 VkDeviceMemory memory = VK_NULL_HANDLE;
860 vkAllocateMemory(device(), NULL, NULL, &memory);
861 m_errorMonitor->VerifyFound();
862
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600864 // Specify 0 for a required VkFlags parameter
865 // Expected to trigger an error with parameter_validation::validate_flags
866 m_commandBuffer->SetStencilReference(0, 0);
867 m_errorMonitor->VerifyFound();
868
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600870 // Specify 0 for a required VkFlags array entry
871 // Expected to trigger an error with
872 // parameter_validation::validate_flags_array
873 VkSemaphore semaphore = VK_NULL_HANDLE;
874 VkPipelineStageFlags stageFlags = 0;
875 VkSubmitInfo submitInfo = {};
876 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
877 submitInfo.waitSemaphoreCount = 1;
878 submitInfo.pWaitSemaphores = &semaphore;
879 submitInfo.pWaitDstStageMask = &stageFlags;
880 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
881 m_errorMonitor->VerifyFound();
882}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600883
Dustin Gravesfce74c02016-05-10 11:42:58 -0600884TEST_F(VkLayerTest, ReservedParameter) {
885 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
886
887 ASSERT_NO_FATAL_FAILURE(InitState());
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600890 // Specify 0 for a reserved VkFlags parameter
891 // Expected to trigger an error with
892 // parameter_validation::validate_reserved_flags
893 VkEvent event_handle = VK_NULL_HANDLE;
894 VkEventCreateInfo event_info = {};
895 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
896 event_info.flags = 1;
897 vkCreateEvent(device(), &event_info, NULL, &event_handle);
898 m_errorMonitor->VerifyFound();
899}
900
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600901TEST_F(VkLayerTest, InvalidStructSType) {
902 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
903 "structure's sType field");
904
905 ASSERT_NO_FATAL_FAILURE(InitState());
906
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600908 // Zero struct memory, effectively setting sType to
909 // VK_STRUCTURE_TYPE_APPLICATION_INFO
910 // Expected to trigger an error with
911 // parameter_validation::validate_struct_type
912 VkMemoryAllocateInfo alloc_info = {};
913 VkDeviceMemory memory = VK_NULL_HANDLE;
914 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
915 m_errorMonitor->VerifyFound();
916
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600918 // Zero struct memory, effectively setting sType to
919 // VK_STRUCTURE_TYPE_APPLICATION_INFO
920 // Expected to trigger an error with
921 // parameter_validation::validate_struct_type_array
922 VkSubmitInfo submit_info = {};
923 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
924 m_errorMonitor->VerifyFound();
925}
926
927TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929
930 ASSERT_NO_FATAL_FAILURE(InitState());
931
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600933 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600934 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600935 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600936 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600937 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600938 // Zero-initialization will provide the correct sType
939 VkApplicationInfo app_info = {};
940 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
941 event_alloc_info.pNext = &app_info;
942 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
943 m_errorMonitor->VerifyFound();
944
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
946 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600947 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
948 // a function that has allowed pNext structure types and specify
949 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600950 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600951 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600952 VkMemoryAllocateInfo memory_alloc_info = {};
953 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
954 memory_alloc_info.pNext = &app_info;
955 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600956 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600957}
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600960 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600961
962 ASSERT_NO_FATAL_FAILURE(InitState());
963
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
965 "range of the core VkFormat "
966 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600967 // Specify an invalid VkFormat value
968 // Expected to trigger an error with
969 // parameter_validation::validate_ranged_enum
970 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 m_errorMonitor->VerifyFound();
973
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600975 // Specify an invalid VkFlags bitmask value
976 // Expected to trigger an error with parameter_validation::validate_flags
977 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600978 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
979 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 m_errorMonitor->VerifyFound();
981
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600983 // Specify an invalid VkFlags array entry
984 // Expected to trigger an error with
985 // parameter_validation::validate_flags_array
986 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600987 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600988 VkSubmitInfo submit_info = {};
989 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
990 submit_info.waitSemaphoreCount = 1;
991 submit_info.pWaitSemaphores = &semaphore;
992 submit_info.pWaitDstStageMask = &stage_flags;
993 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
994 m_errorMonitor->VerifyFound();
995
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600997 // Specify an invalid VkBool32 value
998 // Expected to trigger a warning with
999 // parameter_validation::validate_bool32
1000 VkSampler sampler = VK_NULL_HANDLE;
1001 VkSamplerCreateInfo sampler_info = {};
1002 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1003 sampler_info.pNext = NULL;
1004 sampler_info.magFilter = VK_FILTER_NEAREST;
1005 sampler_info.minFilter = VK_FILTER_NEAREST;
1006 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1007 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1008 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1009 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1010 sampler_info.mipLodBias = 1.0;
1011 sampler_info.maxAnisotropy = 1;
1012 sampler_info.compareEnable = VK_FALSE;
1013 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1014 sampler_info.minLod = 1.0;
1015 sampler_info.maxLod = 1.0;
1016 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1017 sampler_info.unnormalizedCoordinates = VK_FALSE;
1018 // Not VK_TRUE or VK_FALSE
1019 sampler_info.anisotropyEnable = 3;
1020 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1021 m_errorMonitor->VerifyFound();
1022}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001023
1024TEST_F(VkLayerTest, FailedReturnValue) {
1025 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1026
1027 ASSERT_NO_FATAL_FAILURE(InitState());
1028
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001029 // Find an unsupported image format
1030 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1031 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1032 VkFormat format = static_cast<VkFormat>(f);
1033 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001034 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001035 unsupported = format;
1036 break;
1037 }
1038 }
1039
1040 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1042 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001043 // Specify an unsupported VkFormat value to generate a
1044 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1045 // Expected to trigger a warning from
1046 // parameter_validation::validate_result
1047 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001048 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1049 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001050 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1051 m_errorMonitor->VerifyFound();
1052 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001053}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001054
1055TEST_F(VkLayerTest, UpdateBufferAlignment) {
1056 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001057 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001058
1059 ASSERT_NO_FATAL_FAILURE(InitState());
1060
1061 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1062 vk_testing::Buffer buffer;
1063 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1064
1065 BeginCommandBuffer();
1066 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001068 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1069 m_errorMonitor->VerifyFound();
1070
1071 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001073 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1074 m_errorMonitor->VerifyFound();
1075
1076 // Introduce failure by using dataSize that is < 0
1077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001078 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001079 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1080 m_errorMonitor->VerifyFound();
1081
1082 // Introduce failure by using dataSize that is > 65536
1083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 EndCommandBuffer();
1089}
1090
1091TEST_F(VkLayerTest, FillBufferAlignment) {
1092 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1093
1094 ASSERT_NO_FATAL_FAILURE(InitState());
1095
1096 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1097 vk_testing::Buffer buffer;
1098 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1099
1100 BeginCommandBuffer();
1101
1102 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001104 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1105 m_errorMonitor->VerifyFound();
1106
1107 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001109 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1110 m_errorMonitor->VerifyFound();
1111
1112 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001114 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1115 m_errorMonitor->VerifyFound();
1116
1117 EndCommandBuffer();
1118}
Dustin Graves40f35822016-06-23 11:12:53 -06001119
Cortd889ff92016-07-27 09:51:27 -07001120TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1121 VkResult err;
1122
1123 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001124 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001125
1126 ASSERT_NO_FATAL_FAILURE(InitState());
1127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1128
1129 std::vector<const char *> device_extension_names;
1130 auto features = m_device->phy().features();
1131 // Artificially disable support for non-solid fill modes
1132 features.fillModeNonSolid = false;
1133 // The sacrificial device object
1134 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1135
1136 VkRenderpassObj render_pass(&test_device);
1137
1138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1140 pipeline_layout_ci.setLayoutCount = 0;
1141 pipeline_layout_ci.pSetLayouts = NULL;
1142
1143 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001144 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001145 ASSERT_VK_SUCCESS(err);
1146
1147 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1148 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1149 rs_ci.pNext = nullptr;
1150 rs_ci.lineWidth = 1.0f;
1151 rs_ci.rasterizerDiscardEnable = true;
1152
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001153 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1154 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001155
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001156 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1158 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001159 {
1160 VkPipelineObj pipe(&test_device);
1161 pipe.AddShader(&vs);
1162 pipe.AddShader(&fs);
1163 pipe.AddColorAttachment();
1164 // Introduce failure by setting unsupported polygon mode
1165 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1166 pipe.SetRasterization(&rs_ci);
1167 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1168 }
1169 m_errorMonitor->VerifyFound();
1170
1171 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1173 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001174 {
1175 VkPipelineObj pipe(&test_device);
1176 pipe.AddShader(&vs);
1177 pipe.AddShader(&fs);
1178 pipe.AddColorAttachment();
1179 // Introduce failure by setting unsupported polygon mode
1180 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1181 pipe.SetRasterization(&rs_ci);
1182 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1183 }
1184 m_errorMonitor->VerifyFound();
1185
Cortd889ff92016-07-27 09:51:27 -07001186 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1187}
1188
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001189#endif // PARAMETER_VALIDATION_TESTS
1190
Tobin Ehlis0788f522015-05-26 16:11:58 -06001191#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001192#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001193TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001194{
1195 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001196 VkFenceCreateInfo fenceInfo = {};
1197 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1198 fenceInfo.pNext = NULL;
1199 fenceInfo.flags = 0;
1200
Mike Weiblencce7ec72016-10-17 19:33:05 -06001201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001202
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001203 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001204
1205 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1206 vk_testing::Buffer buffer;
1207 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001208
Tony Barbourfe3351b2015-07-28 10:17:20 -06001209 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001210 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001211 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001212
1213 testFence.init(*m_device, fenceInfo);
1214
1215 // Bypass framework since it does the waits automatically
1216 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001217 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001218 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1219 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001221 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001222 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001223 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001224 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001225 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001226 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001227
1228 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001229 ASSERT_VK_SUCCESS( err );
1230
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001231 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001232 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001233
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001234 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235}
1236
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001237TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001238{
1239 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001240 VkFenceCreateInfo fenceInfo = {};
1241 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1242 fenceInfo.pNext = NULL;
1243 fenceInfo.flags = 0;
1244
Mike Weiblencce7ec72016-10-17 19:33:05 -06001245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001246
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001247 ASSERT_NO_FATAL_FAILURE(InitState());
1248 ASSERT_NO_FATAL_FAILURE(InitViewport());
1249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1250
Tony Barbourfe3351b2015-07-28 10:17:20 -06001251 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001252 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001253 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001254
1255 testFence.init(*m_device, fenceInfo);
1256
1257 // Bypass framework since it does the waits automatically
1258 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001259 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001260 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1261 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001263 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001264 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001265 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001266 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001267 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001268 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001269
1270 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001271 ASSERT_VK_SUCCESS( err );
1272
Jon Ashburnf19916e2016-01-11 13:12:43 -07001273 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001274 VkCommandBufferBeginInfo info = {};
1275 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1276 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001277 info.renderPass = VK_NULL_HANDLE;
1278 info.subpass = 0;
1279 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001280 info.occlusionQueryEnable = VK_FALSE;
1281 info.queryFlags = 0;
1282 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001283
1284 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001285 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001286
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001288}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001289#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001290
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001291TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1292 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1293
1294 ASSERT_NO_FATAL_FAILURE(InitState());
1295
1296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1297 VkBuffer buffer;
1298 VkBufferCreateInfo buf_info = {};
1299 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1300 buf_info.pNext = NULL;
1301 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1302 buf_info.size = 2048;
1303 buf_info.queueFamilyIndexCount = 0;
1304 buf_info.pQueueFamilyIndices = NULL;
1305 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1306 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1307 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1308 m_errorMonitor->VerifyFound();
1309
1310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1311 VkImage image;
1312 VkImageCreateInfo image_create_info = {};
1313 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1314 image_create_info.pNext = NULL;
1315 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1316 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1317 image_create_info.extent.width = 512;
1318 image_create_info.extent.height = 64;
1319 image_create_info.extent.depth = 1;
1320 image_create_info.mipLevels = 1;
1321 image_create_info.arrayLayers = 1;
1322 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1323 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1324 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1325 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1326 image_create_info.queueFamilyIndexCount = 0;
1327 image_create_info.pQueueFamilyIndices = NULL;
1328 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1329 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1330 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1331 m_errorMonitor->VerifyFound();
1332}
1333
Tobin Ehlisf11be982016-05-11 13:52:53 -06001334TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1335 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1336 "buffer and image to memory such that they will alias.");
1337 VkResult err;
1338 bool pass;
1339 ASSERT_NO_FATAL_FAILURE(InitState());
1340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001342 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001343 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001344 VkDeviceMemory mem; // buffer will be bound first
1345 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001346 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001347 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001348
1349 VkBufferCreateInfo buf_info = {};
1350 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1351 buf_info.pNext = NULL;
1352 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1353 buf_info.size = 256;
1354 buf_info.queueFamilyIndexCount = 0;
1355 buf_info.pQueueFamilyIndices = NULL;
1356 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1357 buf_info.flags = 0;
1358 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1359 ASSERT_VK_SUCCESS(err);
1360
Tobin Ehlis077ded32016-05-12 17:39:13 -06001361 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001362
1363 VkImageCreateInfo image_create_info = {};
1364 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1365 image_create_info.pNext = NULL;
1366 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1367 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1368 image_create_info.extent.width = 64;
1369 image_create_info.extent.height = 64;
1370 image_create_info.extent.depth = 1;
1371 image_create_info.mipLevels = 1;
1372 image_create_info.arrayLayers = 1;
1373 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001374 // Image tiling must be optimal to trigger error when aliasing linear buffer
1375 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1377 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1378 image_create_info.queueFamilyIndexCount = 0;
1379 image_create_info.pQueueFamilyIndices = NULL;
1380 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1381 image_create_info.flags = 0;
1382
Tobin Ehlisf11be982016-05-11 13:52:53 -06001383 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1384 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001385 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1386 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001387
Tobin Ehlis077ded32016-05-12 17:39:13 -06001388 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1389
1390 VkMemoryAllocateInfo alloc_info = {};
1391 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1392 alloc_info.pNext = NULL;
1393 alloc_info.memoryTypeIndex = 0;
1394 // Ensure memory is big enough for both bindings
1395 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001396 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1397 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001398 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001399 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001400 vkDestroyImage(m_device->device(), image, NULL);
1401 return;
1402 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001403 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1404 ASSERT_VK_SUCCESS(err);
1405 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1406 ASSERT_VK_SUCCESS(err);
1407
Rene Lindsayd14f5572016-12-16 14:57:18 -07001408 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1409
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001411 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001412 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1413 m_errorMonitor->VerifyFound();
1414
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001415 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001416 // aliasing buffer2
1417 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1418 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001419 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1420 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001421 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001422 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001424 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001425 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001426 m_errorMonitor->VerifyFound();
1427
1428 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001429 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001430 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001431 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001432 vkFreeMemory(m_device->device(), mem, NULL);
1433 vkFreeMemory(m_device->device(), mem_img, NULL);
1434}
1435
Tobin Ehlis35372522016-05-12 08:32:31 -06001436TEST_F(VkLayerTest, InvalidMemoryMapping) {
1437 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1438 VkResult err;
1439 bool pass;
1440 ASSERT_NO_FATAL_FAILURE(InitState());
1441
1442 VkBuffer buffer;
1443 VkDeviceMemory mem;
1444 VkMemoryRequirements mem_reqs;
1445
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001446 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1447
Tobin Ehlis35372522016-05-12 08:32:31 -06001448 VkBufferCreateInfo buf_info = {};
1449 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1450 buf_info.pNext = NULL;
1451 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1452 buf_info.size = 256;
1453 buf_info.queueFamilyIndexCount = 0;
1454 buf_info.pQueueFamilyIndices = NULL;
1455 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1456 buf_info.flags = 0;
1457 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1458 ASSERT_VK_SUCCESS(err);
1459
1460 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1461 VkMemoryAllocateInfo alloc_info = {};
1462 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1463 alloc_info.pNext = NULL;
1464 alloc_info.memoryTypeIndex = 0;
1465
1466 // Ensure memory is big enough for both bindings
1467 static const VkDeviceSize allocation_size = 0x10000;
1468 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001469 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 if (!pass) {
1471 vkDestroyBuffer(m_device->device(), buffer, NULL);
1472 return;
1473 }
1474 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1475 ASSERT_VK_SUCCESS(err);
1476
1477 uint8_t *pData;
1478 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001480 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1481 m_errorMonitor->VerifyFound();
1482 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001483 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1486 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1487 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001488 m_errorMonitor->VerifyFound();
1489
1490 // Unmap the memory to avoid re-map error
1491 vkUnmapMemory(m_device->device(), mem);
1492 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1494 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1495 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001496 m_errorMonitor->VerifyFound();
1497 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1499 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001500 m_errorMonitor->VerifyFound();
1501 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001503 vkUnmapMemory(m_device->device(), mem);
1504 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001505
Tobin Ehlis35372522016-05-12 08:32:31 -06001506 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001507 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001508 ASSERT_VK_SUCCESS(err);
1509 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001510 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001511 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001512 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001514 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1515 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001516
Tobin Ehlis35372522016-05-12 08:32:31 -06001517 // Now flush range that oversteps mapped range
1518 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001519 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001520 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001521 mmr.offset = atom_size;
1522 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1524 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1525 m_errorMonitor->VerifyFound();
1526
1527 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1528 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001529 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001530 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001531 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001532 mmr.size = VK_WHOLE_SIZE;
1533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001534 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1535 m_errorMonitor->VerifyFound();
1536
Tony Barboure3975eb2016-12-15 14:52:44 -07001537#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001538 // Some platforms have an atomsize of 1 which makes the test meaningless
1539 if (atom_size > 3) {
1540 // Now with an offset NOT a multiple of the device limit
1541 vkUnmapMemory(m_device->device(), mem);
1542 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1543 ASSERT_VK_SUCCESS(err);
1544 mmr.offset = 3; // Not a multiple of atom_size
1545 mmr.size = VK_WHOLE_SIZE;
1546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1547 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1548 m_errorMonitor->VerifyFound();
1549
1550 // Now with a size NOT a multiple of the device limit
1551 vkUnmapMemory(m_device->device(), mem);
1552 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1553 ASSERT_VK_SUCCESS(err);
1554 mmr.offset = atom_size;
1555 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1557 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1558 m_errorMonitor->VerifyFound();
1559 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001560#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001561 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1562 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001563 if (!pass) {
1564 vkFreeMemory(m_device->device(), mem, NULL);
1565 vkDestroyBuffer(m_device->device(), buffer, NULL);
1566 return;
1567 }
1568 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1569 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1570
1571 vkDestroyBuffer(m_device->device(), buffer, NULL);
1572 vkFreeMemory(m_device->device(), mem, NULL);
1573}
1574
Chris Forbes09368e42016-10-13 11:59:22 +13001575#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001576TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1577 VkResult err;
1578 bool pass;
1579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001580 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1581 // following declaration (which is temporarily being moved below):
1582 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001584 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001585 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001586 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001587 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001588 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001589
1590 ASSERT_NO_FATAL_FAILURE(InitState());
1591
Ian Elliott3f06ce52016-04-29 14:46:21 -06001592#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1593#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1594 // Use the functions from the VK_KHR_android_surface extension without
1595 // enabling that extension:
1596
1597 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001598 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1600 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001601 pass = (err != VK_SUCCESS);
1602 ASSERT_TRUE(pass);
1603 m_errorMonitor->VerifyFound();
1604#endif // VK_USE_PLATFORM_ANDROID_KHR
1605
Ian Elliott3f06ce52016-04-29 14:46:21 -06001606#if defined(VK_USE_PLATFORM_MIR_KHR)
1607 // Use the functions from the VK_KHR_mir_surface extension without enabling
1608 // that extension:
1609
1610 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001611 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001613 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1614 pass = (err != VK_SUCCESS);
1615 ASSERT_TRUE(pass);
1616 m_errorMonitor->VerifyFound();
1617
1618 // Tell whether an mir_connection supports presentation:
1619 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1621 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001622 m_errorMonitor->VerifyFound();
1623#endif // VK_USE_PLATFORM_MIR_KHR
1624
Ian Elliott3f06ce52016-04-29 14:46:21 -06001625#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1626 // Use the functions from the VK_KHR_wayland_surface extension without
1627 // enabling that extension:
1628
1629 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001630 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1632 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001633 pass = (err != VK_SUCCESS);
1634 ASSERT_TRUE(pass);
1635 m_errorMonitor->VerifyFound();
1636
1637 // Tell whether an wayland_display supports presentation:
1638 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1640 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001641 m_errorMonitor->VerifyFound();
1642#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001643#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001644
Ian Elliott3f06ce52016-04-29 14:46:21 -06001645#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001646 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1647 // TO NON-LINUX PLATFORMS:
1648 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001649 // Use the functions from the VK_KHR_win32_surface extension without
1650 // enabling that extension:
1651
1652 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001653 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1655 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001656 pass = (err != VK_SUCCESS);
1657 ASSERT_TRUE(pass);
1658 m_errorMonitor->VerifyFound();
1659
1660 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001662 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001663 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001664// Set this (for now, until all platforms are supported and tested):
1665#define NEED_TO_TEST_THIS_ON_PLATFORM
1666#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001667#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001668 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1669 // TO NON-LINUX PLATFORMS:
1670 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001671#endif
1672#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001673 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1674 // that extension:
1675
1676 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001677 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001679 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1680 pass = (err != VK_SUCCESS);
1681 ASSERT_TRUE(pass);
1682 m_errorMonitor->VerifyFound();
1683
1684 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001685 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001686 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1688 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001689 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001690// Set this (for now, until all platforms are supported and tested):
1691#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001692#endif // VK_USE_PLATFORM_XCB_KHR
1693
Ian Elliott12630812016-04-29 14:35:43 -06001694#if defined(VK_USE_PLATFORM_XLIB_KHR)
1695 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1696 // that extension:
1697
1698 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001699 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001701 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1702 pass = (err != VK_SUCCESS);
1703 ASSERT_TRUE(pass);
1704 m_errorMonitor->VerifyFound();
1705
1706 // Tell whether an Xlib VisualID supports presentation:
1707 Display *dpy = NULL;
1708 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001710 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1711 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001712// Set this (for now, until all platforms are supported and tested):
1713#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001714#endif // VK_USE_PLATFORM_XLIB_KHR
1715
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001716// Use the functions from the VK_KHR_surface extension without enabling
1717// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001718
Ian Elliott489eec02016-05-05 14:12:44 -06001719#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001720 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001722 vkDestroySurfaceKHR(instance(), surface, NULL);
1723 m_errorMonitor->VerifyFound();
1724
1725 // Check if surface supports presentation:
1726 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001728 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1729 pass = (err != VK_SUCCESS);
1730 ASSERT_TRUE(pass);
1731 m_errorMonitor->VerifyFound();
1732
1733 // Check surface capabilities:
1734 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1736 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001737 pass = (err != VK_SUCCESS);
1738 ASSERT_TRUE(pass);
1739 m_errorMonitor->VerifyFound();
1740
1741 // Check surface formats:
1742 uint32_t format_count = 0;
1743 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1745 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001746 pass = (err != VK_SUCCESS);
1747 ASSERT_TRUE(pass);
1748 m_errorMonitor->VerifyFound();
1749
1750 // Check surface present modes:
1751 uint32_t present_mode_count = 0;
1752 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1754 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001755 pass = (err != VK_SUCCESS);
1756 ASSERT_TRUE(pass);
1757 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001758#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001759
Ian Elliott1c32c772016-04-28 14:47:13 -06001760 // Use the functions from the VK_KHR_swapchain extension without enabling
1761 // that extension:
1762
1763 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001765 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1766 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001767 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001768 pass = (err != VK_SUCCESS);
1769 ASSERT_TRUE(pass);
1770 m_errorMonitor->VerifyFound();
1771
1772 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1774 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001775 pass = (err != VK_SUCCESS);
1776 ASSERT_TRUE(pass);
1777 m_errorMonitor->VerifyFound();
1778
Chris Forbeseb7d5502016-09-13 18:19:21 +12001779 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1780 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1781 VkFence fence;
1782 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1783
Ian Elliott1c32c772016-04-28 14:47:13 -06001784 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001786 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001787 pass = (err != VK_SUCCESS);
1788 ASSERT_TRUE(pass);
1789 m_errorMonitor->VerifyFound();
1790
Chris Forbeseb7d5502016-09-13 18:19:21 +12001791 vkDestroyFence(m_device->device(), fence, nullptr);
1792
Ian Elliott1c32c772016-04-28 14:47:13 -06001793 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001794 //
1795 // NOTE: Currently can't test this because a real swapchain is needed (as
1796 // opposed to the fake one we created) in order for the layer to lookup the
1797 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001798
1799 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001801 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1802 m_errorMonitor->VerifyFound();
1803}
Chris Forbes09368e42016-10-13 11:59:22 +13001804#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001805
Karl Schultz6addd812016-02-02 17:17:23 -07001806TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1807 VkResult err;
1808 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001809
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1811 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001812
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001813 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001814
1815 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001816 VkImage image;
1817 VkDeviceMemory mem;
1818 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001819
Karl Schultz6addd812016-02-02 17:17:23 -07001820 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1821 const int32_t tex_width = 32;
1822 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001823
Tony Barboureb254902015-07-15 12:50:33 -06001824 VkImageCreateInfo image_create_info = {};
1825 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001826 image_create_info.pNext = NULL;
1827 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1828 image_create_info.format = tex_format;
1829 image_create_info.extent.width = tex_width;
1830 image_create_info.extent.height = tex_height;
1831 image_create_info.extent.depth = 1;
1832 image_create_info.mipLevels = 1;
1833 image_create_info.arrayLayers = 1;
1834 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1835 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1836 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1837 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001838 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001839
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001840 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001841 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001842 mem_alloc.pNext = NULL;
1843 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001844
Chia-I Wuf7458c52015-10-26 21:10:41 +08001845 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001846 ASSERT_VK_SUCCESS(err);
1847
Karl Schultz6addd812016-02-02 17:17:23 -07001848 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001849
Mark Lobodzinski23065352015-05-29 09:32:35 -05001850 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001851
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001852 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07001853 if (!pass) { // If we can't find any unmappable memory this test doesn't
1854 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001855 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001856 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001857 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001858
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001859 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001860 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001861 ASSERT_VK_SUCCESS(err);
1862
1863 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001864 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001865 ASSERT_VK_SUCCESS(err);
1866
1867 // Map memory as if to initialize the image
1868 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001870
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001871 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001872
Chia-I Wuf7458c52015-10-26 21:10:41 +08001873 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001874 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001875}
1876
Karl Schultz6addd812016-02-02 17:17:23 -07001877TEST_F(VkLayerTest, RebindMemory) {
1878 VkResult err;
1879 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001880
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001882
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001883 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001884
1885 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001886 VkImage image;
1887 VkDeviceMemory mem1;
1888 VkDeviceMemory mem2;
1889 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001890
Karl Schultz6addd812016-02-02 17:17:23 -07001891 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1892 const int32_t tex_width = 32;
1893 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001894
Tony Barboureb254902015-07-15 12:50:33 -06001895 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001896 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1897 image_create_info.pNext = NULL;
1898 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1899 image_create_info.format = tex_format;
1900 image_create_info.extent.width = tex_width;
1901 image_create_info.extent.height = tex_height;
1902 image_create_info.extent.depth = 1;
1903 image_create_info.mipLevels = 1;
1904 image_create_info.arrayLayers = 1;
1905 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1906 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1907 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1908 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001909
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001910 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001911 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1912 mem_alloc.pNext = NULL;
1913 mem_alloc.allocationSize = 0;
1914 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001915
Karl Schultz6addd812016-02-02 17:17:23 -07001916 // Introduce failure, do NOT set memProps to
1917 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001918 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001919 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001920 ASSERT_VK_SUCCESS(err);
1921
Karl Schultz6addd812016-02-02 17:17:23 -07001922 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001923
1924 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001925 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001926 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001927
1928 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001929 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001930 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001931 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001932 ASSERT_VK_SUCCESS(err);
1933
1934 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001935 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001936 ASSERT_VK_SUCCESS(err);
1937
Karl Schultz6addd812016-02-02 17:17:23 -07001938 // Introduce validation failure, try to bind a different memory object to
1939 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001940 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001941
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001942 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001943
Chia-I Wuf7458c52015-10-26 21:10:41 +08001944 vkDestroyImage(m_device->device(), image, NULL);
1945 vkFreeMemory(m_device->device(), mem1, NULL);
1946 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001947}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001948
Karl Schultz6addd812016-02-02 17:17:23 -07001949TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001950 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1953 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001954
1955 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001956 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1957 fenceInfo.pNext = NULL;
1958 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001959
Tony Barbour300a6082015-04-07 13:44:53 -06001960 ASSERT_NO_FATAL_FAILURE(InitState());
1961 ASSERT_NO_FATAL_FAILURE(InitViewport());
1962 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1963
Tony Barbourfe3351b2015-07-28 10:17:20 -06001964 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001965 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001966 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001967
1968 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001969
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001970 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001971 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1972 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001973 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001974 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001975 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001976 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001977 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001978 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001979 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001980
1981 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001982 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001983
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001984 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001985}
Chris Forbes4e44c912016-06-16 10:20:00 +12001986
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001987TEST_F(VkLayerTest, InvalidUsageBits) {
1988 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1989 "Initialize buffer with wrong usage then perform copy expecting errors "
1990 "from both the image and the buffer (2 calls)");
1991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001992
1993 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001994
1995 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1996
Tony Barbourf92621a2016-05-02 14:28:12 -06001997 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001998 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001999 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002000 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002001
Tony Barbourf92621a2016-05-02 14:28:12 -06002002 VkImageView dsv;
2003 VkImageViewCreateInfo dsvci = {};
2004 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2005 dsvci.image = image.handle();
2006 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002007 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002008 dsvci.subresourceRange.layerCount = 1;
2009 dsvci.subresourceRange.baseMipLevel = 0;
2010 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002011 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002012
Tony Barbourf92621a2016-05-02 14:28:12 -06002013 // Create a view with depth / stencil aspect for image with different usage
2014 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002015
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002016 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002017
2018 // Initialize buffer with TRANSFER_DST usage
2019 vk_testing::Buffer buffer;
2020 VkMemoryPropertyFlags reqs = 0;
2021 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2022 VkBufferImageCopy region = {};
2023 region.bufferRowLength = 128;
2024 region.bufferImageHeight = 128;
2025 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2026 region.imageSubresource.layerCount = 1;
2027 region.imageExtent.height = 16;
2028 region.imageExtent.width = 16;
2029 region.imageExtent.depth = 1;
2030
Tony Barbourf92621a2016-05-02 14:28:12 -06002031 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2032 // TRANSFER_DST
2033 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002034
Chris Forbesda581202016-10-06 18:25:26 +13002035 // two separate errors from this call:
2036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2038
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002039 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2040 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002041 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002042}
Tony Barbour75d79f02016-08-30 09:39:07 -06002043
Tony Barbour75d79f02016-08-30 09:39:07 -06002044
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002045#endif // MEM_TRACKER_TESTS
2046
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002047#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002048
2049TEST_F(VkLayerTest, LeakAnObject) {
2050 VkResult err;
2051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002052 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002053
2054 // Note that we have to create a new device since destroying the
2055 // framework's device causes Teardown() to fail and just calling Teardown
2056 // will destroy the errorMonitor.
2057
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002059
2060 ASSERT_NO_FATAL_FAILURE(InitState());
2061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002062 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002063 std::vector<VkDeviceQueueCreateInfo> queue_info;
2064 queue_info.reserve(queue_props.size());
2065 std::vector<std::vector<float>> queue_priorities;
2066 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2067 VkDeviceQueueCreateInfo qi = {};
2068 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2069 qi.pNext = NULL;
2070 qi.queueFamilyIndex = i;
2071 qi.queueCount = queue_props[i].queueCount;
2072 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2073 qi.pQueuePriorities = queue_priorities[i].data();
2074 queue_info.push_back(qi);
2075 }
2076
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002077 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002078
2079 // The sacrificial device object
2080 VkDevice testDevice;
2081 VkDeviceCreateInfo device_create_info = {};
2082 auto features = m_device->phy().features();
2083 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2084 device_create_info.pNext = NULL;
2085 device_create_info.queueCreateInfoCount = queue_info.size();
2086 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002087 device_create_info.enabledLayerCount = 0;
2088 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002089 device_create_info.pEnabledFeatures = &features;
2090 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2091 ASSERT_VK_SUCCESS(err);
2092
2093 VkFence fence;
2094 VkFenceCreateInfo fence_create_info = {};
2095 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2096 fence_create_info.pNext = NULL;
2097 fence_create_info.flags = 0;
2098 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2099 ASSERT_VK_SUCCESS(err);
2100
2101 // Induce failure by not calling vkDestroyFence
2102 vkDestroyDevice(testDevice, NULL);
2103 m_errorMonitor->VerifyFound();
2104}
2105
2106TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2107
2108 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2109 "attempt to delete them from another.");
2110
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002112
Cody Northropc31a84f2016-08-22 10:41:47 -06002113 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002114 VkCommandPool command_pool_one;
2115 VkCommandPool command_pool_two;
2116
2117 VkCommandPoolCreateInfo pool_create_info{};
2118 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2119 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2120 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2121
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002122 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002124 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002125
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002126 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002127 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002128 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002129 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002130 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002131 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002132 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002133
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002134 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002135
2136 m_errorMonitor->VerifyFound();
2137
2138 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2139 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2140}
2141
2142TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2143 VkResult err;
2144
2145 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002146 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002149
2150 ASSERT_NO_FATAL_FAILURE(InitState());
2151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2152
2153 VkDescriptorPoolSize ds_type_count = {};
2154 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2155 ds_type_count.descriptorCount = 1;
2156
2157 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2158 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2159 ds_pool_ci.pNext = NULL;
2160 ds_pool_ci.flags = 0;
2161 ds_pool_ci.maxSets = 1;
2162 ds_pool_ci.poolSizeCount = 1;
2163 ds_pool_ci.pPoolSizes = &ds_type_count;
2164
2165 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002166 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002167 ASSERT_VK_SUCCESS(err);
2168
2169 // Create a second descriptor pool
2170 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002171 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002172 ASSERT_VK_SUCCESS(err);
2173
2174 VkDescriptorSetLayoutBinding dsl_binding = {};
2175 dsl_binding.binding = 0;
2176 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2177 dsl_binding.descriptorCount = 1;
2178 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2179 dsl_binding.pImmutableSamplers = NULL;
2180
2181 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2182 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2183 ds_layout_ci.pNext = NULL;
2184 ds_layout_ci.bindingCount = 1;
2185 ds_layout_ci.pBindings = &dsl_binding;
2186
2187 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002188 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002189 ASSERT_VK_SUCCESS(err);
2190
2191 VkDescriptorSet descriptorSet;
2192 VkDescriptorSetAllocateInfo alloc_info = {};
2193 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2194 alloc_info.descriptorSetCount = 1;
2195 alloc_info.descriptorPool = ds_pool_one;
2196 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002198 ASSERT_VK_SUCCESS(err);
2199
2200 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2201
2202 m_errorMonitor->VerifyFound();
2203
2204 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2205 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2206 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2207}
2208
2209TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002211
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002212 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002213
2214 ASSERT_NO_FATAL_FAILURE(InitState());
2215
2216 // Pass bogus handle into GetImageMemoryRequirements
2217 VkMemoryRequirements mem_reqs;
2218 uint64_t fakeImageHandle = 0xCADECADE;
2219 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2220
2221 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2222
2223 m_errorMonitor->VerifyFound();
2224}
2225
Karl Schultz6addd812016-02-02 17:17:23 -07002226TEST_F(VkLayerTest, PipelineNotBound) {
2227 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002228
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002229 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002230
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002232
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002233 ASSERT_NO_FATAL_FAILURE(InitState());
2234 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002235
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002236 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002237 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2238 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002239
2240 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002241 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2242 ds_pool_ci.pNext = NULL;
2243 ds_pool_ci.maxSets = 1;
2244 ds_pool_ci.poolSizeCount = 1;
2245 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002246
2247 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002248 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002249 ASSERT_VK_SUCCESS(err);
2250
2251 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002252 dsl_binding.binding = 0;
2253 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2254 dsl_binding.descriptorCount = 1;
2255 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2256 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002257
2258 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002259 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2260 ds_layout_ci.pNext = NULL;
2261 ds_layout_ci.bindingCount = 1;
2262 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002263
2264 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002265 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002266 ASSERT_VK_SUCCESS(err);
2267
2268 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002269 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002270 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002271 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002272 alloc_info.descriptorPool = ds_pool;
2273 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002274 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002275 ASSERT_VK_SUCCESS(err);
2276
2277 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002278 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2279 pipeline_layout_ci.pNext = NULL;
2280 pipeline_layout_ci.setLayoutCount = 1;
2281 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002282
2283 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002284 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002285 ASSERT_VK_SUCCESS(err);
2286
Mark Youngad779052016-01-06 14:26:04 -07002287 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002288
2289 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002290 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002291
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002292 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002293
Chia-I Wuf7458c52015-10-26 21:10:41 +08002294 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2295 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2296 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002297}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002298
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002299TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2300 VkResult err;
2301
2302 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2303 "during bind[Buffer|Image]Memory time");
2304
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002305 ASSERT_NO_FATAL_FAILURE(InitState());
2306
2307 // Create an image, allocate memory, set a bad typeIndex and then try to
2308 // bind it
2309 VkImage image;
2310 VkDeviceMemory mem;
2311 VkMemoryRequirements mem_reqs;
2312 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2313 const int32_t tex_width = 32;
2314 const int32_t tex_height = 32;
2315
2316 VkImageCreateInfo image_create_info = {};
2317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2318 image_create_info.pNext = NULL;
2319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2320 image_create_info.format = tex_format;
2321 image_create_info.extent.width = tex_width;
2322 image_create_info.extent.height = tex_height;
2323 image_create_info.extent.depth = 1;
2324 image_create_info.mipLevels = 1;
2325 image_create_info.arrayLayers = 1;
2326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2327 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2328 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2329 image_create_info.flags = 0;
2330
2331 VkMemoryAllocateInfo mem_alloc = {};
2332 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2333 mem_alloc.pNext = NULL;
2334 mem_alloc.allocationSize = 0;
2335 mem_alloc.memoryTypeIndex = 0;
2336
2337 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2338 ASSERT_VK_SUCCESS(err);
2339
2340 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2341 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002342
2343 // Introduce Failure, select invalid TypeIndex
2344 VkPhysicalDeviceMemoryProperties memory_info;
2345
2346 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2347 unsigned int i;
2348 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2349 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2350 mem_alloc.memoryTypeIndex = i;
2351 break;
2352 }
2353 }
2354 if (i >= memory_info.memoryTypeCount) {
2355 printf("No invalid memory type index could be found; skipped.\n");
2356 vkDestroyImage(m_device->device(), image, NULL);
2357 return;
2358 }
2359
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002361
2362 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2363 ASSERT_VK_SUCCESS(err);
2364
2365 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2366 (void)err;
2367
2368 m_errorMonitor->VerifyFound();
2369
2370 vkDestroyImage(m_device->device(), image, NULL);
2371 vkFreeMemory(m_device->device(), mem, NULL);
2372}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002373
Karl Schultz6addd812016-02-02 17:17:23 -07002374TEST_F(VkLayerTest, BindInvalidMemory) {
2375 VkResult err;
2376 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002377
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002379
Tobin Ehlisec598302015-09-15 15:02:17 -06002380 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002381
2382 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002383 VkImage image;
2384 VkDeviceMemory mem;
2385 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002386
Karl Schultz6addd812016-02-02 17:17:23 -07002387 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2388 const int32_t tex_width = 32;
2389 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002390
2391 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002392 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2393 image_create_info.pNext = NULL;
2394 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2395 image_create_info.format = tex_format;
2396 image_create_info.extent.width = tex_width;
2397 image_create_info.extent.height = tex_height;
2398 image_create_info.extent.depth = 1;
2399 image_create_info.mipLevels = 1;
2400 image_create_info.arrayLayers = 1;
2401 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2402 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2403 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2404 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002405
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002406 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002407 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2408 mem_alloc.pNext = NULL;
2409 mem_alloc.allocationSize = 0;
2410 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002411
Chia-I Wuf7458c52015-10-26 21:10:41 +08002412 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002413 ASSERT_VK_SUCCESS(err);
2414
Karl Schultz6addd812016-02-02 17:17:23 -07002415 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002416
2417 mem_alloc.allocationSize = mem_reqs.size;
2418
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002419 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002420 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002421
2422 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002423 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002424 ASSERT_VK_SUCCESS(err);
2425
2426 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002427 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002428
2429 // Try to bind free memory that has been freed
2430 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2431 // This may very well return an error.
2432 (void)err;
2433
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002434 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002435
Chia-I Wuf7458c52015-10-26 21:10:41 +08002436 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002437}
2438
Karl Schultz6addd812016-02-02 17:17:23 -07002439TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2440 VkResult err;
2441 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002442
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002444
Tobin Ehlisec598302015-09-15 15:02:17 -06002445 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002446
Karl Schultz6addd812016-02-02 17:17:23 -07002447 // Create an image object, allocate memory, destroy the object and then try
2448 // to bind it
2449 VkImage image;
2450 VkDeviceMemory mem;
2451 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002452
Karl Schultz6addd812016-02-02 17:17:23 -07002453 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2454 const int32_t tex_width = 32;
2455 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002456
2457 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002458 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2459 image_create_info.pNext = NULL;
2460 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2461 image_create_info.format = tex_format;
2462 image_create_info.extent.width = tex_width;
2463 image_create_info.extent.height = tex_height;
2464 image_create_info.extent.depth = 1;
2465 image_create_info.mipLevels = 1;
2466 image_create_info.arrayLayers = 1;
2467 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2468 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2469 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2470 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002471
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002472 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002473 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2474 mem_alloc.pNext = NULL;
2475 mem_alloc.allocationSize = 0;
2476 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002477
Chia-I Wuf7458c52015-10-26 21:10:41 +08002478 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002479 ASSERT_VK_SUCCESS(err);
2480
Karl Schultz6addd812016-02-02 17:17:23 -07002481 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002482
2483 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002484 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002485 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002486
2487 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002488 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002489 ASSERT_VK_SUCCESS(err);
2490
2491 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002492 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002493 ASSERT_VK_SUCCESS(err);
2494
2495 // Now Try to bind memory to this destroyed object
2496 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2497 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002498 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002499
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002500 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002501
Chia-I Wuf7458c52015-10-26 21:10:41 +08002502 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002503}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002504
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002505#endif // OBJ_TRACKER_TESTS
2506
Tobin Ehlis0788f522015-05-26 16:11:58 -06002507#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002508
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002509TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2510 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2511
2512 ASSERT_NO_FATAL_FAILURE(InitState());
2513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2514
2515 VkVertexInputBindingDescription input_binding;
2516 memset(&input_binding, 0, sizeof(input_binding));
2517
2518 VkVertexInputAttributeDescription input_attribs;
2519 memset(&input_attribs, 0, sizeof(input_attribs));
2520
2521 // Pick a really bad format for this purpose and make sure it should fail
2522 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2523 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2524 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2525 printf("Format unsuitable for test; skipped.\n");
2526 return;
2527 }
2528
2529 input_attribs.location = 0;
2530 char const *vsSource = "#version 450\n"
2531 "\n"
2532 "out gl_PerVertex {\n"
2533 " vec4 gl_Position;\n"
2534 "};\n"
2535 "void main(){\n"
2536 " gl_Position = vec4(1);\n"
2537 "}\n";
2538 char const *fsSource = "#version 450\n"
2539 "\n"
2540 "layout(location=0) out vec4 color;\n"
2541 "void main(){\n"
2542 " color = vec4(1);\n"
2543 "}\n";
2544
2545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2546 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2547 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2548
2549 VkPipelineObj pipe(m_device);
2550 pipe.AddColorAttachment();
2551 pipe.AddShader(&vs);
2552 pipe.AddShader(&fs);
2553
2554 pipe.AddVertexInputBindings(&input_binding, 1);
2555 pipe.AddVertexInputAttribs(&input_attribs, 1);
2556
2557 VkDescriptorSetObj descriptorSet(m_device);
2558 descriptorSet.AppendDummy();
2559 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2560
2561 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2562
2563 m_errorMonitor->VerifyFound();
2564}
2565
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002566TEST_F(VkLayerTest, ImageSampleCounts) {
2567
2568 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2569 "validation errors.");
2570 ASSERT_NO_FATAL_FAILURE(InitState());
2571
2572 VkMemoryPropertyFlags reqs = 0;
2573 VkImageCreateInfo image_create_info = {};
2574 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2575 image_create_info.pNext = NULL;
2576 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2577 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2578 image_create_info.extent.width = 256;
2579 image_create_info.extent.height = 256;
2580 image_create_info.extent.depth = 1;
2581 image_create_info.mipLevels = 1;
2582 image_create_info.arrayLayers = 1;
2583 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2584 image_create_info.flags = 0;
2585
2586 VkImageBlit blit_region = {};
2587 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2588 blit_region.srcSubresource.baseArrayLayer = 0;
2589 blit_region.srcSubresource.layerCount = 1;
2590 blit_region.srcSubresource.mipLevel = 0;
2591 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2592 blit_region.dstSubresource.baseArrayLayer = 0;
2593 blit_region.dstSubresource.layerCount = 1;
2594 blit_region.dstSubresource.mipLevel = 0;
2595
2596 // Create two images, the source with sampleCount = 2, and attempt to blit
2597 // between them
2598 {
2599 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002603 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002604 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002605 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002606 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002607 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2609 "of VK_SAMPLE_COUNT_2_BIT but "
2610 "must be VK_SAMPLE_COUNT_1_BIT");
2611 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2612 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002613 m_errorMonitor->VerifyFound();
2614 m_commandBuffer->EndCommandBuffer();
2615 }
2616
2617 // Create two images, the dest with sampleCount = 4, and attempt to blit
2618 // between them
2619 {
2620 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002622 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002623 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002624 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002625 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002626 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002627 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002628 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2630 "of VK_SAMPLE_COUNT_4_BIT but "
2631 "must be VK_SAMPLE_COUNT_1_BIT");
2632 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2633 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002634 m_errorMonitor->VerifyFound();
2635 m_commandBuffer->EndCommandBuffer();
2636 }
2637
2638 VkBufferImageCopy copy_region = {};
2639 copy_region.bufferRowLength = 128;
2640 copy_region.bufferImageHeight = 128;
2641 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2642 copy_region.imageSubresource.layerCount = 1;
2643 copy_region.imageExtent.height = 64;
2644 copy_region.imageExtent.width = 64;
2645 copy_region.imageExtent.depth = 1;
2646
2647 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2648 // buffer to image
2649 {
2650 vk_testing::Buffer src_buffer;
2651 VkMemoryPropertyFlags reqs = 0;
2652 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2653 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002654 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002655 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002656 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002657 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2659 "of VK_SAMPLE_COUNT_8_BIT but "
2660 "must be VK_SAMPLE_COUNT_1_BIT");
2661 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2662 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002663 m_errorMonitor->VerifyFound();
2664 m_commandBuffer->EndCommandBuffer();
2665 }
2666
2667 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2668 // image to buffer
2669 {
2670 vk_testing::Buffer dst_buffer;
2671 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2672 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002673 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002674 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002675 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002676 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2678 "of VK_SAMPLE_COUNT_2_BIT but "
2679 "must be VK_SAMPLE_COUNT_1_BIT");
2680 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002681 dst_buffer.handle(), 1, &copy_region);
2682 m_errorMonitor->VerifyFound();
2683 m_commandBuffer->EndCommandBuffer();
2684 }
2685}
2686
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002687TEST_F(VkLayerTest, BlitImageFormats) {
2688
2689 // Image blit with mismatched formats
2690 const char * expected_message =
2691 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2692 " the other one must also have signed/unsigned integer format";
2693
2694 ASSERT_NO_FATAL_FAILURE(InitState());
2695
2696 VkImageObj src_image(m_device);
2697 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2698 VkImageObj dst_image(m_device);
2699 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2700 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002701 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002702
2703 VkImageBlit blitRegion = {};
2704 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2705 blitRegion.srcSubresource.baseArrayLayer = 0;
2706 blitRegion.srcSubresource.layerCount = 1;
2707 blitRegion.srcSubresource.mipLevel = 0;
2708 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2709 blitRegion.dstSubresource.baseArrayLayer = 0;
2710 blitRegion.dstSubresource.layerCount = 1;
2711 blitRegion.dstSubresource.mipLevel = 0;
2712
2713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2714
2715 // Unsigned int vs not an int
2716 BeginCommandBuffer();
2717 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2718 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2719
2720 m_errorMonitor->VerifyFound();
2721
2722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2723
2724 // Unsigned int vs signed int
2725 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2726 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2727
2728 m_errorMonitor->VerifyFound();
2729
2730 EndCommandBuffer();
2731}
2732
2733
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002734TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2735 VkResult err;
2736 bool pass;
2737
2738 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2739 ASSERT_NO_FATAL_FAILURE(InitState());
2740
2741 // If w/d/h granularity is 1, test is not meaningful
2742 // TODO: When virtual device limits are available, create a set of limits for this test that
2743 // will always have a granularity of > 1 for w, h, and d
2744 auto index = m_device->graphics_queue_node_index_;
2745 auto queue_family_properties = m_device->phy().queue_properties();
2746
2747 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2748 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2749 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2750 return;
2751 }
2752
2753 // Create two images of different types and try to copy between them
2754 VkImage srcImage;
2755 VkImage dstImage;
2756 VkDeviceMemory srcMem;
2757 VkDeviceMemory destMem;
2758 VkMemoryRequirements memReqs;
2759
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002760 VkImageCreateInfo image_create_info = {};
2761 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2762 image_create_info.pNext = NULL;
2763 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2764 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2765 image_create_info.extent.width = 32;
2766 image_create_info.extent.height = 32;
2767 image_create_info.extent.depth = 1;
2768 image_create_info.mipLevels = 1;
2769 image_create_info.arrayLayers = 4;
2770 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2771 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2772 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2773 image_create_info.flags = 0;
2774
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002775 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002776 ASSERT_VK_SUCCESS(err);
2777
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002778 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002779 ASSERT_VK_SUCCESS(err);
2780
2781 // Allocate memory
2782 VkMemoryAllocateInfo memAlloc = {};
2783 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2784 memAlloc.pNext = NULL;
2785 memAlloc.allocationSize = 0;
2786 memAlloc.memoryTypeIndex = 0;
2787
2788 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2789 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002790 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002791 ASSERT_TRUE(pass);
2792 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2793 ASSERT_VK_SUCCESS(err);
2794
2795 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2796 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002797 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002798 ASSERT_VK_SUCCESS(err);
2799 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2800 ASSERT_VK_SUCCESS(err);
2801
2802 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2803 ASSERT_VK_SUCCESS(err);
2804 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2805 ASSERT_VK_SUCCESS(err);
2806
2807 BeginCommandBuffer();
2808 VkImageCopy copyRegion;
2809 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2810 copyRegion.srcSubresource.mipLevel = 0;
2811 copyRegion.srcSubresource.baseArrayLayer = 0;
2812 copyRegion.srcSubresource.layerCount = 1;
2813 copyRegion.srcOffset.x = 0;
2814 copyRegion.srcOffset.y = 0;
2815 copyRegion.srcOffset.z = 0;
2816 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2817 copyRegion.dstSubresource.mipLevel = 0;
2818 copyRegion.dstSubresource.baseArrayLayer = 0;
2819 copyRegion.dstSubresource.layerCount = 1;
2820 copyRegion.dstOffset.x = 0;
2821 copyRegion.dstOffset.y = 0;
2822 copyRegion.dstOffset.z = 0;
2823 copyRegion.extent.width = 1;
2824 copyRegion.extent.height = 1;
2825 copyRegion.extent.depth = 1;
2826
2827 // Introduce failure by setting srcOffset to a bad granularity value
2828 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2830 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002831 m_errorMonitor->VerifyFound();
2832
2833 // Introduce failure by setting extent to a bad granularity value
2834 copyRegion.srcOffset.y = 0;
2835 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2837 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002838 m_errorMonitor->VerifyFound();
2839
2840 // Now do some buffer/image copies
2841 vk_testing::Buffer buffer;
2842 VkMemoryPropertyFlags reqs = 0;
2843 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2844 VkBufferImageCopy region = {};
2845 region.bufferOffset = 0;
2846 region.bufferRowLength = 3;
2847 region.bufferImageHeight = 128;
2848 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2849 region.imageSubresource.layerCount = 1;
2850 region.imageExtent.height = 16;
2851 region.imageExtent.width = 16;
2852 region.imageExtent.depth = 1;
2853 region.imageOffset.x = 0;
2854 region.imageOffset.y = 0;
2855 region.imageOffset.z = 0;
2856
2857 // Introduce failure by setting bufferRowLength to a bad granularity value
2858 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2860 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2861 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002862 m_errorMonitor->VerifyFound();
2863 region.bufferRowLength = 128;
2864
2865 // Introduce failure by setting bufferOffset to a bad granularity value
2866 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2868 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2869 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002870 m_errorMonitor->VerifyFound();
2871 region.bufferOffset = 0;
2872
2873 // Introduce failure by setting bufferImageHeight to a bad granularity value
2874 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2876 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2877 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002878 m_errorMonitor->VerifyFound();
2879 region.bufferImageHeight = 128;
2880
2881 // Introduce failure by setting imageExtent to a bad granularity value
2882 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2884 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2885 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002886 m_errorMonitor->VerifyFound();
2887 region.imageExtent.width = 16;
2888
2889 // Introduce failure by setting imageOffset to a bad granularity value
2890 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2892 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2893 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002894 m_errorMonitor->VerifyFound();
2895
2896 EndCommandBuffer();
2897
2898 vkDestroyImage(m_device->device(), srcImage, NULL);
2899 vkDestroyImage(m_device->device(), dstImage, NULL);
2900 vkFreeMemory(m_device->device(), srcMem, NULL);
2901 vkFreeMemory(m_device->device(), destMem, NULL);
2902}
2903
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002904TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002905 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2906 "attempt to submit them on a queue created in a different "
2907 "queue family.");
2908
Cody Northropc31a84f2016-08-22 10:41:47 -06002909 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002910 // This test is meaningless unless we have multiple queue families
2911 auto queue_family_properties = m_device->phy().queue_properties();
2912 if (queue_family_properties.size() < 2) {
2913 return;
2914 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002916 // Get safe index of another queue family
2917 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2918 ASSERT_NO_FATAL_FAILURE(InitState());
2919 // Create a second queue using a different queue family
2920 VkQueue other_queue;
2921 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2922
2923 // Record an empty cmd buffer
2924 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2925 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2926 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2927 vkEndCommandBuffer(m_commandBuffer->handle());
2928
2929 // And submit on the wrong queue
2930 VkSubmitInfo submit_info = {};
2931 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2932 submit_info.commandBufferCount = 1;
2933 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002934 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002935
2936 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002937}
2938
Chris Forbes4c24a922016-11-16 08:59:10 +13002939TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2940 ASSERT_NO_FATAL_FAILURE(InitState());
2941
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002942 // There are no attachments, but refer to attachment 0.
2943 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002944 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002945 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2946 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002947 };
2948
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002949 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2950 nullptr,
2951 0,
2952 0,
2953 nullptr,
2954 1,
2955 subpasses,
2956 0,
2957 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002958 VkRenderPass rp;
2959
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002960 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002962 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002963 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2964 m_errorMonitor->VerifyFound();
2965}
2966
Chris Forbesa58c4522016-09-28 15:19:39 +13002967TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2968 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2969 ASSERT_NO_FATAL_FAILURE(InitState());
2970
2971 // A renderpass with two subpasses, both writing the same attachment.
2972 VkAttachmentDescription attach[] = {
2973 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2974 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2975 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2976 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2977 },
2978 };
2979 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2980 VkSubpassDescription subpasses[] = {
2981 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2982 1, &ref, nullptr, nullptr, 0, nullptr },
2983 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2984 1, &ref, nullptr, nullptr, 0, nullptr },
2985 };
2986 VkSubpassDependency dep = {
2987 0, 1,
2988 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2989 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2990 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2991 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2992 VK_DEPENDENCY_BY_REGION_BIT
2993 };
2994 VkRenderPassCreateInfo rpci = {
2995 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2996 0, 1, attach, 2, subpasses, 1, &dep
2997 };
2998 VkRenderPass rp;
2999 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3000 ASSERT_VK_SUCCESS(err);
3001
3002 VkImageObj image(m_device);
3003 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
3004 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
3005 VK_IMAGE_TILING_OPTIMAL, 0);
3006 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3007
3008 VkFramebufferCreateInfo fbci = {
3009 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
3010 0, rp, 1, &imageView, 32, 32, 1
3011 };
3012 VkFramebuffer fb;
3013 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3014 ASSERT_VK_SUCCESS(err);
3015
3016 char const *vsSource =
3017 "#version 450\n"
3018 "void main() { gl_Position = vec4(1); }\n";
3019 char const *fsSource =
3020 "#version 450\n"
3021 "layout(location=0) out vec4 color;\n"
3022 "void main() { color = vec4(1); }\n";
3023
3024 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3025 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3026 VkPipelineObj pipe(m_device);
3027 pipe.AddColorAttachment();
3028 pipe.AddShader(&vs);
3029 pipe.AddShader(&fs);
3030 VkViewport view_port = {};
3031 m_viewports.push_back(view_port);
3032 pipe.SetViewport(m_viewports);
3033 VkRect2D rect = {};
3034 m_scissors.push_back(rect);
3035 pipe.SetScissor(m_scissors);
3036
3037 VkPipelineLayoutCreateInfo plci = {
3038 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
3039 0, 0, nullptr, 0, nullptr
3040 };
3041 VkPipelineLayout pl;
3042 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3043 ASSERT_VK_SUCCESS(err);
3044 pipe.CreateVKPipeline(pl, rp);
3045
3046 BeginCommandBuffer();
3047
3048 VkRenderPassBeginInfo rpbi = {
3049 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
3050 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
3051 };
3052
3053 // subtest 1: bind in the wrong subpass
3054 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3055 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3057 "built for subpass 0 but used in subpass 1");
3058 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3059 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3060 m_errorMonitor->VerifyFound();
3061
3062 vkCmdEndRenderPass(m_commandBuffer->handle());
3063
3064 // subtest 2: bind in correct subpass, then transition to next subpass
3065 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3066 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3067 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3069 "built for subpass 0 but used in subpass 1");
3070 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3071 m_errorMonitor->VerifyFound();
3072
3073 vkCmdEndRenderPass(m_commandBuffer->handle());
3074
3075 EndCommandBuffer();
3076
3077 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3078 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3079 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3080}
3081
Tony Barbour4e919972016-08-09 13:27:40 -06003082TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3083 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3084 "with extent outside of framebuffer");
3085 ASSERT_NO_FATAL_FAILURE(InitState());
3086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3087
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3089 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003090
3091 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3092 m_renderPassBeginInfo.renderArea.extent.width = 257;
3093 m_renderPassBeginInfo.renderArea.extent.height = 257;
3094 BeginCommandBuffer();
3095 m_errorMonitor->VerifyFound();
3096}
3097
3098TEST_F(VkLayerTest, DisabledIndependentBlend) {
3099 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3100 "blend and then specifying different blend states for two "
3101 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003102 VkPhysicalDeviceFeatures features = {};
3103 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003104 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003105
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3107 "Invalid Pipeline CreateInfo: If independent blend feature not "
3108 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003109
Cody Northropc31a84f2016-08-22 10:41:47 -06003110 VkDescriptorSetObj descriptorSet(m_device);
3111 descriptorSet.AppendDummy();
3112 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003113
Cody Northropc31a84f2016-08-22 10:41:47 -06003114 VkPipelineObj pipeline(m_device);
3115 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003116 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003117 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003118
Cody Northropc31a84f2016-08-22 10:41:47 -06003119 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3120 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3121 att_state1.blendEnable = VK_TRUE;
3122 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3123 att_state2.blendEnable = VK_FALSE;
3124 pipeline.AddColorAttachment(0, &att_state1);
3125 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003126 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003127 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003128}
3129
Chris Forbes26ec2122016-11-29 08:58:33 +13003130#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003131TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3132 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3133 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003134 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003135
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3137 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003138
3139 // Create a renderPass with a single color attachment
3140 VkAttachmentReference attach = {};
3141 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3142 VkSubpassDescription subpass = {};
3143 VkRenderPassCreateInfo rpci = {};
3144 rpci.subpassCount = 1;
3145 rpci.pSubpasses = &subpass;
3146 rpci.attachmentCount = 1;
3147 VkAttachmentDescription attach_desc = {};
3148 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3149 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3150 rpci.pAttachments = &attach_desc;
3151 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3152 VkRenderPass rp;
3153 subpass.pDepthStencilAttachment = &attach;
3154 subpass.pColorAttachments = NULL;
3155 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3156 m_errorMonitor->VerifyFound();
3157}
Chris Forbes26ec2122016-11-29 08:58:33 +13003158#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003159
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003160TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3161 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3162 "attachment reference of VK_ATTACHMENT_UNUSED");
3163
3164 ASSERT_NO_FATAL_FAILURE(InitState());
3165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3166
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003168
3169 VkAttachmentReference color_attach = {};
3170 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3171 color_attach.attachment = 0;
3172 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3173 VkSubpassDescription subpass = {};
3174 subpass.colorAttachmentCount = 1;
3175 subpass.pColorAttachments = &color_attach;
3176 subpass.preserveAttachmentCount = 1;
3177 subpass.pPreserveAttachments = &preserve_attachment;
3178
3179 VkRenderPassCreateInfo rpci = {};
3180 rpci.subpassCount = 1;
3181 rpci.pSubpasses = &subpass;
3182 rpci.attachmentCount = 1;
3183 VkAttachmentDescription attach_desc = {};
3184 attach_desc.format = VK_FORMAT_UNDEFINED;
3185 rpci.pAttachments = &attach_desc;
3186 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3187 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003188 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003189
3190 m_errorMonitor->VerifyFound();
3191
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003192 if (result == VK_SUCCESS) {
3193 vkDestroyRenderPass(m_device->device(), rp, NULL);
3194 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003195}
3196
Chris Forbesc5389742016-06-29 11:49:23 +12003197TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003198 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3199 "when the source of a subpass multisample resolve "
3200 "does not have multiple samples.");
3201
Chris Forbesc5389742016-06-29 11:49:23 +12003202 ASSERT_NO_FATAL_FAILURE(InitState());
3203
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3205 "Subpass 0 requests multisample resolve from attachment 0 which has "
3206 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003207
3208 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003209 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3210 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3211 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3212 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3213 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3214 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003215 };
3216
3217 VkAttachmentReference color = {
3218 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3219 };
3220
3221 VkAttachmentReference resolve = {
3222 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3223 };
3224
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003225 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003227 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003228
3229 VkRenderPass rp;
3230 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3231
3232 m_errorMonitor->VerifyFound();
3233
3234 if (err == VK_SUCCESS)
3235 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3236}
3237
3238TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003239 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3240 "when a subpass multisample resolve operation is "
3241 "requested, and the destination of that resolve has "
3242 "multiple samples.");
3243
Chris Forbesc5389742016-06-29 11:49:23 +12003244 ASSERT_NO_FATAL_FAILURE(InitState());
3245
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3247 "Subpass 0 requests multisample resolve into attachment 1, which "
3248 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003249
3250 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003251 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3252 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3253 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3254 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3255 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3256 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003257 };
3258
3259 VkAttachmentReference color = {
3260 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3261 };
3262
3263 VkAttachmentReference resolve = {
3264 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3265 };
3266
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003267 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003268
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003269 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003270
3271 VkRenderPass rp;
3272 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3273
3274 m_errorMonitor->VerifyFound();
3275
3276 if (err == VK_SUCCESS)
3277 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3278}
3279
Chris Forbes3f128ef2016-06-29 14:58:53 +12003280TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003281 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3282 "when the color and depth attachments used by a subpass "
3283 "have inconsistent sample counts");
3284
Chris Forbes3f128ef2016-06-29 14:58:53 +12003285 ASSERT_NO_FATAL_FAILURE(InitState());
3286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3288 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003289
3290 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003291 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3292 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3293 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3294 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3295 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3296 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003297 };
3298
3299 VkAttachmentReference color[] = {
3300 {
3301 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3302 },
3303 {
3304 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3305 },
3306 };
3307
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003308 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003309
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003310 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003311
3312 VkRenderPass rp;
3313 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3314
3315 m_errorMonitor->VerifyFound();
3316
3317 if (err == VK_SUCCESS)
3318 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3319}
3320
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003321TEST_F(VkLayerTest, FramebufferCreateErrors) {
3322 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003323 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003324 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003325 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3326 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3327 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3328 " 6. Framebuffer attachment where dimensions don't match\n"
3329 " 7. Framebuffer attachment w/o identity swizzle\n"
3330 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003331
3332 ASSERT_NO_FATAL_FAILURE(InitState());
3333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3334
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3336 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3337 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003338
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003339 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003340 VkAttachmentReference attach = {};
3341 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3342 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003343 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003344 VkRenderPassCreateInfo rpci = {};
3345 rpci.subpassCount = 1;
3346 rpci.pSubpasses = &subpass;
3347 rpci.attachmentCount = 1;
3348 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003349 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003350 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003351 rpci.pAttachments = &attach_desc;
3352 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3353 VkRenderPass rp;
3354 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3355 ASSERT_VK_SUCCESS(err);
3356
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003357 VkImageView ivs[2];
3358 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3359 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003360 VkFramebufferCreateInfo fb_info = {};
3361 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3362 fb_info.pNext = NULL;
3363 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003364 // Set mis-matching attachmentCount
3365 fb_info.attachmentCount = 2;
3366 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003367 fb_info.width = 100;
3368 fb_info.height = 100;
3369 fb_info.layers = 1;
3370
3371 VkFramebuffer fb;
3372 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3373
3374 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003375 if (err == VK_SUCCESS) {
3376 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3377 }
3378 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003379
3380 // Create a renderPass with a depth-stencil attachment created with
3381 // IMAGE_USAGE_COLOR_ATTACHMENT
3382 // Add our color attachment to pDepthStencilAttachment
3383 subpass.pDepthStencilAttachment = &attach;
3384 subpass.pColorAttachments = NULL;
3385 VkRenderPass rp_ds;
3386 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3387 ASSERT_VK_SUCCESS(err);
3388 // Set correct attachment count, but attachment has COLOR usage bit set
3389 fb_info.attachmentCount = 1;
3390 fb_info.renderPass = rp_ds;
3391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003393 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3394
3395 m_errorMonitor->VerifyFound();
3396 if (err == VK_SUCCESS) {
3397 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3398 }
3399 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003400
3401 // Create new renderpass with alternate attachment format from fb
3402 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3403 subpass.pDepthStencilAttachment = NULL;
3404 subpass.pColorAttachments = &attach;
3405 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3406 ASSERT_VK_SUCCESS(err);
3407
3408 // Cause error due to mis-matched formats between rp & fb
3409 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3410 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3412 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003413 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3414
3415 m_errorMonitor->VerifyFound();
3416 if (err == VK_SUCCESS) {
3417 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3418 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003419 vkDestroyRenderPass(m_device->device(), rp, NULL);
3420
3421 // Create new renderpass with alternate sample count from fb
3422 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3423 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3424 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3425 ASSERT_VK_SUCCESS(err);
3426
3427 // Cause error due to mis-matched sample count between rp & fb
3428 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3430 "that do not match the "
3431 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003432 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3433
3434 m_errorMonitor->VerifyFound();
3435 if (err == VK_SUCCESS) {
3436 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3437 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003438
3439 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003440
3441 // Create a custom imageView with non-1 mip levels
3442 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003443 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003444 ASSERT_TRUE(image.initialized());
3445
3446 VkImageView view;
3447 VkImageViewCreateInfo ivci = {};
3448 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3449 ivci.image = image.handle();
3450 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3451 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3452 ivci.subresourceRange.layerCount = 1;
3453 ivci.subresourceRange.baseMipLevel = 0;
3454 // Set level count 2 (only 1 is allowed for FB attachment)
3455 ivci.subresourceRange.levelCount = 2;
3456 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3457 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3458 ASSERT_VK_SUCCESS(err);
3459 // Re-create renderpass to have matching sample count
3460 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3461 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3462 ASSERT_VK_SUCCESS(err);
3463
3464 fb_info.renderPass = rp;
3465 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003467 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3468
3469 m_errorMonitor->VerifyFound();
3470 if (err == VK_SUCCESS) {
3471 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3472 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003473 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003474 // Update view to original color buffer and grow FB dimensions too big
3475 fb_info.pAttachments = ivs;
3476 fb_info.height = 1024;
3477 fb_info.width = 1024;
3478 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3480 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003481 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3482
3483 m_errorMonitor->VerifyFound();
3484 if (err == VK_SUCCESS) {
3485 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3486 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003487 // Create view attachment with non-identity swizzle
3488 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3489 ivci.image = image.handle();
3490 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3491 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3492 ivci.subresourceRange.layerCount = 1;
3493 ivci.subresourceRange.baseMipLevel = 0;
3494 ivci.subresourceRange.levelCount = 1;
3495 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3496 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3497 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3498 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3499 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3500 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3501 ASSERT_VK_SUCCESS(err);
3502
3503 fb_info.pAttachments = &view;
3504 fb_info.height = 100;
3505 fb_info.width = 100;
3506 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3508 "framebuffer attachments must have "
3509 "been created with the identity "
3510 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003511 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3512
3513 m_errorMonitor->VerifyFound();
3514 if (err == VK_SUCCESS) {
3515 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3516 }
3517 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003518 // Request fb that exceeds max dimensions
3519 // reset attachment to color attachment
3520 fb_info.pAttachments = ivs;
3521 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3522 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3523 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3525 "dimensions exceed physical device "
3526 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003527 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3528
3529 m_errorMonitor->VerifyFound();
3530 if (err == VK_SUCCESS) {
3531 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3532 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003533
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003534 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003535}
3536
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003537TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003538 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3539 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003540
Cody Northropc31a84f2016-08-22 10:41:47 -06003541 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003542 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3544 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003545 m_errorMonitor->VerifyFound();
3546}
3547
3548TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003549 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3550 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003551
Cody Northropc31a84f2016-08-22 10:41:47 -06003552 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003553 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3555 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003556 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003557}
3558
3559TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003560 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3561 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003562
Cody Northropc31a84f2016-08-22 10:41:47 -06003563 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003564 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003567 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003568}
3569
3570TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003571 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3572 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003573
Cody Northropc31a84f2016-08-22 10:41:47 -06003574 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003575 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003577 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003578 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003579}
3580
Cortd713fe82016-07-27 09:51:27 -07003581TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003582 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3583 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003584
3585 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003586 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3588 "Dynamic blend constants state not set for this command buffer");
3589 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003590 m_errorMonitor->VerifyFound();
3591}
3592
3593TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003594 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3595 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003596
3597 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003598 if (!m_device->phy().features().depthBounds) {
3599 printf("Device does not support depthBounds test; skipped.\n");
3600 return;
3601 }
3602 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3604 "Dynamic depth bounds state not set for this command buffer");
3605 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003606 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003607}
3608
3609TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003610 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3611 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003612
3613 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003614 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3616 "Dynamic stencil read mask state not set for this command buffer");
3617 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003618 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003619}
3620
3621TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003622 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3623 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003624
3625 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003626 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3628 "Dynamic stencil write mask state not set for this command buffer");
3629 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003630 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003631}
3632
3633TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003634 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3635 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003636
3637 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003638 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3640 "Dynamic stencil reference state not set for this command buffer");
3641 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003642 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003643}
3644
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003645TEST_F(VkLayerTest, IndexBufferNotBound) {
3646 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003647
3648 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3650 "Index buffer object not bound to this command buffer when Indexed ");
3651 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003652 m_errorMonitor->VerifyFound();
3653}
3654
Karl Schultz6addd812016-02-02 17:17:23 -07003655TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3657 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3658 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003659
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003660 ASSERT_NO_FATAL_FAILURE(InitState());
3661 ASSERT_NO_FATAL_FAILURE(InitViewport());
3662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3663
Karl Schultz6addd812016-02-02 17:17:23 -07003664 // We luck out b/c by default the framework creates CB w/ the
3665 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003666 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003667 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003668 EndCommandBuffer();
3669
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003670 // Bypass framework since it does the waits automatically
3671 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003672 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003673 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3674 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003675 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003676 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003677 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003678 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003679 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003680 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003681 submit_info.pSignalSemaphores = NULL;
3682
Chris Forbes40028e22016-06-13 09:59:34 +12003683 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003684 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003685 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003686
Karl Schultz6addd812016-02-02 17:17:23 -07003687 // Cause validation error by re-submitting cmd buffer that should only be
3688 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003689 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003690 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003691
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003692 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003693}
3694
Karl Schultz6addd812016-02-02 17:17:23 -07003695TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003696 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003697 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003698
3699 ASSERT_NO_FATAL_FAILURE(InitState());
3700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003701
Karl Schultz6addd812016-02-02 17:17:23 -07003702 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3703 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003704 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003705 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003706 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003707
3708 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003709 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3710 ds_pool_ci.pNext = NULL;
3711 ds_pool_ci.flags = 0;
3712 ds_pool_ci.maxSets = 1;
3713 ds_pool_ci.poolSizeCount = 1;
3714 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003715
3716 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003717 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003718 ASSERT_VK_SUCCESS(err);
3719
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003720 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3721 dsl_binding_samp.binding = 0;
3722 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3723 dsl_binding_samp.descriptorCount = 1;
3724 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3725 dsl_binding_samp.pImmutableSamplers = NULL;
3726
3727 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3728 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3729 ds_layout_ci.pNext = NULL;
3730 ds_layout_ci.bindingCount = 1;
3731 ds_layout_ci.pBindings = &dsl_binding_samp;
3732
3733 VkDescriptorSetLayout ds_layout_samp;
3734 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3735 ASSERT_VK_SUCCESS(err);
3736
3737 // Try to allocate 2 sets when pool only has 1 set
3738 VkDescriptorSet descriptor_sets[2];
3739 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3740 VkDescriptorSetAllocateInfo alloc_info = {};
3741 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3742 alloc_info.descriptorSetCount = 2;
3743 alloc_info.descriptorPool = ds_pool;
3744 alloc_info.pSetLayouts = set_layouts;
3745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3746 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3747 m_errorMonitor->VerifyFound();
3748
3749 alloc_info.descriptorSetCount = 1;
3750 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003751 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003752 dsl_binding.binding = 0;
3753 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3754 dsl_binding.descriptorCount = 1;
3755 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3756 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003757
Karl Schultz6addd812016-02-02 17:17:23 -07003758 ds_layout_ci.bindingCount = 1;
3759 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003760
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003761 VkDescriptorSetLayout ds_layout_ub;
3762 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003763 ASSERT_VK_SUCCESS(err);
3764
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003765 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003766 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003767 alloc_info.pSetLayouts = &ds_layout_ub;
3768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3769 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003770
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003771 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003772
Karl Schultz2825ab92016-12-02 08:23:14 -07003773 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003774 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003775 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003776}
3777
Karl Schultz6addd812016-02-02 17:17:23 -07003778TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3779 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003780
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3782 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3783 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003784
Tobin Ehlise735c692015-10-08 13:13:50 -06003785 ASSERT_NO_FATAL_FAILURE(InitState());
3786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003787
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003788 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003789 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3790 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003791
3792 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003793 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3794 ds_pool_ci.pNext = NULL;
3795 ds_pool_ci.maxSets = 1;
3796 ds_pool_ci.poolSizeCount = 1;
3797 ds_pool_ci.flags = 0;
3798 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3799 // app can only call vkResetDescriptorPool on this pool.;
3800 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003801
3802 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003803 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003804 ASSERT_VK_SUCCESS(err);
3805
3806 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003807 dsl_binding.binding = 0;
3808 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3809 dsl_binding.descriptorCount = 1;
3810 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3811 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003812
3813 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003814 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3815 ds_layout_ci.pNext = NULL;
3816 ds_layout_ci.bindingCount = 1;
3817 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003818
3819 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003820 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003821 ASSERT_VK_SUCCESS(err);
3822
3823 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003824 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003825 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003826 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003827 alloc_info.descriptorPool = ds_pool;
3828 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003829 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003830 ASSERT_VK_SUCCESS(err);
3831
3832 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003833 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003834
Chia-I Wuf7458c52015-10-26 21:10:41 +08003835 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3836 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003837}
3838
Karl Schultz6addd812016-02-02 17:17:23 -07003839TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003840 // Attempt to clear Descriptor Pool with bad object.
3841 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003842
3843 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003845 uint64_t fake_pool_handle = 0xbaad6001;
3846 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3847 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003848 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003849}
3850
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003851TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003852 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3853 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003854 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003855 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003856
3857 uint64_t fake_set_handle = 0xbaad6001;
3858 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003859 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003861
3862 ASSERT_NO_FATAL_FAILURE(InitState());
3863
3864 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3865 layout_bindings[0].binding = 0;
3866 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3867 layout_bindings[0].descriptorCount = 1;
3868 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3869 layout_bindings[0].pImmutableSamplers = NULL;
3870
3871 VkDescriptorSetLayout descriptor_set_layout;
3872 VkDescriptorSetLayoutCreateInfo dslci = {};
3873 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3874 dslci.pNext = NULL;
3875 dslci.bindingCount = 1;
3876 dslci.pBindings = layout_bindings;
3877 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003878 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003879
3880 VkPipelineLayout pipeline_layout;
3881 VkPipelineLayoutCreateInfo plci = {};
3882 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3883 plci.pNext = NULL;
3884 plci.setLayoutCount = 1;
3885 plci.pSetLayouts = &descriptor_set_layout;
3886 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003887 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003888
3889 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003890 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3891 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003892 m_errorMonitor->VerifyFound();
3893 EndCommandBuffer();
3894 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3895 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003896}
3897
Karl Schultz6addd812016-02-02 17:17:23 -07003898TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003899 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3900 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003901 uint64_t fake_layout_handle = 0xbaad6001;
3902 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003904 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003905 VkPipelineLayout pipeline_layout;
3906 VkPipelineLayoutCreateInfo plci = {};
3907 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3908 plci.pNext = NULL;
3909 plci.setLayoutCount = 1;
3910 plci.pSetLayouts = &bad_layout;
3911 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3912
3913 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003914}
3915
Mark Muellerd4914412016-06-13 17:52:06 -06003916TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3917 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3918 "1) A uniform buffer update must have a valid buffer index."
3919 "2) When using an array of descriptors in a single WriteDescriptor,"
3920 " the descriptor types and stageflags must all be the same."
3921 "3) Immutable Sampler state must match across descriptors");
3922
3923 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003924 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3925 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3926 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3927 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3928 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003929
Mark Muellerd4914412016-06-13 17:52:06 -06003930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3931
3932 ASSERT_NO_FATAL_FAILURE(InitState());
3933 VkDescriptorPoolSize ds_type_count[4] = {};
3934 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3935 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003936 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003937 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003938 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003939 ds_type_count[2].descriptorCount = 1;
3940 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3941 ds_type_count[3].descriptorCount = 1;
3942
3943 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3944 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3945 ds_pool_ci.maxSets = 1;
3946 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3947 ds_pool_ci.pPoolSizes = ds_type_count;
3948
3949 VkDescriptorPool ds_pool;
3950 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3951 ASSERT_VK_SUCCESS(err);
3952
Mark Muellerb9896722016-06-16 09:54:29 -06003953 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003954 layout_binding[0].binding = 0;
3955 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3956 layout_binding[0].descriptorCount = 1;
3957 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3958 layout_binding[0].pImmutableSamplers = NULL;
3959
3960 layout_binding[1].binding = 1;
3961 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3962 layout_binding[1].descriptorCount = 1;
3963 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3964 layout_binding[1].pImmutableSamplers = NULL;
3965
3966 VkSamplerCreateInfo sampler_ci = {};
3967 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3968 sampler_ci.pNext = NULL;
3969 sampler_ci.magFilter = VK_FILTER_NEAREST;
3970 sampler_ci.minFilter = VK_FILTER_NEAREST;
3971 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3972 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3973 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3974 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3975 sampler_ci.mipLodBias = 1.0;
3976 sampler_ci.anisotropyEnable = VK_FALSE;
3977 sampler_ci.maxAnisotropy = 1;
3978 sampler_ci.compareEnable = VK_FALSE;
3979 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3980 sampler_ci.minLod = 1.0;
3981 sampler_ci.maxLod = 1.0;
3982 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3983 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3984 VkSampler sampler;
3985
3986 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3987 ASSERT_VK_SUCCESS(err);
3988
3989 layout_binding[2].binding = 2;
3990 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3991 layout_binding[2].descriptorCount = 1;
3992 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3993 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3994
Mark Muellerd4914412016-06-13 17:52:06 -06003995 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3996 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3997 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3998 ds_layout_ci.pBindings = layout_binding;
3999 VkDescriptorSetLayout ds_layout;
4000 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4001 ASSERT_VK_SUCCESS(err);
4002
4003 VkDescriptorSetAllocateInfo alloc_info = {};
4004 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4005 alloc_info.descriptorSetCount = 1;
4006 alloc_info.descriptorPool = ds_pool;
4007 alloc_info.pSetLayouts = &ds_layout;
4008 VkDescriptorSet descriptorSet;
4009 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4010 ASSERT_VK_SUCCESS(err);
4011
4012 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4013 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4014 pipeline_layout_ci.pNext = NULL;
4015 pipeline_layout_ci.setLayoutCount = 1;
4016 pipeline_layout_ci.pSetLayouts = &ds_layout;
4017
4018 VkPipelineLayout pipeline_layout;
4019 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4020 ASSERT_VK_SUCCESS(err);
4021
Mark Mueller5c838ce2016-06-16 09:54:29 -06004022 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004023 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4024 descriptor_write.dstSet = descriptorSet;
4025 descriptor_write.dstBinding = 0;
4026 descriptor_write.descriptorCount = 1;
4027 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4028
Mark Mueller5c838ce2016-06-16 09:54:29 -06004029 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004030 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4031 m_errorMonitor->VerifyFound();
4032
4033 // Create a buffer to update the descriptor with
4034 uint32_t qfi = 0;
4035 VkBufferCreateInfo buffCI = {};
4036 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4037 buffCI.size = 1024;
4038 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4039 buffCI.queueFamilyIndexCount = 1;
4040 buffCI.pQueueFamilyIndices = &qfi;
4041
4042 VkBuffer dyub;
4043 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4044 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004045
Tony Barboure132c5f2016-12-12 11:50:20 -07004046 VkDeviceMemory mem;
4047 VkMemoryRequirements mem_reqs;
4048 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4049
4050 VkMemoryAllocateInfo mem_alloc_info = {};
4051 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4052 mem_alloc_info.allocationSize = mem_reqs.size;
4053 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4054 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4055 ASSERT_VK_SUCCESS(err);
4056
4057 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4058 ASSERT_VK_SUCCESS(err);
4059
4060 VkDescriptorBufferInfo buffInfo[2] = {};
4061 buffInfo[0].buffer = dyub;
4062 buffInfo[0].offset = 0;
4063 buffInfo[0].range = 1024;
4064 buffInfo[1].buffer = dyub;
4065 buffInfo[1].offset = 0;
4066 buffInfo[1].range = 1024;
4067 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004068 descriptor_write.descriptorCount = 2;
4069
Mark Mueller5c838ce2016-06-16 09:54:29 -06004070 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4072 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4073 m_errorMonitor->VerifyFound();
4074
Mark Mueller5c838ce2016-06-16 09:54:29 -06004075 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4076 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004077 descriptor_write.dstBinding = 1;
4078 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004079
Mark Mueller5c838ce2016-06-16 09:54:29 -06004080 // Make pImageInfo index non-null to avoid complaints of it missing
4081 VkDescriptorImageInfo imageInfo = {};
4082 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4083 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4085 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4086 m_errorMonitor->VerifyFound();
4087
Mark Muellerd4914412016-06-13 17:52:06 -06004088 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004089 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004090 vkDestroySampler(m_device->device(), sampler, NULL);
4091 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4092 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4093 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4094}
4095
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004096TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4097 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4098 "due to a buffer dependency being destroyed.");
4099 ASSERT_NO_FATAL_FAILURE(InitState());
4100
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004101 VkBuffer buffer;
4102 VkDeviceMemory mem;
4103 VkMemoryRequirements mem_reqs;
4104
4105 VkBufferCreateInfo buf_info = {};
4106 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004107 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004108 buf_info.size = 256;
4109 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4110 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4111 ASSERT_VK_SUCCESS(err);
4112
4113 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4114
4115 VkMemoryAllocateInfo alloc_info = {};
4116 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4117 alloc_info.allocationSize = 256;
4118 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004119 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004120 if (!pass) {
4121 vkDestroyBuffer(m_device->device(), buffer, NULL);
4122 return;
4123 }
4124 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4125 ASSERT_VK_SUCCESS(err);
4126
4127 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4128 ASSERT_VK_SUCCESS(err);
4129
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004130 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004131 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004132 m_commandBuffer->EndCommandBuffer();
4133
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004135 // Destroy buffer dependency prior to submit to cause ERROR
4136 vkDestroyBuffer(m_device->device(), buffer, NULL);
4137
4138 VkSubmitInfo submit_info = {};
4139 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4140 submit_info.commandBufferCount = 1;
4141 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4142 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4143
4144 m_errorMonitor->VerifyFound();
4145 vkFreeMemory(m_device->handle(), mem, NULL);
4146}
4147
Tobin Ehlisea413442016-09-28 10:23:59 -06004148TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4149 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4150
4151 ASSERT_NO_FATAL_FAILURE(InitState());
4152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4153
4154 VkDescriptorPoolSize ds_type_count;
4155 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4156 ds_type_count.descriptorCount = 1;
4157
4158 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4159 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4160 ds_pool_ci.maxSets = 1;
4161 ds_pool_ci.poolSizeCount = 1;
4162 ds_pool_ci.pPoolSizes = &ds_type_count;
4163
4164 VkDescriptorPool ds_pool;
4165 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4166 ASSERT_VK_SUCCESS(err);
4167
4168 VkDescriptorSetLayoutBinding layout_binding;
4169 layout_binding.binding = 0;
4170 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4171 layout_binding.descriptorCount = 1;
4172 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4173 layout_binding.pImmutableSamplers = NULL;
4174
4175 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4176 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4177 ds_layout_ci.bindingCount = 1;
4178 ds_layout_ci.pBindings = &layout_binding;
4179 VkDescriptorSetLayout ds_layout;
4180 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4181 ASSERT_VK_SUCCESS(err);
4182
4183 VkDescriptorSetAllocateInfo alloc_info = {};
4184 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4185 alloc_info.descriptorSetCount = 1;
4186 alloc_info.descriptorPool = ds_pool;
4187 alloc_info.pSetLayouts = &ds_layout;
4188 VkDescriptorSet descriptor_set;
4189 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4190 ASSERT_VK_SUCCESS(err);
4191
4192 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4193 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4194 pipeline_layout_ci.pNext = NULL;
4195 pipeline_layout_ci.setLayoutCount = 1;
4196 pipeline_layout_ci.pSetLayouts = &ds_layout;
4197
4198 VkPipelineLayout pipeline_layout;
4199 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4200 ASSERT_VK_SUCCESS(err);
4201
4202 VkBuffer buffer;
4203 uint32_t queue_family_index = 0;
4204 VkBufferCreateInfo buffer_create_info = {};
4205 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4206 buffer_create_info.size = 1024;
4207 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4208 buffer_create_info.queueFamilyIndexCount = 1;
4209 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4210
4211 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4212 ASSERT_VK_SUCCESS(err);
4213
4214 VkMemoryRequirements memory_reqs;
4215 VkDeviceMemory buffer_memory;
4216
4217 VkMemoryAllocateInfo memory_info = {};
4218 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4219 memory_info.allocationSize = 0;
4220 memory_info.memoryTypeIndex = 0;
4221
4222 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4223 memory_info.allocationSize = memory_reqs.size;
4224 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4225 ASSERT_TRUE(pass);
4226
4227 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4228 ASSERT_VK_SUCCESS(err);
4229 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4230 ASSERT_VK_SUCCESS(err);
4231
4232 VkBufferView view;
4233 VkBufferViewCreateInfo bvci = {};
4234 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4235 bvci.buffer = buffer;
4236 bvci.format = VK_FORMAT_R8_UNORM;
4237 bvci.range = VK_WHOLE_SIZE;
4238
4239 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4240 ASSERT_VK_SUCCESS(err);
4241
4242 VkWriteDescriptorSet descriptor_write = {};
4243 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4244 descriptor_write.dstSet = descriptor_set;
4245 descriptor_write.dstBinding = 0;
4246 descriptor_write.descriptorCount = 1;
4247 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4248 descriptor_write.pTexelBufferView = &view;
4249
4250 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4251
4252 char const *vsSource = "#version 450\n"
4253 "\n"
4254 "out gl_PerVertex { \n"
4255 " vec4 gl_Position;\n"
4256 "};\n"
4257 "void main(){\n"
4258 " gl_Position = vec4(1);\n"
4259 "}\n";
4260 char const *fsSource = "#version 450\n"
4261 "\n"
4262 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4263 "layout(location=0) out vec4 x;\n"
4264 "void main(){\n"
4265 " x = imageLoad(s, 0);\n"
4266 "}\n";
4267 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4268 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4269 VkPipelineObj pipe(m_device);
4270 pipe.AddShader(&vs);
4271 pipe.AddShader(&fs);
4272 pipe.AddColorAttachment();
4273 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4274
4275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4277
4278 BeginCommandBuffer();
4279 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4280 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4281 VkRect2D scissor = {{0, 0}, {16, 16}};
4282 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4283 // Bind pipeline to cmd buffer
4284 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4285 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4286 &descriptor_set, 0, nullptr);
4287 Draw(1, 0, 0, 0);
4288 EndCommandBuffer();
4289
4290 // Delete BufferView in order to invalidate cmd buffer
4291 vkDestroyBufferView(m_device->device(), view, NULL);
4292 // Now attempt submit of cmd buffer
4293 VkSubmitInfo submit_info = {};
4294 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4295 submit_info.commandBufferCount = 1;
4296 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4297 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4298 m_errorMonitor->VerifyFound();
4299
4300 // Clean-up
4301 vkDestroyBuffer(m_device->device(), buffer, NULL);
4302 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4304 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4305 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4306}
4307
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004308TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4309 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4310 "due to an image dependency being destroyed.");
4311 ASSERT_NO_FATAL_FAILURE(InitState());
4312
4313 VkImage image;
4314 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4315 VkImageCreateInfo image_create_info = {};
4316 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4317 image_create_info.pNext = NULL;
4318 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4319 image_create_info.format = tex_format;
4320 image_create_info.extent.width = 32;
4321 image_create_info.extent.height = 32;
4322 image_create_info.extent.depth = 1;
4323 image_create_info.mipLevels = 1;
4324 image_create_info.arrayLayers = 1;
4325 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4326 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004327 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004328 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004329 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004330 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004331 // Have to bind memory to image before recording cmd in cmd buffer using it
4332 VkMemoryRequirements mem_reqs;
4333 VkDeviceMemory image_mem;
4334 bool pass;
4335 VkMemoryAllocateInfo mem_alloc = {};
4336 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4337 mem_alloc.pNext = NULL;
4338 mem_alloc.memoryTypeIndex = 0;
4339 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4340 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004341 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004342 ASSERT_TRUE(pass);
4343 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4344 ASSERT_VK_SUCCESS(err);
4345 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4346 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004347
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004348 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004349 VkClearColorValue ccv;
4350 ccv.float32[0] = 1.0f;
4351 ccv.float32[1] = 1.0f;
4352 ccv.float32[2] = 1.0f;
4353 ccv.float32[3] = 1.0f;
4354 VkImageSubresourceRange isr = {};
4355 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004356 isr.baseArrayLayer = 0;
4357 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004358 isr.layerCount = 1;
4359 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004360 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004361 m_commandBuffer->EndCommandBuffer();
4362
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004364 // Destroy image dependency prior to submit to cause ERROR
4365 vkDestroyImage(m_device->device(), image, NULL);
4366
4367 VkSubmitInfo submit_info = {};
4368 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4369 submit_info.commandBufferCount = 1;
4370 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4371 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4372
4373 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004374 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004375}
4376
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004377TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4378 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4379 "due to a framebuffer image dependency being destroyed.");
4380 VkFormatProperties format_properties;
4381 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004382 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4383 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004384 return;
4385 }
4386
4387 ASSERT_NO_FATAL_FAILURE(InitState());
4388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4389
4390 VkImageCreateInfo image_ci = {};
4391 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4392 image_ci.pNext = NULL;
4393 image_ci.imageType = VK_IMAGE_TYPE_2D;
4394 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4395 image_ci.extent.width = 32;
4396 image_ci.extent.height = 32;
4397 image_ci.extent.depth = 1;
4398 image_ci.mipLevels = 1;
4399 image_ci.arrayLayers = 1;
4400 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4401 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004402 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004403 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4404 image_ci.flags = 0;
4405 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004406 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004407
4408 VkMemoryRequirements memory_reqs;
4409 VkDeviceMemory image_memory;
4410 bool pass;
4411 VkMemoryAllocateInfo memory_info = {};
4412 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4413 memory_info.pNext = NULL;
4414 memory_info.allocationSize = 0;
4415 memory_info.memoryTypeIndex = 0;
4416 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4417 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004418 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004419 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004420 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004421 ASSERT_VK_SUCCESS(err);
4422 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4423 ASSERT_VK_SUCCESS(err);
4424
4425 VkImageViewCreateInfo ivci = {
4426 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4427 nullptr,
4428 0,
4429 image,
4430 VK_IMAGE_VIEW_TYPE_2D,
4431 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004432 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004433 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4434 };
4435 VkImageView view;
4436 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4437 ASSERT_VK_SUCCESS(err);
4438
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004439 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004440 VkFramebuffer fb;
4441 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4442 ASSERT_VK_SUCCESS(err);
4443
4444 // Just use default renderpass with our framebuffer
4445 m_renderPassBeginInfo.framebuffer = fb;
4446 // Create Null cmd buffer for submit
4447 BeginCommandBuffer();
4448 EndCommandBuffer();
4449 // Destroy image attached to framebuffer to invalidate cmd buffer
4450 vkDestroyImage(m_device->device(), image, NULL);
4451 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004453 QueueCommandBuffer(false);
4454 m_errorMonitor->VerifyFound();
4455
4456 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4457 vkDestroyImageView(m_device->device(), view, nullptr);
4458 vkFreeMemory(m_device->device(), image_memory, nullptr);
4459}
4460
Tobin Ehlisb329f992016-10-12 13:20:29 -06004461TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4462 TEST_DESCRIPTION("Delete in-use framebuffer.");
4463 VkFormatProperties format_properties;
4464 VkResult err = VK_SUCCESS;
4465 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4466
4467 ASSERT_NO_FATAL_FAILURE(InitState());
4468 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4469
4470 VkImageObj image(m_device);
4471 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4472 ASSERT_TRUE(image.initialized());
4473 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4474
4475 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4476 VkFramebuffer fb;
4477 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4478 ASSERT_VK_SUCCESS(err);
4479
4480 // Just use default renderpass with our framebuffer
4481 m_renderPassBeginInfo.framebuffer = fb;
4482 // Create Null cmd buffer for submit
4483 BeginCommandBuffer();
4484 EndCommandBuffer();
4485 // Submit cmd buffer to put it in-flight
4486 VkSubmitInfo submit_info = {};
4487 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4488 submit_info.commandBufferCount = 1;
4489 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4490 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4491 // Destroy framebuffer while in-flight
4492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4493 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4494 m_errorMonitor->VerifyFound();
4495 // Wait for queue to complete so we can safely destroy everything
4496 vkQueueWaitIdle(m_device->m_queue);
4497 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4498}
4499
Tobin Ehlis88becd72016-09-21 14:33:41 -06004500TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4501 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4502 VkFormatProperties format_properties;
4503 VkResult err = VK_SUCCESS;
4504 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004505
4506 ASSERT_NO_FATAL_FAILURE(InitState());
4507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4508
4509 VkImageCreateInfo image_ci = {};
4510 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4511 image_ci.pNext = NULL;
4512 image_ci.imageType = VK_IMAGE_TYPE_2D;
4513 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4514 image_ci.extent.width = 256;
4515 image_ci.extent.height = 256;
4516 image_ci.extent.depth = 1;
4517 image_ci.mipLevels = 1;
4518 image_ci.arrayLayers = 1;
4519 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4520 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004521 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004522 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4523 image_ci.flags = 0;
4524 VkImage image;
4525 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4526
4527 VkMemoryRequirements memory_reqs;
4528 VkDeviceMemory image_memory;
4529 bool pass;
4530 VkMemoryAllocateInfo memory_info = {};
4531 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4532 memory_info.pNext = NULL;
4533 memory_info.allocationSize = 0;
4534 memory_info.memoryTypeIndex = 0;
4535 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4536 memory_info.allocationSize = memory_reqs.size;
4537 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4538 ASSERT_TRUE(pass);
4539 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4540 ASSERT_VK_SUCCESS(err);
4541 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4542 ASSERT_VK_SUCCESS(err);
4543
4544 VkImageViewCreateInfo ivci = {
4545 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4546 nullptr,
4547 0,
4548 image,
4549 VK_IMAGE_VIEW_TYPE_2D,
4550 VK_FORMAT_B8G8R8A8_UNORM,
4551 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4552 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4553 };
4554 VkImageView view;
4555 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4556 ASSERT_VK_SUCCESS(err);
4557
4558 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4559 VkFramebuffer fb;
4560 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4561 ASSERT_VK_SUCCESS(err);
4562
4563 // Just use default renderpass with our framebuffer
4564 m_renderPassBeginInfo.framebuffer = fb;
4565 // Create Null cmd buffer for submit
4566 BeginCommandBuffer();
4567 EndCommandBuffer();
4568 // Submit cmd buffer to put it (and attached imageView) in-flight
4569 VkSubmitInfo submit_info = {};
4570 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4571 submit_info.commandBufferCount = 1;
4572 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4573 // Submit cmd buffer to put framebuffer and children in-flight
4574 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4575 // Destroy image attached to framebuffer while in-flight
4576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4577 vkDestroyImage(m_device->device(), image, NULL);
4578 m_errorMonitor->VerifyFound();
4579 // Wait for queue to complete so we can safely destroy image and other objects
4580 vkQueueWaitIdle(m_device->m_queue);
4581 vkDestroyImage(m_device->device(), image, NULL);
4582 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4583 vkDestroyImageView(m_device->device(), view, nullptr);
4584 vkFreeMemory(m_device->device(), image_memory, nullptr);
4585}
4586
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004587TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4588 TEST_DESCRIPTION("Delete in-use renderPass.");
4589
4590 ASSERT_NO_FATAL_FAILURE(InitState());
4591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4592
4593 // Create simple renderpass
4594 VkAttachmentReference attach = {};
4595 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4596 VkSubpassDescription subpass = {};
4597 subpass.pColorAttachments = &attach;
4598 VkRenderPassCreateInfo rpci = {};
4599 rpci.subpassCount = 1;
4600 rpci.pSubpasses = &subpass;
4601 rpci.attachmentCount = 1;
4602 VkAttachmentDescription attach_desc = {};
4603 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4604 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4605 rpci.pAttachments = &attach_desc;
4606 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4607 VkRenderPass rp;
4608 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4609 ASSERT_VK_SUCCESS(err);
4610
4611 // Create a pipeline that uses the given renderpass
4612 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4613 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4614
4615 VkPipelineLayout pipeline_layout;
4616 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4617 ASSERT_VK_SUCCESS(err);
4618
4619 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4620 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4621 vp_state_ci.viewportCount = 1;
4622 VkViewport vp = {}; // Just need dummy vp to point to
4623 vp_state_ci.pViewports = &vp;
4624 vp_state_ci.scissorCount = 1;
4625 VkRect2D scissors = {}; // Dummy scissors to point to
4626 vp_state_ci.pScissors = &scissors;
4627
4628 VkPipelineShaderStageCreateInfo shaderStages[2];
4629 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4630
4631 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4632 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4633 // but add it to be able to run on more devices
4634 shaderStages[0] = vs.GetStageCreateInfo();
4635 shaderStages[1] = fs.GetStageCreateInfo();
4636
4637 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4638 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4639
4640 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4641 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4642 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4643
4644 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4645 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4646 rs_ci.rasterizerDiscardEnable = true;
4647 rs_ci.lineWidth = 1.0f;
4648
4649 VkPipelineColorBlendAttachmentState att = {};
4650 att.blendEnable = VK_FALSE;
4651 att.colorWriteMask = 0xf;
4652
4653 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4654 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4655 cb_ci.attachmentCount = 1;
4656 cb_ci.pAttachments = &att;
4657
4658 VkGraphicsPipelineCreateInfo gp_ci = {};
4659 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4660 gp_ci.stageCount = 2;
4661 gp_ci.pStages = shaderStages;
4662 gp_ci.pVertexInputState = &vi_ci;
4663 gp_ci.pInputAssemblyState = &ia_ci;
4664 gp_ci.pViewportState = &vp_state_ci;
4665 gp_ci.pRasterizationState = &rs_ci;
4666 gp_ci.pColorBlendState = &cb_ci;
4667 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4668 gp_ci.layout = pipeline_layout;
4669 gp_ci.renderPass = rp;
4670
4671 VkPipelineCacheCreateInfo pc_ci = {};
4672 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4673
4674 VkPipeline pipeline;
4675 VkPipelineCache pipe_cache;
4676 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4677 ASSERT_VK_SUCCESS(err);
4678
4679 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4680 ASSERT_VK_SUCCESS(err);
4681 // Bind pipeline to cmd buffer, will also bind renderpass
4682 m_commandBuffer->BeginCommandBuffer();
4683 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4684 m_commandBuffer->EndCommandBuffer();
4685
4686 VkSubmitInfo submit_info = {};
4687 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4688 submit_info.commandBufferCount = 1;
4689 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4690 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4691
4692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4693 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4694 m_errorMonitor->VerifyFound();
4695
4696 // Wait for queue to complete so we can safely destroy everything
4697 vkQueueWaitIdle(m_device->m_queue);
4698 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4699 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4700 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4701 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4702}
4703
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004704TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004705 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004706 ASSERT_NO_FATAL_FAILURE(InitState());
4707
4708 VkImage image;
4709 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4710 VkImageCreateInfo image_create_info = {};
4711 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4712 image_create_info.pNext = NULL;
4713 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4714 image_create_info.format = tex_format;
4715 image_create_info.extent.width = 32;
4716 image_create_info.extent.height = 32;
4717 image_create_info.extent.depth = 1;
4718 image_create_info.mipLevels = 1;
4719 image_create_info.arrayLayers = 1;
4720 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4721 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004722 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004723 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004724 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004725 ASSERT_VK_SUCCESS(err);
4726 // Have to bind memory to image before recording cmd in cmd buffer using it
4727 VkMemoryRequirements mem_reqs;
4728 VkDeviceMemory image_mem;
4729 bool pass;
4730 VkMemoryAllocateInfo mem_alloc = {};
4731 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4732 mem_alloc.pNext = NULL;
4733 mem_alloc.memoryTypeIndex = 0;
4734 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4735 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004736 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004737 ASSERT_TRUE(pass);
4738 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4739 ASSERT_VK_SUCCESS(err);
4740
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004741 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004743 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004744
4745 m_commandBuffer->BeginCommandBuffer();
4746 VkClearColorValue ccv;
4747 ccv.float32[0] = 1.0f;
4748 ccv.float32[1] = 1.0f;
4749 ccv.float32[2] = 1.0f;
4750 ccv.float32[3] = 1.0f;
4751 VkImageSubresourceRange isr = {};
4752 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4753 isr.baseArrayLayer = 0;
4754 isr.baseMipLevel = 0;
4755 isr.layerCount = 1;
4756 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004757 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004758 m_commandBuffer->EndCommandBuffer();
4759
4760 m_errorMonitor->VerifyFound();
4761 vkDestroyImage(m_device->device(), image, NULL);
4762 vkFreeMemory(m_device->device(), image_mem, nullptr);
4763}
4764
4765TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004766 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004767 ASSERT_NO_FATAL_FAILURE(InitState());
4768
4769 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004770 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004771 VK_IMAGE_TILING_OPTIMAL, 0);
4772 ASSERT_TRUE(image.initialized());
4773
4774 VkBuffer buffer;
4775 VkDeviceMemory mem;
4776 VkMemoryRequirements mem_reqs;
4777
4778 VkBufferCreateInfo buf_info = {};
4779 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004780 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004781 buf_info.size = 256;
4782 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4783 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4784 ASSERT_VK_SUCCESS(err);
4785
4786 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4787
4788 VkMemoryAllocateInfo alloc_info = {};
4789 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4790 alloc_info.allocationSize = 256;
4791 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004792 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004793 if (!pass) {
4794 vkDestroyBuffer(m_device->device(), buffer, NULL);
4795 return;
4796 }
4797 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4798 ASSERT_VK_SUCCESS(err);
4799
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004800 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004802 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004803 VkBufferImageCopy region = {};
4804 region.bufferRowLength = 128;
4805 region.bufferImageHeight = 128;
4806 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4807
4808 region.imageSubresource.layerCount = 1;
4809 region.imageExtent.height = 4;
4810 region.imageExtent.width = 4;
4811 region.imageExtent.depth = 1;
4812 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004813 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4814 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004815 m_commandBuffer->EndCommandBuffer();
4816
4817 m_errorMonitor->VerifyFound();
4818
4819 vkDestroyBuffer(m_device->device(), buffer, NULL);
4820 vkFreeMemory(m_device->handle(), mem, NULL);
4821}
4822
Tobin Ehlis85940f52016-07-07 16:57:21 -06004823TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4824 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4825 "due to an event dependency being destroyed.");
4826 ASSERT_NO_FATAL_FAILURE(InitState());
4827
4828 VkEvent event;
4829 VkEventCreateInfo evci = {};
4830 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4831 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4832 ASSERT_VK_SUCCESS(result);
4833
4834 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004835 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004836 m_commandBuffer->EndCommandBuffer();
4837
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004839 // Destroy event dependency prior to submit to cause ERROR
4840 vkDestroyEvent(m_device->device(), event, NULL);
4841
4842 VkSubmitInfo submit_info = {};
4843 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4844 submit_info.commandBufferCount = 1;
4845 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4846 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4847
4848 m_errorMonitor->VerifyFound();
4849}
4850
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004851TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4852 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4853 "due to a query pool dependency being destroyed.");
4854 ASSERT_NO_FATAL_FAILURE(InitState());
4855
4856 VkQueryPool query_pool;
4857 VkQueryPoolCreateInfo qpci{};
4858 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4859 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4860 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004861 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004862 ASSERT_VK_SUCCESS(result);
4863
4864 m_commandBuffer->BeginCommandBuffer();
4865 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4866 m_commandBuffer->EndCommandBuffer();
4867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004869 // Destroy query pool dependency prior to submit to cause ERROR
4870 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4871
4872 VkSubmitInfo submit_info = {};
4873 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4874 submit_info.commandBufferCount = 1;
4875 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4876 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4877
4878 m_errorMonitor->VerifyFound();
4879}
4880
Tobin Ehlis24130d92016-07-08 15:50:53 -06004881TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4882 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4883 "due to a pipeline dependency being destroyed.");
4884 ASSERT_NO_FATAL_FAILURE(InitState());
4885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4886
4887 VkResult err;
4888
4889 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4890 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4891
4892 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004893 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004894 ASSERT_VK_SUCCESS(err);
4895
4896 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4897 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4898 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004899 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004900 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004901 vp_state_ci.scissorCount = 1;
4902 VkRect2D scissors = {}; // Dummy scissors to point to
4903 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004904
4905 VkPipelineShaderStageCreateInfo shaderStages[2];
4906 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4907
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004908 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4909 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4910 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004911 shaderStages[0] = vs.GetStageCreateInfo();
4912 shaderStages[1] = fs.GetStageCreateInfo();
4913
4914 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4915 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4916
4917 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4918 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4919 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4920
4921 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4922 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004923 rs_ci.rasterizerDiscardEnable = true;
4924 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004925
4926 VkPipelineColorBlendAttachmentState att = {};
4927 att.blendEnable = VK_FALSE;
4928 att.colorWriteMask = 0xf;
4929
4930 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4931 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4932 cb_ci.attachmentCount = 1;
4933 cb_ci.pAttachments = &att;
4934
4935 VkGraphicsPipelineCreateInfo gp_ci = {};
4936 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4937 gp_ci.stageCount = 2;
4938 gp_ci.pStages = shaderStages;
4939 gp_ci.pVertexInputState = &vi_ci;
4940 gp_ci.pInputAssemblyState = &ia_ci;
4941 gp_ci.pViewportState = &vp_state_ci;
4942 gp_ci.pRasterizationState = &rs_ci;
4943 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004944 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4945 gp_ci.layout = pipeline_layout;
4946 gp_ci.renderPass = renderPass();
4947
4948 VkPipelineCacheCreateInfo pc_ci = {};
4949 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4950
4951 VkPipeline pipeline;
4952 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004954 ASSERT_VK_SUCCESS(err);
4955
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004956 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004957 ASSERT_VK_SUCCESS(err);
4958
4959 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004960 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004961 m_commandBuffer->EndCommandBuffer();
4962 // Now destroy pipeline in order to cause error when submitting
4963 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4964
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004966
4967 VkSubmitInfo submit_info = {};
4968 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4969 submit_info.commandBufferCount = 1;
4970 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4971 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4972
4973 m_errorMonitor->VerifyFound();
4974 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4975 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4976}
4977
Tobin Ehlis31289162016-08-17 14:57:58 -06004978TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4979 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4980 "due to a bound descriptor set with a buffer dependency "
4981 "being destroyed.");
4982 ASSERT_NO_FATAL_FAILURE(InitState());
4983 ASSERT_NO_FATAL_FAILURE(InitViewport());
4984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4985
4986 VkDescriptorPoolSize ds_type_count = {};
4987 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4988 ds_type_count.descriptorCount = 1;
4989
4990 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4991 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4992 ds_pool_ci.pNext = NULL;
4993 ds_pool_ci.maxSets = 1;
4994 ds_pool_ci.poolSizeCount = 1;
4995 ds_pool_ci.pPoolSizes = &ds_type_count;
4996
4997 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004998 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004999 ASSERT_VK_SUCCESS(err);
5000
5001 VkDescriptorSetLayoutBinding dsl_binding = {};
5002 dsl_binding.binding = 0;
5003 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5004 dsl_binding.descriptorCount = 1;
5005 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5006 dsl_binding.pImmutableSamplers = NULL;
5007
5008 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5009 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5010 ds_layout_ci.pNext = NULL;
5011 ds_layout_ci.bindingCount = 1;
5012 ds_layout_ci.pBindings = &dsl_binding;
5013 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005014 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005015 ASSERT_VK_SUCCESS(err);
5016
5017 VkDescriptorSet descriptorSet;
5018 VkDescriptorSetAllocateInfo alloc_info = {};
5019 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5020 alloc_info.descriptorSetCount = 1;
5021 alloc_info.descriptorPool = ds_pool;
5022 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005023 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005024 ASSERT_VK_SUCCESS(err);
5025
5026 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5027 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5028 pipeline_layout_ci.pNext = NULL;
5029 pipeline_layout_ci.setLayoutCount = 1;
5030 pipeline_layout_ci.pSetLayouts = &ds_layout;
5031
5032 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005033 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005034 ASSERT_VK_SUCCESS(err);
5035
5036 // Create a buffer to update the descriptor with
5037 uint32_t qfi = 0;
5038 VkBufferCreateInfo buffCI = {};
5039 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5040 buffCI.size = 1024;
5041 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5042 buffCI.queueFamilyIndexCount = 1;
5043 buffCI.pQueueFamilyIndices = &qfi;
5044
5045 VkBuffer buffer;
5046 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5047 ASSERT_VK_SUCCESS(err);
5048 // Allocate memory and bind to buffer so we can make it to the appropriate
5049 // error
5050 VkMemoryAllocateInfo mem_alloc = {};
5051 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5052 mem_alloc.pNext = NULL;
5053 mem_alloc.allocationSize = 1024;
5054 mem_alloc.memoryTypeIndex = 0;
5055
5056 VkMemoryRequirements memReqs;
5057 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005058 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005059 if (!pass) {
5060 vkDestroyBuffer(m_device->device(), buffer, NULL);
5061 return;
5062 }
5063
5064 VkDeviceMemory mem;
5065 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5066 ASSERT_VK_SUCCESS(err);
5067 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5068 ASSERT_VK_SUCCESS(err);
5069 // Correctly update descriptor to avoid "NOT_UPDATED" error
5070 VkDescriptorBufferInfo buffInfo = {};
5071 buffInfo.buffer = buffer;
5072 buffInfo.offset = 0;
5073 buffInfo.range = 1024;
5074
5075 VkWriteDescriptorSet descriptor_write;
5076 memset(&descriptor_write, 0, sizeof(descriptor_write));
5077 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5078 descriptor_write.dstSet = descriptorSet;
5079 descriptor_write.dstBinding = 0;
5080 descriptor_write.descriptorCount = 1;
5081 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5082 descriptor_write.pBufferInfo = &buffInfo;
5083
5084 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5085
5086 // Create PSO to be used for draw-time errors below
5087 char const *vsSource = "#version 450\n"
5088 "\n"
5089 "out gl_PerVertex { \n"
5090 " vec4 gl_Position;\n"
5091 "};\n"
5092 "void main(){\n"
5093 " gl_Position = vec4(1);\n"
5094 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005095 char const *fsSource = "#version 450\n"
5096 "\n"
5097 "layout(location=0) out vec4 x;\n"
5098 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5099 "void main(){\n"
5100 " x = vec4(bar.y);\n"
5101 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005102 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5103 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5104 VkPipelineObj pipe(m_device);
5105 pipe.AddShader(&vs);
5106 pipe.AddShader(&fs);
5107 pipe.AddColorAttachment();
5108 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5109
5110 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005111 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5112 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5113 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005114 Draw(1, 0, 0, 0);
5115 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005117 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5118 vkDestroyBuffer(m_device->device(), buffer, NULL);
5119 // Attempt to submit cmd buffer
5120 VkSubmitInfo submit_info = {};
5121 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5122 submit_info.commandBufferCount = 1;
5123 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5124 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5125 m_errorMonitor->VerifyFound();
5126 // Cleanup
5127 vkFreeMemory(m_device->device(), mem, NULL);
5128
5129 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5130 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5131 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5132}
5133
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005134TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5135 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5136 "due to a bound descriptor sets with a combined image "
5137 "sampler having their image, sampler, and descriptor set "
5138 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005139 "submit associated cmd buffers. Attempt to destroy a "
5140 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005141 ASSERT_NO_FATAL_FAILURE(InitState());
5142 ASSERT_NO_FATAL_FAILURE(InitViewport());
5143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5144
5145 VkDescriptorPoolSize ds_type_count = {};
5146 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5147 ds_type_count.descriptorCount = 1;
5148
5149 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5150 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5151 ds_pool_ci.pNext = NULL;
5152 ds_pool_ci.maxSets = 1;
5153 ds_pool_ci.poolSizeCount = 1;
5154 ds_pool_ci.pPoolSizes = &ds_type_count;
5155
5156 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005157 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005158 ASSERT_VK_SUCCESS(err);
5159
5160 VkDescriptorSetLayoutBinding dsl_binding = {};
5161 dsl_binding.binding = 0;
5162 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5163 dsl_binding.descriptorCount = 1;
5164 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5165 dsl_binding.pImmutableSamplers = NULL;
5166
5167 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5168 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5169 ds_layout_ci.pNext = NULL;
5170 ds_layout_ci.bindingCount = 1;
5171 ds_layout_ci.pBindings = &dsl_binding;
5172 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005173 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005174 ASSERT_VK_SUCCESS(err);
5175
5176 VkDescriptorSet descriptorSet;
5177 VkDescriptorSetAllocateInfo alloc_info = {};
5178 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5179 alloc_info.descriptorSetCount = 1;
5180 alloc_info.descriptorPool = ds_pool;
5181 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005182 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005183 ASSERT_VK_SUCCESS(err);
5184
5185 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5186 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5187 pipeline_layout_ci.pNext = NULL;
5188 pipeline_layout_ci.setLayoutCount = 1;
5189 pipeline_layout_ci.pSetLayouts = &ds_layout;
5190
5191 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005192 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005193 ASSERT_VK_SUCCESS(err);
5194
5195 // Create images to update the descriptor with
5196 VkImage image;
5197 VkImage image2;
5198 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5199 const int32_t tex_width = 32;
5200 const int32_t tex_height = 32;
5201 VkImageCreateInfo image_create_info = {};
5202 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5203 image_create_info.pNext = NULL;
5204 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5205 image_create_info.format = tex_format;
5206 image_create_info.extent.width = tex_width;
5207 image_create_info.extent.height = tex_height;
5208 image_create_info.extent.depth = 1;
5209 image_create_info.mipLevels = 1;
5210 image_create_info.arrayLayers = 1;
5211 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5212 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5213 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5214 image_create_info.flags = 0;
5215 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5216 ASSERT_VK_SUCCESS(err);
5217 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5218 ASSERT_VK_SUCCESS(err);
5219
5220 VkMemoryRequirements memory_reqs;
5221 VkDeviceMemory image_memory;
5222 bool pass;
5223 VkMemoryAllocateInfo memory_info = {};
5224 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5225 memory_info.pNext = NULL;
5226 memory_info.allocationSize = 0;
5227 memory_info.memoryTypeIndex = 0;
5228 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5229 // Allocate enough memory for both images
5230 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005231 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005232 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005233 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005234 ASSERT_VK_SUCCESS(err);
5235 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5236 ASSERT_VK_SUCCESS(err);
5237 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005238 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005239 ASSERT_VK_SUCCESS(err);
5240
5241 VkImageViewCreateInfo image_view_create_info = {};
5242 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5243 image_view_create_info.image = image;
5244 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5245 image_view_create_info.format = tex_format;
5246 image_view_create_info.subresourceRange.layerCount = 1;
5247 image_view_create_info.subresourceRange.baseMipLevel = 0;
5248 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005249 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005250
5251 VkImageView view;
5252 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005253 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005254 ASSERT_VK_SUCCESS(err);
5255 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005256 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005257 ASSERT_VK_SUCCESS(err);
5258 // Create Samplers
5259 VkSamplerCreateInfo sampler_ci = {};
5260 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5261 sampler_ci.pNext = NULL;
5262 sampler_ci.magFilter = VK_FILTER_NEAREST;
5263 sampler_ci.minFilter = VK_FILTER_NEAREST;
5264 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5265 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5266 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5267 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5268 sampler_ci.mipLodBias = 1.0;
5269 sampler_ci.anisotropyEnable = VK_FALSE;
5270 sampler_ci.maxAnisotropy = 1;
5271 sampler_ci.compareEnable = VK_FALSE;
5272 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5273 sampler_ci.minLod = 1.0;
5274 sampler_ci.maxLod = 1.0;
5275 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5276 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5277 VkSampler sampler;
5278 VkSampler sampler2;
5279 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5280 ASSERT_VK_SUCCESS(err);
5281 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5282 ASSERT_VK_SUCCESS(err);
5283 // Update descriptor with image and sampler
5284 VkDescriptorImageInfo img_info = {};
5285 img_info.sampler = sampler;
5286 img_info.imageView = view;
5287 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5288
5289 VkWriteDescriptorSet descriptor_write;
5290 memset(&descriptor_write, 0, sizeof(descriptor_write));
5291 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5292 descriptor_write.dstSet = descriptorSet;
5293 descriptor_write.dstBinding = 0;
5294 descriptor_write.descriptorCount = 1;
5295 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5296 descriptor_write.pImageInfo = &img_info;
5297
5298 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5299
5300 // Create PSO to be used for draw-time errors below
5301 char const *vsSource = "#version 450\n"
5302 "\n"
5303 "out gl_PerVertex { \n"
5304 " vec4 gl_Position;\n"
5305 "};\n"
5306 "void main(){\n"
5307 " gl_Position = vec4(1);\n"
5308 "}\n";
5309 char const *fsSource = "#version 450\n"
5310 "\n"
5311 "layout(set=0, binding=0) uniform sampler2D s;\n"
5312 "layout(location=0) out vec4 x;\n"
5313 "void main(){\n"
5314 " x = texture(s, vec2(1));\n"
5315 "}\n";
5316 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5317 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5318 VkPipelineObj pipe(m_device);
5319 pipe.AddShader(&vs);
5320 pipe.AddShader(&fs);
5321 pipe.AddColorAttachment();
5322 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5323
5324 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005326 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005327 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5328 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5329 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005330 Draw(1, 0, 0, 0);
5331 EndCommandBuffer();
5332 // Destroy sampler invalidates the cmd buffer, causing error on submit
5333 vkDestroySampler(m_device->device(), sampler, NULL);
5334 // Attempt to submit cmd buffer
5335 VkSubmitInfo submit_info = {};
5336 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5337 submit_info.commandBufferCount = 1;
5338 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5339 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5340 m_errorMonitor->VerifyFound();
5341 // Now re-update descriptor with valid sampler and delete image
5342 img_info.sampler = sampler2;
5343 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005345 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005346 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5347 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5348 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005349 Draw(1, 0, 0, 0);
5350 EndCommandBuffer();
5351 // Destroy image invalidates the cmd buffer, causing error on submit
5352 vkDestroyImage(m_device->device(), image, NULL);
5353 // Attempt to submit cmd buffer
5354 submit_info = {};
5355 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5356 submit_info.commandBufferCount = 1;
5357 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5358 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5359 m_errorMonitor->VerifyFound();
5360 // Now update descriptor to be valid, but then free descriptor
5361 img_info.imageView = view2;
5362 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005364 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005365 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5366 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5367 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005368 Draw(1, 0, 0, 0);
5369 EndCommandBuffer();
5370 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005372 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005373 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005374 // Attempt to submit cmd buffer
5375 submit_info = {};
5376 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5377 submit_info.commandBufferCount = 1;
5378 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5379 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5380 m_errorMonitor->VerifyFound();
5381 // Cleanup
5382 vkFreeMemory(m_device->device(), image_memory, NULL);
5383 vkDestroySampler(m_device->device(), sampler2, NULL);
5384 vkDestroyImage(m_device->device(), image2, NULL);
5385 vkDestroyImageView(m_device->device(), view, NULL);
5386 vkDestroyImageView(m_device->device(), view2, NULL);
5387 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5388 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5389 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5390}
5391
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005392TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5393 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5394 ASSERT_NO_FATAL_FAILURE(InitState());
5395 ASSERT_NO_FATAL_FAILURE(InitViewport());
5396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5397
5398 VkDescriptorPoolSize ds_type_count = {};
5399 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5400 ds_type_count.descriptorCount = 1;
5401
5402 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5403 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5404 ds_pool_ci.pNext = NULL;
5405 ds_pool_ci.maxSets = 1;
5406 ds_pool_ci.poolSizeCount = 1;
5407 ds_pool_ci.pPoolSizes = &ds_type_count;
5408
5409 VkDescriptorPool ds_pool;
5410 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5411 ASSERT_VK_SUCCESS(err);
5412
5413 VkDescriptorSetLayoutBinding dsl_binding = {};
5414 dsl_binding.binding = 0;
5415 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5416 dsl_binding.descriptorCount = 1;
5417 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5418 dsl_binding.pImmutableSamplers = NULL;
5419
5420 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5421 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5422 ds_layout_ci.pNext = NULL;
5423 ds_layout_ci.bindingCount = 1;
5424 ds_layout_ci.pBindings = &dsl_binding;
5425 VkDescriptorSetLayout ds_layout;
5426 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5427 ASSERT_VK_SUCCESS(err);
5428
5429 VkDescriptorSet descriptor_set;
5430 VkDescriptorSetAllocateInfo alloc_info = {};
5431 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5432 alloc_info.descriptorSetCount = 1;
5433 alloc_info.descriptorPool = ds_pool;
5434 alloc_info.pSetLayouts = &ds_layout;
5435 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5436 ASSERT_VK_SUCCESS(err);
5437
5438 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5439 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5440 pipeline_layout_ci.pNext = NULL;
5441 pipeline_layout_ci.setLayoutCount = 1;
5442 pipeline_layout_ci.pSetLayouts = &ds_layout;
5443
5444 VkPipelineLayout pipeline_layout;
5445 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5446 ASSERT_VK_SUCCESS(err);
5447
5448 // Create image to update the descriptor with
5449 VkImageObj image(m_device);
5450 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5451 ASSERT_TRUE(image.initialized());
5452
5453 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5454 // Create Sampler
5455 VkSamplerCreateInfo sampler_ci = {};
5456 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5457 sampler_ci.pNext = NULL;
5458 sampler_ci.magFilter = VK_FILTER_NEAREST;
5459 sampler_ci.minFilter = VK_FILTER_NEAREST;
5460 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5461 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5462 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5463 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5464 sampler_ci.mipLodBias = 1.0;
5465 sampler_ci.anisotropyEnable = VK_FALSE;
5466 sampler_ci.maxAnisotropy = 1;
5467 sampler_ci.compareEnable = VK_FALSE;
5468 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5469 sampler_ci.minLod = 1.0;
5470 sampler_ci.maxLod = 1.0;
5471 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5472 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5473 VkSampler sampler;
5474 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5475 ASSERT_VK_SUCCESS(err);
5476 // Update descriptor with image and sampler
5477 VkDescriptorImageInfo img_info = {};
5478 img_info.sampler = sampler;
5479 img_info.imageView = view;
5480 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5481
5482 VkWriteDescriptorSet descriptor_write;
5483 memset(&descriptor_write, 0, sizeof(descriptor_write));
5484 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5485 descriptor_write.dstSet = descriptor_set;
5486 descriptor_write.dstBinding = 0;
5487 descriptor_write.descriptorCount = 1;
5488 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5489 descriptor_write.pImageInfo = &img_info;
5490
5491 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5492
5493 // Create PSO to be used for draw-time errors below
5494 char const *vsSource = "#version 450\n"
5495 "\n"
5496 "out gl_PerVertex { \n"
5497 " vec4 gl_Position;\n"
5498 "};\n"
5499 "void main(){\n"
5500 " gl_Position = vec4(1);\n"
5501 "}\n";
5502 char const *fsSource = "#version 450\n"
5503 "\n"
5504 "layout(set=0, binding=0) uniform sampler2D s;\n"
5505 "layout(location=0) out vec4 x;\n"
5506 "void main(){\n"
5507 " x = texture(s, vec2(1));\n"
5508 "}\n";
5509 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5510 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5511 VkPipelineObj pipe(m_device);
5512 pipe.AddShader(&vs);
5513 pipe.AddShader(&fs);
5514 pipe.AddColorAttachment();
5515 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5516
5517 BeginCommandBuffer();
5518 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5519 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5520 &descriptor_set, 0, NULL);
5521 Draw(1, 0, 0, 0);
5522 EndCommandBuffer();
5523 // Submit cmd buffer to put pool in-flight
5524 VkSubmitInfo submit_info = {};
5525 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5526 submit_info.commandBufferCount = 1;
5527 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5528 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5529 // Destroy pool while in-flight, causing error
5530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5531 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5532 m_errorMonitor->VerifyFound();
5533 vkQueueWaitIdle(m_device->m_queue);
5534 // Cleanup
5535 vkDestroySampler(m_device->device(), sampler, NULL);
5536 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5537 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5538 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5539}
5540
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005541TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5542 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5543 ASSERT_NO_FATAL_FAILURE(InitState());
5544 ASSERT_NO_FATAL_FAILURE(InitViewport());
5545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5546
5547 VkDescriptorPoolSize ds_type_count = {};
5548 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5549 ds_type_count.descriptorCount = 1;
5550
5551 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5552 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5553 ds_pool_ci.pNext = NULL;
5554 ds_pool_ci.maxSets = 1;
5555 ds_pool_ci.poolSizeCount = 1;
5556 ds_pool_ci.pPoolSizes = &ds_type_count;
5557
5558 VkDescriptorPool ds_pool;
5559 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5560 ASSERT_VK_SUCCESS(err);
5561
5562 VkDescriptorSetLayoutBinding dsl_binding = {};
5563 dsl_binding.binding = 0;
5564 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5565 dsl_binding.descriptorCount = 1;
5566 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5567 dsl_binding.pImmutableSamplers = NULL;
5568
5569 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5570 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5571 ds_layout_ci.pNext = NULL;
5572 ds_layout_ci.bindingCount = 1;
5573 ds_layout_ci.pBindings = &dsl_binding;
5574 VkDescriptorSetLayout ds_layout;
5575 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5576 ASSERT_VK_SUCCESS(err);
5577
5578 VkDescriptorSet descriptorSet;
5579 VkDescriptorSetAllocateInfo alloc_info = {};
5580 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5581 alloc_info.descriptorSetCount = 1;
5582 alloc_info.descriptorPool = ds_pool;
5583 alloc_info.pSetLayouts = &ds_layout;
5584 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5585 ASSERT_VK_SUCCESS(err);
5586
5587 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5588 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5589 pipeline_layout_ci.pNext = NULL;
5590 pipeline_layout_ci.setLayoutCount = 1;
5591 pipeline_layout_ci.pSetLayouts = &ds_layout;
5592
5593 VkPipelineLayout pipeline_layout;
5594 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5595 ASSERT_VK_SUCCESS(err);
5596
5597 // Create images to update the descriptor with
5598 VkImage image;
5599 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5600 const int32_t tex_width = 32;
5601 const int32_t tex_height = 32;
5602 VkImageCreateInfo image_create_info = {};
5603 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5604 image_create_info.pNext = NULL;
5605 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5606 image_create_info.format = tex_format;
5607 image_create_info.extent.width = tex_width;
5608 image_create_info.extent.height = tex_height;
5609 image_create_info.extent.depth = 1;
5610 image_create_info.mipLevels = 1;
5611 image_create_info.arrayLayers = 1;
5612 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5613 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5614 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5615 image_create_info.flags = 0;
5616 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5617 ASSERT_VK_SUCCESS(err);
5618 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5619 VkMemoryRequirements memory_reqs;
5620 VkDeviceMemory image_memory;
5621 bool pass;
5622 VkMemoryAllocateInfo memory_info = {};
5623 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5624 memory_info.pNext = NULL;
5625 memory_info.allocationSize = 0;
5626 memory_info.memoryTypeIndex = 0;
5627 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5628 // Allocate enough memory for image
5629 memory_info.allocationSize = memory_reqs.size;
5630 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5631 ASSERT_TRUE(pass);
5632 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5633 ASSERT_VK_SUCCESS(err);
5634 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5635 ASSERT_VK_SUCCESS(err);
5636
5637 VkImageViewCreateInfo image_view_create_info = {};
5638 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5639 image_view_create_info.image = image;
5640 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5641 image_view_create_info.format = tex_format;
5642 image_view_create_info.subresourceRange.layerCount = 1;
5643 image_view_create_info.subresourceRange.baseMipLevel = 0;
5644 image_view_create_info.subresourceRange.levelCount = 1;
5645 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5646
5647 VkImageView view;
5648 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5649 ASSERT_VK_SUCCESS(err);
5650 // Create Samplers
5651 VkSamplerCreateInfo sampler_ci = {};
5652 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5653 sampler_ci.pNext = NULL;
5654 sampler_ci.magFilter = VK_FILTER_NEAREST;
5655 sampler_ci.minFilter = VK_FILTER_NEAREST;
5656 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5657 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5658 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5659 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5660 sampler_ci.mipLodBias = 1.0;
5661 sampler_ci.anisotropyEnable = VK_FALSE;
5662 sampler_ci.maxAnisotropy = 1;
5663 sampler_ci.compareEnable = VK_FALSE;
5664 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5665 sampler_ci.minLod = 1.0;
5666 sampler_ci.maxLod = 1.0;
5667 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5668 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5669 VkSampler sampler;
5670 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5671 ASSERT_VK_SUCCESS(err);
5672 // Update descriptor with image and sampler
5673 VkDescriptorImageInfo img_info = {};
5674 img_info.sampler = sampler;
5675 img_info.imageView = view;
5676 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5677
5678 VkWriteDescriptorSet descriptor_write;
5679 memset(&descriptor_write, 0, sizeof(descriptor_write));
5680 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5681 descriptor_write.dstSet = descriptorSet;
5682 descriptor_write.dstBinding = 0;
5683 descriptor_write.descriptorCount = 1;
5684 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5685 descriptor_write.pImageInfo = &img_info;
5686 // Break memory binding and attempt update
5687 vkFreeMemory(m_device->device(), image_memory, nullptr);
5688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005689 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5691 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5692 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5693 m_errorMonitor->VerifyFound();
5694 // Cleanup
5695 vkDestroyImage(m_device->device(), image, NULL);
5696 vkDestroySampler(m_device->device(), sampler, NULL);
5697 vkDestroyImageView(m_device->device(), view, NULL);
5698 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5699 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5700 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5701}
5702
Karl Schultz6addd812016-02-02 17:17:23 -07005703TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005704 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5705 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005706 // Create a valid cmd buffer
5707 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005708 uint64_t fake_pipeline_handle = 0xbaad6001;
5709 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005710 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005711 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5712
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Karl Schultzbdb75952016-04-19 11:36:49 -06005714 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005715 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005716 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005717
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005718 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005720 Draw(1, 0, 0, 0);
5721 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005722
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005723 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005725 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005726 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5727 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005728}
5729
Karl Schultz6addd812016-02-02 17:17:23 -07005730TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005731 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005732 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005735
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005736 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005737 ASSERT_NO_FATAL_FAILURE(InitViewport());
5738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005739 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005740 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5741 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005742
5743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5745 ds_pool_ci.pNext = NULL;
5746 ds_pool_ci.maxSets = 1;
5747 ds_pool_ci.poolSizeCount = 1;
5748 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005749
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005750 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005751 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005752 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005753
Tony Barboureb254902015-07-15 12:50:33 -06005754 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005755 dsl_binding.binding = 0;
5756 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5757 dsl_binding.descriptorCount = 1;
5758 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5759 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005760
Tony Barboureb254902015-07-15 12:50:33 -06005761 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005762 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5763 ds_layout_ci.pNext = NULL;
5764 ds_layout_ci.bindingCount = 1;
5765 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005766 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005767 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005768 ASSERT_VK_SUCCESS(err);
5769
5770 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005771 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005772 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005773 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005774 alloc_info.descriptorPool = ds_pool;
5775 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005776 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005777 ASSERT_VK_SUCCESS(err);
5778
Tony Barboureb254902015-07-15 12:50:33 -06005779 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005780 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5781 pipeline_layout_ci.pNext = NULL;
5782 pipeline_layout_ci.setLayoutCount = 1;
5783 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005784
5785 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005786 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005787 ASSERT_VK_SUCCESS(err);
5788
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005789 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005790 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005791 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005792 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005793
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005794 VkPipelineObj pipe(m_device);
5795 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005796 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005797 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005798 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005799
5800 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005801 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5802 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5803 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005804
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005805 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005806
Chia-I Wuf7458c52015-10-26 21:10:41 +08005807 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5808 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5809 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005810}
5811
Karl Schultz6addd812016-02-02 17:17:23 -07005812TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005813 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005814 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005815
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005817
5818 ASSERT_NO_FATAL_FAILURE(InitState());
5819 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005820 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5821 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005822
5823 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005824 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5825 ds_pool_ci.pNext = NULL;
5826 ds_pool_ci.maxSets = 1;
5827 ds_pool_ci.poolSizeCount = 1;
5828 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005829
5830 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005831 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005832 ASSERT_VK_SUCCESS(err);
5833
5834 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005835 dsl_binding.binding = 0;
5836 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5837 dsl_binding.descriptorCount = 1;
5838 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5839 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005840
5841 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005842 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5843 ds_layout_ci.pNext = NULL;
5844 ds_layout_ci.bindingCount = 1;
5845 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005846 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005847 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005848 ASSERT_VK_SUCCESS(err);
5849
5850 VkDescriptorSet descriptorSet;
5851 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005852 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005853 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005854 alloc_info.descriptorPool = ds_pool;
5855 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005856 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005857 ASSERT_VK_SUCCESS(err);
5858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005859 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005860 VkWriteDescriptorSet descriptor_write;
5861 memset(&descriptor_write, 0, sizeof(descriptor_write));
5862 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5863 descriptor_write.dstSet = descriptorSet;
5864 descriptor_write.dstBinding = 0;
5865 descriptor_write.descriptorCount = 1;
5866 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5867 descriptor_write.pTexelBufferView = &view;
5868
5869 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5870
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005871 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005872
5873 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5874 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5875}
5876
Mark Youngd339ba32016-05-30 13:28:35 -06005877TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005878 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has no memory bound to it.");
Mark Youngd339ba32016-05-30 13:28:35 -06005879
5880 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005882 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005883
5884 ASSERT_NO_FATAL_FAILURE(InitState());
5885
5886 // Create a buffer with no bound memory and then attempt to create
5887 // a buffer view.
5888 VkBufferCreateInfo buff_ci = {};
5889 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005890 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005891 buff_ci.size = 256;
5892 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5893 VkBuffer buffer;
5894 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5895 ASSERT_VK_SUCCESS(err);
5896
5897 VkBufferViewCreateInfo buff_view_ci = {};
5898 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5899 buff_view_ci.buffer = buffer;
5900 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5901 buff_view_ci.range = VK_WHOLE_SIZE;
5902 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005903 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005904
5905 m_errorMonitor->VerifyFound();
5906 vkDestroyBuffer(m_device->device(), buffer, NULL);
5907 // If last error is success, it still created the view, so delete it.
5908 if (err == VK_SUCCESS) {
5909 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5910 }
5911}
5912
Karl Schultz6addd812016-02-02 17:17:23 -07005913TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5914 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5915 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005916 // 1. No dynamicOffset supplied
5917 // 2. Too many dynamicOffsets supplied
5918 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005919 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5921 "0 dynamicOffsets are left in "
5922 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005923
5924 ASSERT_NO_FATAL_FAILURE(InitState());
5925 ASSERT_NO_FATAL_FAILURE(InitViewport());
5926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5927
5928 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005929 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5930 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005931
5932 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005933 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5934 ds_pool_ci.pNext = NULL;
5935 ds_pool_ci.maxSets = 1;
5936 ds_pool_ci.poolSizeCount = 1;
5937 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005938
5939 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005940 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005941 ASSERT_VK_SUCCESS(err);
5942
5943 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005944 dsl_binding.binding = 0;
5945 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5946 dsl_binding.descriptorCount = 1;
5947 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5948 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005949
5950 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005951 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5952 ds_layout_ci.pNext = NULL;
5953 ds_layout_ci.bindingCount = 1;
5954 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005955 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005956 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005957 ASSERT_VK_SUCCESS(err);
5958
5959 VkDescriptorSet descriptorSet;
5960 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005961 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005962 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005963 alloc_info.descriptorPool = ds_pool;
5964 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005965 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005966 ASSERT_VK_SUCCESS(err);
5967
5968 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005969 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5970 pipeline_layout_ci.pNext = NULL;
5971 pipeline_layout_ci.setLayoutCount = 1;
5972 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005973
5974 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005975 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005976 ASSERT_VK_SUCCESS(err);
5977
5978 // Create a buffer to update the descriptor with
5979 uint32_t qfi = 0;
5980 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005981 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5982 buffCI.size = 1024;
5983 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5984 buffCI.queueFamilyIndexCount = 1;
5985 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005986
5987 VkBuffer dyub;
5988 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5989 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005990 // Allocate memory and bind to buffer so we can make it to the appropriate
5991 // error
5992 VkMemoryAllocateInfo mem_alloc = {};
5993 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5994 mem_alloc.pNext = NULL;
5995 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005996 mem_alloc.memoryTypeIndex = 0;
5997
5998 VkMemoryRequirements memReqs;
5999 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006000 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006001 if (!pass) {
6002 vkDestroyBuffer(m_device->device(), dyub, NULL);
6003 return;
6004 }
6005
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006006 VkDeviceMemory mem;
6007 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6008 ASSERT_VK_SUCCESS(err);
6009 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6010 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006011 // Correctly update descriptor to avoid "NOT_UPDATED" error
6012 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006013 buffInfo.buffer = dyub;
6014 buffInfo.offset = 0;
6015 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006016
6017 VkWriteDescriptorSet descriptor_write;
6018 memset(&descriptor_write, 0, sizeof(descriptor_write));
6019 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6020 descriptor_write.dstSet = descriptorSet;
6021 descriptor_write.dstBinding = 0;
6022 descriptor_write.descriptorCount = 1;
6023 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6024 descriptor_write.pBufferInfo = &buffInfo;
6025
6026 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6027
6028 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006029 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6030 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006031 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006032 uint32_t pDynOff[2] = {512, 756};
6033 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6035 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6036 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6037 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006038 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006039 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
6041 "offset 0 and range 1024 that "
6042 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006043 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006044 char const *vsSource = "#version 450\n"
6045 "\n"
6046 "out gl_PerVertex { \n"
6047 " vec4 gl_Position;\n"
6048 "};\n"
6049 "void main(){\n"
6050 " gl_Position = vec4(1);\n"
6051 "}\n";
6052 char const *fsSource = "#version 450\n"
6053 "\n"
6054 "layout(location=0) out vec4 x;\n"
6055 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6056 "void main(){\n"
6057 " x = vec4(bar.y);\n"
6058 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006059 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6060 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6061 VkPipelineObj pipe(m_device);
6062 pipe.AddShader(&vs);
6063 pipe.AddShader(&fs);
6064 pipe.AddColorAttachment();
6065 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6066
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006067 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6068 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6069 VkRect2D scissor = {{0, 0}, {16, 16}};
6070 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6071
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006072 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006073 // This update should succeed, but offset size of 512 will overstep buffer
6074 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006075 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6076 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006077 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006078 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006079
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006080 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006081 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006082
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006083 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006084 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006085 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6086}
6087
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006088TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6089 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6090 "that doesn't have memory bound");
6091 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006093 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6095 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006096
6097 ASSERT_NO_FATAL_FAILURE(InitState());
6098 ASSERT_NO_FATAL_FAILURE(InitViewport());
6099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6100
6101 VkDescriptorPoolSize ds_type_count = {};
6102 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6103 ds_type_count.descriptorCount = 1;
6104
6105 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6106 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6107 ds_pool_ci.pNext = NULL;
6108 ds_pool_ci.maxSets = 1;
6109 ds_pool_ci.poolSizeCount = 1;
6110 ds_pool_ci.pPoolSizes = &ds_type_count;
6111
6112 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006113 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006114 ASSERT_VK_SUCCESS(err);
6115
6116 VkDescriptorSetLayoutBinding dsl_binding = {};
6117 dsl_binding.binding = 0;
6118 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6119 dsl_binding.descriptorCount = 1;
6120 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6121 dsl_binding.pImmutableSamplers = NULL;
6122
6123 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6124 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6125 ds_layout_ci.pNext = NULL;
6126 ds_layout_ci.bindingCount = 1;
6127 ds_layout_ci.pBindings = &dsl_binding;
6128 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006129 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006130 ASSERT_VK_SUCCESS(err);
6131
6132 VkDescriptorSet descriptorSet;
6133 VkDescriptorSetAllocateInfo alloc_info = {};
6134 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6135 alloc_info.descriptorSetCount = 1;
6136 alloc_info.descriptorPool = ds_pool;
6137 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006138 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006139 ASSERT_VK_SUCCESS(err);
6140
6141 // Create a buffer to update the descriptor with
6142 uint32_t qfi = 0;
6143 VkBufferCreateInfo buffCI = {};
6144 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6145 buffCI.size = 1024;
6146 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6147 buffCI.queueFamilyIndexCount = 1;
6148 buffCI.pQueueFamilyIndices = &qfi;
6149
6150 VkBuffer dyub;
6151 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6152 ASSERT_VK_SUCCESS(err);
6153
6154 // Attempt to update descriptor without binding memory to it
6155 VkDescriptorBufferInfo buffInfo = {};
6156 buffInfo.buffer = dyub;
6157 buffInfo.offset = 0;
6158 buffInfo.range = 1024;
6159
6160 VkWriteDescriptorSet descriptor_write;
6161 memset(&descriptor_write, 0, sizeof(descriptor_write));
6162 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6163 descriptor_write.dstSet = descriptorSet;
6164 descriptor_write.dstBinding = 0;
6165 descriptor_write.descriptorCount = 1;
6166 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6167 descriptor_write.pBufferInfo = &buffInfo;
6168
6169 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6170 m_errorMonitor->VerifyFound();
6171
6172 vkDestroyBuffer(m_device->device(), dyub, NULL);
6173 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6174 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6175}
6176
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006177TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006178 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006179 ASSERT_NO_FATAL_FAILURE(InitState());
6180 ASSERT_NO_FATAL_FAILURE(InitViewport());
6181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6182
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006183 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006184 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006185 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6186 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6187 pipeline_layout_ci.pushConstantRangeCount = 1;
6188 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6189
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006190 //
6191 // Check for invalid push constant ranges in pipeline layouts.
6192 //
6193 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006194 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006195 char const *msg;
6196 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006197
Karl Schultzc81037d2016-05-12 08:11:23 -06006198 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6199 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6200 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6201 "vkCreatePipelineLayout() call has push constants index 0 with "
6202 "size 0."},
6203 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6204 "vkCreatePipelineLayout() call has push constants index 0 with "
6205 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006206 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006207 "vkCreatePipelineLayout() call has push constants index 0 with "
6208 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006209 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006210 "vkCreatePipelineLayout() call has push constants index 0 with "
6211 "size 0."},
6212 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6213 "vkCreatePipelineLayout() call has push constants index 0 with "
6214 "offset 1. Offset must"},
6215 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6216 "vkCreatePipelineLayout() call has push constants index 0 "
6217 "with offset "},
6218 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6219 "vkCreatePipelineLayout() call has push constants "
6220 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006221 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006222 "vkCreatePipelineLayout() call has push constants index 0 "
6223 "with offset "},
6224 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6225 "vkCreatePipelineLayout() call has push "
6226 "constants index 0 with offset "},
6227 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6228 "vkCreatePipelineLayout() call has push "
6229 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006230 }};
6231
6232 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006233 for (const auto &iter : range_tests) {
6234 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6236 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006237 m_errorMonitor->VerifyFound();
6238 if (VK_SUCCESS == err) {
6239 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6240 }
6241 }
6242
6243 // Check for invalid stage flag
6244 pc_range.offset = 0;
6245 pc_range.size = 16;
6246 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006247 m_errorMonitor->SetDesiredFailureMsg(
6248 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6249 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006250 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006251 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006252 if (VK_SUCCESS == err) {
6253 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6254 }
6255
6256 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006257 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006258 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006259 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006260 char const *msg;
6261 };
6262
Karl Schultzc81037d2016-05-12 08:11:23 -06006263 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006264 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6265 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6266 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6267 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6268 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006269 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006270 {
6271 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6272 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6273 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6274 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6275 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006276 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006277 },
6278 {
6279 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6280 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6281 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6282 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6283 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006284 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006285 },
6286 {
6287 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6288 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6289 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6290 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6291 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006292 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006293 },
6294 {
6295 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6296 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6297 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6298 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6299 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006300 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006301 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006302
Karl Schultzc81037d2016-05-12 08:11:23 -06006303 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006304 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006305 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6307 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006308 m_errorMonitor->VerifyFound();
6309 if (VK_SUCCESS == err) {
6310 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6311 }
6312 }
6313
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006314 //
6315 // CmdPushConstants tests
6316 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006317 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006318
6319 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006320 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6321 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006322 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6323 "vkCmdPushConstants() call has push constants with size 1. Size "
6324 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006325 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006326 "vkCmdPushConstants() call has push constants with size 1. Size "
6327 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006328 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006329 "vkCmdPushConstants() call has push constants with offset 1. "
6330 "Offset must be a multiple of 4."},
6331 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6332 "vkCmdPushConstants() call has push constants with offset 1. "
6333 "Offset must be a multiple of 4."},
6334 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6335 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6336 "0x1 not within flag-matching ranges in pipeline layout"},
6337 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6338 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6339 "0x1 not within flag-matching ranges in pipeline layout"},
6340 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6341 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6342 "0x1 not within flag-matching ranges in pipeline layout"},
6343 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6344 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6345 "0x1 not within flag-matching ranges in pipeline layout"},
6346 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6347 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6348 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006349 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006350 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6351 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006352 }};
6353
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006354 BeginCommandBuffer();
6355
6356 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006357 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006358 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006359 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006360 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006361 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006362 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006363 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006364 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6366 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006367 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006368 m_errorMonitor->VerifyFound();
6369 }
6370
6371 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006373 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006374 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006375 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006376
Karl Schultzc81037d2016-05-12 08:11:23 -06006377 // overlapping range tests with cmd
6378 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6379 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6380 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6381 "0x1 not within flag-matching ranges in pipeline layout"},
6382 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6383 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6384 "0x1 not within flag-matching ranges in pipeline layout"},
6385 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6386 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6387 "0x1 not within flag-matching ranges in pipeline layout"},
6388 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006389 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006390 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006391 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6392 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006393 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006394 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006395 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006396 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006397 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006398 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6400 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006401 iter.range.size, dummy_values);
6402 m_errorMonitor->VerifyFound();
6403 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006404 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6405
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006406 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006407}
6408
Karl Schultz6addd812016-02-02 17:17:23 -07006409TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006410 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006411 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006412
6413 ASSERT_NO_FATAL_FAILURE(InitState());
6414 ASSERT_NO_FATAL_FAILURE(InitViewport());
6415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6416
Mike Stroyanb8a61002016-06-20 16:00:28 -06006417 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6418 VkImageTiling tiling;
6419 VkFormatProperties format_properties;
6420 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006421 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006422 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006423 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006424 tiling = VK_IMAGE_TILING_OPTIMAL;
6425 } else {
6426 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6427 "skipped.\n");
6428 return;
6429 }
6430
Tobin Ehlis559c6382015-11-05 09:52:49 -07006431 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6432 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006433 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6434 ds_type_count[0].descriptorCount = 10;
6435 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6436 ds_type_count[1].descriptorCount = 2;
6437 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6438 ds_type_count[2].descriptorCount = 2;
6439 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6440 ds_type_count[3].descriptorCount = 5;
6441 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6442 // type
6443 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6444 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6445 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006446
6447 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006448 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6449 ds_pool_ci.pNext = NULL;
6450 ds_pool_ci.maxSets = 5;
6451 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6452 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006453
6454 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006455 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006456 ASSERT_VK_SUCCESS(err);
6457
6458 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6459 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006460 dsl_binding[0].binding = 0;
6461 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6462 dsl_binding[0].descriptorCount = 5;
6463 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6464 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006465
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006466 // Create layout identical to set0 layout but w/ different stageFlags
6467 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006468 dsl_fs_stage_only.binding = 0;
6469 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6470 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006471 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6472 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006473 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006474 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006475 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6476 ds_layout_ci.pNext = NULL;
6477 ds_layout_ci.bindingCount = 1;
6478 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006479 static const uint32_t NUM_LAYOUTS = 4;
6480 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006481 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006482 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6483 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006484 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006485 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006486 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006487 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006488 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006489 dsl_binding[0].binding = 0;
6490 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006491 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006492 dsl_binding[1].binding = 1;
6493 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6494 dsl_binding[1].descriptorCount = 2;
6495 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6496 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006497 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006498 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006499 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006500 ASSERT_VK_SUCCESS(err);
6501 dsl_binding[0].binding = 0;
6502 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006503 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006504 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006505 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006506 ASSERT_VK_SUCCESS(err);
6507 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006508 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006509 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006510 ASSERT_VK_SUCCESS(err);
6511
6512 static const uint32_t NUM_SETS = 4;
6513 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6514 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006515 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006516 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006517 alloc_info.descriptorPool = ds_pool;
6518 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006519 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006520 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006521 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006522 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006523 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006524 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006525 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006526
6527 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006528 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6529 pipeline_layout_ci.pNext = NULL;
6530 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6531 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006532
6533 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006534 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006535 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006536 // Create pipelineLayout with only one setLayout
6537 pipeline_layout_ci.setLayoutCount = 1;
6538 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006539 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006540 ASSERT_VK_SUCCESS(err);
6541 // Create pipelineLayout with 2 descriptor setLayout at index 0
6542 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6543 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006544 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006545 ASSERT_VK_SUCCESS(err);
6546 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6547 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6548 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006549 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006550 ASSERT_VK_SUCCESS(err);
6551 // Create pipelineLayout with UB type, but stageFlags for FS only
6552 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6553 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006554 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006555 ASSERT_VK_SUCCESS(err);
6556 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6557 VkDescriptorSetLayout pl_bad_s0[2] = {};
6558 pl_bad_s0[0] = ds_layout_fs_only;
6559 pl_bad_s0[1] = ds_layout[1];
6560 pipeline_layout_ci.setLayoutCount = 2;
6561 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6562 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006563 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006564 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006565
6566 // Create a buffer to update the descriptor with
6567 uint32_t qfi = 0;
6568 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006569 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6570 buffCI.size = 1024;
6571 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6572 buffCI.queueFamilyIndexCount = 1;
6573 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006574
6575 VkBuffer dyub;
6576 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6577 ASSERT_VK_SUCCESS(err);
6578 // Correctly update descriptor to avoid "NOT_UPDATED" error
6579 static const uint32_t NUM_BUFFS = 5;
6580 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006581 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006582 buffInfo[i].buffer = dyub;
6583 buffInfo[i].offset = 0;
6584 buffInfo[i].range = 1024;
6585 }
Karl Schultz6addd812016-02-02 17:17:23 -07006586 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006587 const int32_t tex_width = 32;
6588 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006589 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006590 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6591 image_create_info.pNext = NULL;
6592 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6593 image_create_info.format = tex_format;
6594 image_create_info.extent.width = tex_width;
6595 image_create_info.extent.height = tex_height;
6596 image_create_info.extent.depth = 1;
6597 image_create_info.mipLevels = 1;
6598 image_create_info.arrayLayers = 1;
6599 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006600 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006601 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006602 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006603 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6604 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006605
Karl Schultz6addd812016-02-02 17:17:23 -07006606 VkMemoryRequirements memReqs;
6607 VkDeviceMemory imageMem;
6608 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006609 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006610 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6611 memAlloc.pNext = NULL;
6612 memAlloc.allocationSize = 0;
6613 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006614 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6615 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006616 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006617 ASSERT_TRUE(pass);
6618 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6619 ASSERT_VK_SUCCESS(err);
6620 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6621 ASSERT_VK_SUCCESS(err);
6622
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006623 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006624 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6625 image_view_create_info.image = image;
6626 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6627 image_view_create_info.format = tex_format;
6628 image_view_create_info.subresourceRange.layerCount = 1;
6629 image_view_create_info.subresourceRange.baseMipLevel = 0;
6630 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006631 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006632
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006633 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006634 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006635 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006636 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006637 imageInfo[0].imageView = view;
6638 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6639 imageInfo[1].imageView = view;
6640 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006641 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006642 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006643 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006644 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006645
6646 static const uint32_t NUM_SET_UPDATES = 3;
6647 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6648 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6649 descriptor_write[0].dstSet = descriptorSet[0];
6650 descriptor_write[0].dstBinding = 0;
6651 descriptor_write[0].descriptorCount = 5;
6652 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6653 descriptor_write[0].pBufferInfo = buffInfo;
6654 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6655 descriptor_write[1].dstSet = descriptorSet[1];
6656 descriptor_write[1].dstBinding = 0;
6657 descriptor_write[1].descriptorCount = 2;
6658 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6659 descriptor_write[1].pImageInfo = imageInfo;
6660 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6661 descriptor_write[2].dstSet = descriptorSet[1];
6662 descriptor_write[2].dstBinding = 1;
6663 descriptor_write[2].descriptorCount = 2;
6664 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006665 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006666
6667 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006668
Tobin Ehlis88452832015-12-03 09:40:56 -07006669 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006670 char const *vsSource = "#version 450\n"
6671 "\n"
6672 "out gl_PerVertex {\n"
6673 " vec4 gl_Position;\n"
6674 "};\n"
6675 "void main(){\n"
6676 " gl_Position = vec4(1);\n"
6677 "}\n";
6678 char const *fsSource = "#version 450\n"
6679 "\n"
6680 "layout(location=0) out vec4 x;\n"
6681 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6682 "void main(){\n"
6683 " x = vec4(bar.y);\n"
6684 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006685 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6686 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006687 VkPipelineObj pipe(m_device);
6688 pipe.AddShader(&vs);
6689 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006690 pipe.AddColorAttachment();
6691 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006692
6693 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006694
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006695 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006696 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6697 // of PSO
6698 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6699 // cmd_pipeline.c
6700 // due to the fact that cmd_alloc_dset_data() has not been called in
6701 // cmd_bind_graphics_pipeline()
6702 // TODO : Want to cause various binding incompatibility issues here to test
6703 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006704 // First cause various verify_layout_compatibility() fails
6705 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006706 // verify_set_layout_compatibility fail cases:
6707 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006709 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6710 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006711 m_errorMonitor->VerifyFound();
6712
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006713 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6715 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6716 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006717 m_errorMonitor->VerifyFound();
6718
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006719 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006720 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6721 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6723 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6724 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006725 m_errorMonitor->VerifyFound();
6726
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006727 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6728 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6730 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6731 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006732 m_errorMonitor->VerifyFound();
6733
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006734 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6735 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6737 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6738 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6739 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006740 m_errorMonitor->VerifyFound();
6741
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006742 // Cause INFO messages due to disturbing previously bound Sets
6743 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006744 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6745 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006746 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6748 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6749 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006750 m_errorMonitor->VerifyFound();
6751
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006752 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6753 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006754 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6756 "any subsequent sets were disturbed ");
6757 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6758 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006759 m_errorMonitor->VerifyFound();
6760
Tobin Ehlis10fad692016-07-07 12:00:36 -06006761 // Now that we're done actively using the pipelineLayout that gfx pipeline
6762 // was created with, we should be able to delete it. Do that now to verify
6763 // that validation obeys pipelineLayout lifetime
6764 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6765
Tobin Ehlis88452832015-12-03 09:40:56 -07006766 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006767 // 1. Error due to not binding required set (we actually use same code as
6768 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006769 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6770 &descriptorSet[0], 0, NULL);
6771 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6772 &descriptorSet[1], 0, NULL);
6773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006774 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006775 m_errorMonitor->VerifyFound();
6776
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006777 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006778 // 2. Error due to bound set not being compatible with PSO's
6779 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006780 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6781 &descriptorSet[0], 0, NULL);
6782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006783 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006784 m_errorMonitor->VerifyFound();
6785
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006786 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006787 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006788 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6789 }
6790 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006791 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006792 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6793 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006794 vkFreeMemory(m_device->device(), imageMem, NULL);
6795 vkDestroyImage(m_device->device(), image, NULL);
6796 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006797}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006798
Karl Schultz6addd812016-02-02 17:17:23 -07006799TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006800
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6802 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006803
6804 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006805 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006806 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006807 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006808
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006809 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006810}
6811
Karl Schultz6addd812016-02-02 17:17:23 -07006812TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6813 VkResult err;
6814 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006815
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006817
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006818 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006819
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006820 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006821 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006822 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006823 cmd.commandPool = m_commandPool;
6824 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006825 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006826
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006827 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006828 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006829
6830 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006831 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006832 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006833 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006834 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006835 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006836 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006837
6838 // The error should be caught by validation of the BeginCommandBuffer call
6839 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6840
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006841 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006842 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006843}
6844
Karl Schultz6addd812016-02-02 17:17:23 -07006845TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006846 // Cause error due to Begin while recording CB
6847 // Then cause 2 errors for attempting to reset CB w/o having
6848 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6849 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006851
6852 ASSERT_NO_FATAL_FAILURE(InitState());
6853
6854 // Calls AllocateCommandBuffers
6855 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6856
Karl Schultz6addd812016-02-02 17:17:23 -07006857 // Force the failure by setting the Renderpass and Framebuffer fields with
6858 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006859 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006860 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006861 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6862 cmd_buf_info.pNext = NULL;
6863 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006864 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006865
6866 // Begin CB to transition to recording state
6867 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6868 // Can't re-begin. This should trigger error
6869 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006870 m_errorMonitor->VerifyFound();
6871
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006873 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6874 // Reset attempt will trigger error due to incorrect CommandPool state
6875 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006876 m_errorMonitor->VerifyFound();
6877
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006879 // Transition CB to RECORDED state
6880 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6881 // Now attempting to Begin will implicitly reset, which triggers error
6882 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006883 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006884}
6885
Karl Schultz6addd812016-02-02 17:17:23 -07006886TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006887 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006888 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006889
Mike Weiblencce7ec72016-10-17 19:33:05 -06006890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006891
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006892 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006894
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006895 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006896 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6897 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006898
6899 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006900 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6901 ds_pool_ci.pNext = NULL;
6902 ds_pool_ci.maxSets = 1;
6903 ds_pool_ci.poolSizeCount = 1;
6904 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006905
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006906 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006907 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006908 ASSERT_VK_SUCCESS(err);
6909
Tony Barboureb254902015-07-15 12:50:33 -06006910 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006911 dsl_binding.binding = 0;
6912 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6913 dsl_binding.descriptorCount = 1;
6914 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6915 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006916
Tony Barboureb254902015-07-15 12:50:33 -06006917 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006918 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6919 ds_layout_ci.pNext = NULL;
6920 ds_layout_ci.bindingCount = 1;
6921 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006922
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006923 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006924 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006925 ASSERT_VK_SUCCESS(err);
6926
6927 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006928 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006929 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006930 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006931 alloc_info.descriptorPool = ds_pool;
6932 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006933 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006934 ASSERT_VK_SUCCESS(err);
6935
Tony Barboureb254902015-07-15 12:50:33 -06006936 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006937 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6938 pipeline_layout_ci.setLayoutCount = 1;
6939 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006940
6941 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006942 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006943 ASSERT_VK_SUCCESS(err);
6944
Tobin Ehlise68360f2015-10-01 11:15:13 -06006945 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006946 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006947
6948 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006949 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6950 vp_state_ci.scissorCount = 1;
6951 vp_state_ci.pScissors = &sc;
6952 vp_state_ci.viewportCount = 1;
6953 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006954
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006955 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6956 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6957 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6958 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6959 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6960 rs_state_ci.depthClampEnable = VK_FALSE;
6961 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6962 rs_state_ci.depthBiasEnable = VK_FALSE;
6963
Tony Barboureb254902015-07-15 12:50:33 -06006964 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006965 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6966 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006967 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006968 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6969 gp_ci.layout = pipeline_layout;
6970 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006971
6972 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006973 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6974 pc_ci.initialDataSize = 0;
6975 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006976
6977 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006978 VkPipelineCache pipelineCache;
6979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006980 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006981 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006982 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006983
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006984 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006985
Chia-I Wuf7458c52015-10-26 21:10:41 +08006986 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6987 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6988 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6989 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006990}
Tobin Ehlis912df022015-09-17 08:46:18 -06006991/*// TODO : This test should be good, but needs Tess support in compiler to run
6992TEST_F(VkLayerTest, InvalidPatchControlPoints)
6993{
6994 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006995 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006996
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006998 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6999primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007000
Tobin Ehlis912df022015-09-17 08:46:18 -06007001 ASSERT_NO_FATAL_FAILURE(InitState());
7002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007003
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007004 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007005 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007006 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007007
7008 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7009 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7010 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007011 ds_pool_ci.poolSizeCount = 1;
7012 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007013
7014 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007015 err = vkCreateDescriptorPool(m_device->device(),
7016VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007017 ASSERT_VK_SUCCESS(err);
7018
7019 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007020 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007021 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007022 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007023 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7024 dsl_binding.pImmutableSamplers = NULL;
7025
7026 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007027 ds_layout_ci.sType =
7028VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007029 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007030 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007031 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007032
7033 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007034 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7035&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007036 ASSERT_VK_SUCCESS(err);
7037
7038 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007039 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7040VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007041 ASSERT_VK_SUCCESS(err);
7042
7043 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007044 pipeline_layout_ci.sType =
7045VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007046 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007047 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007048 pipeline_layout_ci.pSetLayouts = &ds_layout;
7049
7050 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007051 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7052&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007053 ASSERT_VK_SUCCESS(err);
7054
7055 VkPipelineShaderStageCreateInfo shaderStages[3];
7056 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7057
Karl Schultz6addd812016-02-02 17:17:23 -07007058 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7059this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007060 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007061 VkShaderObj
7062tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7063this);
7064 VkShaderObj
7065te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7066this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007067
Karl Schultz6addd812016-02-02 17:17:23 -07007068 shaderStages[0].sType =
7069VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007070 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007071 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007072 shaderStages[1].sType =
7073VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007074 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007075 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007076 shaderStages[2].sType =
7077VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007078 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007079 shaderStages[2].shader = te.handle();
7080
7081 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007082 iaCI.sType =
7083VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007084 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007085
7086 VkPipelineTessellationStateCreateInfo tsCI = {};
7087 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7088 tsCI.patchControlPoints = 0; // This will cause an error
7089
7090 VkGraphicsPipelineCreateInfo gp_ci = {};
7091 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7092 gp_ci.pNext = NULL;
7093 gp_ci.stageCount = 3;
7094 gp_ci.pStages = shaderStages;
7095 gp_ci.pVertexInputState = NULL;
7096 gp_ci.pInputAssemblyState = &iaCI;
7097 gp_ci.pTessellationState = &tsCI;
7098 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007099 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007100 gp_ci.pMultisampleState = NULL;
7101 gp_ci.pDepthStencilState = NULL;
7102 gp_ci.pColorBlendState = NULL;
7103 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7104 gp_ci.layout = pipeline_layout;
7105 gp_ci.renderPass = renderPass();
7106
7107 VkPipelineCacheCreateInfo pc_ci = {};
7108 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7109 pc_ci.pNext = NULL;
7110 pc_ci.initialSize = 0;
7111 pc_ci.initialData = 0;
7112 pc_ci.maxSize = 0;
7113
7114 VkPipeline pipeline;
7115 VkPipelineCache pipelineCache;
7116
Karl Schultz6addd812016-02-02 17:17:23 -07007117 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7118&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007119 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007120 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7121&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007122
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007123 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007124
Chia-I Wuf7458c52015-10-26 21:10:41 +08007125 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7126 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7127 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7128 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007129}
7130*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007131
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007132TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007133 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007135 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007136
Tobin Ehlise68360f2015-10-01 11:15:13 -06007137 ASSERT_NO_FATAL_FAILURE(InitState());
7138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007139
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007140 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007141 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7142 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007143
7144 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007145 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7146 ds_pool_ci.maxSets = 1;
7147 ds_pool_ci.poolSizeCount = 1;
7148 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007149
7150 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007151 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007152 ASSERT_VK_SUCCESS(err);
7153
7154 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007155 dsl_binding.binding = 0;
7156 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7157 dsl_binding.descriptorCount = 1;
7158 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007159
7160 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007161 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7162 ds_layout_ci.bindingCount = 1;
7163 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007164
7165 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007166 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007167 ASSERT_VK_SUCCESS(err);
7168
7169 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007170 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007171 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007172 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007173 alloc_info.descriptorPool = ds_pool;
7174 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007175 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007176 ASSERT_VK_SUCCESS(err);
7177
7178 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007179 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7180 pipeline_layout_ci.setLayoutCount = 1;
7181 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007182
7183 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007184 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007185 ASSERT_VK_SUCCESS(err);
7186
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007187 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007188 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007189 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007190 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007191 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007192 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007193
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007194 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7195 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7196 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7197 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7198 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7199 rs_state_ci.depthClampEnable = VK_FALSE;
7200 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7201 rs_state_ci.depthBiasEnable = VK_FALSE;
7202
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007203 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7204 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7205 vi_ci.pNext = nullptr;
7206 vi_ci.vertexBindingDescriptionCount = 0;
7207 vi_ci.pVertexBindingDescriptions = nullptr;
7208 vi_ci.vertexAttributeDescriptionCount = 0;
7209 vi_ci.pVertexAttributeDescriptions = nullptr;
7210
7211 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7212 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7213 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7214
7215 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7216 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7217 pipe_ms_state_ci.pNext = NULL;
7218 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7219 pipe_ms_state_ci.sampleShadingEnable = 0;
7220 pipe_ms_state_ci.minSampleShading = 1.0;
7221 pipe_ms_state_ci.pSampleMask = NULL;
7222
Cody Northropeb3a6c12015-10-05 14:44:45 -06007223 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007224 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007225
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007226 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007227 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007228 shaderStages[0] = vs.GetStageCreateInfo();
7229 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007230
7231 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007232 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7233 gp_ci.stageCount = 2;
7234 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007235 gp_ci.pVertexInputState = &vi_ci;
7236 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007237 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007238 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007239 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007240 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7241 gp_ci.layout = pipeline_layout;
7242 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007243
7244 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007245 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007246
7247 VkPipeline pipeline;
7248 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007249 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007250 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007251
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007252 if (!m_device->phy().features().multiViewport) {
7253 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7254
7255 // Check case where multiViewport is disabled and viewport count is not 1
7256 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7259 vp_state_ci.scissorCount = 0;
7260 vp_state_ci.viewportCount = 0;
7261 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7262 m_errorMonitor->VerifyFound();
7263 } else {
7264 if (m_device->props.limits.maxViewports == 1) {
7265 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7266 } else {
7267 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7268
7269 // Check is that viewportcount and scissorcount match
7270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7271 vp_state_ci.scissorCount = 1;
7272 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7273 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7274 m_errorMonitor->VerifyFound();
7275
7276
7277 // Check case where multiViewport is enabled and viewport count is greater than max
7278 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7281 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7282 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7283 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7284 m_errorMonitor->VerifyFound();
7285 }
7286 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007287
Chia-I Wuf7458c52015-10-26 21:10:41 +08007288 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7289 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7290 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7291 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007292}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007293
7294// Don't set viewport state in PSO. This is an error b/c we always need this state for the counts even if the data is going to be
7295// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007296TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007297 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007298
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007299 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7300
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007302
Tobin Ehlise68360f2015-10-01 11:15:13 -06007303 ASSERT_NO_FATAL_FAILURE(InitState());
7304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007305
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007306 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007307 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7308 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007309
7310 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007311 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7312 ds_pool_ci.maxSets = 1;
7313 ds_pool_ci.poolSizeCount = 1;
7314 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007315
7316 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007317 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007318 ASSERT_VK_SUCCESS(err);
7319
7320 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007321 dsl_binding.binding = 0;
7322 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7323 dsl_binding.descriptorCount = 1;
7324 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007325
7326 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007327 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7328 ds_layout_ci.bindingCount = 1;
7329 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007330
7331 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007332 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007333 ASSERT_VK_SUCCESS(err);
7334
7335 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007336 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007337 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007338 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007339 alloc_info.descriptorPool = ds_pool;
7340 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007341 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007342 ASSERT_VK_SUCCESS(err);
7343
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007344 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7345 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7346 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7347
7348 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7349 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7350 vi_ci.pNext = nullptr;
7351 vi_ci.vertexBindingDescriptionCount = 0;
7352 vi_ci.pVertexBindingDescriptions = nullptr;
7353 vi_ci.vertexAttributeDescriptionCount = 0;
7354 vi_ci.pVertexAttributeDescriptions = nullptr;
7355
7356 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7357 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7358 pipe_ms_state_ci.pNext = NULL;
7359 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7360 pipe_ms_state_ci.sampleShadingEnable = 0;
7361 pipe_ms_state_ci.minSampleShading = 1.0;
7362 pipe_ms_state_ci.pSampleMask = NULL;
7363
Tobin Ehlise68360f2015-10-01 11:15:13 -06007364 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007365 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7366 pipeline_layout_ci.setLayoutCount = 1;
7367 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007368
7369 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007370 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007371 ASSERT_VK_SUCCESS(err);
7372
7373 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7374 // Set scissor as dynamic to avoid second error
7375 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007376 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7377 dyn_state_ci.dynamicStateCount = 1;
7378 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007379
Cody Northropeb3a6c12015-10-05 14:44:45 -06007380 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007381 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007382
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007383 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007384 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7385 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007386 shaderStages[0] = vs.GetStageCreateInfo();
7387 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007388
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007389 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7390 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7391 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7392 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7393 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7394 rs_state_ci.depthClampEnable = VK_FALSE;
7395 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7396 rs_state_ci.depthBiasEnable = VK_FALSE;
7397
Tobin Ehlise68360f2015-10-01 11:15:13 -06007398 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007399 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7400 gp_ci.stageCount = 2;
7401 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007402 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007403 // Not setting VP state w/o dynamic vp state should cause validation error
7404 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007405 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007406 gp_ci.pVertexInputState = &vi_ci;
7407 gp_ci.pInputAssemblyState = &ia_ci;
7408 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007409 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7410 gp_ci.layout = pipeline_layout;
7411 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007412
7413 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007414 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007415
7416 VkPipeline pipeline;
7417 VkPipelineCache pipelineCache;
7418
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007419 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007420 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007421 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007422
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007423 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007424
Chia-I Wuf7458c52015-10-26 21:10:41 +08007425 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7426 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7427 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7428 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007429}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007430
7431// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7432// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007433TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7434 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007435
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007437
Tobin Ehlise68360f2015-10-01 11:15:13 -06007438 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007439
7440 if (!m_device->phy().features().multiViewport) {
7441 printf("Device does not support multiple viewports/scissors; skipped.\n");
7442 return;
7443 }
7444
Tobin Ehlise68360f2015-10-01 11:15:13 -06007445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007446
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007447 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007448 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7449 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007450
7451 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007452 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7453 ds_pool_ci.maxSets = 1;
7454 ds_pool_ci.poolSizeCount = 1;
7455 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007456
7457 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007458 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007459 ASSERT_VK_SUCCESS(err);
7460
7461 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007462 dsl_binding.binding = 0;
7463 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7464 dsl_binding.descriptorCount = 1;
7465 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007466
7467 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007468 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7469 ds_layout_ci.bindingCount = 1;
7470 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007471
7472 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007473 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007474 ASSERT_VK_SUCCESS(err);
7475
7476 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007477 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007478 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007479 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007480 alloc_info.descriptorPool = ds_pool;
7481 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007482 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007483 ASSERT_VK_SUCCESS(err);
7484
7485 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007486 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7487 pipeline_layout_ci.setLayoutCount = 1;
7488 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007489
7490 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007491 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007492 ASSERT_VK_SUCCESS(err);
7493
7494 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007495 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7496 vp_state_ci.viewportCount = 1;
7497 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7498 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007499 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007500
7501 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7502 // Set scissor as dynamic to avoid that error
7503 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007504 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7505 dyn_state_ci.dynamicStateCount = 1;
7506 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007507
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007508 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7509 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7510 pipe_ms_state_ci.pNext = NULL;
7511 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7512 pipe_ms_state_ci.sampleShadingEnable = 0;
7513 pipe_ms_state_ci.minSampleShading = 1.0;
7514 pipe_ms_state_ci.pSampleMask = NULL;
7515
Cody Northropeb3a6c12015-10-05 14:44:45 -06007516 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007517 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007518
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007519 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007520 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7521 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007522 shaderStages[0] = vs.GetStageCreateInfo();
7523 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007524
Cody Northropf6622dc2015-10-06 10:33:21 -06007525 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7526 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7527 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007528 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007529 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007530 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007531 vi_ci.pVertexAttributeDescriptions = nullptr;
7532
7533 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7534 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7535 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7536
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007537 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007538 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007539 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007540 rs_ci.pNext = nullptr;
7541
Mark Youngc89c6312016-03-31 16:03:20 -06007542 VkPipelineColorBlendAttachmentState att = {};
7543 att.blendEnable = VK_FALSE;
7544 att.colorWriteMask = 0xf;
7545
Cody Northropf6622dc2015-10-06 10:33:21 -06007546 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7547 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7548 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007549 cb_ci.attachmentCount = 1;
7550 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007551
Tobin Ehlise68360f2015-10-01 11:15:13 -06007552 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007553 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7554 gp_ci.stageCount = 2;
7555 gp_ci.pStages = shaderStages;
7556 gp_ci.pVertexInputState = &vi_ci;
7557 gp_ci.pInputAssemblyState = &ia_ci;
7558 gp_ci.pViewportState = &vp_state_ci;
7559 gp_ci.pRasterizationState = &rs_ci;
7560 gp_ci.pColorBlendState = &cb_ci;
7561 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007562 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007563 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7564 gp_ci.layout = pipeline_layout;
7565 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007566
7567 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007568 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007569
7570 VkPipeline pipeline;
7571 VkPipelineCache pipelineCache;
7572
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007573 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007574 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007575 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007576
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007577 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007578
Tobin Ehlisd332f282015-10-02 11:00:56 -06007579 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007580 // First need to successfully create the PSO from above by setting
7581 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007582 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 -07007583
7584 VkViewport vp = {}; // Just need dummy vp to point to
7585 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007586 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007587 ASSERT_VK_SUCCESS(err);
7588 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007589 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007590 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007591 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007592 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007593 Draw(1, 0, 0, 0);
7594
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007595 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007596
7597 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7598 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7599 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7600 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007601 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007602}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007603
7604// Create PSO w/o non-zero scissorCount but no scissor data, then run second test where dynamic viewportCount doesn't match PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007605// viewportCount
7606TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7607 VkResult err;
7608
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007610
7611 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007612
7613 if (!m_device->phy().features().multiViewport) {
7614 printf("Device does not support multiple viewports/scissors; skipped.\n");
7615 return;
7616 }
7617
Karl Schultz6addd812016-02-02 17:17:23 -07007618 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7619
7620 VkDescriptorPoolSize ds_type_count = {};
7621 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7622 ds_type_count.descriptorCount = 1;
7623
7624 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7625 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7626 ds_pool_ci.maxSets = 1;
7627 ds_pool_ci.poolSizeCount = 1;
7628 ds_pool_ci.pPoolSizes = &ds_type_count;
7629
7630 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007631 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007632 ASSERT_VK_SUCCESS(err);
7633
7634 VkDescriptorSetLayoutBinding dsl_binding = {};
7635 dsl_binding.binding = 0;
7636 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7637 dsl_binding.descriptorCount = 1;
7638 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7639
7640 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7641 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7642 ds_layout_ci.bindingCount = 1;
7643 ds_layout_ci.pBindings = &dsl_binding;
7644
7645 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007646 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007647 ASSERT_VK_SUCCESS(err);
7648
7649 VkDescriptorSet descriptorSet;
7650 VkDescriptorSetAllocateInfo alloc_info = {};
7651 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7652 alloc_info.descriptorSetCount = 1;
7653 alloc_info.descriptorPool = ds_pool;
7654 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007655 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007656 ASSERT_VK_SUCCESS(err);
7657
7658 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7659 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7660 pipeline_layout_ci.setLayoutCount = 1;
7661 pipeline_layout_ci.pSetLayouts = &ds_layout;
7662
7663 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007664 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007665 ASSERT_VK_SUCCESS(err);
7666
7667 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7668 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7669 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007670 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007671 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007672 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007673
7674 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7675 // Set scissor as dynamic to avoid that error
7676 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7677 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7678 dyn_state_ci.dynamicStateCount = 1;
7679 dyn_state_ci.pDynamicStates = &vp_state;
7680
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007681 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7682 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7683 pipe_ms_state_ci.pNext = NULL;
7684 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7685 pipe_ms_state_ci.sampleShadingEnable = 0;
7686 pipe_ms_state_ci.minSampleShading = 1.0;
7687 pipe_ms_state_ci.pSampleMask = NULL;
7688
Karl Schultz6addd812016-02-02 17:17:23 -07007689 VkPipelineShaderStageCreateInfo shaderStages[2];
7690 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7691
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007692 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007693 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7694 // We shouldn't need a fragment shader but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007695 shaderStages[0] = vs.GetStageCreateInfo();
7696 shaderStages[1] = fs.GetStageCreateInfo();
7697
7698 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7699 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7700 vi_ci.pNext = nullptr;
7701 vi_ci.vertexBindingDescriptionCount = 0;
7702 vi_ci.pVertexBindingDescriptions = nullptr;
7703 vi_ci.vertexAttributeDescriptionCount = 0;
7704 vi_ci.pVertexAttributeDescriptions = nullptr;
7705
7706 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7707 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7708 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7709
7710 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7711 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007712 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007713 rs_ci.pNext = nullptr;
7714
Mark Youngc89c6312016-03-31 16:03:20 -06007715 VkPipelineColorBlendAttachmentState att = {};
7716 att.blendEnable = VK_FALSE;
7717 att.colorWriteMask = 0xf;
7718
Karl Schultz6addd812016-02-02 17:17:23 -07007719 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7720 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7721 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007722 cb_ci.attachmentCount = 1;
7723 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007724
7725 VkGraphicsPipelineCreateInfo gp_ci = {};
7726 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7727 gp_ci.stageCount = 2;
7728 gp_ci.pStages = shaderStages;
7729 gp_ci.pVertexInputState = &vi_ci;
7730 gp_ci.pInputAssemblyState = &ia_ci;
7731 gp_ci.pViewportState = &vp_state_ci;
7732 gp_ci.pRasterizationState = &rs_ci;
7733 gp_ci.pColorBlendState = &cb_ci;
7734 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007735 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007736 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7737 gp_ci.layout = pipeline_layout;
7738 gp_ci.renderPass = renderPass();
7739
7740 VkPipelineCacheCreateInfo pc_ci = {};
7741 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7742
7743 VkPipeline pipeline;
7744 VkPipelineCache pipelineCache;
7745
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007746 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007747 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007748 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007749
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007750 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007751
7752 // Now hit second fail case where we set scissor w/ different count than PSO
7753 // First need to successfully create the PSO from above by setting
7754 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007755 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 -06007756
Tobin Ehlisd332f282015-10-02 11:00:56 -06007757 VkRect2D sc = {}; // Just need dummy vp to point to
7758 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007759 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007760 ASSERT_VK_SUCCESS(err);
7761 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007762 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007763 VkViewport viewports[1] = {};
7764 viewports[0].width = 8;
7765 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007766 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007767 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007768 Draw(1, 0, 0, 0);
7769
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007770 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007771
Chia-I Wuf7458c52015-10-26 21:10:41 +08007772 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7773 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7774 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7775 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007776 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007777}
7778
Mark Young7394fdd2016-03-31 14:56:43 -06007779TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7780 VkResult err;
7781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007783
7784 ASSERT_NO_FATAL_FAILURE(InitState());
7785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7786
7787 VkDescriptorPoolSize ds_type_count = {};
7788 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7789 ds_type_count.descriptorCount = 1;
7790
7791 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7792 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7793 ds_pool_ci.maxSets = 1;
7794 ds_pool_ci.poolSizeCount = 1;
7795 ds_pool_ci.pPoolSizes = &ds_type_count;
7796
7797 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007798 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007799 ASSERT_VK_SUCCESS(err);
7800
7801 VkDescriptorSetLayoutBinding dsl_binding = {};
7802 dsl_binding.binding = 0;
7803 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7804 dsl_binding.descriptorCount = 1;
7805 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7806
7807 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7808 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7809 ds_layout_ci.bindingCount = 1;
7810 ds_layout_ci.pBindings = &dsl_binding;
7811
7812 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007813 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007814 ASSERT_VK_SUCCESS(err);
7815
7816 VkDescriptorSet descriptorSet;
7817 VkDescriptorSetAllocateInfo alloc_info = {};
7818 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7819 alloc_info.descriptorSetCount = 1;
7820 alloc_info.descriptorPool = ds_pool;
7821 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007822 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007823 ASSERT_VK_SUCCESS(err);
7824
7825 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7826 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7827 pipeline_layout_ci.setLayoutCount = 1;
7828 pipeline_layout_ci.pSetLayouts = &ds_layout;
7829
7830 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007831 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007832 ASSERT_VK_SUCCESS(err);
7833
7834 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7835 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7836 vp_state_ci.scissorCount = 1;
7837 vp_state_ci.pScissors = NULL;
7838 vp_state_ci.viewportCount = 1;
7839 vp_state_ci.pViewports = NULL;
7840
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007841 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007842 // Set scissor as dynamic to avoid that error
7843 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7844 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7845 dyn_state_ci.dynamicStateCount = 2;
7846 dyn_state_ci.pDynamicStates = dynamic_states;
7847
7848 VkPipelineShaderStageCreateInfo shaderStages[2];
7849 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7850
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007851 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7852 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007853 this); // TODO - We shouldn't need a fragment shader
7854 // but add it to be able to run on more devices
7855 shaderStages[0] = vs.GetStageCreateInfo();
7856 shaderStages[1] = fs.GetStageCreateInfo();
7857
7858 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7859 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7860 vi_ci.pNext = nullptr;
7861 vi_ci.vertexBindingDescriptionCount = 0;
7862 vi_ci.pVertexBindingDescriptions = nullptr;
7863 vi_ci.vertexAttributeDescriptionCount = 0;
7864 vi_ci.pVertexAttributeDescriptions = nullptr;
7865
7866 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7867 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7868 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7869
7870 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7871 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7872 rs_ci.pNext = nullptr;
7873
Mark Young47107952016-05-02 15:59:55 -06007874 // Check too low (line width of -1.0f).
7875 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007876
7877 VkPipelineColorBlendAttachmentState att = {};
7878 att.blendEnable = VK_FALSE;
7879 att.colorWriteMask = 0xf;
7880
7881 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7882 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7883 cb_ci.pNext = nullptr;
7884 cb_ci.attachmentCount = 1;
7885 cb_ci.pAttachments = &att;
7886
7887 VkGraphicsPipelineCreateInfo gp_ci = {};
7888 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7889 gp_ci.stageCount = 2;
7890 gp_ci.pStages = shaderStages;
7891 gp_ci.pVertexInputState = &vi_ci;
7892 gp_ci.pInputAssemblyState = &ia_ci;
7893 gp_ci.pViewportState = &vp_state_ci;
7894 gp_ci.pRasterizationState = &rs_ci;
7895 gp_ci.pColorBlendState = &cb_ci;
7896 gp_ci.pDynamicState = &dyn_state_ci;
7897 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7898 gp_ci.layout = pipeline_layout;
7899 gp_ci.renderPass = renderPass();
7900
7901 VkPipelineCacheCreateInfo pc_ci = {};
7902 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7903
7904 VkPipeline pipeline;
7905 VkPipelineCache pipelineCache;
7906
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007907 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007908 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007910
7911 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007912 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007913
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007915
7916 // Check too high (line width of 65536.0f).
7917 rs_ci.lineWidth = 65536.0f;
7918
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007919 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007920 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007922
7923 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007924 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007925
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007927
7928 dyn_state_ci.dynamicStateCount = 3;
7929
7930 rs_ci.lineWidth = 1.0f;
7931
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007932 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007933 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007935 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007936 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007937
7938 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007939 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007940 m_errorMonitor->VerifyFound();
7941
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007943
7944 // Check too high with dynamic setting.
7945 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7946 m_errorMonitor->VerifyFound();
7947 EndCommandBuffer();
7948
7949 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7950 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7951 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7952 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007953 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007954}
7955
Karl Schultz6addd812016-02-02 17:17:23 -07007956TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007957 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7959 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007960
7961 ASSERT_NO_FATAL_FAILURE(InitState());
7962 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007963
Tony Barbourfe3351b2015-07-28 10:17:20 -06007964 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007965 // Don't care about RenderPass handle b/c error should be flagged before
7966 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007967 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007968
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007969 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007970}
7971
Karl Schultz6addd812016-02-02 17:17:23 -07007972TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007973 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7975 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007976
7977 ASSERT_NO_FATAL_FAILURE(InitState());
7978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007979
Tony Barbourfe3351b2015-07-28 10:17:20 -06007980 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007981 // Just create a dummy Renderpass that's non-NULL so we can get to the
7982 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007983 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007984
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007985 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007986}
7987
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007988TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7989 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7990 "the number of renderPass attachments that use loadOp"
7991 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7992
7993 ASSERT_NO_FATAL_FAILURE(InitState());
7994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7995
7996 // Create a renderPass with a single attachment that uses loadOp CLEAR
7997 VkAttachmentReference attach = {};
7998 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7999 VkSubpassDescription subpass = {};
8000 subpass.inputAttachmentCount = 1;
8001 subpass.pInputAttachments = &attach;
8002 VkRenderPassCreateInfo rpci = {};
8003 rpci.subpassCount = 1;
8004 rpci.pSubpasses = &subpass;
8005 rpci.attachmentCount = 1;
8006 VkAttachmentDescription attach_desc = {};
8007 attach_desc.format = VK_FORMAT_UNDEFINED;
8008 // Set loadOp to CLEAR
8009 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8010 rpci.pAttachments = &attach_desc;
8011 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8012 VkRenderPass rp;
8013 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8014
8015 VkCommandBufferInheritanceInfo hinfo = {};
8016 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8017 hinfo.renderPass = VK_NULL_HANDLE;
8018 hinfo.subpass = 0;
8019 hinfo.framebuffer = VK_NULL_HANDLE;
8020 hinfo.occlusionQueryEnable = VK_FALSE;
8021 hinfo.queryFlags = 0;
8022 hinfo.pipelineStatistics = 0;
8023 VkCommandBufferBeginInfo info = {};
8024 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8025 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8026 info.pInheritanceInfo = &hinfo;
8027
8028 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8029 VkRenderPassBeginInfo rp_begin = {};
8030 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8031 rp_begin.pNext = NULL;
8032 rp_begin.renderPass = renderPass();
8033 rp_begin.framebuffer = framebuffer();
8034 rp_begin.clearValueCount = 0; // Should be 1
8035
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
8037 "there must be at least 1 entries in "
8038 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008039
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008040 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008041
8042 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008043
8044 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008045}
8046
Slawomir Cygan0808f392016-11-28 17:53:23 +01008047TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
8048 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
8049 "the number of renderPass attachments that use loadOp"
8050 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8051
8052 ASSERT_NO_FATAL_FAILURE(InitState());
8053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8054
8055 // Create a renderPass with a single attachment that uses loadOp CLEAR
8056 VkAttachmentReference attach = {};
8057 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8058 VkSubpassDescription subpass = {};
8059 subpass.inputAttachmentCount = 1;
8060 subpass.pInputAttachments = &attach;
8061 VkRenderPassCreateInfo rpci = {};
8062 rpci.subpassCount = 1;
8063 rpci.pSubpasses = &subpass;
8064 rpci.attachmentCount = 1;
8065 VkAttachmentDescription attach_desc = {};
8066 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8067 // Set loadOp to CLEAR
8068 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8069 rpci.pAttachments = &attach_desc;
8070 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8071 VkRenderPass rp;
8072 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8073
8074 VkCommandBufferBeginInfo info = {};
8075 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8076 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8077
8078 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8079 VkRenderPassBeginInfo rp_begin = {};
8080 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8081 rp_begin.pNext = NULL;
8082 rp_begin.renderPass = renderPass();
8083 rp_begin.framebuffer = framebuffer();
8084 rp_begin.clearValueCount = 2; // Should be 1
8085
8086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
8087 " 2 but only first 1 entries in pClearValues array are used");
8088
8089 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8090
8091 m_errorMonitor->VerifyFound();
8092
8093 vkDestroyRenderPass(m_device->device(), rp, NULL);
8094}
8095
8096
Cody Northrop3bb4d962016-05-09 16:15:57 -06008097TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
8098
8099 TEST_DESCRIPTION("End a command buffer with an active render pass");
8100
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8102 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008103
8104 ASSERT_NO_FATAL_FAILURE(InitState());
8105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8106
8107 // The framework's BeginCommandBuffer calls CreateRenderPass
8108 BeginCommandBuffer();
8109
8110 // Call directly into vkEndCommandBuffer instead of the
8111 // the framework's EndCommandBuffer, which inserts a
8112 // vkEndRenderPass
8113 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
8114
8115 m_errorMonitor->VerifyFound();
8116
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008117 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8118 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008119}
8120
Karl Schultz6addd812016-02-02 17:17:23 -07008121TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008122 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8124 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008125
8126 ASSERT_NO_FATAL_FAILURE(InitState());
8127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008128
8129 // Renderpass is started here
8130 BeginCommandBuffer();
8131
8132 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008133 vk_testing::Buffer dstBuffer;
8134 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008135
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008136 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008137
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008138 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008139}
8140
Karl Schultz6addd812016-02-02 17:17:23 -07008141TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008142 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8144 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008145
8146 ASSERT_NO_FATAL_FAILURE(InitState());
8147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008148
8149 // Renderpass is started here
8150 BeginCommandBuffer();
8151
8152 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008153 vk_testing::Buffer dstBuffer;
8154 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008155
Karl Schultz6addd812016-02-02 17:17:23 -07008156 VkDeviceSize dstOffset = 0;
8157 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008158 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008159
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008160 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008161
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008162 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008163}
8164
Karl Schultz6addd812016-02-02 17:17:23 -07008165TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008166 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8168 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008169
8170 ASSERT_NO_FATAL_FAILURE(InitState());
8171 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008172
8173 // Renderpass is started here
8174 BeginCommandBuffer();
8175
Michael Lentine0a369f62016-02-03 16:51:46 -06008176 VkClearColorValue clear_color;
8177 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008178 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8179 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8180 const int32_t tex_width = 32;
8181 const int32_t tex_height = 32;
8182 VkImageCreateInfo image_create_info = {};
8183 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8184 image_create_info.pNext = NULL;
8185 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8186 image_create_info.format = tex_format;
8187 image_create_info.extent.width = tex_width;
8188 image_create_info.extent.height = tex_height;
8189 image_create_info.extent.depth = 1;
8190 image_create_info.mipLevels = 1;
8191 image_create_info.arrayLayers = 1;
8192 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8193 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8194 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008195
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008196 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008197 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008198
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008199 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008200
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008201 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008202
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008203 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008204}
8205
Karl Schultz6addd812016-02-02 17:17:23 -07008206TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008207 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8209 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008210
8211 ASSERT_NO_FATAL_FAILURE(InitState());
8212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008213
8214 // Renderpass is started here
8215 BeginCommandBuffer();
8216
8217 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008218 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008219 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8220 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8221 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8222 image_create_info.extent.width = 64;
8223 image_create_info.extent.height = 64;
8224 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8225 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008226
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008227 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008228 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008229
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008230 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008231
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008232 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8233 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008234
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008235 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008236}
8237
Karl Schultz6addd812016-02-02 17:17:23 -07008238TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008239 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008240 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8243 "must be issued inside an active "
8244 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008245
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008246 ASSERT_NO_FATAL_FAILURE(InitState());
8247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008248
8249 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008250 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008251 ASSERT_VK_SUCCESS(err);
8252
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008253 VkClearAttachment color_attachment;
8254 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8255 color_attachment.clearValue.color.float32[0] = 0;
8256 color_attachment.clearValue.color.float32[1] = 0;
8257 color_attachment.clearValue.color.float32[2] = 0;
8258 color_attachment.clearValue.color.float32[3] = 0;
8259 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008260 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008261 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008262
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008263 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008264}
8265
Chris Forbes3b97e932016-09-07 11:29:24 +12008266TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8267 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8268 "called too many times in a renderpass instance");
8269
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8271 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008272
8273 ASSERT_NO_FATAL_FAILURE(InitState());
8274 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8275
8276 BeginCommandBuffer();
8277
8278 // error here.
8279 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8280 m_errorMonitor->VerifyFound();
8281
8282 EndCommandBuffer();
8283}
8284
Chris Forbes6d624702016-09-07 13:57:05 +12008285TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8286 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8287 "called before the final subpass has been reached");
8288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8290 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008291
8292 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008293 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8294 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008295
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008296 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008297
8298 VkRenderPass rp;
8299 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8300 ASSERT_VK_SUCCESS(err);
8301
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008302 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008303
8304 VkFramebuffer fb;
8305 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8306 ASSERT_VK_SUCCESS(err);
8307
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008308 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008309
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008310 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 +12008311
8312 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8313
8314 // Error here.
8315 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8316 m_errorMonitor->VerifyFound();
8317
8318 // Clean up.
8319 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8320 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8321}
8322
Karl Schultz9e66a292016-04-21 15:57:51 -06008323TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8324 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8326 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008327
8328 ASSERT_NO_FATAL_FAILURE(InitState());
8329 BeginCommandBuffer();
8330
8331 VkBufferMemoryBarrier buf_barrier = {};
8332 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8333 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8334 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8335 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8336 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8337 buf_barrier.buffer = VK_NULL_HANDLE;
8338 buf_barrier.offset = 0;
8339 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008340 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8341 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008342
8343 m_errorMonitor->VerifyFound();
8344}
8345
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008346TEST_F(VkLayerTest, InvalidBarriers) {
8347 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8348
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008350
8351 ASSERT_NO_FATAL_FAILURE(InitState());
8352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8353
8354 VkMemoryBarrier mem_barrier = {};
8355 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8356 mem_barrier.pNext = NULL;
8357 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8358 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8359 BeginCommandBuffer();
8360 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008361 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008362 &mem_barrier, 0, nullptr, 0, nullptr);
8363 m_errorMonitor->VerifyFound();
8364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008366 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008367 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 -06008368 ASSERT_TRUE(image.initialized());
8369 VkImageMemoryBarrier img_barrier = {};
8370 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8371 img_barrier.pNext = NULL;
8372 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8373 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8374 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8375 // New layout can't be UNDEFINED
8376 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8377 img_barrier.image = image.handle();
8378 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8379 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8380 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8381 img_barrier.subresourceRange.baseArrayLayer = 0;
8382 img_barrier.subresourceRange.baseMipLevel = 0;
8383 img_barrier.subresourceRange.layerCount = 1;
8384 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008385 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8386 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008387 m_errorMonitor->VerifyFound();
8388 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8389
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8391 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008392 // baseArrayLayer + layerCount must be <= image's arrayLayers
8393 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008394 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8395 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008396 m_errorMonitor->VerifyFound();
8397 img_barrier.subresourceRange.baseArrayLayer = 0;
8398
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008400 // baseMipLevel + levelCount must be <= image's mipLevels
8401 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008402 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8403 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008404 m_errorMonitor->VerifyFound();
8405 img_barrier.subresourceRange.baseMipLevel = 0;
8406
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008407 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 -06008408 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008409 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8410 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008411 VkBufferMemoryBarrier buf_barrier = {};
8412 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8413 buf_barrier.pNext = NULL;
8414 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8415 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8416 buf_barrier.buffer = buffer.handle();
8417 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8418 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8419 buf_barrier.offset = 0;
8420 buf_barrier.size = VK_WHOLE_SIZE;
8421 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008422 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8423 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008424 m_errorMonitor->VerifyFound();
8425 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8426
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008428 buf_barrier.offset = 257;
8429 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008430 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8431 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008432 m_errorMonitor->VerifyFound();
8433 buf_barrier.offset = 0;
8434
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008436 buf_barrier.size = 257;
8437 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008438 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8439 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008440 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008441
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008442 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008443 m_errorMonitor->SetDesiredFailureMsg(
8444 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8445 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8446 m_errorMonitor->SetDesiredFailureMsg(
8447 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8448 "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 -06008449 VkDepthStencilObj ds_image(m_device);
8450 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8451 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008452 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8453 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008454 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008455 // Use of COLOR aspect on DS image is error
8456 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008457 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8458 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008459 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008460 // Now test depth-only
8461 VkFormatProperties format_props;
8462
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008463 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8464 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8466 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8468 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008469 VkDepthStencilObj d_image(m_device);
8470 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8471 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008472 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008473 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008474 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008475 // Use of COLOR aspect on depth image is error
8476 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008477 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8478 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008479 m_errorMonitor->VerifyFound();
8480 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8482 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008483 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8485 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008486 VkDepthStencilObj s_image(m_device);
8487 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8488 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008489 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008490 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008491 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008492 // Use of COLOR aspect on depth image is error
8493 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008494 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8495 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008496 m_errorMonitor->VerifyFound();
8497 }
8498 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8500 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8502 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008503 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008504 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 -06008505 ASSERT_TRUE(c_image.initialized());
8506 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8507 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8508 img_barrier.image = c_image.handle();
8509 // Set aspect to depth (non-color)
8510 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008511 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8512 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008513 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008514
8515 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8516
8517 // Create command pool with incompatible queueflags
8518 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8519 uint32_t queue_family_index = UINT32_MAX;
8520 for (uint32_t i = 0; i < queue_props.size(); i++) {
8521 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8522 queue_family_index = i;
8523 break;
8524 }
8525 }
8526 if (queue_family_index == UINT32_MAX) {
8527 printf("No non-compute queue found; skipped.\n");
8528 return;
8529 }
8530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8531
8532 VkCommandPool command_pool;
8533 VkCommandPoolCreateInfo pool_create_info{};
8534 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8535 pool_create_info.queueFamilyIndex = queue_family_index;
8536 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8537 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8538
8539 // Allocate a command buffer
8540 VkCommandBuffer bad_command_buffer;
8541 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8542 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8543 command_buffer_allocate_info.commandPool = command_pool;
8544 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8545 command_buffer_allocate_info.commandBufferCount = 1;
8546 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8547
8548 VkCommandBufferBeginInfo cbbi = {};
8549 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8550 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8551 buf_barrier.offset = 0;
8552 buf_barrier.size = VK_WHOLE_SIZE;
8553 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8554 &buf_barrier, 0, nullptr);
8555 m_errorMonitor->VerifyFound();
8556
8557 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8558 vkEndCommandBuffer(bad_command_buffer);
8559 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8560 printf("The non-compute queue does not support graphics; skipped.\n");
8561 return;
8562 }
8563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8564 VkEvent event;
8565 VkEventCreateInfo event_create_info{};
8566 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8567 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8568 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8569 nullptr, 0, nullptr);
8570 m_errorMonitor->VerifyFound();
8571
8572 vkEndCommandBuffer(bad_command_buffer);
8573 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008574}
8575
Tony Barbour18ba25c2016-09-29 13:42:40 -06008576TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8577 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8578
8579 m_errorMonitor->SetDesiredFailureMsg(
8580 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8581 "must have required access bit");
8582 ASSERT_NO_FATAL_FAILURE(InitState());
8583 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008584 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 -06008585 ASSERT_TRUE(image.initialized());
8586
8587 VkImageMemoryBarrier barrier = {};
8588 VkImageSubresourceRange range;
8589 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8590 barrier.srcAccessMask = 0;
8591 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8592 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8593 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8594 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8595 barrier.image = image.handle();
8596 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8597 range.baseMipLevel = 0;
8598 range.levelCount = 1;
8599 range.baseArrayLayer = 0;
8600 range.layerCount = 1;
8601 barrier.subresourceRange = range;
8602 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8603 cmdbuf.BeginCommandBuffer();
8604 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8605 &barrier);
8606 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8607 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8608 barrier.srcAccessMask = 0;
8609 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8610 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8611 &barrier);
8612
8613 m_errorMonitor->VerifyFound();
8614}
8615
Karl Schultz6addd812016-02-02 17:17:23 -07008616TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008617 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008618 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008619
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008621
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008622 ASSERT_NO_FATAL_FAILURE(InitState());
8623 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008624 uint32_t qfi = 0;
8625 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008626 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8627 buffCI.size = 1024;
8628 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8629 buffCI.queueFamilyIndexCount = 1;
8630 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008631
8632 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008633 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008634 ASSERT_VK_SUCCESS(err);
8635
8636 BeginCommandBuffer();
8637 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008638 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8639 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008640 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008641 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008642
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008643 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008644
Chia-I Wuf7458c52015-10-26 21:10:41 +08008645 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008646}
8647
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008648TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8649 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8651 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8652 "of the indices specified when the device was created, via the "
8653 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008654
8655 ASSERT_NO_FATAL_FAILURE(InitState());
8656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8657 VkBufferCreateInfo buffCI = {};
8658 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8659 buffCI.size = 1024;
8660 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8661 buffCI.queueFamilyIndexCount = 1;
8662 // Introduce failure by specifying invalid queue_family_index
8663 uint32_t qfi = 777;
8664 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008665 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008666
8667 VkBuffer ib;
8668 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8669
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008670 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008671 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008672}
8673
Karl Schultz6addd812016-02-02 17:17:23 -07008674TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008675TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008676 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008677
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008678 ASSERT_NO_FATAL_FAILURE(InitState());
8679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008680
Chris Forbesf29a84f2016-10-06 18:39:28 +13008681 // An empty primary command buffer
8682 VkCommandBufferObj cb(m_device, m_commandPool);
8683 cb.BeginCommandBuffer();
8684 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008685
Chris Forbesf29a84f2016-10-06 18:39:28 +13008686 m_commandBuffer->BeginCommandBuffer();
8687 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8688 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008689
Chris Forbesf29a84f2016-10-06 18:39:28 +13008690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8691 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008692 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008693}
8694
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008695TEST_F(VkLayerTest, DSUsageBitsErrors) {
8696 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8697 "that do not have correct usage bits sets.");
8698 VkResult err;
8699
8700 ASSERT_NO_FATAL_FAILURE(InitState());
8701 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8702 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8703 ds_type_count[i].type = VkDescriptorType(i);
8704 ds_type_count[i].descriptorCount = 1;
8705 }
8706 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8707 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8708 ds_pool_ci.pNext = NULL;
8709 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8710 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8711 ds_pool_ci.pPoolSizes = ds_type_count;
8712
8713 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008714 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008715 ASSERT_VK_SUCCESS(err);
8716
8717 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008718 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008719 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8720 dsl_binding[i].binding = 0;
8721 dsl_binding[i].descriptorType = VkDescriptorType(i);
8722 dsl_binding[i].descriptorCount = 1;
8723 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8724 dsl_binding[i].pImmutableSamplers = NULL;
8725 }
8726
8727 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8728 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8729 ds_layout_ci.pNext = NULL;
8730 ds_layout_ci.bindingCount = 1;
8731 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8732 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8733 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008734 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008735 ASSERT_VK_SUCCESS(err);
8736 }
8737 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8738 VkDescriptorSetAllocateInfo alloc_info = {};
8739 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8740 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8741 alloc_info.descriptorPool = ds_pool;
8742 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008743 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008744 ASSERT_VK_SUCCESS(err);
8745
8746 // Create a buffer & bufferView to be used for invalid updates
8747 VkBufferCreateInfo buff_ci = {};
8748 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8749 // This usage is not valid for any descriptor type
8750 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8751 buff_ci.size = 256;
8752 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8753 VkBuffer buffer;
8754 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8755 ASSERT_VK_SUCCESS(err);
8756
8757 VkBufferViewCreateInfo buff_view_ci = {};
8758 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8759 buff_view_ci.buffer = buffer;
8760 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8761 buff_view_ci.range = VK_WHOLE_SIZE;
8762 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008763 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008764 ASSERT_VK_SUCCESS(err);
8765
8766 // Create an image to be used for invalid updates
8767 VkImageCreateInfo image_ci = {};
8768 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8769 image_ci.imageType = VK_IMAGE_TYPE_2D;
8770 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8771 image_ci.extent.width = 64;
8772 image_ci.extent.height = 64;
8773 image_ci.extent.depth = 1;
8774 image_ci.mipLevels = 1;
8775 image_ci.arrayLayers = 1;
8776 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8777 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8778 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8779 // This usage is not valid for any descriptor type
8780 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8781 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8782 VkImage image;
8783 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8784 ASSERT_VK_SUCCESS(err);
8785 // Bind memory to image
8786 VkMemoryRequirements mem_reqs;
8787 VkDeviceMemory image_mem;
8788 bool pass;
8789 VkMemoryAllocateInfo mem_alloc = {};
8790 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8791 mem_alloc.pNext = NULL;
8792 mem_alloc.allocationSize = 0;
8793 mem_alloc.memoryTypeIndex = 0;
8794 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8795 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008796 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008797 ASSERT_TRUE(pass);
8798 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8799 ASSERT_VK_SUCCESS(err);
8800 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8801 ASSERT_VK_SUCCESS(err);
8802 // Now create view for image
8803 VkImageViewCreateInfo image_view_ci = {};
8804 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8805 image_view_ci.image = image;
8806 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8807 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8808 image_view_ci.subresourceRange.layerCount = 1;
8809 image_view_ci.subresourceRange.baseArrayLayer = 0;
8810 image_view_ci.subresourceRange.levelCount = 1;
8811 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8812 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008813 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008814 ASSERT_VK_SUCCESS(err);
8815
8816 VkDescriptorBufferInfo buff_info = {};
8817 buff_info.buffer = buffer;
8818 VkDescriptorImageInfo img_info = {};
8819 img_info.imageView = image_view;
8820 VkWriteDescriptorSet descriptor_write = {};
8821 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8822 descriptor_write.dstBinding = 0;
8823 descriptor_write.descriptorCount = 1;
8824 descriptor_write.pTexelBufferView = &buff_view;
8825 descriptor_write.pBufferInfo = &buff_info;
8826 descriptor_write.pImageInfo = &img_info;
8827
8828 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008829 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8830 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8831 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8832 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8833 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8834 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8835 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8836 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8837 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8838 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8839 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008840 // Start loop at 1 as SAMPLER desc type has no usage bit error
8841 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8842 descriptor_write.descriptorType = VkDescriptorType(i);
8843 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008845
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008846 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008847
8848 m_errorMonitor->VerifyFound();
8849 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8850 }
8851 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8852 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008853 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008854 vkDestroyImageView(m_device->device(), image_view, NULL);
8855 vkDestroyBuffer(m_device->device(), buffer, NULL);
8856 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008857 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008858 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8859}
8860
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008861TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008862 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8863 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8864 "1. offset value greater than buffer size\n"
8865 "2. range value of 0\n"
8866 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008867 VkResult err;
8868
8869 ASSERT_NO_FATAL_FAILURE(InitState());
8870 VkDescriptorPoolSize ds_type_count = {};
8871 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8872 ds_type_count.descriptorCount = 1;
8873
8874 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8875 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8876 ds_pool_ci.pNext = NULL;
8877 ds_pool_ci.maxSets = 1;
8878 ds_pool_ci.poolSizeCount = 1;
8879 ds_pool_ci.pPoolSizes = &ds_type_count;
8880
8881 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008882 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008883 ASSERT_VK_SUCCESS(err);
8884
8885 // Create layout with single uniform buffer descriptor
8886 VkDescriptorSetLayoutBinding dsl_binding = {};
8887 dsl_binding.binding = 0;
8888 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8889 dsl_binding.descriptorCount = 1;
8890 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8891 dsl_binding.pImmutableSamplers = NULL;
8892
8893 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8894 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8895 ds_layout_ci.pNext = NULL;
8896 ds_layout_ci.bindingCount = 1;
8897 ds_layout_ci.pBindings = &dsl_binding;
8898 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008899 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008900 ASSERT_VK_SUCCESS(err);
8901
8902 VkDescriptorSet descriptor_set = {};
8903 VkDescriptorSetAllocateInfo alloc_info = {};
8904 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8905 alloc_info.descriptorSetCount = 1;
8906 alloc_info.descriptorPool = ds_pool;
8907 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008908 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008909 ASSERT_VK_SUCCESS(err);
8910
8911 // Create a buffer to be used for invalid updates
8912 VkBufferCreateInfo buff_ci = {};
8913 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8914 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8915 buff_ci.size = 256;
8916 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8917 VkBuffer buffer;
8918 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8919 ASSERT_VK_SUCCESS(err);
8920 // Have to bind memory to buffer before descriptor update
8921 VkMemoryAllocateInfo mem_alloc = {};
8922 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8923 mem_alloc.pNext = NULL;
8924 mem_alloc.allocationSize = 256;
8925 mem_alloc.memoryTypeIndex = 0;
8926
8927 VkMemoryRequirements mem_reqs;
8928 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008929 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008930 if (!pass) {
8931 vkDestroyBuffer(m_device->device(), buffer, NULL);
8932 return;
8933 }
8934
8935 VkDeviceMemory mem;
8936 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8937 ASSERT_VK_SUCCESS(err);
8938 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8939 ASSERT_VK_SUCCESS(err);
8940
8941 VkDescriptorBufferInfo buff_info = {};
8942 buff_info.buffer = buffer;
8943 // First make offset 1 larger than buffer size
8944 buff_info.offset = 257;
8945 buff_info.range = VK_WHOLE_SIZE;
8946 VkWriteDescriptorSet descriptor_write = {};
8947 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8948 descriptor_write.dstBinding = 0;
8949 descriptor_write.descriptorCount = 1;
8950 descriptor_write.pTexelBufferView = nullptr;
8951 descriptor_write.pBufferInfo = &buff_info;
8952 descriptor_write.pImageInfo = nullptr;
8953
8954 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8955 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008957
8958 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8959
8960 m_errorMonitor->VerifyFound();
8961 // Now cause error due to range of 0
8962 buff_info.offset = 0;
8963 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8965 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008966
8967 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8968
8969 m_errorMonitor->VerifyFound();
8970 // Now cause error due to range exceeding buffer size - offset
8971 buff_info.offset = 128;
8972 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008973 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 -06008974
8975 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8976
8977 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008978 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008979 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8980 vkDestroyBuffer(m_device->device(), buffer, NULL);
8981 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8982 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8983}
8984
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008985TEST_F(VkLayerTest, DSAspectBitsErrors) {
8986 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8987 // are set, but could expand this test to hit more cases.
8988 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8989 "that do not have correct aspect bits sets.");
8990 VkResult err;
8991
8992 ASSERT_NO_FATAL_FAILURE(InitState());
8993 VkDescriptorPoolSize ds_type_count = {};
8994 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8995 ds_type_count.descriptorCount = 1;
8996
8997 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8998 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8999 ds_pool_ci.pNext = NULL;
9000 ds_pool_ci.maxSets = 5;
9001 ds_pool_ci.poolSizeCount = 1;
9002 ds_pool_ci.pPoolSizes = &ds_type_count;
9003
9004 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009005 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009006 ASSERT_VK_SUCCESS(err);
9007
9008 VkDescriptorSetLayoutBinding dsl_binding = {};
9009 dsl_binding.binding = 0;
9010 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9011 dsl_binding.descriptorCount = 1;
9012 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9013 dsl_binding.pImmutableSamplers = NULL;
9014
9015 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9016 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9017 ds_layout_ci.pNext = NULL;
9018 ds_layout_ci.bindingCount = 1;
9019 ds_layout_ci.pBindings = &dsl_binding;
9020 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009021 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009022 ASSERT_VK_SUCCESS(err);
9023
9024 VkDescriptorSet descriptor_set = {};
9025 VkDescriptorSetAllocateInfo alloc_info = {};
9026 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9027 alloc_info.descriptorSetCount = 1;
9028 alloc_info.descriptorPool = ds_pool;
9029 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009030 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009031 ASSERT_VK_SUCCESS(err);
9032
9033 // Create an image to be used for invalid updates
9034 VkImageCreateInfo image_ci = {};
9035 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9036 image_ci.imageType = VK_IMAGE_TYPE_2D;
9037 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9038 image_ci.extent.width = 64;
9039 image_ci.extent.height = 64;
9040 image_ci.extent.depth = 1;
9041 image_ci.mipLevels = 1;
9042 image_ci.arrayLayers = 1;
9043 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9044 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9045 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9046 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9047 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9048 VkImage image;
9049 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9050 ASSERT_VK_SUCCESS(err);
9051 // Bind memory to image
9052 VkMemoryRequirements mem_reqs;
9053 VkDeviceMemory image_mem;
9054 bool pass;
9055 VkMemoryAllocateInfo mem_alloc = {};
9056 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9057 mem_alloc.pNext = NULL;
9058 mem_alloc.allocationSize = 0;
9059 mem_alloc.memoryTypeIndex = 0;
9060 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9061 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009062 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009063 ASSERT_TRUE(pass);
9064 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9065 ASSERT_VK_SUCCESS(err);
9066 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9067 ASSERT_VK_SUCCESS(err);
9068 // Now create view for image
9069 VkImageViewCreateInfo image_view_ci = {};
9070 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9071 image_view_ci.image = image;
9072 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9073 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9074 image_view_ci.subresourceRange.layerCount = 1;
9075 image_view_ci.subresourceRange.baseArrayLayer = 0;
9076 image_view_ci.subresourceRange.levelCount = 1;
9077 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009078 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009079
9080 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009081 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009082 ASSERT_VK_SUCCESS(err);
9083
9084 VkDescriptorImageInfo img_info = {};
9085 img_info.imageView = image_view;
9086 VkWriteDescriptorSet descriptor_write = {};
9087 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9088 descriptor_write.dstBinding = 0;
9089 descriptor_write.descriptorCount = 1;
9090 descriptor_write.pTexelBufferView = NULL;
9091 descriptor_write.pBufferInfo = NULL;
9092 descriptor_write.pImageInfo = &img_info;
9093 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9094 descriptor_write.dstSet = descriptor_set;
9095 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9096 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009098
9099 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9100
9101 m_errorMonitor->VerifyFound();
9102 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9103 vkDestroyImage(m_device->device(), image, NULL);
9104 vkFreeMemory(m_device->device(), image_mem, NULL);
9105 vkDestroyImageView(m_device->device(), image_view, NULL);
9106 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9107 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9108}
9109
Karl Schultz6addd812016-02-02 17:17:23 -07009110TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009111 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009112 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009113
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9115 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9116 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009117
Tobin Ehlis3b780662015-05-28 12:11:26 -06009118 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009119 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009120 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009121 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9122 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009123
9124 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009125 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9126 ds_pool_ci.pNext = NULL;
9127 ds_pool_ci.maxSets = 1;
9128 ds_pool_ci.poolSizeCount = 1;
9129 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009130
Tobin Ehlis3b780662015-05-28 12:11:26 -06009131 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009132 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009133 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009134 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009135 dsl_binding.binding = 0;
9136 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9137 dsl_binding.descriptorCount = 1;
9138 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9139 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009140
Tony Barboureb254902015-07-15 12:50:33 -06009141 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009142 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9143 ds_layout_ci.pNext = NULL;
9144 ds_layout_ci.bindingCount = 1;
9145 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009146
Tobin Ehlis3b780662015-05-28 12:11:26 -06009147 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009148 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009149 ASSERT_VK_SUCCESS(err);
9150
9151 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009152 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009153 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009154 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009155 alloc_info.descriptorPool = ds_pool;
9156 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009157 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009158 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009159
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009160 VkSamplerCreateInfo sampler_ci = {};
9161 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9162 sampler_ci.pNext = NULL;
9163 sampler_ci.magFilter = VK_FILTER_NEAREST;
9164 sampler_ci.minFilter = VK_FILTER_NEAREST;
9165 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9166 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9167 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9168 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9169 sampler_ci.mipLodBias = 1.0;
9170 sampler_ci.anisotropyEnable = VK_FALSE;
9171 sampler_ci.maxAnisotropy = 1;
9172 sampler_ci.compareEnable = VK_FALSE;
9173 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9174 sampler_ci.minLod = 1.0;
9175 sampler_ci.maxLod = 1.0;
9176 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9177 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9178 VkSampler sampler;
9179 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9180 ASSERT_VK_SUCCESS(err);
9181
9182 VkDescriptorImageInfo info = {};
9183 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009184
9185 VkWriteDescriptorSet descriptor_write;
9186 memset(&descriptor_write, 0, sizeof(descriptor_write));
9187 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009188 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009189 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009190 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009191 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009192 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009193
9194 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9195
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009196 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009197
Chia-I Wuf7458c52015-10-26 21:10:41 +08009198 vkDestroySampler(m_device->device(), sampler, NULL);
9199 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9200 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009201}
9202
Karl Schultz6addd812016-02-02 17:17:23 -07009203TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009204 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009205 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009206
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009208
Tobin Ehlis3b780662015-05-28 12:11:26 -06009209 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009210 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009211 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009212 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9213 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009214
9215 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009216 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9217 ds_pool_ci.pNext = NULL;
9218 ds_pool_ci.maxSets = 1;
9219 ds_pool_ci.poolSizeCount = 1;
9220 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009221
Tobin Ehlis3b780662015-05-28 12:11:26 -06009222 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009223 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009224 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009225
Tony Barboureb254902015-07-15 12:50:33 -06009226 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009227 dsl_binding.binding = 0;
9228 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9229 dsl_binding.descriptorCount = 1;
9230 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9231 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009232
9233 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009234 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9235 ds_layout_ci.pNext = NULL;
9236 ds_layout_ci.bindingCount = 1;
9237 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009238
Tobin Ehlis3b780662015-05-28 12:11:26 -06009239 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009240 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009241 ASSERT_VK_SUCCESS(err);
9242
9243 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009244 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009245 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009246 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009247 alloc_info.descriptorPool = ds_pool;
9248 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009249 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009250 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009251
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009252 // Correctly update descriptor to avoid "NOT_UPDATED" error
9253 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009254 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009255 buff_info.offset = 0;
9256 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009257
9258 VkWriteDescriptorSet descriptor_write;
9259 memset(&descriptor_write, 0, sizeof(descriptor_write));
9260 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009261 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009262 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009263 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009264 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9265 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009266
9267 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9268
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009269 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009270
Chia-I Wuf7458c52015-10-26 21:10:41 +08009271 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9272 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009273}
9274
Karl Schultz6addd812016-02-02 17:17:23 -07009275TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009276 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009277 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009278
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009280
Tobin Ehlis3b780662015-05-28 12:11:26 -06009281 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009282 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009283 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009284 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9285 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009286
9287 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009288 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9289 ds_pool_ci.pNext = NULL;
9290 ds_pool_ci.maxSets = 1;
9291 ds_pool_ci.poolSizeCount = 1;
9292 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009293
Tobin Ehlis3b780662015-05-28 12:11:26 -06009294 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009295 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009296 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009297
Tony Barboureb254902015-07-15 12:50:33 -06009298 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009299 dsl_binding.binding = 0;
9300 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9301 dsl_binding.descriptorCount = 1;
9302 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9303 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009304
9305 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009306 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9307 ds_layout_ci.pNext = NULL;
9308 ds_layout_ci.bindingCount = 1;
9309 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009310 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009311 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009312 ASSERT_VK_SUCCESS(err);
9313
9314 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009315 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009316 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009317 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009318 alloc_info.descriptorPool = ds_pool;
9319 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009320 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009321 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009322
Tony Barboureb254902015-07-15 12:50:33 -06009323 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009324 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9325 sampler_ci.pNext = NULL;
9326 sampler_ci.magFilter = VK_FILTER_NEAREST;
9327 sampler_ci.minFilter = VK_FILTER_NEAREST;
9328 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9329 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9330 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9331 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9332 sampler_ci.mipLodBias = 1.0;
9333 sampler_ci.anisotropyEnable = VK_FALSE;
9334 sampler_ci.maxAnisotropy = 1;
9335 sampler_ci.compareEnable = VK_FALSE;
9336 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9337 sampler_ci.minLod = 1.0;
9338 sampler_ci.maxLod = 1.0;
9339 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9340 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009341
Tobin Ehlis3b780662015-05-28 12:11:26 -06009342 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009343 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009344 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009345
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009346 VkDescriptorImageInfo info = {};
9347 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009348
9349 VkWriteDescriptorSet descriptor_write;
9350 memset(&descriptor_write, 0, sizeof(descriptor_write));
9351 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009352 descriptor_write.dstSet = descriptorSet;
9353 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009354 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009355 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009356 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009357 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009358
9359 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009361 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009362
Chia-I Wuf7458c52015-10-26 21:10:41 +08009363 vkDestroySampler(m_device->device(), sampler, NULL);
9364 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9365 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009366}
9367
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009368TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9369 // Create layout w/ empty binding and attempt to update it
9370 VkResult err;
9371
9372 ASSERT_NO_FATAL_FAILURE(InitState());
9373
9374 VkDescriptorPoolSize ds_type_count = {};
9375 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9376 ds_type_count.descriptorCount = 1;
9377
9378 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9379 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9380 ds_pool_ci.pNext = NULL;
9381 ds_pool_ci.maxSets = 1;
9382 ds_pool_ci.poolSizeCount = 1;
9383 ds_pool_ci.pPoolSizes = &ds_type_count;
9384
9385 VkDescriptorPool ds_pool;
9386 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9387 ASSERT_VK_SUCCESS(err);
9388
9389 VkDescriptorSetLayoutBinding dsl_binding = {};
9390 dsl_binding.binding = 0;
9391 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9392 dsl_binding.descriptorCount = 0;
9393 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9394 dsl_binding.pImmutableSamplers = NULL;
9395
9396 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9397 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9398 ds_layout_ci.pNext = NULL;
9399 ds_layout_ci.bindingCount = 1;
9400 ds_layout_ci.pBindings = &dsl_binding;
9401 VkDescriptorSetLayout ds_layout;
9402 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9403 ASSERT_VK_SUCCESS(err);
9404
9405 VkDescriptorSet descriptor_set;
9406 VkDescriptorSetAllocateInfo alloc_info = {};
9407 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9408 alloc_info.descriptorSetCount = 1;
9409 alloc_info.descriptorPool = ds_pool;
9410 alloc_info.pSetLayouts = &ds_layout;
9411 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9412 ASSERT_VK_SUCCESS(err);
9413
9414 VkSamplerCreateInfo sampler_ci = {};
9415 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9416 sampler_ci.magFilter = VK_FILTER_NEAREST;
9417 sampler_ci.minFilter = VK_FILTER_NEAREST;
9418 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9419 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9420 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9421 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9422 sampler_ci.mipLodBias = 1.0;
9423 sampler_ci.maxAnisotropy = 1;
9424 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9425 sampler_ci.minLod = 1.0;
9426 sampler_ci.maxLod = 1.0;
9427 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9428
9429 VkSampler sampler;
9430 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9431 ASSERT_VK_SUCCESS(err);
9432
9433 VkDescriptorImageInfo info = {};
9434 info.sampler = sampler;
9435
9436 VkWriteDescriptorSet descriptor_write;
9437 memset(&descriptor_write, 0, sizeof(descriptor_write));
9438 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9439 descriptor_write.dstSet = descriptor_set;
9440 descriptor_write.dstBinding = 0;
9441 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9442 // This is the wrong type, but empty binding error will be flagged first
9443 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9444 descriptor_write.pImageInfo = &info;
9445
9446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9447 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9448 m_errorMonitor->VerifyFound();
9449
9450 vkDestroySampler(m_device->device(), sampler, NULL);
9451 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9452 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9453}
9454
Karl Schultz6addd812016-02-02 17:17:23 -07009455TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9456 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9457 // types
9458 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009459
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009460 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 -06009461
Tobin Ehlis3b780662015-05-28 12:11:26 -06009462 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009463
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009464 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009465 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9466 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009467
9468 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009469 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9470 ds_pool_ci.pNext = NULL;
9471 ds_pool_ci.maxSets = 1;
9472 ds_pool_ci.poolSizeCount = 1;
9473 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009474
Tobin Ehlis3b780662015-05-28 12:11:26 -06009475 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009476 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009477 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009478 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009479 dsl_binding.binding = 0;
9480 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9481 dsl_binding.descriptorCount = 1;
9482 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9483 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009484
Tony Barboureb254902015-07-15 12:50:33 -06009485 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009486 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9487 ds_layout_ci.pNext = NULL;
9488 ds_layout_ci.bindingCount = 1;
9489 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009490
Tobin Ehlis3b780662015-05-28 12:11:26 -06009491 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009492 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009493 ASSERT_VK_SUCCESS(err);
9494
9495 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009496 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009497 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009498 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009499 alloc_info.descriptorPool = ds_pool;
9500 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009501 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009502 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009503
Tony Barboureb254902015-07-15 12:50:33 -06009504 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009505 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9506 sampler_ci.pNext = NULL;
9507 sampler_ci.magFilter = VK_FILTER_NEAREST;
9508 sampler_ci.minFilter = VK_FILTER_NEAREST;
9509 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9510 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9511 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9512 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9513 sampler_ci.mipLodBias = 1.0;
9514 sampler_ci.anisotropyEnable = VK_FALSE;
9515 sampler_ci.maxAnisotropy = 1;
9516 sampler_ci.compareEnable = VK_FALSE;
9517 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9518 sampler_ci.minLod = 1.0;
9519 sampler_ci.maxLod = 1.0;
9520 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9521 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009522 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009523 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009524 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009525
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009526 VkDescriptorImageInfo info = {};
9527 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009528
9529 VkWriteDescriptorSet descriptor_write;
9530 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009531 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009532 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009533 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009534 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009535 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009536 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009537
9538 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9539
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009540 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009541
Chia-I Wuf7458c52015-10-26 21:10:41 +08009542 vkDestroySampler(m_device->device(), sampler, NULL);
9543 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9544 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009545}
9546
Karl Schultz6addd812016-02-02 17:17:23 -07009547TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009548 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009549 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009550
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9552 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009553
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009554 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009555 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9556 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009557 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009558 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9559 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009560
9561 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009562 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9563 ds_pool_ci.pNext = NULL;
9564 ds_pool_ci.maxSets = 1;
9565 ds_pool_ci.poolSizeCount = 1;
9566 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009567
9568 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009569 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009570 ASSERT_VK_SUCCESS(err);
9571
9572 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009573 dsl_binding.binding = 0;
9574 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9575 dsl_binding.descriptorCount = 1;
9576 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9577 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009578
9579 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009580 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9581 ds_layout_ci.pNext = NULL;
9582 ds_layout_ci.bindingCount = 1;
9583 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009584 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009585 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009586 ASSERT_VK_SUCCESS(err);
9587
9588 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009589 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009590 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009591 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009592 alloc_info.descriptorPool = ds_pool;
9593 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009594 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009595 ASSERT_VK_SUCCESS(err);
9596
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009597 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009598
9599 VkDescriptorImageInfo descriptor_info;
9600 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9601 descriptor_info.sampler = sampler;
9602
9603 VkWriteDescriptorSet descriptor_write;
9604 memset(&descriptor_write, 0, sizeof(descriptor_write));
9605 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009606 descriptor_write.dstSet = descriptorSet;
9607 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009608 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009609 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9610 descriptor_write.pImageInfo = &descriptor_info;
9611
9612 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9613
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009614 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009615
Chia-I Wuf7458c52015-10-26 21:10:41 +08009616 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9617 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009618}
9619
Karl Schultz6addd812016-02-02 17:17:23 -07009620TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9621 // Create a single combined Image/Sampler descriptor and send it an invalid
9622 // imageView
9623 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009624
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009626
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009627 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009628 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009629 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9630 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009631
9632 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009633 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9634 ds_pool_ci.pNext = NULL;
9635 ds_pool_ci.maxSets = 1;
9636 ds_pool_ci.poolSizeCount = 1;
9637 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009638
9639 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009640 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009641 ASSERT_VK_SUCCESS(err);
9642
9643 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009644 dsl_binding.binding = 0;
9645 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9646 dsl_binding.descriptorCount = 1;
9647 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9648 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009649
9650 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009651 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9652 ds_layout_ci.pNext = NULL;
9653 ds_layout_ci.bindingCount = 1;
9654 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009655 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009656 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -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 Ehlisa1c28562015-10-23 16:00:08 -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 Ehlisa1c28562015-10-23 16:00:08 -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 Ehlisa1c28562015-10-23 16:00:08 -06009686
9687 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009688 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009689 ASSERT_VK_SUCCESS(err);
9690
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009691 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009692
9693 VkDescriptorImageInfo descriptor_info;
9694 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9695 descriptor_info.sampler = sampler;
9696 descriptor_info.imageView = view;
9697
9698 VkWriteDescriptorSet descriptor_write;
9699 memset(&descriptor_write, 0, sizeof(descriptor_write));
9700 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009701 descriptor_write.dstSet = descriptorSet;
9702 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009703 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009704 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9705 descriptor_write.pImageInfo = &descriptor_info;
9706
9707 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9708
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009709 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009710
Chia-I Wuf7458c52015-10-26 21:10:41 +08009711 vkDestroySampler(m_device->device(), sampler, NULL);
9712 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9713 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009714}
9715
Karl Schultz6addd812016-02-02 17:17:23 -07009716TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9717 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9718 // into the other
9719 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9722 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9723 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009724
Tobin Ehlis04356f92015-10-27 16:35:27 -06009725 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009726 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009727 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009728 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9729 ds_type_count[0].descriptorCount = 1;
9730 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9731 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009732
9733 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009734 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9735 ds_pool_ci.pNext = NULL;
9736 ds_pool_ci.maxSets = 1;
9737 ds_pool_ci.poolSizeCount = 2;
9738 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009739
9740 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009741 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009742 ASSERT_VK_SUCCESS(err);
9743 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009744 dsl_binding[0].binding = 0;
9745 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9746 dsl_binding[0].descriptorCount = 1;
9747 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9748 dsl_binding[0].pImmutableSamplers = NULL;
9749 dsl_binding[1].binding = 1;
9750 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9751 dsl_binding[1].descriptorCount = 1;
9752 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9753 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009754
9755 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009756 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9757 ds_layout_ci.pNext = NULL;
9758 ds_layout_ci.bindingCount = 2;
9759 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009760
9761 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009762 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009763 ASSERT_VK_SUCCESS(err);
9764
9765 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009766 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009767 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009768 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009769 alloc_info.descriptorPool = ds_pool;
9770 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009771 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009772 ASSERT_VK_SUCCESS(err);
9773
9774 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009775 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9776 sampler_ci.pNext = NULL;
9777 sampler_ci.magFilter = VK_FILTER_NEAREST;
9778 sampler_ci.minFilter = VK_FILTER_NEAREST;
9779 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9780 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9781 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9782 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9783 sampler_ci.mipLodBias = 1.0;
9784 sampler_ci.anisotropyEnable = VK_FALSE;
9785 sampler_ci.maxAnisotropy = 1;
9786 sampler_ci.compareEnable = VK_FALSE;
9787 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9788 sampler_ci.minLod = 1.0;
9789 sampler_ci.maxLod = 1.0;
9790 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9791 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009792
9793 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009794 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009795 ASSERT_VK_SUCCESS(err);
9796
9797 VkDescriptorImageInfo info = {};
9798 info.sampler = sampler;
9799
9800 VkWriteDescriptorSet descriptor_write;
9801 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9802 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009803 descriptor_write.dstSet = descriptorSet;
9804 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009805 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009806 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9807 descriptor_write.pImageInfo = &info;
9808 // This write update should succeed
9809 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9810 // Now perform a copy update that fails due to type mismatch
9811 VkCopyDescriptorSet copy_ds_update;
9812 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9813 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9814 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009815 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009816 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009817 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009818 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009819 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9820
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009821 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009822 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009823 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 -06009824 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9825 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9826 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009827 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009828 copy_ds_update.dstSet = descriptorSet;
9829 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009830 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009831 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9832
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009833 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009834
Tobin Ehlis04356f92015-10-27 16:35:27 -06009835 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9837 "update array offset of 0 and update of "
9838 "5 descriptors oversteps total number "
9839 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009840
Tobin Ehlis04356f92015-10-27 16:35:27 -06009841 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9842 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9843 copy_ds_update.srcSet = descriptorSet;
9844 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009845 copy_ds_update.dstSet = descriptorSet;
9846 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009847 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009848 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9849
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009850 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009851
Chia-I Wuf7458c52015-10-26 21:10:41 +08009852 vkDestroySampler(m_device->device(), sampler, NULL);
9853 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9854 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009855}
9856
Karl Schultz6addd812016-02-02 17:17:23 -07009857TEST_F(VkLayerTest, NumSamplesMismatch) {
9858 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9859 // sampleCount
9860 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009863
Tobin Ehlis3b780662015-05-28 12:11:26 -06009864 ASSERT_NO_FATAL_FAILURE(InitState());
9865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009866 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009867 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009868 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009869
9870 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009871 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9872 ds_pool_ci.pNext = NULL;
9873 ds_pool_ci.maxSets = 1;
9874 ds_pool_ci.poolSizeCount = 1;
9875 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009876
Tobin Ehlis3b780662015-05-28 12:11:26 -06009877 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009878 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009879 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009880
Tony Barboureb254902015-07-15 12:50:33 -06009881 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009882 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009883 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009884 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009885 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9886 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009887
Tony Barboureb254902015-07-15 12:50:33 -06009888 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9889 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9890 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009891 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009892 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009893
Tobin Ehlis3b780662015-05-28 12:11:26 -06009894 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009896 ASSERT_VK_SUCCESS(err);
9897
9898 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009899 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009900 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009901 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009902 alloc_info.descriptorPool = ds_pool;
9903 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009904 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009905 ASSERT_VK_SUCCESS(err);
9906
Tony Barboureb254902015-07-15 12:50:33 -06009907 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009908 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009909 pipe_ms_state_ci.pNext = NULL;
9910 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9911 pipe_ms_state_ci.sampleShadingEnable = 0;
9912 pipe_ms_state_ci.minSampleShading = 1.0;
9913 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009914
Tony Barboureb254902015-07-15 12:50:33 -06009915 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009916 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9917 pipeline_layout_ci.pNext = NULL;
9918 pipeline_layout_ci.setLayoutCount = 1;
9919 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009920
9921 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009922 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009923 ASSERT_VK_SUCCESS(err);
9924
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009925 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9926 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9927 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009928 VkPipelineObj pipe(m_device);
9929 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009930 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009931 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009932 pipe.SetMSAA(&pipe_ms_state_ci);
9933 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009934
Tony Barbourfe3351b2015-07-28 10:17:20 -06009935 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009936 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009937
Mark Young29927482016-05-04 14:38:51 -06009938 // Render triangle (the error should trigger on the attempt to draw).
9939 Draw(3, 1, 0, 0);
9940
9941 // Finalize recording of the command buffer
9942 EndCommandBuffer();
9943
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009944 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009945
Chia-I Wuf7458c52015-10-26 21:10:41 +08009946 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9947 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9948 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009949}
Mark Young29927482016-05-04 14:38:51 -06009950
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009951TEST_F(VkLayerTest, RenderPassIncompatible) {
9952 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9953 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009954 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009955 VkResult err;
9956
9957 ASSERT_NO_FATAL_FAILURE(InitState());
9958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9959
9960 VkDescriptorSetLayoutBinding dsl_binding = {};
9961 dsl_binding.binding = 0;
9962 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9963 dsl_binding.descriptorCount = 1;
9964 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9965 dsl_binding.pImmutableSamplers = NULL;
9966
9967 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9968 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9969 ds_layout_ci.pNext = NULL;
9970 ds_layout_ci.bindingCount = 1;
9971 ds_layout_ci.pBindings = &dsl_binding;
9972
9973 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009974 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009975 ASSERT_VK_SUCCESS(err);
9976
9977 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9978 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9979 pipeline_layout_ci.pNext = NULL;
9980 pipeline_layout_ci.setLayoutCount = 1;
9981 pipeline_layout_ci.pSetLayouts = &ds_layout;
9982
9983 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009984 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009985 ASSERT_VK_SUCCESS(err);
9986
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009987 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9988 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9989 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009990 // Create a renderpass that will be incompatible with default renderpass
9991 VkAttachmentReference attach = {};
9992 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9993 VkAttachmentReference color_att = {};
9994 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9995 VkSubpassDescription subpass = {};
9996 subpass.inputAttachmentCount = 1;
9997 subpass.pInputAttachments = &attach;
9998 subpass.colorAttachmentCount = 1;
9999 subpass.pColorAttachments = &color_att;
10000 VkRenderPassCreateInfo rpci = {};
10001 rpci.subpassCount = 1;
10002 rpci.pSubpasses = &subpass;
10003 rpci.attachmentCount = 1;
10004 VkAttachmentDescription attach_desc = {};
10005 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010006 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10007 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010008 rpci.pAttachments = &attach_desc;
10009 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10010 VkRenderPass rp;
10011 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10012 VkPipelineObj pipe(m_device);
10013 pipe.AddShader(&vs);
10014 pipe.AddShader(&fs);
10015 pipe.AddColorAttachment();
10016 VkViewport view_port = {};
10017 m_viewports.push_back(view_port);
10018 pipe.SetViewport(m_viewports);
10019 VkRect2D rect = {};
10020 m_scissors.push_back(rect);
10021 pipe.SetScissor(m_scissors);
10022 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10023
10024 VkCommandBufferInheritanceInfo cbii = {};
10025 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10026 cbii.renderPass = rp;
10027 cbii.subpass = 0;
10028 VkCommandBufferBeginInfo cbbi = {};
10029 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10030 cbbi.pInheritanceInfo = &cbii;
10031 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10032 VkRenderPassBeginInfo rpbi = {};
10033 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10034 rpbi.framebuffer = m_framebuffer;
10035 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010036 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10037 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010040 // Render triangle (the error should trigger on the attempt to draw).
10041 Draw(3, 1, 0, 0);
10042
10043 // Finalize recording of the command buffer
10044 EndCommandBuffer();
10045
10046 m_errorMonitor->VerifyFound();
10047
10048 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10049 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10050 vkDestroyRenderPass(m_device->device(), rp, NULL);
10051}
10052
Mark Youngc89c6312016-03-31 16:03:20 -060010053TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10054 // Create Pipeline where the number of blend attachments doesn't match the
10055 // number of color attachments. In this case, we don't add any color
10056 // blend attachments even though we have a color attachment.
10057 VkResult err;
10058
10059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010060 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010061
10062 ASSERT_NO_FATAL_FAILURE(InitState());
10063 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10064 VkDescriptorPoolSize ds_type_count = {};
10065 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10066 ds_type_count.descriptorCount = 1;
10067
10068 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10069 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;
10074
10075 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010076 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010077 ASSERT_VK_SUCCESS(err);
10078
10079 VkDescriptorSetLayoutBinding dsl_binding = {};
10080 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;
10085
10086 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10087 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;
10091
10092 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010093 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010094 ASSERT_VK_SUCCESS(err);
10095
10096 VkDescriptorSet descriptorSet;
10097 VkDescriptorSetAllocateInfo alloc_info = {};
10098 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10099 alloc_info.descriptorSetCount = 1;
10100 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);
Mark Youngc89c6312016-03-31 16:03:20 -060010103 ASSERT_VK_SUCCESS(err);
10104
10105 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;
Mark Youngc89c6312016-03-31 16:03:20 -060010107 pipe_ms_state_ci.pNext = NULL;
10108 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10109 pipe_ms_state_ci.sampleShadingEnable = 0;
10110 pipe_ms_state_ci.minSampleShading = 1.0;
10111 pipe_ms_state_ci.pSampleMask = NULL;
10112
10113 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10114 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;
10118
10119 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010120 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010121 ASSERT_VK_SUCCESS(err);
10122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010123 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10124 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10125 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010126 VkPipelineObj pipe(m_device);
10127 pipe.AddShader(&vs);
10128 pipe.AddShader(&fs);
10129 pipe.SetMSAA(&pipe_ms_state_ci);
10130 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10131
10132 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010133 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010134
Mark Young29927482016-05-04 14:38:51 -060010135 // Render triangle (the error should trigger on the attempt to draw).
10136 Draw(3, 1, 0, 0);
10137
10138 // Finalize recording of the command buffer
10139 EndCommandBuffer();
10140
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010141 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010142
10143 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10144 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10145 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10146}
Mark Young29927482016-05-04 14:38:51 -060010147
Mark Muellerd4914412016-06-13 17:52:06 -060010148TEST_F(VkLayerTest, MissingClearAttachment) {
10149 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10150 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010151 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120010152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +130010153 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -060010154
10155 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10156 m_errorMonitor->VerifyFound();
10157}
10158
Karl Schultz6addd812016-02-02 17:17:23 -070010159TEST_F(VkLayerTest, ClearCmdNoDraw) {
10160 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
10161 // to issuing a Draw
10162 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060010165 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010166
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010167 ASSERT_NO_FATAL_FAILURE(InitState());
10168 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010169
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010170 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010171 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10172 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010173
10174 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010175 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10176 ds_pool_ci.pNext = NULL;
10177 ds_pool_ci.maxSets = 1;
10178 ds_pool_ci.poolSizeCount = 1;
10179 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010180
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010181 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010182 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010183 ASSERT_VK_SUCCESS(err);
10184
Tony Barboureb254902015-07-15 12:50:33 -060010185 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010186 dsl_binding.binding = 0;
10187 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10188 dsl_binding.descriptorCount = 1;
10189 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10190 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010191
Tony Barboureb254902015-07-15 12:50:33 -060010192 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010193 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10194 ds_layout_ci.pNext = NULL;
10195 ds_layout_ci.bindingCount = 1;
10196 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010197
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010198 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010199 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010200 ASSERT_VK_SUCCESS(err);
10201
10202 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010203 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010204 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010205 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010206 alloc_info.descriptorPool = ds_pool;
10207 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010209 ASSERT_VK_SUCCESS(err);
10210
Tony Barboureb254902015-07-15 12:50:33 -060010211 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010212 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010213 pipe_ms_state_ci.pNext = NULL;
10214 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10215 pipe_ms_state_ci.sampleShadingEnable = 0;
10216 pipe_ms_state_ci.minSampleShading = 1.0;
10217 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010218
Tony Barboureb254902015-07-15 12:50:33 -060010219 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010220 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10221 pipeline_layout_ci.pNext = NULL;
10222 pipeline_layout_ci.setLayoutCount = 1;
10223 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010224
10225 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010226 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010227 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010228
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010229 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010230 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010231 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010232 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010233
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010234 VkPipelineObj pipe(m_device);
10235 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010236 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010237 pipe.SetMSAA(&pipe_ms_state_ci);
10238 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010239
10240 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010241
Karl Schultz6addd812016-02-02 17:17:23 -070010242 // Main thing we care about for this test is that the VkImage obj we're
10243 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010244 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010245 VkClearAttachment color_attachment;
10246 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10247 color_attachment.clearValue.color.float32[0] = 1.0;
10248 color_attachment.clearValue.color.float32[1] = 1.0;
10249 color_attachment.clearValue.color.float32[2] = 1.0;
10250 color_attachment.clearValue.color.float32[3] = 1.0;
10251 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010252 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010254 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010255
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010256 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010257
Chia-I Wuf7458c52015-10-26 21:10:41 +080010258 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10259 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10260 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010261}
10262
Karl Schultz6addd812016-02-02 17:17:23 -070010263TEST_F(VkLayerTest, VtxBufferBadIndex) {
10264 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10267 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010268
Tobin Ehlis502480b2015-06-24 15:53:07 -060010269 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010270 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010271 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010272
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010273 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010274 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10275 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010276
10277 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010278 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10279 ds_pool_ci.pNext = NULL;
10280 ds_pool_ci.maxSets = 1;
10281 ds_pool_ci.poolSizeCount = 1;
10282 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010283
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010284 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010285 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010286 ASSERT_VK_SUCCESS(err);
10287
Tony Barboureb254902015-07-15 12:50:33 -060010288 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010289 dsl_binding.binding = 0;
10290 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10291 dsl_binding.descriptorCount = 1;
10292 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10293 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010294
Tony Barboureb254902015-07-15 12:50:33 -060010295 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010296 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10297 ds_layout_ci.pNext = NULL;
10298 ds_layout_ci.bindingCount = 1;
10299 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010300
Tobin Ehlis502480b2015-06-24 15:53:07 -060010301 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010302 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010303 ASSERT_VK_SUCCESS(err);
10304
10305 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010306 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010307 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010308 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010309 alloc_info.descriptorPool = ds_pool;
10310 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010311 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010312 ASSERT_VK_SUCCESS(err);
10313
Tony Barboureb254902015-07-15 12:50:33 -060010314 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010315 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010316 pipe_ms_state_ci.pNext = NULL;
10317 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10318 pipe_ms_state_ci.sampleShadingEnable = 0;
10319 pipe_ms_state_ci.minSampleShading = 1.0;
10320 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010321
Tony Barboureb254902015-07-15 12:50:33 -060010322 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010323 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10324 pipeline_layout_ci.pNext = NULL;
10325 pipeline_layout_ci.setLayoutCount = 1;
10326 pipeline_layout_ci.pSetLayouts = &ds_layout;
10327 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010329 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010330 ASSERT_VK_SUCCESS(err);
10331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010332 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10333 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10334 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010335 VkPipelineObj pipe(m_device);
10336 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010337 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010338 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010339 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010340 pipe.SetViewport(m_viewports);
10341 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010342 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010343
10344 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010345 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010346 // Don't care about actual data, just need to get to draw to flag error
10347 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010348 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010349 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010350 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010351
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010352 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010353
Chia-I Wuf7458c52015-10-26 21:10:41 +080010354 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10355 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10356 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010357}
Mark Muellerdfe37552016-07-07 14:47:42 -060010358
Mark Mueller2ee294f2016-08-04 12:59:48 -060010359TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10360 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10361 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010362 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010364 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10365 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010367 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10368 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010370 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010373 // The following test fails with recent NVidia drivers.
10374 // By the time core_validation is reached, the NVidia
10375 // driver has sanitized the invalid condition and core_validation
10376 // is not introduced to the failure condition. This is not the case
10377 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010378 // uint32_t count = static_cast<uint32_t>(~0);
10379 // VkPhysicalDevice physical_device;
10380 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10381 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010384 float queue_priority = 0.0;
10385
10386 VkDeviceQueueCreateInfo queue_create_info = {};
10387 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10388 queue_create_info.queueCount = 1;
10389 queue_create_info.pQueuePriorities = &queue_priority;
10390 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10391
10392 VkPhysicalDeviceFeatures features = m_device->phy().features();
10393 VkDevice testDevice;
10394 VkDeviceCreateInfo device_create_info = {};
10395 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10396 device_create_info.queueCreateInfoCount = 1;
10397 device_create_info.pQueueCreateInfos = &queue_create_info;
10398 device_create_info.pEnabledFeatures = &features;
10399 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10400 m_errorMonitor->VerifyFound();
10401
10402 queue_create_info.queueFamilyIndex = 1;
10403
10404 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10405 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10406 for (unsigned i = 0; i < feature_count; i++) {
10407 if (VK_FALSE == feature_array[i]) {
10408 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010410 device_create_info.pEnabledFeatures = &features;
10411 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10412 m_errorMonitor->VerifyFound();
10413 break;
10414 }
10415 }
10416}
10417
Tobin Ehlis16edf082016-11-21 12:33:49 -070010418TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10419 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10420
10421 ASSERT_NO_FATAL_FAILURE(InitState());
10422
10423 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10424 std::vector<VkDeviceQueueCreateInfo> queue_info;
10425 queue_info.reserve(queue_props.size());
10426 std::vector<std::vector<float>> queue_priorities;
10427 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10428 VkDeviceQueueCreateInfo qi{};
10429 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10430 qi.queueFamilyIndex = i;
10431 qi.queueCount = queue_props[i].queueCount;
10432 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10433 qi.pQueuePriorities = queue_priorities[i].data();
10434 queue_info.push_back(qi);
10435 }
10436
10437 std::vector<const char *> device_extension_names;
10438
10439 VkDevice local_device;
10440 VkDeviceCreateInfo device_create_info = {};
10441 auto features = m_device->phy().features();
10442 // Intentionally disable pipeline stats
10443 features.pipelineStatisticsQuery = VK_FALSE;
10444 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10445 device_create_info.pNext = NULL;
10446 device_create_info.queueCreateInfoCount = queue_info.size();
10447 device_create_info.pQueueCreateInfos = queue_info.data();
10448 device_create_info.enabledLayerCount = 0;
10449 device_create_info.ppEnabledLayerNames = NULL;
10450 device_create_info.pEnabledFeatures = &features;
10451 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10452 ASSERT_VK_SUCCESS(err);
10453
10454 VkQueryPoolCreateInfo qpci{};
10455 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10456 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10457 qpci.queryCount = 1;
10458 VkQueryPool query_pool;
10459
10460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10461 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10462 m_errorMonitor->VerifyFound();
10463
10464 vkDestroyDevice(local_device, nullptr);
10465}
10466
Mark Mueller2ee294f2016-08-04 12:59:48 -060010467TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10468 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10469 "End a command buffer with a query still in progress.");
10470
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010471 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10472 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10473 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010474
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010475 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010476
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010478
10479 ASSERT_NO_FATAL_FAILURE(InitState());
10480
10481 VkEvent event;
10482 VkEventCreateInfo event_create_info{};
10483 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10484 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10485
Mark Mueller2ee294f2016-08-04 12:59:48 -060010486 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010487 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010488
10489 BeginCommandBuffer();
10490
10491 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010492 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 -060010493 ASSERT_TRUE(image.initialized());
10494 VkImageMemoryBarrier img_barrier = {};
10495 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10496 img_barrier.pNext = NULL;
10497 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10498 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10499 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10500 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10501 img_barrier.image = image.handle();
10502 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010503
10504 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10505 // that layer validation catches the case when it is not.
10506 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010507 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10508 img_barrier.subresourceRange.baseArrayLayer = 0;
10509 img_barrier.subresourceRange.baseMipLevel = 0;
10510 img_barrier.subresourceRange.layerCount = 1;
10511 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010512 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10513 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010514 m_errorMonitor->VerifyFound();
10515
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010517
10518 VkQueryPool query_pool;
10519 VkQueryPoolCreateInfo query_pool_create_info = {};
10520 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10521 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10522 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010523 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010524
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010525 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010526 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10527
10528 vkEndCommandBuffer(m_commandBuffer->handle());
10529 m_errorMonitor->VerifyFound();
10530
10531 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10532 vkDestroyEvent(m_device->device(), event, nullptr);
10533}
10534
Mark Muellerdfe37552016-07-07 14:47:42 -060010535TEST_F(VkLayerTest, VertexBufferInvalid) {
10536 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10537 "delete a buffer twice, use an invalid offset for each "
10538 "buffer type, and attempt to bind a null buffer");
10539
10540 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10541 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010542 const char *invalid_offset_message = "vkBindBufferMemory(): "
10543 "memoryOffset is 0x";
10544 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10545 "storage memoryOffset "
10546 "is 0x";
10547 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10548 "texel memoryOffset "
10549 "is 0x";
10550 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10551 "uniform memoryOffset "
10552 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010553
10554 ASSERT_NO_FATAL_FAILURE(InitState());
10555 ASSERT_NO_FATAL_FAILURE(InitViewport());
10556 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10557
10558 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010559 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010560 pipe_ms_state_ci.pNext = NULL;
10561 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10562 pipe_ms_state_ci.sampleShadingEnable = 0;
10563 pipe_ms_state_ci.minSampleShading = 1.0;
10564 pipe_ms_state_ci.pSampleMask = nullptr;
10565
10566 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10567 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10568 VkPipelineLayout pipeline_layout;
10569
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010570 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010571 ASSERT_VK_SUCCESS(err);
10572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010573 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10574 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010575 VkPipelineObj pipe(m_device);
10576 pipe.AddShader(&vs);
10577 pipe.AddShader(&fs);
10578 pipe.AddColorAttachment();
10579 pipe.SetMSAA(&pipe_ms_state_ci);
10580 pipe.SetViewport(m_viewports);
10581 pipe.SetScissor(m_scissors);
10582 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10583
10584 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010585 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010586
10587 {
10588 // Create and bind a vertex buffer in a reduced scope, which will cause
10589 // it to be deleted upon leaving this scope
10590 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010591 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010592 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10593 draw_verticies.AddVertexInputToPipe(pipe);
10594 }
10595
10596 Draw(1, 0, 0, 0);
10597
10598 EndCommandBuffer();
10599
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010601 QueueCommandBuffer(false);
10602 m_errorMonitor->VerifyFound();
10603
10604 {
10605 // Create and bind a vertex buffer in a reduced scope, and delete it
10606 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010607 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010609 buffer_test.TestDoubleDestroy();
10610 }
10611 m_errorMonitor->VerifyFound();
10612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010613 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010614 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10616 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10617 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010618 m_errorMonitor->VerifyFound();
10619 }
10620
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010621 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10622 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010623 // Create and bind a memory buffer with an invalid offset again,
10624 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10626 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10627 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010628 m_errorMonitor->VerifyFound();
10629 }
10630
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010631 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010632 // Create and bind a memory buffer with an invalid offset again, but
10633 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10635 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10636 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010637 m_errorMonitor->VerifyFound();
10638 }
10639
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010640 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010641 // Create and bind a memory buffer with an invalid offset again, but
10642 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10644 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10645 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010646 m_errorMonitor->VerifyFound();
10647 }
10648
10649 {
10650 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010652 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10653 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010654 m_errorMonitor->VerifyFound();
10655 }
10656
10657 {
10658 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010660 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10661 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010662 }
10663 m_errorMonitor->VerifyFound();
10664
10665 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10666}
10667
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010668// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10669TEST_F(VkLayerTest, InvalidImageLayout) {
10670 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010671 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10672 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010673 // 3 in ValidateCmdBufImageLayouts
10674 // * -1 Attempt to submit cmd buf w/ deleted image
10675 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10676 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010677
10678 ASSERT_NO_FATAL_FAILURE(InitState());
10679 // Create src & dst images to use for copy operations
10680 VkImage src_image;
10681 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010682 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010683
10684 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10685 const int32_t tex_width = 32;
10686 const int32_t tex_height = 32;
10687
10688 VkImageCreateInfo image_create_info = {};
10689 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10690 image_create_info.pNext = NULL;
10691 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10692 image_create_info.format = tex_format;
10693 image_create_info.extent.width = tex_width;
10694 image_create_info.extent.height = tex_height;
10695 image_create_info.extent.depth = 1;
10696 image_create_info.mipLevels = 1;
10697 image_create_info.arrayLayers = 4;
10698 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10699 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10700 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010701 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010702 image_create_info.flags = 0;
10703
10704 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10705 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010706 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010707 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10708 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010709 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10710 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10711 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10712 ASSERT_VK_SUCCESS(err);
10713
10714 // Allocate memory
10715 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010716 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010717 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010718 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10719 mem_alloc.pNext = NULL;
10720 mem_alloc.allocationSize = 0;
10721 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010722
10723 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010724 mem_alloc.allocationSize = img_mem_reqs.size;
10725 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010726 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010727 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010728 ASSERT_VK_SUCCESS(err);
10729
10730 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010731 mem_alloc.allocationSize = img_mem_reqs.size;
10732 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010733 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010734 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010735 ASSERT_VK_SUCCESS(err);
10736
10737 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010738 mem_alloc.allocationSize = img_mem_reqs.size;
10739 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010740 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010741 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010742 ASSERT_VK_SUCCESS(err);
10743
10744 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10745 ASSERT_VK_SUCCESS(err);
10746 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10747 ASSERT_VK_SUCCESS(err);
10748 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10749 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010750
10751 BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010752 VkImageCopy copy_region;
10753 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10754 copy_region.srcSubresource.mipLevel = 0;
10755 copy_region.srcSubresource.baseArrayLayer = 0;
10756 copy_region.srcSubresource.layerCount = 1;
10757 copy_region.srcOffset.x = 0;
10758 copy_region.srcOffset.y = 0;
10759 copy_region.srcOffset.z = 0;
10760 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10761 copy_region.dstSubresource.mipLevel = 0;
10762 copy_region.dstSubresource.baseArrayLayer = 0;
10763 copy_region.dstSubresource.layerCount = 1;
10764 copy_region.dstOffset.x = 0;
10765 copy_region.dstOffset.y = 0;
10766 copy_region.dstOffset.z = 0;
10767 copy_region.extent.width = 1;
10768 copy_region.extent.height = 1;
10769 copy_region.extent.depth = 1;
10770
10771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10772 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10773 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 -060010774 m_errorMonitor->VerifyFound();
10775 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10777 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10778 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010779 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 -060010780 m_errorMonitor->VerifyFound();
10781 // Final src error is due to bad layout type
10782 m_errorMonitor->SetDesiredFailureMsg(
10783 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10784 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010785 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 -060010786 m_errorMonitor->VerifyFound();
10787 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10789 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010790 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 -060010791 m_errorMonitor->VerifyFound();
10792 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10794 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10795 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010796 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 -060010797 m_errorMonitor->VerifyFound();
10798 m_errorMonitor->SetDesiredFailureMsg(
10799 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10800 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010801 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 -060010802 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010803
Cort3b021012016-12-07 12:00:57 -080010804 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10805 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10806 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10807 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10808 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10809 transfer_dst_image_barrier[0].srcAccessMask = 0;
10810 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10811 transfer_dst_image_barrier[0].image = dst_image;
10812 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10813 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10814 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10815 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10816 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10817 transfer_dst_image_barrier[0].image = depth_image;
10818 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10819 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10820 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10821
10822 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010823 VkClearColorValue color_clear_value = {};
10824 VkImageSubresourceRange clear_range;
10825 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10826 clear_range.baseMipLevel = 0;
10827 clear_range.baseArrayLayer = 0;
10828 clear_range.layerCount = 1;
10829 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010830
Cort3b021012016-12-07 12:00:57 -080010831 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10832 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010835 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010836 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010837 // Fail due to provided layout not matching actual current layout for color clear.
10838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010839 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010840 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010841
Cort530cf382016-12-08 09:59:47 -080010842 VkClearDepthStencilValue depth_clear_value = {};
10843 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010844
10845 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10846 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010849 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010850 m_errorMonitor->VerifyFound();
10851 // Fail due to provided layout not matching actual current layout for depth clear.
10852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010853 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010854 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010855
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010856 // Now cause error due to bad image layout transition in PipelineBarrier
10857 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010858 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010859 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010860 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010861 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010862 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10863 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010864 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10866 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10867 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10868 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10869 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010870 m_errorMonitor->VerifyFound();
10871
10872 // Finally some layout errors at RenderPass create time
10873 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10874 VkAttachmentReference attach = {};
10875 // perf warning for GENERAL layout w/ non-DS input attachment
10876 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10877 VkSubpassDescription subpass = {};
10878 subpass.inputAttachmentCount = 1;
10879 subpass.pInputAttachments = &attach;
10880 VkRenderPassCreateInfo rpci = {};
10881 rpci.subpassCount = 1;
10882 rpci.pSubpasses = &subpass;
10883 rpci.attachmentCount = 1;
10884 VkAttachmentDescription attach_desc = {};
10885 attach_desc.format = VK_FORMAT_UNDEFINED;
10886 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010887 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010888 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10890 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010891 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10892 m_errorMonitor->VerifyFound();
10893 // error w/ non-general layout
10894 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10895
10896 m_errorMonitor->SetDesiredFailureMsg(
10897 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10898 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10899 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10900 m_errorMonitor->VerifyFound();
10901 subpass.inputAttachmentCount = 0;
10902 subpass.colorAttachmentCount = 1;
10903 subpass.pColorAttachments = &attach;
10904 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10905 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10907 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010908 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10909 m_errorMonitor->VerifyFound();
10910 // error w/ non-color opt or GENERAL layout for color attachment
10911 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10912 m_errorMonitor->SetDesiredFailureMsg(
10913 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10914 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10915 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10916 m_errorMonitor->VerifyFound();
10917 subpass.colorAttachmentCount = 0;
10918 subpass.pDepthStencilAttachment = &attach;
10919 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10920 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10922 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010923 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10924 m_errorMonitor->VerifyFound();
10925 // error w/ non-ds opt or GENERAL layout for color attachment
10926 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10928 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10929 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010930 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10931 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010932 // For this error we need a valid renderpass so create default one
10933 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10934 attach.attachment = 0;
10935 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10936 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10937 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10938 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10939 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10940 // Can't do a CLEAR load on READ_ONLY initialLayout
10941 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10942 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10943 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10945 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10946 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010947 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10948 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010949
Cort3b021012016-12-07 12:00:57 -080010950 vkFreeMemory(m_device->device(), src_image_mem, NULL);
10951 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
10952 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010953 vkDestroyImage(m_device->device(), src_image, NULL);
10954 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080010955 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010956}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010957
Tobin Ehlise0936662016-10-11 08:10:51 -060010958TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10959 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10960 VkResult err;
10961
10962 ASSERT_NO_FATAL_FAILURE(InitState());
10963
10964 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10965 VkImageTiling tiling;
10966 VkFormatProperties format_properties;
10967 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10968 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10969 tiling = VK_IMAGE_TILING_LINEAR;
10970 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10971 tiling = VK_IMAGE_TILING_OPTIMAL;
10972 } else {
10973 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10974 "skipped.\n");
10975 return;
10976 }
10977
10978 VkDescriptorPoolSize ds_type = {};
10979 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10980 ds_type.descriptorCount = 1;
10981
10982 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10983 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10984 ds_pool_ci.maxSets = 1;
10985 ds_pool_ci.poolSizeCount = 1;
10986 ds_pool_ci.pPoolSizes = &ds_type;
10987 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10988
10989 VkDescriptorPool ds_pool;
10990 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10991 ASSERT_VK_SUCCESS(err);
10992
10993 VkDescriptorSetLayoutBinding dsl_binding = {};
10994 dsl_binding.binding = 0;
10995 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10996 dsl_binding.descriptorCount = 1;
10997 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10998 dsl_binding.pImmutableSamplers = NULL;
10999
11000 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11001 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11002 ds_layout_ci.pNext = NULL;
11003 ds_layout_ci.bindingCount = 1;
11004 ds_layout_ci.pBindings = &dsl_binding;
11005
11006 VkDescriptorSetLayout ds_layout;
11007 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11008 ASSERT_VK_SUCCESS(err);
11009
11010 VkDescriptorSetAllocateInfo alloc_info = {};
11011 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11012 alloc_info.descriptorSetCount = 1;
11013 alloc_info.descriptorPool = ds_pool;
11014 alloc_info.pSetLayouts = &ds_layout;
11015 VkDescriptorSet descriptor_set;
11016 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11017 ASSERT_VK_SUCCESS(err);
11018
11019 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11020 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11021 pipeline_layout_ci.pNext = NULL;
11022 pipeline_layout_ci.setLayoutCount = 1;
11023 pipeline_layout_ci.pSetLayouts = &ds_layout;
11024 VkPipelineLayout pipeline_layout;
11025 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11026 ASSERT_VK_SUCCESS(err);
11027
11028 VkImageObj image(m_device);
11029 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11030 ASSERT_TRUE(image.initialized());
11031 VkImageView view = image.targetView(tex_format);
11032
11033 VkDescriptorImageInfo image_info = {};
11034 image_info.imageView = view;
11035 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11036
11037 VkWriteDescriptorSet descriptor_write = {};
11038 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11039 descriptor_write.dstSet = descriptor_set;
11040 descriptor_write.dstBinding = 0;
11041 descriptor_write.descriptorCount = 1;
11042 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11043 descriptor_write.pImageInfo = &image_info;
11044
11045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11046 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11047 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11048 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11049 m_errorMonitor->VerifyFound();
11050
11051 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11052 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11053 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11054 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11055}
11056
Mark Mueller93b938f2016-08-18 10:27:40 -060011057TEST_F(VkLayerTest, SimultaneousUse) {
11058 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11059 "in primary and secondary command buffers.");
11060
11061 ASSERT_NO_FATAL_FAILURE(InitState());
11062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11063
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011064 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011065 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11066 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011067
11068 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011069 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011070 command_buffer_allocate_info.commandPool = m_commandPool;
11071 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11072 command_buffer_allocate_info.commandBufferCount = 1;
11073
11074 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011075 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011076 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11077 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011078 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011079 command_buffer_inheritance_info.renderPass = m_renderPass;
11080 command_buffer_inheritance_info.framebuffer = m_framebuffer;
11081 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011082 command_buffer_begin_info.flags =
11083 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011084 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11085
11086 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011087 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11088 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060011089 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011090 vkEndCommandBuffer(secondary_command_buffer);
11091
Mark Mueller93b938f2016-08-18 10:27:40 -060011092 VkSubmitInfo submit_info = {};
11093 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11094 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011095 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060011096 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060011097
Mark Mueller4042b652016-09-05 22:52:21 -060011098 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011099 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11101 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011102 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011103 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11104 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011105
11106 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060011107 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11108
Mark Mueller4042b652016-09-05 22:52:21 -060011109 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011110 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011111 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011112
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11114 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011115 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011116 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11117 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011118}
11119
Mark Mueller917f6bc2016-08-30 10:57:19 -060011120TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11121 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11122 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011123 "Delete objects that are inuse. Call VkQueueSubmit "
11124 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011125
11126 ASSERT_NO_FATAL_FAILURE(InitState());
11127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11128
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011129 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
11130 const char *cannot_delete_event_message = "Cannot delete event 0x";
11131 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
11132 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011133
11134 BeginCommandBuffer();
11135
11136 VkEvent event;
11137 VkEventCreateInfo event_create_info = {};
11138 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11139 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011140 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011141
Mark Muellerc8d441e2016-08-23 17:36:00 -060011142 EndCommandBuffer();
11143 vkDestroyEvent(m_device->device(), event, nullptr);
11144
11145 VkSubmitInfo submit_info = {};
11146 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11147 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011148 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011150 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11151 m_errorMonitor->VerifyFound();
11152
11153 m_errorMonitor->SetDesiredFailureMsg(0, "");
11154 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11155
11156 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11157
Mark Mueller917f6bc2016-08-30 10:57:19 -060011158 VkSemaphoreCreateInfo semaphore_create_info = {};
11159 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11160 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011161 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011162 VkFenceCreateInfo fence_create_info = {};
11163 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11164 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011165 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011166
11167 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011168 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011169 descriptor_pool_type_count.descriptorCount = 1;
11170
11171 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11172 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11173 descriptor_pool_create_info.maxSets = 1;
11174 descriptor_pool_create_info.poolSizeCount = 1;
11175 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011176 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011177
11178 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011179 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011180
11181 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011182 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011183 descriptorset_layout_binding.descriptorCount = 1;
11184 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11185
11186 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011187 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011188 descriptorset_layout_create_info.bindingCount = 1;
11189 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11190
11191 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011192 ASSERT_VK_SUCCESS(
11193 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011194
11195 VkDescriptorSet descriptorset;
11196 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011197 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011198 descriptorset_allocate_info.descriptorSetCount = 1;
11199 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11200 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011201 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011202
Mark Mueller4042b652016-09-05 22:52:21 -060011203 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11204
11205 VkDescriptorBufferInfo buffer_info = {};
11206 buffer_info.buffer = buffer_test.GetBuffer();
11207 buffer_info.offset = 0;
11208 buffer_info.range = 1024;
11209
11210 VkWriteDescriptorSet write_descriptor_set = {};
11211 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11212 write_descriptor_set.dstSet = descriptorset;
11213 write_descriptor_set.descriptorCount = 1;
11214 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11215 write_descriptor_set.pBufferInfo = &buffer_info;
11216
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011217 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011219 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11220 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011221
11222 VkPipelineObj pipe(m_device);
11223 pipe.AddColorAttachment();
11224 pipe.AddShader(&vs);
11225 pipe.AddShader(&fs);
11226
11227 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011228 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011229 pipeline_layout_create_info.setLayoutCount = 1;
11230 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11231
11232 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011233 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011234
11235 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11236
Mark Muellerc8d441e2016-08-23 17:36:00 -060011237 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011238 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011240 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11241 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11242 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011243
Mark Muellerc8d441e2016-08-23 17:36:00 -060011244 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011245
Mark Mueller917f6bc2016-08-30 10:57:19 -060011246 submit_info.signalSemaphoreCount = 1;
11247 submit_info.pSignalSemaphores = &semaphore;
11248 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011249
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011251 vkDestroyEvent(m_device->device(), event, nullptr);
11252 m_errorMonitor->VerifyFound();
11253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011255 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11256 m_errorMonitor->VerifyFound();
11257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011259 vkDestroyFence(m_device->device(), fence, nullptr);
11260 m_errorMonitor->VerifyFound();
11261
Tobin Ehlis122207b2016-09-01 08:50:06 -070011262 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011263 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11264 vkDestroyFence(m_device->device(), fence, nullptr);
11265 vkDestroyEvent(m_device->device(), event, nullptr);
11266 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011267 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011268 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11269}
11270
Tobin Ehlis2adda372016-09-01 08:51:06 -070011271TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11272 TEST_DESCRIPTION("Delete in-use query pool.");
11273
11274 ASSERT_NO_FATAL_FAILURE(InitState());
11275 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11276
11277 VkQueryPool query_pool;
11278 VkQueryPoolCreateInfo query_pool_ci{};
11279 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11280 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11281 query_pool_ci.queryCount = 1;
11282 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
11283 BeginCommandBuffer();
11284 // Reset query pool to create binding with cmd buffer
11285 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11286
11287 EndCommandBuffer();
11288
11289 VkSubmitInfo submit_info = {};
11290 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11291 submit_info.commandBufferCount = 1;
11292 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11293 // Submit cmd buffer and then destroy query pool while in-flight
11294 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070011297 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11298 m_errorMonitor->VerifyFound();
11299
11300 vkQueueWaitIdle(m_device->m_queue);
11301 // Now that cmd buffer done we can safely destroy query_pool
11302 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11303}
11304
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011305TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11306 TEST_DESCRIPTION("Delete in-use pipeline.");
11307
11308 ASSERT_NO_FATAL_FAILURE(InitState());
11309 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11310
11311 // Empty pipeline layout used for binding PSO
11312 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11313 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11314 pipeline_layout_ci.setLayoutCount = 0;
11315 pipeline_layout_ci.pSetLayouts = NULL;
11316
11317 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011318 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011319 ASSERT_VK_SUCCESS(err);
11320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011322 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011323 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11324 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011325 // Store pipeline handle so we can actually delete it before test finishes
11326 VkPipeline delete_this_pipeline;
11327 { // Scope pipeline so it will be auto-deleted
11328 VkPipelineObj pipe(m_device);
11329 pipe.AddShader(&vs);
11330 pipe.AddShader(&fs);
11331 pipe.AddColorAttachment();
11332 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11333 delete_this_pipeline = pipe.handle();
11334
11335 BeginCommandBuffer();
11336 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011337 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011338
11339 EndCommandBuffer();
11340
11341 VkSubmitInfo submit_info = {};
11342 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11343 submit_info.commandBufferCount = 1;
11344 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11345 // Submit cmd buffer and then pipeline destroyed while in-flight
11346 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11347 } // Pipeline deletion triggered here
11348 m_errorMonitor->VerifyFound();
11349 // Make sure queue finished and then actually delete pipeline
11350 vkQueueWaitIdle(m_device->m_queue);
11351 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11352 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11353}
11354
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011355TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11356 TEST_DESCRIPTION("Delete in-use imageView.");
11357
11358 ASSERT_NO_FATAL_FAILURE(InitState());
11359 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11360
11361 VkDescriptorPoolSize ds_type_count;
11362 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11363 ds_type_count.descriptorCount = 1;
11364
11365 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11366 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11367 ds_pool_ci.maxSets = 1;
11368 ds_pool_ci.poolSizeCount = 1;
11369 ds_pool_ci.pPoolSizes = &ds_type_count;
11370
11371 VkDescriptorPool ds_pool;
11372 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11373 ASSERT_VK_SUCCESS(err);
11374
11375 VkSamplerCreateInfo sampler_ci = {};
11376 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11377 sampler_ci.pNext = NULL;
11378 sampler_ci.magFilter = VK_FILTER_NEAREST;
11379 sampler_ci.minFilter = VK_FILTER_NEAREST;
11380 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11381 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11382 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11383 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11384 sampler_ci.mipLodBias = 1.0;
11385 sampler_ci.anisotropyEnable = VK_FALSE;
11386 sampler_ci.maxAnisotropy = 1;
11387 sampler_ci.compareEnable = VK_FALSE;
11388 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11389 sampler_ci.minLod = 1.0;
11390 sampler_ci.maxLod = 1.0;
11391 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11392 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11393 VkSampler sampler;
11394
11395 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11396 ASSERT_VK_SUCCESS(err);
11397
11398 VkDescriptorSetLayoutBinding layout_binding;
11399 layout_binding.binding = 0;
11400 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11401 layout_binding.descriptorCount = 1;
11402 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11403 layout_binding.pImmutableSamplers = NULL;
11404
11405 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11406 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11407 ds_layout_ci.bindingCount = 1;
11408 ds_layout_ci.pBindings = &layout_binding;
11409 VkDescriptorSetLayout ds_layout;
11410 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11411 ASSERT_VK_SUCCESS(err);
11412
11413 VkDescriptorSetAllocateInfo alloc_info = {};
11414 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11415 alloc_info.descriptorSetCount = 1;
11416 alloc_info.descriptorPool = ds_pool;
11417 alloc_info.pSetLayouts = &ds_layout;
11418 VkDescriptorSet descriptor_set;
11419 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11420 ASSERT_VK_SUCCESS(err);
11421
11422 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11423 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11424 pipeline_layout_ci.pNext = NULL;
11425 pipeline_layout_ci.setLayoutCount = 1;
11426 pipeline_layout_ci.pSetLayouts = &ds_layout;
11427
11428 VkPipelineLayout pipeline_layout;
11429 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11430 ASSERT_VK_SUCCESS(err);
11431
11432 VkImageObj image(m_device);
11433 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11434 ASSERT_TRUE(image.initialized());
11435
11436 VkImageView view;
11437 VkImageViewCreateInfo ivci = {};
11438 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11439 ivci.image = image.handle();
11440 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11441 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11442 ivci.subresourceRange.layerCount = 1;
11443 ivci.subresourceRange.baseMipLevel = 0;
11444 ivci.subresourceRange.levelCount = 1;
11445 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11446
11447 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11448 ASSERT_VK_SUCCESS(err);
11449
11450 VkDescriptorImageInfo image_info{};
11451 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11452 image_info.imageView = view;
11453 image_info.sampler = sampler;
11454
11455 VkWriteDescriptorSet descriptor_write = {};
11456 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11457 descriptor_write.dstSet = descriptor_set;
11458 descriptor_write.dstBinding = 0;
11459 descriptor_write.descriptorCount = 1;
11460 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11461 descriptor_write.pImageInfo = &image_info;
11462
11463 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11464
11465 // Create PSO to use the sampler
11466 char const *vsSource = "#version 450\n"
11467 "\n"
11468 "out gl_PerVertex { \n"
11469 " vec4 gl_Position;\n"
11470 "};\n"
11471 "void main(){\n"
11472 " gl_Position = vec4(1);\n"
11473 "}\n";
11474 char const *fsSource = "#version 450\n"
11475 "\n"
11476 "layout(set=0, binding=0) uniform sampler2D s;\n"
11477 "layout(location=0) out vec4 x;\n"
11478 "void main(){\n"
11479 " x = texture(s, vec2(1));\n"
11480 "}\n";
11481 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11482 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11483 VkPipelineObj pipe(m_device);
11484 pipe.AddShader(&vs);
11485 pipe.AddShader(&fs);
11486 pipe.AddColorAttachment();
11487 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11488
11489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11490
11491 BeginCommandBuffer();
11492 // Bind pipeline to cmd buffer
11493 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11494 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11495 &descriptor_set, 0, nullptr);
11496 Draw(1, 0, 0, 0);
11497 EndCommandBuffer();
11498 // Submit cmd buffer then destroy sampler
11499 VkSubmitInfo submit_info = {};
11500 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11501 submit_info.commandBufferCount = 1;
11502 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11503 // Submit cmd buffer and then destroy imageView while in-flight
11504 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11505
11506 vkDestroyImageView(m_device->device(), view, nullptr);
11507 m_errorMonitor->VerifyFound();
11508 vkQueueWaitIdle(m_device->m_queue);
11509 // Now we can actually destroy imageView
11510 vkDestroyImageView(m_device->device(), view, NULL);
11511 vkDestroySampler(m_device->device(), sampler, nullptr);
11512 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11513 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11514 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11515}
11516
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011517TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11518 TEST_DESCRIPTION("Delete in-use bufferView.");
11519
11520 ASSERT_NO_FATAL_FAILURE(InitState());
11521 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11522
11523 VkDescriptorPoolSize ds_type_count;
11524 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11525 ds_type_count.descriptorCount = 1;
11526
11527 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11528 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11529 ds_pool_ci.maxSets = 1;
11530 ds_pool_ci.poolSizeCount = 1;
11531 ds_pool_ci.pPoolSizes = &ds_type_count;
11532
11533 VkDescriptorPool ds_pool;
11534 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11535 ASSERT_VK_SUCCESS(err);
11536
11537 VkDescriptorSetLayoutBinding layout_binding;
11538 layout_binding.binding = 0;
11539 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11540 layout_binding.descriptorCount = 1;
11541 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11542 layout_binding.pImmutableSamplers = NULL;
11543
11544 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11545 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11546 ds_layout_ci.bindingCount = 1;
11547 ds_layout_ci.pBindings = &layout_binding;
11548 VkDescriptorSetLayout ds_layout;
11549 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11550 ASSERT_VK_SUCCESS(err);
11551
11552 VkDescriptorSetAllocateInfo alloc_info = {};
11553 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11554 alloc_info.descriptorSetCount = 1;
11555 alloc_info.descriptorPool = ds_pool;
11556 alloc_info.pSetLayouts = &ds_layout;
11557 VkDescriptorSet descriptor_set;
11558 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11559 ASSERT_VK_SUCCESS(err);
11560
11561 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11562 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11563 pipeline_layout_ci.pNext = NULL;
11564 pipeline_layout_ci.setLayoutCount = 1;
11565 pipeline_layout_ci.pSetLayouts = &ds_layout;
11566
11567 VkPipelineLayout pipeline_layout;
11568 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11569 ASSERT_VK_SUCCESS(err);
11570
11571 VkBuffer buffer;
11572 uint32_t queue_family_index = 0;
11573 VkBufferCreateInfo buffer_create_info = {};
11574 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11575 buffer_create_info.size = 1024;
11576 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11577 buffer_create_info.queueFamilyIndexCount = 1;
11578 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11579
11580 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11581 ASSERT_VK_SUCCESS(err);
11582
11583 VkMemoryRequirements memory_reqs;
11584 VkDeviceMemory buffer_memory;
11585
11586 VkMemoryAllocateInfo memory_info = {};
11587 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11588 memory_info.allocationSize = 0;
11589 memory_info.memoryTypeIndex = 0;
11590
11591 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11592 memory_info.allocationSize = memory_reqs.size;
11593 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11594 ASSERT_TRUE(pass);
11595
11596 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11597 ASSERT_VK_SUCCESS(err);
11598 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11599 ASSERT_VK_SUCCESS(err);
11600
11601 VkBufferView view;
11602 VkBufferViewCreateInfo bvci = {};
11603 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11604 bvci.buffer = buffer;
11605 bvci.format = VK_FORMAT_R8_UNORM;
11606 bvci.range = VK_WHOLE_SIZE;
11607
11608 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11609 ASSERT_VK_SUCCESS(err);
11610
11611 VkWriteDescriptorSet descriptor_write = {};
11612 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11613 descriptor_write.dstSet = descriptor_set;
11614 descriptor_write.dstBinding = 0;
11615 descriptor_write.descriptorCount = 1;
11616 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11617 descriptor_write.pTexelBufferView = &view;
11618
11619 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11620
11621 char const *vsSource = "#version 450\n"
11622 "\n"
11623 "out gl_PerVertex { \n"
11624 " vec4 gl_Position;\n"
11625 "};\n"
11626 "void main(){\n"
11627 " gl_Position = vec4(1);\n"
11628 "}\n";
11629 char const *fsSource = "#version 450\n"
11630 "\n"
11631 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11632 "layout(location=0) out vec4 x;\n"
11633 "void main(){\n"
11634 " x = imageLoad(s, 0);\n"
11635 "}\n";
11636 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11637 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11638 VkPipelineObj pipe(m_device);
11639 pipe.AddShader(&vs);
11640 pipe.AddShader(&fs);
11641 pipe.AddColorAttachment();
11642 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11643
11644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11645
11646 BeginCommandBuffer();
11647 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11648 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11649 VkRect2D scissor = {{0, 0}, {16, 16}};
11650 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11651 // Bind pipeline to cmd buffer
11652 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11653 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11654 &descriptor_set, 0, nullptr);
11655 Draw(1, 0, 0, 0);
11656 EndCommandBuffer();
11657
11658 VkSubmitInfo submit_info = {};
11659 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11660 submit_info.commandBufferCount = 1;
11661 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11662 // Submit cmd buffer and then destroy bufferView while in-flight
11663 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11664
11665 vkDestroyBufferView(m_device->device(), view, nullptr);
11666 m_errorMonitor->VerifyFound();
11667 vkQueueWaitIdle(m_device->m_queue);
11668 // Now we can actually destroy bufferView
11669 vkDestroyBufferView(m_device->device(), view, NULL);
11670 vkDestroyBuffer(m_device->device(), buffer, NULL);
11671 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11672 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11673 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11674 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11675}
11676
Tobin Ehlis209532e2016-09-07 13:52:18 -060011677TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11678 TEST_DESCRIPTION("Delete in-use sampler.");
11679
11680 ASSERT_NO_FATAL_FAILURE(InitState());
11681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11682
11683 VkDescriptorPoolSize ds_type_count;
11684 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11685 ds_type_count.descriptorCount = 1;
11686
11687 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11688 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11689 ds_pool_ci.maxSets = 1;
11690 ds_pool_ci.poolSizeCount = 1;
11691 ds_pool_ci.pPoolSizes = &ds_type_count;
11692
11693 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011694 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011695 ASSERT_VK_SUCCESS(err);
11696
11697 VkSamplerCreateInfo sampler_ci = {};
11698 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11699 sampler_ci.pNext = NULL;
11700 sampler_ci.magFilter = VK_FILTER_NEAREST;
11701 sampler_ci.minFilter = VK_FILTER_NEAREST;
11702 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11703 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11704 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11705 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11706 sampler_ci.mipLodBias = 1.0;
11707 sampler_ci.anisotropyEnable = VK_FALSE;
11708 sampler_ci.maxAnisotropy = 1;
11709 sampler_ci.compareEnable = VK_FALSE;
11710 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11711 sampler_ci.minLod = 1.0;
11712 sampler_ci.maxLod = 1.0;
11713 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11714 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11715 VkSampler sampler;
11716
11717 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11718 ASSERT_VK_SUCCESS(err);
11719
11720 VkDescriptorSetLayoutBinding layout_binding;
11721 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011722 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011723 layout_binding.descriptorCount = 1;
11724 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11725 layout_binding.pImmutableSamplers = NULL;
11726
11727 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11728 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11729 ds_layout_ci.bindingCount = 1;
11730 ds_layout_ci.pBindings = &layout_binding;
11731 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011732 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011733 ASSERT_VK_SUCCESS(err);
11734
11735 VkDescriptorSetAllocateInfo alloc_info = {};
11736 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11737 alloc_info.descriptorSetCount = 1;
11738 alloc_info.descriptorPool = ds_pool;
11739 alloc_info.pSetLayouts = &ds_layout;
11740 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011741 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011742 ASSERT_VK_SUCCESS(err);
11743
11744 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11745 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11746 pipeline_layout_ci.pNext = NULL;
11747 pipeline_layout_ci.setLayoutCount = 1;
11748 pipeline_layout_ci.pSetLayouts = &ds_layout;
11749
11750 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011751 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011752 ASSERT_VK_SUCCESS(err);
11753
11754 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011755 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 -060011756 ASSERT_TRUE(image.initialized());
11757
11758 VkImageView view;
11759 VkImageViewCreateInfo ivci = {};
11760 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11761 ivci.image = image.handle();
11762 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11763 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11764 ivci.subresourceRange.layerCount = 1;
11765 ivci.subresourceRange.baseMipLevel = 0;
11766 ivci.subresourceRange.levelCount = 1;
11767 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11768
11769 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11770 ASSERT_VK_SUCCESS(err);
11771
11772 VkDescriptorImageInfo image_info{};
11773 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11774 image_info.imageView = view;
11775 image_info.sampler = sampler;
11776
11777 VkWriteDescriptorSet descriptor_write = {};
11778 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11779 descriptor_write.dstSet = descriptor_set;
11780 descriptor_write.dstBinding = 0;
11781 descriptor_write.descriptorCount = 1;
11782 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11783 descriptor_write.pImageInfo = &image_info;
11784
11785 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11786
11787 // Create PSO to use the sampler
11788 char const *vsSource = "#version 450\n"
11789 "\n"
11790 "out gl_PerVertex { \n"
11791 " vec4 gl_Position;\n"
11792 "};\n"
11793 "void main(){\n"
11794 " gl_Position = vec4(1);\n"
11795 "}\n";
11796 char const *fsSource = "#version 450\n"
11797 "\n"
11798 "layout(set=0, binding=0) uniform sampler2D s;\n"
11799 "layout(location=0) out vec4 x;\n"
11800 "void main(){\n"
11801 " x = texture(s, vec2(1));\n"
11802 "}\n";
11803 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11804 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11805 VkPipelineObj pipe(m_device);
11806 pipe.AddShader(&vs);
11807 pipe.AddShader(&fs);
11808 pipe.AddColorAttachment();
11809 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11810
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011812
11813 BeginCommandBuffer();
11814 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011815 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11816 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11817 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011818 Draw(1, 0, 0, 0);
11819 EndCommandBuffer();
11820 // Submit cmd buffer then destroy sampler
11821 VkSubmitInfo submit_info = {};
11822 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11823 submit_info.commandBufferCount = 1;
11824 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11825 // Submit cmd buffer and then destroy sampler while in-flight
11826 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11827
11828 vkDestroySampler(m_device->device(), sampler, nullptr);
11829 m_errorMonitor->VerifyFound();
11830 vkQueueWaitIdle(m_device->m_queue);
11831 // Now we can actually destroy sampler
11832 vkDestroySampler(m_device->device(), sampler, nullptr);
11833 vkDestroyImageView(m_device->device(), view, NULL);
11834 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11835 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11836 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11837}
11838
Mark Mueller1cd9f412016-08-25 13:23:52 -060011839TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011840 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011841 "signaled but not waited on by the queue. Wait on a "
11842 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011843
11844 ASSERT_NO_FATAL_FAILURE(InitState());
11845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11846
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011847 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11848 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11849 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011850
11851 BeginCommandBuffer();
11852 EndCommandBuffer();
11853
11854 VkSemaphoreCreateInfo semaphore_create_info = {};
11855 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11856 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011857 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011858 VkSubmitInfo submit_info = {};
11859 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11860 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011861 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011862 submit_info.signalSemaphoreCount = 1;
11863 submit_info.pSignalSemaphores = &semaphore;
11864 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11865 m_errorMonitor->SetDesiredFailureMsg(0, "");
11866 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11867 BeginCommandBuffer();
11868 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011870 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11871 m_errorMonitor->VerifyFound();
11872
Mark Mueller1cd9f412016-08-25 13:23:52 -060011873 VkFenceCreateInfo fence_create_info = {};
11874 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11875 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011876 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011879 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11880 m_errorMonitor->VerifyFound();
11881
Mark Mueller4042b652016-09-05 22:52:21 -060011882 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011883 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011884 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11885}
11886
Tobin Ehlis4af23302016-07-19 10:50:30 -060011887TEST_F(VkLayerTest, FramebufferIncompatible) {
11888 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11889 "that does not match the framebuffer for the active "
11890 "renderpass.");
11891 ASSERT_NO_FATAL_FAILURE(InitState());
11892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11893
11894 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011895 VkAttachmentDescription attachment = {0,
11896 VK_FORMAT_B8G8R8A8_UNORM,
11897 VK_SAMPLE_COUNT_1_BIT,
11898 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11899 VK_ATTACHMENT_STORE_OP_STORE,
11900 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11901 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11902 VK_IMAGE_LAYOUT_UNDEFINED,
11903 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011904
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011905 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011906
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011907 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011908
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011909 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011910
11911 VkRenderPass rp;
11912 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11913 ASSERT_VK_SUCCESS(err);
11914
11915 // A compatible framebuffer.
11916 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011917 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 -060011918 ASSERT_TRUE(image.initialized());
11919
11920 VkImageViewCreateInfo ivci = {
11921 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11922 nullptr,
11923 0,
11924 image.handle(),
11925 VK_IMAGE_VIEW_TYPE_2D,
11926 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011927 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11928 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011929 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11930 };
11931 VkImageView view;
11932 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11933 ASSERT_VK_SUCCESS(err);
11934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011935 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011936 VkFramebuffer fb;
11937 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11938 ASSERT_VK_SUCCESS(err);
11939
11940 VkCommandBufferAllocateInfo cbai = {};
11941 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11942 cbai.commandPool = m_commandPool;
11943 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11944 cbai.commandBufferCount = 1;
11945
11946 VkCommandBuffer sec_cb;
11947 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11948 ASSERT_VK_SUCCESS(err);
11949 VkCommandBufferBeginInfo cbbi = {};
11950 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011951 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011952 cbii.renderPass = renderPass();
11953 cbii.framebuffer = fb;
11954 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11955 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011956 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 -060011957 cbbi.pInheritanceInfo = &cbii;
11958 vkBeginCommandBuffer(sec_cb, &cbbi);
11959 vkEndCommandBuffer(sec_cb);
11960
Chris Forbes3400bc52016-09-13 18:10:34 +120011961 VkCommandBufferBeginInfo cbbi2 = {
11962 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11963 0, nullptr
11964 };
11965 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11966 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011969 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011970 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11971 m_errorMonitor->VerifyFound();
11972 // Cleanup
11973 vkDestroyImageView(m_device->device(), view, NULL);
11974 vkDestroyRenderPass(m_device->device(), rp, NULL);
11975 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11976}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011977
11978TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11979 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11980 "invalid value. If logicOp is not available, attempt to "
11981 "use it and verify that we see the correct error.");
11982 ASSERT_NO_FATAL_FAILURE(InitState());
11983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11984
11985 auto features = m_device->phy().features();
11986 // Set the expected error depending on whether or not logicOp available
11987 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11989 "enabled, logicOpEnable must be "
11990 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011991 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011993 }
11994 // Create a pipeline using logicOp
11995 VkResult err;
11996
11997 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11998 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11999
12000 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012001 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012002 ASSERT_VK_SUCCESS(err);
12003
12004 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12005 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12006 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012007 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012008 vp_state_ci.pViewports = &vp;
12009 vp_state_ci.scissorCount = 1;
12010 VkRect2D scissors = {}; // Dummy scissors to point to
12011 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012012
12013 VkPipelineShaderStageCreateInfo shaderStages[2];
12014 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012016 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12017 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012018 shaderStages[0] = vs.GetStageCreateInfo();
12019 shaderStages[1] = fs.GetStageCreateInfo();
12020
12021 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12022 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12023
12024 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12025 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12026 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12027
12028 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12029 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012030 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012031
12032 VkPipelineColorBlendAttachmentState att = {};
12033 att.blendEnable = VK_FALSE;
12034 att.colorWriteMask = 0xf;
12035
12036 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12037 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12038 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12039 cb_ci.logicOpEnable = VK_TRUE;
12040 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
12041 cb_ci.attachmentCount = 1;
12042 cb_ci.pAttachments = &att;
12043
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012044 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12045 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12046 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12047
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012048 VkGraphicsPipelineCreateInfo gp_ci = {};
12049 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12050 gp_ci.stageCount = 2;
12051 gp_ci.pStages = shaderStages;
12052 gp_ci.pVertexInputState = &vi_ci;
12053 gp_ci.pInputAssemblyState = &ia_ci;
12054 gp_ci.pViewportState = &vp_state_ci;
12055 gp_ci.pRasterizationState = &rs_ci;
12056 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012057 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012058 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12059 gp_ci.layout = pipeline_layout;
12060 gp_ci.renderPass = renderPass();
12061
12062 VkPipelineCacheCreateInfo pc_ci = {};
12063 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12064
12065 VkPipeline pipeline;
12066 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012067 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012068 ASSERT_VK_SUCCESS(err);
12069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012070 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012071 m_errorMonitor->VerifyFound();
12072 if (VK_SUCCESS == err) {
12073 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12074 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012075 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12076 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12077}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012078#endif // DRAW_STATE_TESTS
12079
Tobin Ehlis0788f522015-05-26 16:11:58 -060012080#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012081#if GTEST_IS_THREADSAFE
12082struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012083 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012084 VkEvent event;
12085 bool bailout;
12086};
12087
Karl Schultz6addd812016-02-02 17:17:23 -070012088extern "C" void *AddToCommandBuffer(void *arg) {
12089 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012090
Mike Stroyana6d14942016-07-13 15:10:05 -060012091 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012092 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012093 if (data->bailout) {
12094 break;
12095 }
12096 }
12097 return NULL;
12098}
12099
Karl Schultz6addd812016-02-02 17:17:23 -070012100TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012101 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012104
Mike Stroyanaccf7692015-05-12 16:00:45 -060012105 ASSERT_NO_FATAL_FAILURE(InitState());
12106 ASSERT_NO_FATAL_FAILURE(InitViewport());
12107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12108
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012109 // Calls AllocateCommandBuffers
12110 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012111
12112 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012113 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012114
12115 VkEventCreateInfo event_info;
12116 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012117 VkResult err;
12118
12119 memset(&event_info, 0, sizeof(event_info));
12120 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12121
Chia-I Wuf7458c52015-10-26 21:10:41 +080012122 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012123 ASSERT_VK_SUCCESS(err);
12124
Mike Stroyanaccf7692015-05-12 16:00:45 -060012125 err = vkResetEvent(device(), event);
12126 ASSERT_VK_SUCCESS(err);
12127
12128 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012129 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012130 data.event = event;
12131 data.bailout = false;
12132 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012133
12134 // First do some correct operations using multiple threads.
12135 // Add many entries to command buffer from another thread.
12136 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12137 // Make non-conflicting calls from this thread at the same time.
12138 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012139 uint32_t count;
12140 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012141 }
12142 test_platform_thread_join(thread, NULL);
12143
12144 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012145 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012146 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012147 // Add many entries to command buffer from this thread at the same time.
12148 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012149
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012150 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012151 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012152
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012153 m_errorMonitor->SetBailout(NULL);
12154
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012155 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012156
Chia-I Wuf7458c52015-10-26 21:10:41 +080012157 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012158}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012159#endif // GTEST_IS_THREADSAFE
12160#endif // THREADING_TESTS
12161
Chris Forbes9f7ff632015-05-25 11:13:08 +120012162#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012163TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012164 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12165 "with an impossible code size");
12166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012168
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012169 ASSERT_NO_FATAL_FAILURE(InitState());
12170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12171
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012172 VkShaderModule module;
12173 VkShaderModuleCreateInfo moduleCreateInfo;
12174 struct icd_spv_header spv;
12175
12176 spv.magic = ICD_SPV_MAGIC;
12177 spv.version = ICD_SPV_VERSION;
12178 spv.gen_magic = 0;
12179
12180 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12181 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012182 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012183 moduleCreateInfo.codeSize = 4;
12184 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012185 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012186
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012187 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012188}
12189
Karl Schultz6addd812016-02-02 17:17:23 -070012190TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012191 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12192 "with a bad magic number");
12193
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012195
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012196 ASSERT_NO_FATAL_FAILURE(InitState());
12197 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12198
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012199 VkShaderModule module;
12200 VkShaderModuleCreateInfo moduleCreateInfo;
12201 struct icd_spv_header spv;
12202
12203 spv.magic = ~ICD_SPV_MAGIC;
12204 spv.version = ICD_SPV_VERSION;
12205 spv.gen_magic = 0;
12206
12207 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12208 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012209 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012210 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12211 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012212 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012213
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012214 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012215}
12216
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012217#if 0
12218// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012219TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012221 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012222
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012223 ASSERT_NO_FATAL_FAILURE(InitState());
12224 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12225
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012226 VkShaderModule module;
12227 VkShaderModuleCreateInfo moduleCreateInfo;
12228 struct icd_spv_header spv;
12229
12230 spv.magic = ICD_SPV_MAGIC;
12231 spv.version = ~ICD_SPV_VERSION;
12232 spv.gen_magic = 0;
12233
12234 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12235 moduleCreateInfo.pNext = NULL;
12236
Karl Schultz6addd812016-02-02 17:17:23 -070012237 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012238 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12239 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012240 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012241
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012242 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012243}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012244#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012245
Karl Schultz6addd812016-02-02 17:17:23 -070012246TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012247 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12248 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012250
Chris Forbes9f7ff632015-05-25 11:13:08 +120012251 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012254 char const *vsSource = "#version 450\n"
12255 "\n"
12256 "layout(location=0) out float x;\n"
12257 "out gl_PerVertex {\n"
12258 " vec4 gl_Position;\n"
12259 "};\n"
12260 "void main(){\n"
12261 " gl_Position = vec4(1);\n"
12262 " x = 0;\n"
12263 "}\n";
12264 char const *fsSource = "#version 450\n"
12265 "\n"
12266 "layout(location=0) out vec4 color;\n"
12267 "void main(){\n"
12268 " color = vec4(1);\n"
12269 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012270
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012271 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12272 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012273
12274 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012275 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012276 pipe.AddShader(&vs);
12277 pipe.AddShader(&fs);
12278
Chris Forbes9f7ff632015-05-25 11:13:08 +120012279 VkDescriptorSetObj descriptorSet(m_device);
12280 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012281 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012282
Tony Barbour5781e8f2015-08-04 16:23:11 -060012283 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012284
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012285 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012286}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012287
Mark Mueller098c9cb2016-09-08 09:01:57 -060012288TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12289 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12290
12291 ASSERT_NO_FATAL_FAILURE(InitState());
12292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12293
12294 const char *bad_specialization_message =
12295 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12296
12297 char const *vsSource =
12298 "#version 450\n"
12299 "\n"
12300 "out gl_PerVertex {\n"
12301 " vec4 gl_Position;\n"
12302 "};\n"
12303 "void main(){\n"
12304 " gl_Position = vec4(1);\n"
12305 "}\n";
12306
12307 char const *fsSource =
12308 "#version 450\n"
12309 "\n"
12310 "layout (constant_id = 0) const float r = 0.0f;\n"
12311 "layout(location = 0) out vec4 uFragColor;\n"
12312 "void main(){\n"
12313 " uFragColor = vec4(r,1,0,1);\n"
12314 "}\n";
12315
12316 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12317 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12318
12319 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12320 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12321
12322 VkPipelineLayout pipeline_layout;
12323 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12324
12325 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12326 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12327 vp_state_create_info.viewportCount = 1;
12328 VkViewport viewport = {};
12329 vp_state_create_info.pViewports = &viewport;
12330 vp_state_create_info.scissorCount = 1;
12331 VkRect2D scissors = {};
12332 vp_state_create_info.pScissors = &scissors;
12333
12334 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12335
12336 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12337 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12338 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12339 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12340
12341 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12342 vs.GetStageCreateInfo(),
12343 fs.GetStageCreateInfo()
12344 };
12345
12346 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12347 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12348
12349 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12350 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12351 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12352
12353 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12354 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12355 rasterization_state_create_info.pNext = nullptr;
12356 rasterization_state_create_info.lineWidth = 1.0f;
12357 rasterization_state_create_info.rasterizerDiscardEnable = true;
12358
12359 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12360 color_blend_attachment_state.blendEnable = VK_FALSE;
12361 color_blend_attachment_state.colorWriteMask = 0xf;
12362
12363 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12364 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12365 color_blend_state_create_info.attachmentCount = 1;
12366 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12367
12368 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12369 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12370 graphicspipe_create_info.stageCount = 2;
12371 graphicspipe_create_info.pStages = shader_stage_create_info;
12372 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12373 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12374 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12375 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12376 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12377 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12378 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12379 graphicspipe_create_info.layout = pipeline_layout;
12380 graphicspipe_create_info.renderPass = renderPass();
12381
12382 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12383 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12384
12385 VkPipelineCache pipelineCache;
12386 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12387
12388 // This structure maps constant ids to data locations.
12389 const VkSpecializationMapEntry entry =
12390 // id, offset, size
12391 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12392
12393 uint32_t data = 1;
12394
12395 // Set up the info describing spec map and data
12396 const VkSpecializationInfo specialization_info = {
12397 1,
12398 &entry,
12399 1 * sizeof(float),
12400 &data,
12401 };
12402 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12403
12404 VkPipeline pipeline;
12405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12406 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12407 m_errorMonitor->VerifyFound();
12408
12409 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12410 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12411}
12412
12413TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12414 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12415
12416 ASSERT_NO_FATAL_FAILURE(InitState());
12417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12418
12419 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12420
12421 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12422 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12423 descriptor_pool_type_count[0].descriptorCount = 1;
12424 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12425 descriptor_pool_type_count[1].descriptorCount = 1;
12426
12427 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12428 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12429 descriptor_pool_create_info.maxSets = 1;
12430 descriptor_pool_create_info.poolSizeCount = 2;
12431 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12432 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12433
12434 VkDescriptorPool descriptorset_pool;
12435 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12436
12437 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12438 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12439 descriptorset_layout_binding.descriptorCount = 1;
12440 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12441
12442 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12443 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12444 descriptorset_layout_create_info.bindingCount = 1;
12445 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12446
12447 VkDescriptorSetLayout descriptorset_layout;
12448 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12449
12450 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12451 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12452 descriptorset_allocate_info.descriptorSetCount = 1;
12453 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12454 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12455 VkDescriptorSet descriptorset;
12456 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12457
12458 // Challenge core_validation with a non uniform buffer type.
12459 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12460
Mark Mueller098c9cb2016-09-08 09:01:57 -060012461 char const *vsSource =
12462 "#version 450\n"
12463 "\n"
12464 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12465 " mat4 mvp;\n"
12466 "} ubuf;\n"
12467 "out gl_PerVertex {\n"
12468 " vec4 gl_Position;\n"
12469 "};\n"
12470 "void main(){\n"
12471 " gl_Position = ubuf.mvp * vec4(1);\n"
12472 "}\n";
12473
12474 char const *fsSource =
12475 "#version 450\n"
12476 "\n"
12477 "layout(location = 0) out vec4 uFragColor;\n"
12478 "void main(){\n"
12479 " uFragColor = vec4(0,1,0,1);\n"
12480 "}\n";
12481
12482 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12483 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12484
12485 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12486 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12487 pipeline_layout_create_info.setLayoutCount = 1;
12488 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12489
12490 VkPipelineLayout pipeline_layout;
12491 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12492
12493 VkPipelineObj pipe(m_device);
12494 pipe.AddColorAttachment();
12495 pipe.AddShader(&vs);
12496 pipe.AddShader(&fs);
12497
12498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12499 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12500 m_errorMonitor->VerifyFound();
12501
12502 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12503 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12504 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12505}
12506
12507TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12508 TEST_DESCRIPTION(
12509 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12510
12511 ASSERT_NO_FATAL_FAILURE(InitState());
12512 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12513
12514 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12515
12516 VkDescriptorPoolSize descriptor_pool_type_count = {};
12517 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12518 descriptor_pool_type_count.descriptorCount = 1;
12519
12520 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12521 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12522 descriptor_pool_create_info.maxSets = 1;
12523 descriptor_pool_create_info.poolSizeCount = 1;
12524 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12525 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12526
12527 VkDescriptorPool descriptorset_pool;
12528 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12529
12530 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12531 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12532 descriptorset_layout_binding.descriptorCount = 1;
12533 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12534 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12535
12536 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12537 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12538 descriptorset_layout_create_info.bindingCount = 1;
12539 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12540
12541 VkDescriptorSetLayout descriptorset_layout;
12542 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12543 nullptr, &descriptorset_layout));
12544
12545 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12546 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12547 descriptorset_allocate_info.descriptorSetCount = 1;
12548 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12549 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12550 VkDescriptorSet descriptorset;
12551 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12552
12553 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12554
Mark Mueller098c9cb2016-09-08 09:01:57 -060012555 char const *vsSource =
12556 "#version 450\n"
12557 "\n"
12558 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12559 " mat4 mvp;\n"
12560 "} ubuf;\n"
12561 "out gl_PerVertex {\n"
12562 " vec4 gl_Position;\n"
12563 "};\n"
12564 "void main(){\n"
12565 " gl_Position = ubuf.mvp * vec4(1);\n"
12566 "}\n";
12567
12568 char const *fsSource =
12569 "#version 450\n"
12570 "\n"
12571 "layout(location = 0) out vec4 uFragColor;\n"
12572 "void main(){\n"
12573 " uFragColor = vec4(0,1,0,1);\n"
12574 "}\n";
12575
12576 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12577 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12578
12579 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12580 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12581 pipeline_layout_create_info.setLayoutCount = 1;
12582 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12583
12584 VkPipelineLayout pipeline_layout;
12585 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12586
12587 VkPipelineObj pipe(m_device);
12588 pipe.AddColorAttachment();
12589 pipe.AddShader(&vs);
12590 pipe.AddShader(&fs);
12591
12592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12593 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12594 m_errorMonitor->VerifyFound();
12595
12596 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12597 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12598 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12599}
12600
12601TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12602 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12603 "accessible from the current shader stage.");
12604
12605 ASSERT_NO_FATAL_FAILURE(InitState());
12606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12607
12608 const char *push_constant_not_accessible_message =
12609 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12610
12611 char const *vsSource =
12612 "#version 450\n"
12613 "\n"
12614 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12615 "out gl_PerVertex {\n"
12616 " vec4 gl_Position;\n"
12617 "};\n"
12618 "void main(){\n"
12619 " gl_Position = vec4(consts.x);\n"
12620 "}\n";
12621
12622 char const *fsSource =
12623 "#version 450\n"
12624 "\n"
12625 "layout(location = 0) out vec4 uFragColor;\n"
12626 "void main(){\n"
12627 " uFragColor = vec4(0,1,0,1);\n"
12628 "}\n";
12629
12630 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12631 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12632
12633 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12634 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12635
12636 // Set up a push constant range
12637 VkPushConstantRange push_constant_ranges = {};
12638 // Set to the wrong stage to challenge core_validation
12639 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12640 push_constant_ranges.size = 4;
12641
12642 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12643 pipeline_layout_create_info.pushConstantRangeCount = 1;
12644
12645 VkPipelineLayout pipeline_layout;
12646 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12647
12648 VkPipelineObj pipe(m_device);
12649 pipe.AddColorAttachment();
12650 pipe.AddShader(&vs);
12651 pipe.AddShader(&fs);
12652
12653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12654 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12655 m_errorMonitor->VerifyFound();
12656
12657 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12658}
12659
12660TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12661 TEST_DESCRIPTION(
12662 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12663
12664 ASSERT_NO_FATAL_FAILURE(InitState());
12665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12666
12667 const char *feature_not_enabled_message =
12668 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12669
12670 // Some awkward steps are required to test with custom device features.
12671 std::vector<const char *> device_extension_names;
12672 auto features = m_device->phy().features();
12673 // Disable support for 64 bit floats
12674 features.shaderFloat64 = false;
12675 // The sacrificial device object
12676 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12677
12678 char const *vsSource = "#version 450\n"
12679 "\n"
12680 "out gl_PerVertex {\n"
12681 " vec4 gl_Position;\n"
12682 "};\n"
12683 "void main(){\n"
12684 " gl_Position = vec4(1);\n"
12685 "}\n";
12686 char const *fsSource = "#version 450\n"
12687 "\n"
12688 "layout(location=0) out vec4 color;\n"
12689 "void main(){\n"
12690 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12691 " color = vec4(green);\n"
12692 "}\n";
12693
12694 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12695 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12696
12697 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012698
12699 VkPipelineObj pipe(&test_device);
12700 pipe.AddColorAttachment();
12701 pipe.AddShader(&vs);
12702 pipe.AddShader(&fs);
12703
12704 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12705 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12706 VkPipelineLayout pipeline_layout;
12707 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12708
12709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12710 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12711 m_errorMonitor->VerifyFound();
12712
12713 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12714}
12715
12716TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12717 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12718
12719 ASSERT_NO_FATAL_FAILURE(InitState());
12720 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12721
12722 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12723
12724 char const *vsSource = "#version 450\n"
12725 "\n"
12726 "out gl_PerVertex {\n"
12727 " vec4 gl_Position;\n"
12728 "};\n"
12729 "layout(xfb_buffer = 1) out;"
12730 "void main(){\n"
12731 " gl_Position = vec4(1);\n"
12732 "}\n";
12733 char const *fsSource = "#version 450\n"
12734 "\n"
12735 "layout(location=0) out vec4 color;\n"
12736 "void main(){\n"
12737 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12738 " color = vec4(green);\n"
12739 "}\n";
12740
12741 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12742 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12743
12744 VkPipelineObj pipe(m_device);
12745 pipe.AddColorAttachment();
12746 pipe.AddShader(&vs);
12747 pipe.AddShader(&fs);
12748
12749 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12750 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12751 VkPipelineLayout pipeline_layout;
12752 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12753
12754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12755 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12756 m_errorMonitor->VerifyFound();
12757
12758 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12759}
12760
Karl Schultz6addd812016-02-02 17:17:23 -070012761TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012762 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12763 "which is not present in the outputs of the previous stage");
12764
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012766
Chris Forbes59cb88d2015-05-25 11:13:13 +120012767 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012770 char const *vsSource = "#version 450\n"
12771 "\n"
12772 "out gl_PerVertex {\n"
12773 " vec4 gl_Position;\n"
12774 "};\n"
12775 "void main(){\n"
12776 " gl_Position = vec4(1);\n"
12777 "}\n";
12778 char const *fsSource = "#version 450\n"
12779 "\n"
12780 "layout(location=0) in float x;\n"
12781 "layout(location=0) out vec4 color;\n"
12782 "void main(){\n"
12783 " color = vec4(x);\n"
12784 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012785
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012786 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12787 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012788
12789 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012790 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012791 pipe.AddShader(&vs);
12792 pipe.AddShader(&fs);
12793
Chris Forbes59cb88d2015-05-25 11:13:13 +120012794 VkDescriptorSetObj descriptorSet(m_device);
12795 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012796 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012797
Tony Barbour5781e8f2015-08-04 16:23:11 -060012798 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012799
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012800 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012801}
12802
Karl Schultz6addd812016-02-02 17:17:23 -070012803TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012804 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12805 "within an interace block, which is not present in the outputs "
12806 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012808
12809 ASSERT_NO_FATAL_FAILURE(InitState());
12810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12811
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012812 char const *vsSource = "#version 450\n"
12813 "\n"
12814 "out gl_PerVertex {\n"
12815 " vec4 gl_Position;\n"
12816 "};\n"
12817 "void main(){\n"
12818 " gl_Position = vec4(1);\n"
12819 "}\n";
12820 char const *fsSource = "#version 450\n"
12821 "\n"
12822 "in block { layout(location=0) float x; } ins;\n"
12823 "layout(location=0) out vec4 color;\n"
12824 "void main(){\n"
12825 " color = vec4(ins.x);\n"
12826 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012827
12828 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12829 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12830
12831 VkPipelineObj pipe(m_device);
12832 pipe.AddColorAttachment();
12833 pipe.AddShader(&vs);
12834 pipe.AddShader(&fs);
12835
12836 VkDescriptorSetObj descriptorSet(m_device);
12837 descriptorSet.AppendDummy();
12838 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12839
12840 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12841
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012842 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012843}
12844
Karl Schultz6addd812016-02-02 17:17:23 -070012845TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012846 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012847 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12849 "output arr[2] of float32' vs 'ptr to "
12850 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012851
12852 ASSERT_NO_FATAL_FAILURE(InitState());
12853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12854
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012855 char const *vsSource = "#version 450\n"
12856 "\n"
12857 "layout(location=0) out float x[2];\n"
12858 "out gl_PerVertex {\n"
12859 " vec4 gl_Position;\n"
12860 "};\n"
12861 "void main(){\n"
12862 " x[0] = 0; x[1] = 0;\n"
12863 " gl_Position = vec4(1);\n"
12864 "}\n";
12865 char const *fsSource = "#version 450\n"
12866 "\n"
12867 "layout(location=0) in float x[3];\n"
12868 "layout(location=0) out vec4 color;\n"
12869 "void main(){\n"
12870 " color = vec4(x[0] + x[1] + x[2]);\n"
12871 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012872
12873 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12874 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12875
12876 VkPipelineObj pipe(m_device);
12877 pipe.AddColorAttachment();
12878 pipe.AddShader(&vs);
12879 pipe.AddShader(&fs);
12880
12881 VkDescriptorSetObj descriptorSet(m_device);
12882 descriptorSet.AppendDummy();
12883 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12884
12885 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12886
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012887 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012888}
12889
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012890
Karl Schultz6addd812016-02-02 17:17:23 -070012891TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012892 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012893 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012895
Chris Forbesb56af562015-05-25 11:13:17 +120012896 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012899 char const *vsSource = "#version 450\n"
12900 "\n"
12901 "layout(location=0) out int x;\n"
12902 "out gl_PerVertex {\n"
12903 " vec4 gl_Position;\n"
12904 "};\n"
12905 "void main(){\n"
12906 " x = 0;\n"
12907 " gl_Position = vec4(1);\n"
12908 "}\n";
12909 char const *fsSource = "#version 450\n"
12910 "\n"
12911 "layout(location=0) in float x;\n" /* VS writes int */
12912 "layout(location=0) out vec4 color;\n"
12913 "void main(){\n"
12914 " color = vec4(x);\n"
12915 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012916
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012917 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12918 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012919
12920 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012921 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012922 pipe.AddShader(&vs);
12923 pipe.AddShader(&fs);
12924
Chris Forbesb56af562015-05-25 11:13:17 +120012925 VkDescriptorSetObj descriptorSet(m_device);
12926 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012927 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012928
Tony Barbour5781e8f2015-08-04 16:23:11 -060012929 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012930
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012931 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012932}
12933
Karl Schultz6addd812016-02-02 17:17:23 -070012934TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012935 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012936 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012937 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012939
12940 ASSERT_NO_FATAL_FAILURE(InitState());
12941 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12942
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012943 char const *vsSource = "#version 450\n"
12944 "\n"
12945 "out block { layout(location=0) int x; } outs;\n"
12946 "out gl_PerVertex {\n"
12947 " vec4 gl_Position;\n"
12948 "};\n"
12949 "void main(){\n"
12950 " outs.x = 0;\n"
12951 " gl_Position = vec4(1);\n"
12952 "}\n";
12953 char const *fsSource = "#version 450\n"
12954 "\n"
12955 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12956 "layout(location=0) out vec4 color;\n"
12957 "void main(){\n"
12958 " color = vec4(ins.x);\n"
12959 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012960
12961 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12962 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12963
12964 VkPipelineObj pipe(m_device);
12965 pipe.AddColorAttachment();
12966 pipe.AddShader(&vs);
12967 pipe.AddShader(&fs);
12968
12969 VkDescriptorSetObj descriptorSet(m_device);
12970 descriptorSet.AppendDummy();
12971 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12972
12973 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12974
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012975 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012976}
12977
12978TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012979 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012980 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012981 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012982 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 +130012983
12984 ASSERT_NO_FATAL_FAILURE(InitState());
12985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012987 char const *vsSource = "#version 450\n"
12988 "\n"
12989 "out block { layout(location=1) float x; } outs;\n"
12990 "out gl_PerVertex {\n"
12991 " vec4 gl_Position;\n"
12992 "};\n"
12993 "void main(){\n"
12994 " outs.x = 0;\n"
12995 " gl_Position = vec4(1);\n"
12996 "}\n";
12997 char const *fsSource = "#version 450\n"
12998 "\n"
12999 "in block { layout(location=0) float x; } ins;\n"
13000 "layout(location=0) out vec4 color;\n"
13001 "void main(){\n"
13002 " color = vec4(ins.x);\n"
13003 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013004
13005 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13006 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13007
13008 VkPipelineObj pipe(m_device);
13009 pipe.AddColorAttachment();
13010 pipe.AddShader(&vs);
13011 pipe.AddShader(&fs);
13012
13013 VkDescriptorSetObj descriptorSet(m_device);
13014 descriptorSet.AppendDummy();
13015 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13016
13017 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13018
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013019 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013020}
13021
13022TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013023 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013024 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120013025 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013026 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 +130013027
13028 ASSERT_NO_FATAL_FAILURE(InitState());
13029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13030
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013031 char const *vsSource = "#version 450\n"
13032 "\n"
13033 "out block { layout(location=0, component=0) float x; } outs;\n"
13034 "out gl_PerVertex {\n"
13035 " vec4 gl_Position;\n"
13036 "};\n"
13037 "void main(){\n"
13038 " outs.x = 0;\n"
13039 " gl_Position = vec4(1);\n"
13040 "}\n";
13041 char const *fsSource = "#version 450\n"
13042 "\n"
13043 "in block { layout(location=0, component=1) float x; } ins;\n"
13044 "layout(location=0) out vec4 color;\n"
13045 "void main(){\n"
13046 " color = vec4(ins.x);\n"
13047 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013048
13049 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13050 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13051
13052 VkPipelineObj pipe(m_device);
13053 pipe.AddColorAttachment();
13054 pipe.AddShader(&vs);
13055 pipe.AddShader(&fs);
13056
13057 VkDescriptorSetObj descriptorSet(m_device);
13058 descriptorSet.AppendDummy();
13059 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13060
13061 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13062
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013063 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013064}
13065
Chris Forbes1f3b0152016-11-30 12:48:40 +130013066TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13067 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13068
13069 ASSERT_NO_FATAL_FAILURE(InitState());
13070 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13071
13072 char const *vsSource = "#version 450\n"
13073 "layout(location=0) out mediump float x;\n"
13074 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13075 char const *fsSource = "#version 450\n"
13076 "layout(location=0) in highp float x;\n"
13077 "layout(location=0) out vec4 color;\n"
13078 "void main() { color = vec4(x); }\n";
13079
13080 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13081 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13082
13083 VkPipelineObj pipe(m_device);
13084 pipe.AddColorAttachment();
13085 pipe.AddShader(&vs);
13086 pipe.AddShader(&fs);
13087
13088 VkDescriptorSetObj descriptorSet(m_device);
13089 descriptorSet.AppendDummy();
13090 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13091
13092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13093
13094 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13095
13096 m_errorMonitor->VerifyFound();
13097}
13098
Chris Forbes870a39e2016-11-30 12:55:56 +130013099TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13100 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13101
13102 ASSERT_NO_FATAL_FAILURE(InitState());
13103 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13104
13105 char const *vsSource = "#version 450\n"
13106 "out block { layout(location=0) mediump float x; };\n"
13107 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13108 char const *fsSource = "#version 450\n"
13109 "in block { layout(location=0) highp float x; };\n"
13110 "layout(location=0) out vec4 color;\n"
13111 "void main() { color = vec4(x); }\n";
13112
13113 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13114 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13115
13116 VkPipelineObj pipe(m_device);
13117 pipe.AddColorAttachment();
13118 pipe.AddShader(&vs);
13119 pipe.AddShader(&fs);
13120
13121 VkDescriptorSetObj descriptorSet(m_device);
13122 descriptorSet.AppendDummy();
13123 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13124
13125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13126
13127 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13128
13129 m_errorMonitor->VerifyFound();
13130}
13131
Karl Schultz6addd812016-02-02 17:17:23 -070013132TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013133 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13134 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013136
Chris Forbesde136e02015-05-25 11:13:28 +120013137 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013139
13140 VkVertexInputBindingDescription input_binding;
13141 memset(&input_binding, 0, sizeof(input_binding));
13142
13143 VkVertexInputAttributeDescription input_attrib;
13144 memset(&input_attrib, 0, sizeof(input_attrib));
13145 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013147 char const *vsSource = "#version 450\n"
13148 "\n"
13149 "out gl_PerVertex {\n"
13150 " vec4 gl_Position;\n"
13151 "};\n"
13152 "void main(){\n"
13153 " gl_Position = vec4(1);\n"
13154 "}\n";
13155 char const *fsSource = "#version 450\n"
13156 "\n"
13157 "layout(location=0) out vec4 color;\n"
13158 "void main(){\n"
13159 " color = vec4(1);\n"
13160 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013161
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013162 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13163 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013164
13165 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013166 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013167 pipe.AddShader(&vs);
13168 pipe.AddShader(&fs);
13169
13170 pipe.AddVertexInputBindings(&input_binding, 1);
13171 pipe.AddVertexInputAttribs(&input_attrib, 1);
13172
Chris Forbesde136e02015-05-25 11:13:28 +120013173 VkDescriptorSetObj descriptorSet(m_device);
13174 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013175 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013176
Tony Barbour5781e8f2015-08-04 16:23:11 -060013177 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013178
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013179 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013180}
13181
Karl Schultz6addd812016-02-02 17:17:23 -070013182TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013183 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13184 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013186
13187 ASSERT_NO_FATAL_FAILURE(InitState());
13188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13189
13190 VkVertexInputBindingDescription input_binding;
13191 memset(&input_binding, 0, sizeof(input_binding));
13192
13193 VkVertexInputAttributeDescription input_attrib;
13194 memset(&input_attrib, 0, sizeof(input_attrib));
13195 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013197 char const *vsSource = "#version 450\n"
13198 "\n"
13199 "layout(location=1) in float x;\n"
13200 "out gl_PerVertex {\n"
13201 " vec4 gl_Position;\n"
13202 "};\n"
13203 "void main(){\n"
13204 " gl_Position = vec4(x);\n"
13205 "}\n";
13206 char const *fsSource = "#version 450\n"
13207 "\n"
13208 "layout(location=0) out vec4 color;\n"
13209 "void main(){\n"
13210 " color = vec4(1);\n"
13211 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013212
13213 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13214 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13215
13216 VkPipelineObj pipe(m_device);
13217 pipe.AddColorAttachment();
13218 pipe.AddShader(&vs);
13219 pipe.AddShader(&fs);
13220
13221 pipe.AddVertexInputBindings(&input_binding, 1);
13222 pipe.AddVertexInputAttribs(&input_attrib, 1);
13223
13224 VkDescriptorSetObj descriptorSet(m_device);
13225 descriptorSet.AppendDummy();
13226 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13227
13228 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13229
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013230 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013231}
13232
Karl Schultz6addd812016-02-02 17:17:23 -070013233TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013234 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013235 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013236 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 -060013237
Chris Forbes62e8e502015-05-25 11:13:29 +120013238 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013241 char const *vsSource = "#version 450\n"
13242 "\n"
13243 "layout(location=0) in vec4 x;\n" /* not provided */
13244 "out gl_PerVertex {\n"
13245 " vec4 gl_Position;\n"
13246 "};\n"
13247 "void main(){\n"
13248 " gl_Position = x;\n"
13249 "}\n";
13250 char const *fsSource = "#version 450\n"
13251 "\n"
13252 "layout(location=0) out vec4 color;\n"
13253 "void main(){\n"
13254 " color = vec4(1);\n"
13255 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013256
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013257 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13258 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013259
13260 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013261 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013262 pipe.AddShader(&vs);
13263 pipe.AddShader(&fs);
13264
Chris Forbes62e8e502015-05-25 11:13:29 +120013265 VkDescriptorSetObj descriptorSet(m_device);
13266 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013267 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013268
Tony Barbour5781e8f2015-08-04 16:23:11 -060013269 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013270
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013271 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013272}
13273
Karl Schultz6addd812016-02-02 17:17:23 -070013274TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013275 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13276 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013277 "vertex shader input that consumes it");
13278 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 -060013279
Chris Forbesc97d98e2015-05-25 11:13:31 +120013280 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013281 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013282
13283 VkVertexInputBindingDescription input_binding;
13284 memset(&input_binding, 0, sizeof(input_binding));
13285
13286 VkVertexInputAttributeDescription input_attrib;
13287 memset(&input_attrib, 0, sizeof(input_attrib));
13288 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013290 char const *vsSource = "#version 450\n"
13291 "\n"
13292 "layout(location=0) in int x;\n" /* attrib provided float */
13293 "out gl_PerVertex {\n"
13294 " vec4 gl_Position;\n"
13295 "};\n"
13296 "void main(){\n"
13297 " gl_Position = vec4(x);\n"
13298 "}\n";
13299 char const *fsSource = "#version 450\n"
13300 "\n"
13301 "layout(location=0) out vec4 color;\n"
13302 "void main(){\n"
13303 " color = vec4(1);\n"
13304 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013305
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013306 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13307 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013308
13309 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013310 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013311 pipe.AddShader(&vs);
13312 pipe.AddShader(&fs);
13313
13314 pipe.AddVertexInputBindings(&input_binding, 1);
13315 pipe.AddVertexInputAttribs(&input_attrib, 1);
13316
Chris Forbesc97d98e2015-05-25 11:13:31 +120013317 VkDescriptorSetObj descriptorSet(m_device);
13318 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013319 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013320
Tony Barbour5781e8f2015-08-04 16:23:11 -060013321 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013322
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013323 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013324}
13325
Chris Forbesc68b43c2016-04-06 11:18:47 +120013326TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013327 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13328 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13330 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013331
13332 ASSERT_NO_FATAL_FAILURE(InitState());
13333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013335 char const *vsSource = "#version 450\n"
13336 "\n"
13337 "out gl_PerVertex {\n"
13338 " vec4 gl_Position;\n"
13339 "};\n"
13340 "void main(){\n"
13341 " gl_Position = vec4(1);\n"
13342 "}\n";
13343 char const *fsSource = "#version 450\n"
13344 "\n"
13345 "layout(location=0) out vec4 color;\n"
13346 "void main(){\n"
13347 " color = vec4(1);\n"
13348 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013349
13350 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13351 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13352
13353 VkPipelineObj pipe(m_device);
13354 pipe.AddColorAttachment();
13355 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013356 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013357 pipe.AddShader(&fs);
13358
13359 VkDescriptorSetObj descriptorSet(m_device);
13360 descriptorSet.AppendDummy();
13361 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13362
13363 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13364
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013365 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013366}
13367
Chris Forbes82ff92a2016-09-09 10:50:24 +120013368TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13370 "No entrypoint found named `foo`");
13371
13372 ASSERT_NO_FATAL_FAILURE(InitState());
13373 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13374
13375 char const *vsSource = "#version 450\n"
13376 "out gl_PerVertex {\n"
13377 " vec4 gl_Position;\n"
13378 "};\n"
13379 "void main(){\n"
13380 " gl_Position = vec4(0);\n"
13381 "}\n";
13382 char const *fsSource = "#version 450\n"
13383 "\n"
13384 "layout(location=0) out vec4 color;\n"
13385 "void main(){\n"
13386 " color = vec4(1);\n"
13387 "}\n";
13388
13389 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13390 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13391
13392 VkPipelineObj pipe(m_device);
13393 pipe.AddColorAttachment();
13394 pipe.AddShader(&vs);
13395 pipe.AddShader(&fs);
13396
13397 VkDescriptorSetObj descriptorSet(m_device);
13398 descriptorSet.AppendDummy();
13399 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13400
13401 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13402
13403 m_errorMonitor->VerifyFound();
13404}
13405
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013406TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13407 m_errorMonitor->SetDesiredFailureMsg(
13408 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13409 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13410 "uses a depth/stencil attachment");
13411
13412 ASSERT_NO_FATAL_FAILURE(InitState());
13413 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13414
13415 char const *vsSource = "#version 450\n"
13416 "void main(){ gl_Position = vec4(0); }\n";
13417 char const *fsSource = "#version 450\n"
13418 "\n"
13419 "layout(location=0) out vec4 color;\n"
13420 "void main(){\n"
13421 " color = vec4(1);\n"
13422 "}\n";
13423
13424 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13425 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13426
13427 VkPipelineObj pipe(m_device);
13428 pipe.AddColorAttachment();
13429 pipe.AddShader(&vs);
13430 pipe.AddShader(&fs);
13431
13432 VkDescriptorSetObj descriptorSet(m_device);
13433 descriptorSet.AppendDummy();
13434 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13435
13436 VkAttachmentDescription attachments[] = {
13437 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13438 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13439 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13440 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13441 },
13442 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13443 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13444 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13445 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13446 },
13447 };
13448 VkAttachmentReference refs[] = {
13449 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13450 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13451 };
13452 VkSubpassDescription subpass = {
13453 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13454 1, &refs[0], nullptr, &refs[1],
13455 0, nullptr
13456 };
13457 VkRenderPassCreateInfo rpci = {
13458 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13459 0, 2, attachments, 1, &subpass, 0, nullptr
13460 };
13461 VkRenderPass rp;
13462 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13463 ASSERT_VK_SUCCESS(err);
13464
13465 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13466
13467 m_errorMonitor->VerifyFound();
13468
13469 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13470}
13471
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013472TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013473 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13474 "the TCS without the patch decoration, but consumed in the TES "
13475 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13477 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013478
13479 ASSERT_NO_FATAL_FAILURE(InitState());
13480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13481
Chris Forbesc1e852d2016-04-04 19:26:42 +120013482 if (!m_device->phy().features().tessellationShader) {
13483 printf("Device does not support tessellation shaders; skipped.\n");
13484 return;
13485 }
13486
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013487 char const *vsSource = "#version 450\n"
13488 "void main(){}\n";
13489 char const *tcsSource = "#version 450\n"
13490 "layout(location=0) out int x[];\n"
13491 "layout(vertices=3) out;\n"
13492 "void main(){\n"
13493 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13494 " gl_TessLevelInner[0] = 1;\n"
13495 " x[gl_InvocationID] = gl_InvocationID;\n"
13496 "}\n";
13497 char const *tesSource = "#version 450\n"
13498 "layout(triangles, equal_spacing, cw) in;\n"
13499 "layout(location=0) patch in int x;\n"
13500 "out gl_PerVertex { vec4 gl_Position; };\n"
13501 "void main(){\n"
13502 " gl_Position.xyz = gl_TessCoord;\n"
13503 " gl_Position.w = x;\n"
13504 "}\n";
13505 char const *fsSource = "#version 450\n"
13506 "layout(location=0) out vec4 color;\n"
13507 "void main(){\n"
13508 " color = vec4(1);\n"
13509 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013510
13511 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13512 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13513 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13514 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13515
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013516 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13517 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013518
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013519 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013520
13521 VkPipelineObj pipe(m_device);
13522 pipe.SetInputAssembly(&iasci);
13523 pipe.SetTessellation(&tsci);
13524 pipe.AddColorAttachment();
13525 pipe.AddShader(&vs);
13526 pipe.AddShader(&tcs);
13527 pipe.AddShader(&tes);
13528 pipe.AddShader(&fs);
13529
13530 VkDescriptorSetObj descriptorSet(m_device);
13531 descriptorSet.AppendDummy();
13532 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13533
13534 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13535
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013536 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013537}
13538
Karl Schultz6addd812016-02-02 17:17:23 -070013539TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013540 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13541 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13543 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013544
Chris Forbes280ba2c2015-06-12 11:16:41 +120013545 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013547
13548 /* Two binding descriptions for binding 0 */
13549 VkVertexInputBindingDescription input_bindings[2];
13550 memset(input_bindings, 0, sizeof(input_bindings));
13551
13552 VkVertexInputAttributeDescription input_attrib;
13553 memset(&input_attrib, 0, sizeof(input_attrib));
13554 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13555
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013556 char const *vsSource = "#version 450\n"
13557 "\n"
13558 "layout(location=0) in float x;\n" /* attrib provided float */
13559 "out gl_PerVertex {\n"
13560 " vec4 gl_Position;\n"
13561 "};\n"
13562 "void main(){\n"
13563 " gl_Position = vec4(x);\n"
13564 "}\n";
13565 char const *fsSource = "#version 450\n"
13566 "\n"
13567 "layout(location=0) out vec4 color;\n"
13568 "void main(){\n"
13569 " color = vec4(1);\n"
13570 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013571
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013572 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13573 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013574
13575 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013576 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013577 pipe.AddShader(&vs);
13578 pipe.AddShader(&fs);
13579
13580 pipe.AddVertexInputBindings(input_bindings, 2);
13581 pipe.AddVertexInputAttribs(&input_attrib, 1);
13582
Chris Forbes280ba2c2015-06-12 11:16:41 +120013583 VkDescriptorSetObj descriptorSet(m_device);
13584 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013585 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013586
Tony Barbour5781e8f2015-08-04 16:23:11 -060013587 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013588
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013589 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013590}
Chris Forbes8f68b562015-05-25 11:13:32 +120013591
Karl Schultz6addd812016-02-02 17:17:23 -070013592TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013593 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013594 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013596
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013597 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013598
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013599 char const *vsSource = "#version 450\n"
13600 "\n"
13601 "out gl_PerVertex {\n"
13602 " vec4 gl_Position;\n"
13603 "};\n"
13604 "void main(){\n"
13605 " gl_Position = vec4(1);\n"
13606 "}\n";
13607 char const *fsSource = "#version 450\n"
13608 "\n"
13609 "void main(){\n"
13610 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013611
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013612 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13613 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013614
13615 VkPipelineObj pipe(m_device);
13616 pipe.AddShader(&vs);
13617 pipe.AddShader(&fs);
13618
Chia-I Wu08accc62015-07-07 11:50:03 +080013619 /* set up CB 0, not written */
13620 pipe.AddColorAttachment();
13621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013622
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013623 VkDescriptorSetObj descriptorSet(m_device);
13624 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013625 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013626
Tony Barbour5781e8f2015-08-04 16:23:11 -060013627 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013628
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013629 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013630}
13631
Karl Schultz6addd812016-02-02 17:17:23 -070013632TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013633 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013634 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013636 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013637
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013638 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013639
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013640 char const *vsSource = "#version 450\n"
13641 "\n"
13642 "out gl_PerVertex {\n"
13643 " vec4 gl_Position;\n"
13644 "};\n"
13645 "void main(){\n"
13646 " gl_Position = vec4(1);\n"
13647 "}\n";
13648 char const *fsSource = "#version 450\n"
13649 "\n"
13650 "layout(location=0) out vec4 x;\n"
13651 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13652 "void main(){\n"
13653 " x = vec4(1);\n"
13654 " y = vec4(1);\n"
13655 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013656
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013657 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13658 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013659
13660 VkPipelineObj pipe(m_device);
13661 pipe.AddShader(&vs);
13662 pipe.AddShader(&fs);
13663
Chia-I Wu08accc62015-07-07 11:50:03 +080013664 /* set up CB 0, not written */
13665 pipe.AddColorAttachment();
13666 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013667 /* FS writes CB 1, but we don't configure it */
13668
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013669 VkDescriptorSetObj descriptorSet(m_device);
13670 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013671 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013672
Tony Barbour5781e8f2015-08-04 16:23:11 -060013673 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013674
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013675 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013676}
13677
Karl Schultz6addd812016-02-02 17:17:23 -070013678TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013679 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013680 "type of an fragment shader output variable, and the format of the corresponding attachment");
13681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013682
Chris Forbesa36d69e2015-05-25 11:13:44 +120013683 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013684
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013685 char const *vsSource = "#version 450\n"
13686 "\n"
13687 "out gl_PerVertex {\n"
13688 " vec4 gl_Position;\n"
13689 "};\n"
13690 "void main(){\n"
13691 " gl_Position = vec4(1);\n"
13692 "}\n";
13693 char const *fsSource = "#version 450\n"
13694 "\n"
13695 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13696 "void main(){\n"
13697 " x = ivec4(1);\n"
13698 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013699
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013700 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13701 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013702
13703 VkPipelineObj pipe(m_device);
13704 pipe.AddShader(&vs);
13705 pipe.AddShader(&fs);
13706
Chia-I Wu08accc62015-07-07 11:50:03 +080013707 /* set up CB 0; type is UNORM by default */
13708 pipe.AddColorAttachment();
13709 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013710
Chris Forbesa36d69e2015-05-25 11:13:44 +120013711 VkDescriptorSetObj descriptorSet(m_device);
13712 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013713 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013714
Tony Barbour5781e8f2015-08-04 16:23:11 -060013715 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013716
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013717 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013718}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013719
Karl Schultz6addd812016-02-02 17:17:23 -070013720TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013721 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13722 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013724
Chris Forbes556c76c2015-08-14 12:04:59 +120013725 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013726
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013727 char const *vsSource = "#version 450\n"
13728 "\n"
13729 "out gl_PerVertex {\n"
13730 " vec4 gl_Position;\n"
13731 "};\n"
13732 "void main(){\n"
13733 " gl_Position = vec4(1);\n"
13734 "}\n";
13735 char const *fsSource = "#version 450\n"
13736 "\n"
13737 "layout(location=0) out vec4 x;\n"
13738 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13739 "void main(){\n"
13740 " x = vec4(bar.y);\n"
13741 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013742
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013743 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13744 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013745
Chris Forbes556c76c2015-08-14 12:04:59 +120013746 VkPipelineObj pipe(m_device);
13747 pipe.AddShader(&vs);
13748 pipe.AddShader(&fs);
13749
13750 /* set up CB 0; type is UNORM by default */
13751 pipe.AddColorAttachment();
13752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13753
13754 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013755 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013756
13757 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13758
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013759 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013760}
13761
Chris Forbes5c59e902016-02-26 16:56:09 +130013762TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013763 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13764 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013766
13767 ASSERT_NO_FATAL_FAILURE(InitState());
13768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013769 char const *vsSource = "#version 450\n"
13770 "\n"
13771 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13772 "out gl_PerVertex {\n"
13773 " vec4 gl_Position;\n"
13774 "};\n"
13775 "void main(){\n"
13776 " gl_Position = vec4(consts.x);\n"
13777 "}\n";
13778 char const *fsSource = "#version 450\n"
13779 "\n"
13780 "layout(location=0) out vec4 x;\n"
13781 "void main(){\n"
13782 " x = vec4(1);\n"
13783 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013784
13785 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13786 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13787
13788 VkPipelineObj pipe(m_device);
13789 pipe.AddShader(&vs);
13790 pipe.AddShader(&fs);
13791
13792 /* set up CB 0; type is UNORM by default */
13793 pipe.AddColorAttachment();
13794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13795
13796 VkDescriptorSetObj descriptorSet(m_device);
13797 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13798
13799 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13800
13801 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013802 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013803}
13804
Chris Forbes3fb17902016-08-22 14:57:55 +120013805TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13806 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13807 "which is not included in the subpass description");
13808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13809 "consumes input attachment index 0 but not provided in subpass");
13810
13811 ASSERT_NO_FATAL_FAILURE(InitState());
13812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013813 char const *vsSource = "#version 450\n"
13814 "\n"
13815 "out gl_PerVertex {\n"
13816 " vec4 gl_Position;\n"
13817 "};\n"
13818 "void main(){\n"
13819 " gl_Position = vec4(1);\n"
13820 "}\n";
13821 char const *fsSource = "#version 450\n"
13822 "\n"
13823 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13824 "layout(location=0) out vec4 color;\n"
13825 "void main() {\n"
13826 " color = subpassLoad(x);\n"
13827 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013828
13829 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13830 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13831
13832 VkPipelineObj pipe(m_device);
13833 pipe.AddShader(&vs);
13834 pipe.AddShader(&fs);
13835 pipe.AddColorAttachment();
13836 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013838 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13839 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013840 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013841 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013842 ASSERT_VK_SUCCESS(err);
13843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013844 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013845 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013846 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013847 ASSERT_VK_SUCCESS(err);
13848
13849 // error here.
13850 pipe.CreateVKPipeline(pl, renderPass());
13851
13852 m_errorMonitor->VerifyFound();
13853
13854 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13855 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13856}
13857
Chris Forbes5a9a0472016-08-22 16:02:09 +120013858TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13859 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13860 "with a format having a different fundamental type");
13861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13862 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13863
13864 ASSERT_NO_FATAL_FAILURE(InitState());
13865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013866 char const *vsSource = "#version 450\n"
13867 "\n"
13868 "out gl_PerVertex {\n"
13869 " vec4 gl_Position;\n"
13870 "};\n"
13871 "void main(){\n"
13872 " gl_Position = vec4(1);\n"
13873 "}\n";
13874 char const *fsSource = "#version 450\n"
13875 "\n"
13876 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13877 "layout(location=0) out vec4 color;\n"
13878 "void main() {\n"
13879 " color = subpassLoad(x);\n"
13880 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013881
13882 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13883 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13884
13885 VkPipelineObj pipe(m_device);
13886 pipe.AddShader(&vs);
13887 pipe.AddShader(&fs);
13888 pipe.AddColorAttachment();
13889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13890
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013891 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13892 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013893 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013894 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013895 ASSERT_VK_SUCCESS(err);
13896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013897 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013898 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013899 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013900 ASSERT_VK_SUCCESS(err);
13901
13902 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013903 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13904 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13905 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13906 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13907 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 +120013908 };
13909 VkAttachmentReference color = {
13910 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13911 };
13912 VkAttachmentReference input = {
13913 1, VK_IMAGE_LAYOUT_GENERAL,
13914 };
13915
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013916 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013917
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013918 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013919 VkRenderPass rp;
13920 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13921 ASSERT_VK_SUCCESS(err);
13922
13923 // error here.
13924 pipe.CreateVKPipeline(pl, rp);
13925
13926 m_errorMonitor->VerifyFound();
13927
13928 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13929 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13930 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13931}
13932
Chris Forbes541f7b02016-08-22 15:30:27 +120013933TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13934 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13935 "which is not included in the subpass description -- array case");
13936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13937 "consumes input attachment index 1 but not provided in subpass");
13938
13939 ASSERT_NO_FATAL_FAILURE(InitState());
13940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013941 char const *vsSource = "#version 450\n"
13942 "\n"
13943 "out gl_PerVertex {\n"
13944 " vec4 gl_Position;\n"
13945 "};\n"
13946 "void main(){\n"
13947 " gl_Position = vec4(1);\n"
13948 "}\n";
13949 char const *fsSource = "#version 450\n"
13950 "\n"
13951 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13952 "layout(location=0) out vec4 color;\n"
13953 "void main() {\n"
13954 " color = subpassLoad(xs[1]);\n"
13955 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013956
13957 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13958 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13959
13960 VkPipelineObj pipe(m_device);
13961 pipe.AddShader(&vs);
13962 pipe.AddShader(&fs);
13963 pipe.AddColorAttachment();
13964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013966 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13967 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013968 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013969 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013970 ASSERT_VK_SUCCESS(err);
13971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013972 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013973 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013974 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013975 ASSERT_VK_SUCCESS(err);
13976
13977 // error here.
13978 pipe.CreateVKPipeline(pl, renderPass());
13979
13980 m_errorMonitor->VerifyFound();
13981
13982 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13983 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13984}
13985
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013986TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013987 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13988 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013990
13991 ASSERT_NO_FATAL_FAILURE(InitState());
13992
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013993 char const *csSource = "#version 450\n"
13994 "\n"
13995 "layout(local_size_x=1) in;\n"
13996 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13997 "void main(){\n"
13998 " x = vec4(1);\n"
13999 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014000
14001 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14002
14003 VkDescriptorSetObj descriptorSet(m_device);
14004 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014006 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14007 nullptr,
14008 0,
14009 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14010 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14011 descriptorSet.GetPipelineLayout(),
14012 VK_NULL_HANDLE,
14013 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014014
14015 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014016 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014017
14018 m_errorMonitor->VerifyFound();
14019
14020 if (err == VK_SUCCESS) {
14021 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14022 }
14023}
14024
Chris Forbes22a9b092016-07-19 14:34:05 +120014025TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014026 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
14027 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14029 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014030
14031 ASSERT_NO_FATAL_FAILURE(InitState());
14032
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014033 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14034 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014035 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014036 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014037 ASSERT_VK_SUCCESS(err);
14038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014039 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014040 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014041 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014042 ASSERT_VK_SUCCESS(err);
14043
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014044 char const *csSource = "#version 450\n"
14045 "\n"
14046 "layout(local_size_x=1) in;\n"
14047 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14048 "void main() {\n"
14049 " x.x = 1.0f;\n"
14050 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014051 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014053 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14054 nullptr,
14055 0,
14056 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14057 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14058 pl,
14059 VK_NULL_HANDLE,
14060 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014061
14062 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014063 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014064
14065 m_errorMonitor->VerifyFound();
14066
14067 if (err == VK_SUCCESS) {
14068 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14069 }
14070
14071 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14072 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14073}
14074
Chris Forbes50020592016-07-27 13:52:41 +120014075TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
14076 TEST_DESCRIPTION("Test that an error is produced when an image view type "
14077 "does not match the dimensionality declared in the shader");
14078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014079 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 +120014080
14081 ASSERT_NO_FATAL_FAILURE(InitState());
14082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14083
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014084 char const *vsSource = "#version 450\n"
14085 "\n"
14086 "out gl_PerVertex { vec4 gl_Position; };\n"
14087 "void main() { gl_Position = vec4(0); }\n";
14088 char const *fsSource = "#version 450\n"
14089 "\n"
14090 "layout(set=0, binding=0) uniform sampler3D s;\n"
14091 "layout(location=0) out vec4 color;\n"
14092 "void main() {\n"
14093 " color = texture(s, vec3(0));\n"
14094 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014095 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14096 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14097
14098 VkPipelineObj pipe(m_device);
14099 pipe.AddShader(&vs);
14100 pipe.AddShader(&fs);
14101 pipe.AddColorAttachment();
14102
14103 VkTextureObj texture(m_device, nullptr);
14104 VkSamplerObj sampler(m_device);
14105
14106 VkDescriptorSetObj descriptorSet(m_device);
14107 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14108 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14109
14110 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14111 ASSERT_VK_SUCCESS(err);
14112
14113 BeginCommandBuffer();
14114
14115 m_commandBuffer->BindPipeline(pipe);
14116 m_commandBuffer->BindDescriptorSet(descriptorSet);
14117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014118 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014119 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014120 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014121 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14122
14123 // error produced here.
14124 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14125
14126 m_errorMonitor->VerifyFound();
14127
14128 EndCommandBuffer();
14129}
14130
Chris Forbes5533bfc2016-07-27 14:12:34 +120014131TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14132 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14133 "are consumed via singlesample images types in the shader, or vice versa.");
14134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014136
14137 ASSERT_NO_FATAL_FAILURE(InitState());
14138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014140 char const *vsSource = "#version 450\n"
14141 "\n"
14142 "out gl_PerVertex { vec4 gl_Position; };\n"
14143 "void main() { gl_Position = vec4(0); }\n";
14144 char const *fsSource = "#version 450\n"
14145 "\n"
14146 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14147 "layout(location=0) out vec4 color;\n"
14148 "void main() {\n"
14149 " color = texelFetch(s, ivec2(0), 0);\n"
14150 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014151 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14152 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14153
14154 VkPipelineObj pipe(m_device);
14155 pipe.AddShader(&vs);
14156 pipe.AddShader(&fs);
14157 pipe.AddColorAttachment();
14158
14159 VkTextureObj texture(m_device, nullptr);
14160 VkSamplerObj sampler(m_device);
14161
14162 VkDescriptorSetObj descriptorSet(m_device);
14163 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14165
14166 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14167 ASSERT_VK_SUCCESS(err);
14168
14169 BeginCommandBuffer();
14170
14171 m_commandBuffer->BindPipeline(pipe);
14172 m_commandBuffer->BindDescriptorSet(descriptorSet);
14173
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014174 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014175 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014176 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014177 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14178
14179 // error produced here.
14180 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14181
14182 m_errorMonitor->VerifyFound();
14183
14184 EndCommandBuffer();
14185}
14186
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014187#endif // SHADER_CHECKER_TESTS
14188
14189#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014190TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014192
14193 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014194
14195 // Create an image
14196 VkImage image;
14197
Karl Schultz6addd812016-02-02 17:17:23 -070014198 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14199 const int32_t tex_width = 32;
14200 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014201
14202 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014203 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14204 image_create_info.pNext = NULL;
14205 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14206 image_create_info.format = tex_format;
14207 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014208 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014209 image_create_info.extent.depth = 1;
14210 image_create_info.mipLevels = 1;
14211 image_create_info.arrayLayers = 1;
14212 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14213 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14214 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14215 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014216
14217 // Introduce error by sending down a bogus width extent
14218 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014219 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014220
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014221 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014222}
14223
Mark Youngc48c4c12016-04-11 14:26:49 -060014224TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14226 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014227
14228 ASSERT_NO_FATAL_FAILURE(InitState());
14229
14230 // Create an image
14231 VkImage image;
14232
14233 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14234 const int32_t tex_width = 32;
14235 const int32_t tex_height = 32;
14236
14237 VkImageCreateInfo image_create_info = {};
14238 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14239 image_create_info.pNext = NULL;
14240 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14241 image_create_info.format = tex_format;
14242 image_create_info.extent.width = tex_width;
14243 image_create_info.extent.height = tex_height;
14244 image_create_info.extent.depth = 1;
14245 image_create_info.mipLevels = 1;
14246 image_create_info.arrayLayers = 1;
14247 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14248 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14249 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14250 image_create_info.flags = 0;
14251
14252 // Introduce error by sending down a bogus width extent
14253 image_create_info.extent.width = 0;
14254 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14255
14256 m_errorMonitor->VerifyFound();
14257}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014258#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014259
Tobin Ehliscde08892015-09-22 10:11:37 -060014260#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014261
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014262TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14263 TEST_DESCRIPTION("Create a render pass with an attachment description "
14264 "format set to VK_FORMAT_UNDEFINED");
14265
14266 ASSERT_NO_FATAL_FAILURE(InitState());
14267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014270
14271 VkAttachmentReference color_attach = {};
14272 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14273 color_attach.attachment = 0;
14274 VkSubpassDescription subpass = {};
14275 subpass.colorAttachmentCount = 1;
14276 subpass.pColorAttachments = &color_attach;
14277
14278 VkRenderPassCreateInfo rpci = {};
14279 rpci.subpassCount = 1;
14280 rpci.pSubpasses = &subpass;
14281 rpci.attachmentCount = 1;
14282 VkAttachmentDescription attach_desc = {};
14283 attach_desc.format = VK_FORMAT_UNDEFINED;
14284 rpci.pAttachments = &attach_desc;
14285 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14286 VkRenderPass rp;
14287 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14288
14289 m_errorMonitor->VerifyFound();
14290
14291 if (result == VK_SUCCESS) {
14292 vkDestroyRenderPass(m_device->device(), rp, NULL);
14293 }
14294}
14295
Karl Schultz6addd812016-02-02 17:17:23 -070014296TEST_F(VkLayerTest, InvalidImageView) {
14297 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014300
Tobin Ehliscde08892015-09-22 10:11:37 -060014301 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014302
Mike Stroyana3082432015-09-25 13:39:21 -060014303 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014304 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014305
Karl Schultz6addd812016-02-02 17:17:23 -070014306 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14307 const int32_t tex_width = 32;
14308 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014309
14310 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014311 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14312 image_create_info.pNext = NULL;
14313 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14314 image_create_info.format = tex_format;
14315 image_create_info.extent.width = tex_width;
14316 image_create_info.extent.height = tex_height;
14317 image_create_info.extent.depth = 1;
14318 image_create_info.mipLevels = 1;
14319 image_create_info.arrayLayers = 1;
14320 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14321 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14322 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14323 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014324
Chia-I Wuf7458c52015-10-26 21:10:41 +080014325 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014326 ASSERT_VK_SUCCESS(err);
14327
14328 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014329 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014330 image_view_create_info.image = image;
14331 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14332 image_view_create_info.format = tex_format;
14333 image_view_create_info.subresourceRange.layerCount = 1;
14334 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14335 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014336 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014337
14338 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014339 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014340
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014341 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014342 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014343}
Mike Stroyana3082432015-09-25 13:39:21 -060014344
Mark Youngd339ba32016-05-30 13:28:35 -060014345TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14346 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014348 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014349
14350 ASSERT_NO_FATAL_FAILURE(InitState());
14351
14352 // Create an image and try to create a view with no memory backing the image
14353 VkImage image;
14354
14355 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14356 const int32_t tex_width = 32;
14357 const int32_t tex_height = 32;
14358
14359 VkImageCreateInfo image_create_info = {};
14360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14361 image_create_info.pNext = NULL;
14362 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14363 image_create_info.format = tex_format;
14364 image_create_info.extent.width = tex_width;
14365 image_create_info.extent.height = tex_height;
14366 image_create_info.extent.depth = 1;
14367 image_create_info.mipLevels = 1;
14368 image_create_info.arrayLayers = 1;
14369 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14370 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14371 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14372 image_create_info.flags = 0;
14373
14374 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14375 ASSERT_VK_SUCCESS(err);
14376
14377 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014378 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014379 image_view_create_info.image = image;
14380 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14381 image_view_create_info.format = tex_format;
14382 image_view_create_info.subresourceRange.layerCount = 1;
14383 image_view_create_info.subresourceRange.baseMipLevel = 0;
14384 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014385 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014386
14387 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014388 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014389
14390 m_errorMonitor->VerifyFound();
14391 vkDestroyImage(m_device->device(), image, NULL);
14392 // If last error is success, it still created the view, so delete it.
14393 if (err == VK_SUCCESS) {
14394 vkDestroyImageView(m_device->device(), view, NULL);
14395 }
Mark Youngd339ba32016-05-30 13:28:35 -060014396}
14397
Karl Schultz6addd812016-02-02 17:17:23 -070014398TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014399 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014401 "formats must have ONLY the "
14402 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14404 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014405
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014406 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014407
Karl Schultz6addd812016-02-02 17:17:23 -070014408 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014409 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014410 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014411 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014412
14413 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014414 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014415 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014416 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14417 image_view_create_info.format = tex_format;
14418 image_view_create_info.subresourceRange.baseMipLevel = 0;
14419 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014420 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014421 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014422 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014423
14424 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014425 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014426
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014427 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014428}
14429
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014430TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014431 VkResult err;
14432 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14435 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014436
Mike Stroyana3082432015-09-25 13:39:21 -060014437 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014438
14439 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014440 VkImage srcImage;
14441 VkImage dstImage;
14442 VkDeviceMemory srcMem;
14443 VkDeviceMemory destMem;
14444 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014445
14446 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014447 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14448 image_create_info.pNext = NULL;
14449 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14450 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14451 image_create_info.extent.width = 32;
14452 image_create_info.extent.height = 32;
14453 image_create_info.extent.depth = 1;
14454 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014455 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014456 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14457 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14458 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14459 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014460
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014461 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014462 ASSERT_VK_SUCCESS(err);
14463
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014464 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014465 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014466 ASSERT_VK_SUCCESS(err);
14467
14468 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014469 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014470 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14471 memAlloc.pNext = NULL;
14472 memAlloc.allocationSize = 0;
14473 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014474
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014475 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014476 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014477 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014478 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014479 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014480 ASSERT_VK_SUCCESS(err);
14481
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014482 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014483 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014484 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014485 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014486 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014487 ASSERT_VK_SUCCESS(err);
14488
14489 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14490 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014491 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014492 ASSERT_VK_SUCCESS(err);
14493
14494 BeginCommandBuffer();
14495 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014496 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014497 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014498 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014499 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014500 copyRegion.srcOffset.x = 0;
14501 copyRegion.srcOffset.y = 0;
14502 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014503 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014504 copyRegion.dstSubresource.mipLevel = 0;
14505 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014506 // Introduce failure by forcing the dst layerCount to differ from src
14507 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014508 copyRegion.dstOffset.x = 0;
14509 copyRegion.dstOffset.y = 0;
14510 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014511 copyRegion.extent.width = 1;
14512 copyRegion.extent.height = 1;
14513 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014514 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014515 EndCommandBuffer();
14516
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014517 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014518
Chia-I Wuf7458c52015-10-26 21:10:41 +080014519 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014520 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014521 vkFreeMemory(m_device->device(), srcMem, NULL);
14522 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014523}
14524
Tony Barbourd6673642016-05-05 14:46:39 -060014525TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14526
14527 TEST_DESCRIPTION("Creating images with unsuported formats ");
14528
14529 ASSERT_NO_FATAL_FAILURE(InitState());
14530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14531 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014532 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 -060014533 VK_IMAGE_TILING_OPTIMAL, 0);
14534 ASSERT_TRUE(image.initialized());
14535
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014536 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014537 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014538 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014539 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14540 image_create_info.format = VK_FORMAT_UNDEFINED;
14541 image_create_info.extent.width = 32;
14542 image_create_info.extent.height = 32;
14543 image_create_info.extent.depth = 1;
14544 image_create_info.mipLevels = 1;
14545 image_create_info.arrayLayers = 1;
14546 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14547 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14548 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014549
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14551 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014552
14553 VkImage localImage;
14554 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14555 m_errorMonitor->VerifyFound();
14556
Tony Barbourd6673642016-05-05 14:46:39 -060014557 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014558 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014559 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14560 VkFormat format = static_cast<VkFormat>(f);
14561 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014562 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014563 unsupported = format;
14564 break;
14565 }
14566 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014567
Tony Barbourd6673642016-05-05 14:46:39 -060014568 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014569 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014571
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014572 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014573 m_errorMonitor->VerifyFound();
14574 }
14575}
14576
14577TEST_F(VkLayerTest, ImageLayerViewTests) {
14578 VkResult ret;
14579 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14580
14581 ASSERT_NO_FATAL_FAILURE(InitState());
14582
14583 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014584 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 -060014585 VK_IMAGE_TILING_OPTIMAL, 0);
14586 ASSERT_TRUE(image.initialized());
14587
14588 VkImageView imgView;
14589 VkImageViewCreateInfo imgViewInfo = {};
14590 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14591 imgViewInfo.image = image.handle();
14592 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14593 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14594 imgViewInfo.subresourceRange.layerCount = 1;
14595 imgViewInfo.subresourceRange.baseMipLevel = 0;
14596 imgViewInfo.subresourceRange.levelCount = 1;
14597 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14598
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014600 // View can't have baseMipLevel >= image's mipLevels - Expect
14601 // VIEW_CREATE_ERROR
14602 imgViewInfo.subresourceRange.baseMipLevel = 1;
14603 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14604 m_errorMonitor->VerifyFound();
14605 imgViewInfo.subresourceRange.baseMipLevel = 0;
14606
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014608 // View can't have baseArrayLayer >= image's arraySize - Expect
14609 // VIEW_CREATE_ERROR
14610 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14611 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14612 m_errorMonitor->VerifyFound();
14613 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14614
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14616 "pCreateInfo->subresourceRange."
14617 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014618 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14619 imgViewInfo.subresourceRange.levelCount = 0;
14620 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14621 m_errorMonitor->VerifyFound();
14622 imgViewInfo.subresourceRange.levelCount = 1;
14623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14625 "pCreateInfo->subresourceRange."
14626 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014627 m_errorMonitor->SetDesiredFailureMsg(
14628 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14629 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014630 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14631 imgViewInfo.subresourceRange.layerCount = 0;
14632 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14633 m_errorMonitor->VerifyFound();
14634 imgViewInfo.subresourceRange.layerCount = 1;
14635
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14638 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14639 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014640 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14641 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14642 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14643 m_errorMonitor->VerifyFound();
14644 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14645
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14647 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14648 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014649 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14650 // VIEW_CREATE_ERROR
14651 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14652 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14653 m_errorMonitor->VerifyFound();
14654 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14655
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14657 "differing formats but they must be "
14658 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014659 // TODO: Update framework to easily passing mutable flag into ImageObj init
14660 // For now just allowing image for this one test to not have memory bound
14661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14662 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014663 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14664 // VIEW_CREATE_ERROR
14665 VkImageCreateInfo mutImgInfo = image.create_info();
14666 VkImage mutImage;
14667 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014668 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014669 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14670 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14671 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14672 ASSERT_VK_SUCCESS(ret);
14673 imgViewInfo.image = mutImage;
14674 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14675 m_errorMonitor->VerifyFound();
14676 imgViewInfo.image = image.handle();
14677 vkDestroyImage(m_device->handle(), mutImage, NULL);
14678}
14679
14680TEST_F(VkLayerTest, MiscImageLayerTests) {
14681
14682 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14683
14684 ASSERT_NO_FATAL_FAILURE(InitState());
14685
14686 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014687 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 -060014688 VK_IMAGE_TILING_OPTIMAL, 0);
14689 ASSERT_TRUE(image.initialized());
14690
Tony Barbourd6673642016-05-05 14:46:39 -060014691 vk_testing::Buffer buffer;
14692 VkMemoryPropertyFlags reqs = 0;
14693 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14694 VkBufferImageCopy region = {};
14695 region.bufferRowLength = 128;
14696 region.bufferImageHeight = 128;
14697 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14698 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014699 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014700 region.imageExtent.height = 4;
14701 region.imageExtent.width = 4;
14702 region.imageExtent.depth = 1;
14703 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014704
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014705 // Image must have offset.z of 0 and extent.depth of 1
14706 // Introduce failure by setting imageExtent.depth to 0
14707 region.imageExtent.depth = 0;
14708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14709 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14710 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14711 m_errorMonitor->VerifyFound();
14712
14713 region.imageExtent.depth = 1;
14714
14715 // Image must have offset.z of 0 and extent.depth of 1
14716 // Introduce failure by setting imageOffset.z to 4
14717 region.imageOffset.z = 4;
14718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14719 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14720 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14721 m_errorMonitor->VerifyFound();
14722
14723 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014724 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14725 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14726 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014728 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14729 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014730 m_errorMonitor->VerifyFound();
14731
14732 // BufferOffset must be a multiple of 4
14733 // Introduce failure by setting bufferOffset to a value not divisible by 4
14734 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014736 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14737 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014738 m_errorMonitor->VerifyFound();
14739
14740 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14741 region.bufferOffset = 0;
14742 region.imageExtent.height = 128;
14743 region.imageExtent.width = 128;
14744 // Introduce failure by setting bufferRowLength > 0 but less than width
14745 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014747 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14748 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014749 m_errorMonitor->VerifyFound();
14750
14751 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14752 region.bufferRowLength = 128;
14753 // Introduce failure by setting bufferRowHeight > 0 but less than height
14754 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014756 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14757 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014758 m_errorMonitor->VerifyFound();
14759
14760 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14762 "If the format of srcImage is a depth, stencil, depth stencil or "
14763 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014764 // Expect INVALID_FILTER
14765 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014766 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 -060014767 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014768 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 -060014769 VkImageBlit blitRegion = {};
14770 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14771 blitRegion.srcSubresource.baseArrayLayer = 0;
14772 blitRegion.srcSubresource.layerCount = 1;
14773 blitRegion.srcSubresource.mipLevel = 0;
14774 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14775 blitRegion.dstSubresource.baseArrayLayer = 0;
14776 blitRegion.dstSubresource.layerCount = 1;
14777 blitRegion.dstSubresource.mipLevel = 0;
14778
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014779 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14780 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014781 m_errorMonitor->VerifyFound();
14782
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014783 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14785 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14786 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014787 m_errorMonitor->VerifyFound();
14788
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014790 VkImageMemoryBarrier img_barrier;
14791 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14792 img_barrier.pNext = NULL;
14793 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14794 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14795 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14796 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14797 img_barrier.image = image.handle();
14798 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14799 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14800 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14801 img_barrier.subresourceRange.baseArrayLayer = 0;
14802 img_barrier.subresourceRange.baseMipLevel = 0;
14803 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14804 img_barrier.subresourceRange.layerCount = 0;
14805 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014806 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14807 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014808 m_errorMonitor->VerifyFound();
14809 img_barrier.subresourceRange.layerCount = 1;
14810}
14811
14812TEST_F(VkLayerTest, ImageFormatLimits) {
14813
14814 TEST_DESCRIPTION("Exceed the limits of image format ");
14815
Cody Northropc31a84f2016-08-22 10:41:47 -060014816 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014818 VkImageCreateInfo image_create_info = {};
14819 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14820 image_create_info.pNext = NULL;
14821 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14822 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14823 image_create_info.extent.width = 32;
14824 image_create_info.extent.height = 32;
14825 image_create_info.extent.depth = 1;
14826 image_create_info.mipLevels = 1;
14827 image_create_info.arrayLayers = 1;
14828 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14829 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14830 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14831 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14832 image_create_info.flags = 0;
14833
14834 VkImage nullImg;
14835 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014836 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14837 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014838 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14839 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14840 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14841 m_errorMonitor->VerifyFound();
14842 image_create_info.extent.depth = 1;
14843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014845 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14846 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14847 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14848 m_errorMonitor->VerifyFound();
14849 image_create_info.mipLevels = 1;
14850
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014852 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14853 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14854 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14855 m_errorMonitor->VerifyFound();
14856 image_create_info.arrayLayers = 1;
14857
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014859 int samples = imgFmtProps.sampleCounts >> 1;
14860 image_create_info.samples = (VkSampleCountFlagBits)samples;
14861 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14862 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14863 m_errorMonitor->VerifyFound();
14864 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14867 "VK_IMAGE_LAYOUT_UNDEFINED or "
14868 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014869 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14870 // Expect INVALID_LAYOUT
14871 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14872 m_errorMonitor->VerifyFound();
14873 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14874}
14875
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014876TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14877
14878 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014880
14881 ASSERT_NO_FATAL_FAILURE(InitState());
14882
14883 VkImageObj src_image(m_device);
14884 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14885 VkImageObj dst_image(m_device);
14886 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14887
14888 BeginCommandBuffer();
14889 VkImageCopy copy_region;
14890 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14891 copy_region.srcSubresource.mipLevel = 0;
14892 copy_region.srcSubresource.baseArrayLayer = 0;
14893 copy_region.srcSubresource.layerCount = 0;
14894 copy_region.srcOffset.x = 0;
14895 copy_region.srcOffset.y = 0;
14896 copy_region.srcOffset.z = 0;
14897 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14898 copy_region.dstSubresource.mipLevel = 0;
14899 copy_region.dstSubresource.baseArrayLayer = 0;
14900 copy_region.dstSubresource.layerCount = 0;
14901 copy_region.dstOffset.x = 0;
14902 copy_region.dstOffset.y = 0;
14903 copy_region.dstOffset.z = 0;
14904 copy_region.extent.width = 64;
14905 copy_region.extent.height = 64;
14906 copy_region.extent.depth = 1;
14907 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14908 &copy_region);
14909 EndCommandBuffer();
14910
14911 m_errorMonitor->VerifyFound();
14912}
14913
14914TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14915
14916 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014918
14919 ASSERT_NO_FATAL_FAILURE(InitState());
14920
14921 VkImageObj src_image(m_device);
14922 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14923 VkImageObj dst_image(m_device);
14924 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14925
14926 BeginCommandBuffer();
14927 VkImageCopy copy_region;
14928 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14929 copy_region.srcSubresource.mipLevel = 0;
14930 copy_region.srcSubresource.baseArrayLayer = 0;
14931 copy_region.srcSubresource.layerCount = 0;
14932 copy_region.srcOffset.x = 0;
14933 copy_region.srcOffset.y = 0;
14934 copy_region.srcOffset.z = 0;
14935 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14936 copy_region.dstSubresource.mipLevel = 0;
14937 copy_region.dstSubresource.baseArrayLayer = 0;
14938 copy_region.dstSubresource.layerCount = 0;
14939 copy_region.dstOffset.x = 0;
14940 copy_region.dstOffset.y = 0;
14941 copy_region.dstOffset.z = 0;
14942 copy_region.extent.width = 64;
14943 copy_region.extent.height = 64;
14944 copy_region.extent.depth = 1;
14945 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14946 &copy_region);
14947 EndCommandBuffer();
14948
14949 m_errorMonitor->VerifyFound();
14950}
14951
Karl Schultz6addd812016-02-02 17:17:23 -070014952TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014953 VkResult err;
14954 bool pass;
14955
14956 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14958 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014959
14960 ASSERT_NO_FATAL_FAILURE(InitState());
14961
14962 // Create two images of different types and try to copy between them
14963 VkImage srcImage;
14964 VkImage dstImage;
14965 VkDeviceMemory srcMem;
14966 VkDeviceMemory destMem;
14967 VkMemoryRequirements memReqs;
14968
14969 VkImageCreateInfo image_create_info = {};
14970 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14971 image_create_info.pNext = NULL;
14972 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14973 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14974 image_create_info.extent.width = 32;
14975 image_create_info.extent.height = 32;
14976 image_create_info.extent.depth = 1;
14977 image_create_info.mipLevels = 1;
14978 image_create_info.arrayLayers = 1;
14979 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14980 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14981 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14982 image_create_info.flags = 0;
14983
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014984 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014985 ASSERT_VK_SUCCESS(err);
14986
14987 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14988 // Introduce failure by creating second image with a different-sized format.
14989 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014991 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014992 ASSERT_VK_SUCCESS(err);
14993
14994 // Allocate memory
14995 VkMemoryAllocateInfo memAlloc = {};
14996 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14997 memAlloc.pNext = NULL;
14998 memAlloc.allocationSize = 0;
14999 memAlloc.memoryTypeIndex = 0;
15000
15001 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15002 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015003 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015004 ASSERT_TRUE(pass);
15005 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15006 ASSERT_VK_SUCCESS(err);
15007
15008 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15009 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015010 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015011 ASSERT_TRUE(pass);
15012 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15013 ASSERT_VK_SUCCESS(err);
15014
15015 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15016 ASSERT_VK_SUCCESS(err);
15017 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15018 ASSERT_VK_SUCCESS(err);
15019
15020 BeginCommandBuffer();
15021 VkImageCopy copyRegion;
15022 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15023 copyRegion.srcSubresource.mipLevel = 0;
15024 copyRegion.srcSubresource.baseArrayLayer = 0;
15025 copyRegion.srcSubresource.layerCount = 0;
15026 copyRegion.srcOffset.x = 0;
15027 copyRegion.srcOffset.y = 0;
15028 copyRegion.srcOffset.z = 0;
15029 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15030 copyRegion.dstSubresource.mipLevel = 0;
15031 copyRegion.dstSubresource.baseArrayLayer = 0;
15032 copyRegion.dstSubresource.layerCount = 0;
15033 copyRegion.dstOffset.x = 0;
15034 copyRegion.dstOffset.y = 0;
15035 copyRegion.dstOffset.z = 0;
15036 copyRegion.extent.width = 1;
15037 copyRegion.extent.height = 1;
15038 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015039 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060015040 EndCommandBuffer();
15041
15042 m_errorMonitor->VerifyFound();
15043
15044 vkDestroyImage(m_device->device(), srcImage, NULL);
15045 vkDestroyImage(m_device->device(), dstImage, NULL);
15046 vkFreeMemory(m_device->device(), srcMem, NULL);
15047 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015048}
15049
Karl Schultz6addd812016-02-02 17:17:23 -070015050TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15051 VkResult err;
15052 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015053
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015054 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15056 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015057
Mike Stroyana3082432015-09-25 13:39:21 -060015058 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015059
15060 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015061 VkImage srcImage;
15062 VkImage dstImage;
15063 VkDeviceMemory srcMem;
15064 VkDeviceMemory destMem;
15065 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015066
15067 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015068 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15069 image_create_info.pNext = NULL;
15070 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15071 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15072 image_create_info.extent.width = 32;
15073 image_create_info.extent.height = 32;
15074 image_create_info.extent.depth = 1;
15075 image_create_info.mipLevels = 1;
15076 image_create_info.arrayLayers = 1;
15077 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15078 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15079 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15080 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015081
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015082 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015083 ASSERT_VK_SUCCESS(err);
15084
Karl Schultzbdb75952016-04-19 11:36:49 -060015085 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15086
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015087 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015088 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015089 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015090 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015092 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015093 ASSERT_VK_SUCCESS(err);
15094
15095 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015096 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015097 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15098 memAlloc.pNext = NULL;
15099 memAlloc.allocationSize = 0;
15100 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015101
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015102 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015103 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015104 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015105 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015106 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015107 ASSERT_VK_SUCCESS(err);
15108
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015109 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015110 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015111 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015112 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015113 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015114 ASSERT_VK_SUCCESS(err);
15115
15116 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15117 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015118 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015119 ASSERT_VK_SUCCESS(err);
15120
15121 BeginCommandBuffer();
15122 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015123 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015124 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015125 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015126 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015127 copyRegion.srcOffset.x = 0;
15128 copyRegion.srcOffset.y = 0;
15129 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015130 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015131 copyRegion.dstSubresource.mipLevel = 0;
15132 copyRegion.dstSubresource.baseArrayLayer = 0;
15133 copyRegion.dstSubresource.layerCount = 0;
15134 copyRegion.dstOffset.x = 0;
15135 copyRegion.dstOffset.y = 0;
15136 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015137 copyRegion.extent.width = 1;
15138 copyRegion.extent.height = 1;
15139 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015140 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015141 EndCommandBuffer();
15142
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015143 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015144
Chia-I Wuf7458c52015-10-26 21:10:41 +080015145 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015146 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015147 vkFreeMemory(m_device->device(), srcMem, NULL);
15148 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015149}
15150
Karl Schultz6addd812016-02-02 17:17:23 -070015151TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15152 VkResult err;
15153 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015154
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15156 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015157
Mike Stroyana3082432015-09-25 13:39:21 -060015158 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015159
15160 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015161 VkImage srcImage;
15162 VkImage dstImage;
15163 VkDeviceMemory srcMem;
15164 VkDeviceMemory destMem;
15165 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015166
15167 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015168 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15169 image_create_info.pNext = NULL;
15170 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15171 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15172 image_create_info.extent.width = 32;
15173 image_create_info.extent.height = 1;
15174 image_create_info.extent.depth = 1;
15175 image_create_info.mipLevels = 1;
15176 image_create_info.arrayLayers = 1;
15177 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15178 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15179 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15180 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015182 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015183 ASSERT_VK_SUCCESS(err);
15184
Karl Schultz6addd812016-02-02 17:17:23 -070015185 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015186
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015187 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015188 ASSERT_VK_SUCCESS(err);
15189
15190 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015191 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015192 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15193 memAlloc.pNext = NULL;
15194 memAlloc.allocationSize = 0;
15195 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015196
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015197 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015198 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015199 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015200 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015201 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015202 ASSERT_VK_SUCCESS(err);
15203
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015204 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015205 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015206 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015207 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015208 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015209 ASSERT_VK_SUCCESS(err);
15210
15211 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15212 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015213 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015214 ASSERT_VK_SUCCESS(err);
15215
15216 BeginCommandBuffer();
15217 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015218 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15219 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015220 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015221 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015222 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015223 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015224 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015225 resolveRegion.srcOffset.x = 0;
15226 resolveRegion.srcOffset.y = 0;
15227 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015228 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015229 resolveRegion.dstSubresource.mipLevel = 0;
15230 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015231 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015232 resolveRegion.dstOffset.x = 0;
15233 resolveRegion.dstOffset.y = 0;
15234 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015235 resolveRegion.extent.width = 1;
15236 resolveRegion.extent.height = 1;
15237 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015238 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015239 EndCommandBuffer();
15240
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015241 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015242
Chia-I Wuf7458c52015-10-26 21:10:41 +080015243 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015244 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015245 vkFreeMemory(m_device->device(), srcMem, NULL);
15246 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015247}
15248
Karl Schultz6addd812016-02-02 17:17:23 -070015249TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15250 VkResult err;
15251 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15254 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015255
Mike Stroyana3082432015-09-25 13:39:21 -060015256 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015257
Chris Forbesa7530692016-05-08 12:35:39 +120015258 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015259 VkImage srcImage;
15260 VkImage dstImage;
15261 VkDeviceMemory srcMem;
15262 VkDeviceMemory destMem;
15263 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015264
15265 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015266 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15267 image_create_info.pNext = NULL;
15268 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15269 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15270 image_create_info.extent.width = 32;
15271 image_create_info.extent.height = 1;
15272 image_create_info.extent.depth = 1;
15273 image_create_info.mipLevels = 1;
15274 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015275 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015276 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15277 // Note: Some implementations expect color attachment usage for any
15278 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015279 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015280 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015281
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015282 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015283 ASSERT_VK_SUCCESS(err);
15284
Karl Schultz6addd812016-02-02 17:17:23 -070015285 // Note: Some implementations expect color attachment usage for any
15286 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015287 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015288
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015289 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015290 ASSERT_VK_SUCCESS(err);
15291
15292 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015293 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015294 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15295 memAlloc.pNext = NULL;
15296 memAlloc.allocationSize = 0;
15297 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015298
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015299 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015300 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015301 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015302 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015303 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015304 ASSERT_VK_SUCCESS(err);
15305
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015306 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015307 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015308 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015309 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015310 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015311 ASSERT_VK_SUCCESS(err);
15312
15313 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15314 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015315 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015316 ASSERT_VK_SUCCESS(err);
15317
15318 BeginCommandBuffer();
15319 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015320 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15321 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015322 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015323 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015324 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015325 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015326 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015327 resolveRegion.srcOffset.x = 0;
15328 resolveRegion.srcOffset.y = 0;
15329 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015330 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015331 resolveRegion.dstSubresource.mipLevel = 0;
15332 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015333 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015334 resolveRegion.dstOffset.x = 0;
15335 resolveRegion.dstOffset.y = 0;
15336 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015337 resolveRegion.extent.width = 1;
15338 resolveRegion.extent.height = 1;
15339 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015340 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015341 EndCommandBuffer();
15342
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015343 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015344
Chia-I Wuf7458c52015-10-26 21:10:41 +080015345 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015346 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015347 vkFreeMemory(m_device->device(), srcMem, NULL);
15348 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015349}
15350
Karl Schultz6addd812016-02-02 17:17:23 -070015351TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15352 VkResult err;
15353 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015354
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15356 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015357
Mike Stroyana3082432015-09-25 13:39:21 -060015358 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015359
15360 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015361 VkImage srcImage;
15362 VkImage dstImage;
15363 VkDeviceMemory srcMem;
15364 VkDeviceMemory destMem;
15365 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015366
15367 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015368 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15369 image_create_info.pNext = NULL;
15370 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15371 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15372 image_create_info.extent.width = 32;
15373 image_create_info.extent.height = 1;
15374 image_create_info.extent.depth = 1;
15375 image_create_info.mipLevels = 1;
15376 image_create_info.arrayLayers = 1;
15377 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15378 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15379 // Note: Some implementations expect color attachment usage for any
15380 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015381 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015382 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015383
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015384 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015385 ASSERT_VK_SUCCESS(err);
15386
Karl Schultz6addd812016-02-02 17:17:23 -070015387 // Set format to something other than source image
15388 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15389 // Note: Some implementations expect color attachment usage for any
15390 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015391 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015392 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015393
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015394 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015395 ASSERT_VK_SUCCESS(err);
15396
15397 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015398 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015399 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15400 memAlloc.pNext = NULL;
15401 memAlloc.allocationSize = 0;
15402 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015403
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015404 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015405 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015406 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015407 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015408 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015409 ASSERT_VK_SUCCESS(err);
15410
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015411 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015412 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015413 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015414 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015415 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015416 ASSERT_VK_SUCCESS(err);
15417
15418 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15419 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015420 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015421 ASSERT_VK_SUCCESS(err);
15422
15423 BeginCommandBuffer();
15424 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015425 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15426 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015427 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015428 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015429 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015430 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015431 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015432 resolveRegion.srcOffset.x = 0;
15433 resolveRegion.srcOffset.y = 0;
15434 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015435 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015436 resolveRegion.dstSubresource.mipLevel = 0;
15437 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015438 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015439 resolveRegion.dstOffset.x = 0;
15440 resolveRegion.dstOffset.y = 0;
15441 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015442 resolveRegion.extent.width = 1;
15443 resolveRegion.extent.height = 1;
15444 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015445 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015446 EndCommandBuffer();
15447
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015448 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015449
Chia-I Wuf7458c52015-10-26 21:10:41 +080015450 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015451 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015452 vkFreeMemory(m_device->device(), srcMem, NULL);
15453 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015454}
15455
Karl Schultz6addd812016-02-02 17:17:23 -070015456TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15457 VkResult err;
15458 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015459
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15461 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015462
Mike Stroyana3082432015-09-25 13:39:21 -060015463 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015464
15465 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015466 VkImage srcImage;
15467 VkImage dstImage;
15468 VkDeviceMemory srcMem;
15469 VkDeviceMemory destMem;
15470 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015471
15472 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015473 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15474 image_create_info.pNext = NULL;
15475 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15476 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15477 image_create_info.extent.width = 32;
15478 image_create_info.extent.height = 1;
15479 image_create_info.extent.depth = 1;
15480 image_create_info.mipLevels = 1;
15481 image_create_info.arrayLayers = 1;
15482 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15483 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15484 // Note: Some implementations expect color attachment usage for any
15485 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015486 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015487 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015489 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015490 ASSERT_VK_SUCCESS(err);
15491
Karl Schultz6addd812016-02-02 17:17:23 -070015492 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15493 // Note: Some implementations expect color attachment usage for any
15494 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015495 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015496 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015497
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015498 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015499 ASSERT_VK_SUCCESS(err);
15500
15501 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015502 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015503 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15504 memAlloc.pNext = NULL;
15505 memAlloc.allocationSize = 0;
15506 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015507
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015508 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015509 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015510 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015511 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015512 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015513 ASSERT_VK_SUCCESS(err);
15514
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015515 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015516 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015517 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015518 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015519 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015520 ASSERT_VK_SUCCESS(err);
15521
15522 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15523 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015524 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015525 ASSERT_VK_SUCCESS(err);
15526
15527 BeginCommandBuffer();
15528 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015529 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15530 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015531 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015532 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015533 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015534 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015535 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015536 resolveRegion.srcOffset.x = 0;
15537 resolveRegion.srcOffset.y = 0;
15538 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015539 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015540 resolveRegion.dstSubresource.mipLevel = 0;
15541 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015542 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015543 resolveRegion.dstOffset.x = 0;
15544 resolveRegion.dstOffset.y = 0;
15545 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015546 resolveRegion.extent.width = 1;
15547 resolveRegion.extent.height = 1;
15548 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015549 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015550 EndCommandBuffer();
15551
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015552 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015553
Chia-I Wuf7458c52015-10-26 21:10:41 +080015554 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015555 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015556 vkFreeMemory(m_device->device(), srcMem, NULL);
15557 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015558}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015559
Karl Schultz6addd812016-02-02 17:17:23 -070015560TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015561 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015562 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15563 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015564 // The image format check comes 2nd in validation so we trigger it first,
15565 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015566 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15569 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015570
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015571 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015572
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015573 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015574 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15575 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015576
15577 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015578 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15579 ds_pool_ci.pNext = NULL;
15580 ds_pool_ci.maxSets = 1;
15581 ds_pool_ci.poolSizeCount = 1;
15582 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015583
15584 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015585 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015586 ASSERT_VK_SUCCESS(err);
15587
15588 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015589 dsl_binding.binding = 0;
15590 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15591 dsl_binding.descriptorCount = 1;
15592 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15593 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015594
15595 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015596 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15597 ds_layout_ci.pNext = NULL;
15598 ds_layout_ci.bindingCount = 1;
15599 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015600 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015601 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015602 ASSERT_VK_SUCCESS(err);
15603
15604 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015605 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015606 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015607 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015608 alloc_info.descriptorPool = ds_pool;
15609 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015610 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015611 ASSERT_VK_SUCCESS(err);
15612
Karl Schultz6addd812016-02-02 17:17:23 -070015613 VkImage image_bad;
15614 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015615 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015616 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015617 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015618 const int32_t tex_width = 32;
15619 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015620
15621 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015622 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15623 image_create_info.pNext = NULL;
15624 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15625 image_create_info.format = tex_format_bad;
15626 image_create_info.extent.width = tex_width;
15627 image_create_info.extent.height = tex_height;
15628 image_create_info.extent.depth = 1;
15629 image_create_info.mipLevels = 1;
15630 image_create_info.arrayLayers = 1;
15631 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15632 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015633 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015634 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015635
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015636 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015637 ASSERT_VK_SUCCESS(err);
15638 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015639 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15640 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015641 ASSERT_VK_SUCCESS(err);
15642
15643 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015644 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015645 image_view_create_info.image = image_bad;
15646 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15647 image_view_create_info.format = tex_format_bad;
15648 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15649 image_view_create_info.subresourceRange.baseMipLevel = 0;
15650 image_view_create_info.subresourceRange.layerCount = 1;
15651 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015652 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015653
15654 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015655 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015656
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015657 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015658
Chia-I Wuf7458c52015-10-26 21:10:41 +080015659 vkDestroyImage(m_device->device(), image_bad, NULL);
15660 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015661 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15662 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015663}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015664
15665TEST_F(VkLayerTest, ClearImageErrors) {
15666 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15667 "ClearDepthStencilImage with a color image.");
15668
15669 ASSERT_NO_FATAL_FAILURE(InitState());
15670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15671
15672 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15673 BeginCommandBuffer();
15674 m_commandBuffer->EndRenderPass();
15675
15676 // Color image
15677 VkClearColorValue clear_color;
15678 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15679 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15680 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15681 const int32_t img_width = 32;
15682 const int32_t img_height = 32;
15683 VkImageCreateInfo image_create_info = {};
15684 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15685 image_create_info.pNext = NULL;
15686 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15687 image_create_info.format = color_format;
15688 image_create_info.extent.width = img_width;
15689 image_create_info.extent.height = img_height;
15690 image_create_info.extent.depth = 1;
15691 image_create_info.mipLevels = 1;
15692 image_create_info.arrayLayers = 1;
15693 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15694 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15695 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15696
15697 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015698 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015700 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015701
15702 // Depth/Stencil image
15703 VkClearDepthStencilValue clear_value = {0};
15704 reqs = 0; // don't need HOST_VISIBLE DS image
15705 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15706 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15707 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15708 ds_image_create_info.extent.width = 64;
15709 ds_image_create_info.extent.height = 64;
15710 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15711 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15712
15713 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015714 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015715
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015716 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 -060015717
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015719
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015720 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015721 &color_range);
15722
15723 m_errorMonitor->VerifyFound();
15724
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15726 "image created without "
15727 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015728
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015729 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015730 &color_range);
15731
15732 m_errorMonitor->VerifyFound();
15733
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015734 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15736 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015738 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15739 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015740
15741 m_errorMonitor->VerifyFound();
15742}
Tobin Ehliscde08892015-09-22 10:11:37 -060015743#endif // IMAGE_TESTS
15744
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015745
15746// WSI Enabled Tests
15747//
Chris Forbes09368e42016-10-13 11:59:22 +130015748#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015749TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15750
15751#if defined(VK_USE_PLATFORM_XCB_KHR)
15752 VkSurfaceKHR surface = VK_NULL_HANDLE;
15753
15754 VkResult err;
15755 bool pass;
15756 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15757 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15758 // uint32_t swapchain_image_count = 0;
15759 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15760 // uint32_t image_index = 0;
15761 // VkPresentInfoKHR present_info = {};
15762
15763 ASSERT_NO_FATAL_FAILURE(InitState());
15764
15765 // Use the create function from one of the VK_KHR_*_surface extension in
15766 // order to create a surface, testing all known errors in the process,
15767 // before successfully creating a surface:
15768 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15770 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15771 pass = (err != VK_SUCCESS);
15772 ASSERT_TRUE(pass);
15773 m_errorMonitor->VerifyFound();
15774
15775 // Next, try to create a surface with the wrong
15776 // VkXcbSurfaceCreateInfoKHR::sType:
15777 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15778 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15780 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15781 pass = (err != VK_SUCCESS);
15782 ASSERT_TRUE(pass);
15783 m_errorMonitor->VerifyFound();
15784
15785 // Create a native window, and then correctly create a surface:
15786 xcb_connection_t *connection;
15787 xcb_screen_t *screen;
15788 xcb_window_t xcb_window;
15789 xcb_intern_atom_reply_t *atom_wm_delete_window;
15790
15791 const xcb_setup_t *setup;
15792 xcb_screen_iterator_t iter;
15793 int scr;
15794 uint32_t value_mask, value_list[32];
15795 int width = 1;
15796 int height = 1;
15797
15798 connection = xcb_connect(NULL, &scr);
15799 ASSERT_TRUE(connection != NULL);
15800 setup = xcb_get_setup(connection);
15801 iter = xcb_setup_roots_iterator(setup);
15802 while (scr-- > 0)
15803 xcb_screen_next(&iter);
15804 screen = iter.data;
15805
15806 xcb_window = xcb_generate_id(connection);
15807
15808 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15809 value_list[0] = screen->black_pixel;
15810 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15811
15812 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15813 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15814
15815 /* Magic code that will send notification when window is destroyed */
15816 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15817 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15818
15819 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15820 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15821 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15822 free(reply);
15823
15824 xcb_map_window(connection, xcb_window);
15825
15826 // Force the x/y coordinates to 100,100 results are identical in consecutive
15827 // runs
15828 const uint32_t coords[] = { 100, 100 };
15829 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15830
15831 // Finally, try to correctly create a surface:
15832 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15833 xcb_create_info.pNext = NULL;
15834 xcb_create_info.flags = 0;
15835 xcb_create_info.connection = connection;
15836 xcb_create_info.window = xcb_window;
15837 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15838 pass = (err == VK_SUCCESS);
15839 ASSERT_TRUE(pass);
15840
15841 // Check if surface supports presentation:
15842
15843 // 1st, do so without having queried the queue families:
15844 VkBool32 supported = false;
15845 // TODO: Get the following error to come out:
15846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15847 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15848 "function");
15849 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15850 pass = (err != VK_SUCCESS);
15851 // ASSERT_TRUE(pass);
15852 // m_errorMonitor->VerifyFound();
15853
15854 // Next, query a queue family index that's too large:
15855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15856 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15857 pass = (err != VK_SUCCESS);
15858 ASSERT_TRUE(pass);
15859 m_errorMonitor->VerifyFound();
15860
15861 // Finally, do so correctly:
15862 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15863 // SUPPORTED
15864 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15865 pass = (err == VK_SUCCESS);
15866 ASSERT_TRUE(pass);
15867
15868 // Before proceeding, try to create a swapchain without having called
15869 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15870 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15871 swapchain_create_info.pNext = NULL;
15872 swapchain_create_info.flags = 0;
15873 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15874 swapchain_create_info.surface = surface;
15875 swapchain_create_info.imageArrayLayers = 1;
15876 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15877 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15879 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15880 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15881 pass = (err != VK_SUCCESS);
15882 ASSERT_TRUE(pass);
15883 m_errorMonitor->VerifyFound();
15884
15885 // Get the surface capabilities:
15886 VkSurfaceCapabilitiesKHR surface_capabilities;
15887
15888 // Do so correctly (only error logged by this entrypoint is if the
15889 // extension isn't enabled):
15890 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15891 pass = (err == VK_SUCCESS);
15892 ASSERT_TRUE(pass);
15893
15894 // Get the surface formats:
15895 uint32_t surface_format_count;
15896
15897 // First, try without a pointer to surface_format_count:
15898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15899 "specified as NULL");
15900 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15901 pass = (err == VK_SUCCESS);
15902 ASSERT_TRUE(pass);
15903 m_errorMonitor->VerifyFound();
15904
15905 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15906 // correctly done a 1st try (to get the count):
15907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15908 surface_format_count = 0;
15909 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15910 pass = (err == VK_SUCCESS);
15911 ASSERT_TRUE(pass);
15912 m_errorMonitor->VerifyFound();
15913
15914 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15915 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15916 pass = (err == VK_SUCCESS);
15917 ASSERT_TRUE(pass);
15918
15919 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15920 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15921
15922 // Next, do a 2nd try with surface_format_count being set too high:
15923 surface_format_count += 5;
15924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15925 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15926 pass = (err == VK_SUCCESS);
15927 ASSERT_TRUE(pass);
15928 m_errorMonitor->VerifyFound();
15929
15930 // Finally, do a correct 1st and 2nd try:
15931 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15932 pass = (err == VK_SUCCESS);
15933 ASSERT_TRUE(pass);
15934 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15935 pass = (err == VK_SUCCESS);
15936 ASSERT_TRUE(pass);
15937
15938 // Get the surface present modes:
15939 uint32_t surface_present_mode_count;
15940
15941 // First, try without a pointer to surface_format_count:
15942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15943 "specified as NULL");
15944
15945 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15946 pass = (err == VK_SUCCESS);
15947 ASSERT_TRUE(pass);
15948 m_errorMonitor->VerifyFound();
15949
15950 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15951 // correctly done a 1st try (to get the count):
15952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15953 surface_present_mode_count = 0;
15954 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15955 (VkPresentModeKHR *)&surface_present_mode_count);
15956 pass = (err == VK_SUCCESS);
15957 ASSERT_TRUE(pass);
15958 m_errorMonitor->VerifyFound();
15959
15960 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15961 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15962 pass = (err == VK_SUCCESS);
15963 ASSERT_TRUE(pass);
15964
15965 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15966 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15967
15968 // Next, do a 2nd try with surface_format_count being set too high:
15969 surface_present_mode_count += 5;
15970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15971 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15972 pass = (err == VK_SUCCESS);
15973 ASSERT_TRUE(pass);
15974 m_errorMonitor->VerifyFound();
15975
15976 // Finally, do a correct 1st and 2nd try:
15977 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15978 pass = (err == VK_SUCCESS);
15979 ASSERT_TRUE(pass);
15980 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15981 pass = (err == VK_SUCCESS);
15982 ASSERT_TRUE(pass);
15983
15984 // Create a swapchain:
15985
15986 // First, try without a pointer to swapchain_create_info:
15987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15988 "specified as NULL");
15989
15990 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15991 pass = (err != VK_SUCCESS);
15992 ASSERT_TRUE(pass);
15993 m_errorMonitor->VerifyFound();
15994
15995 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15996 // sType:
15997 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15999
16000 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16001 pass = (err != VK_SUCCESS);
16002 ASSERT_TRUE(pass);
16003 m_errorMonitor->VerifyFound();
16004
16005 // Next, call with a NULL swapchain pointer:
16006 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16007 swapchain_create_info.pNext = NULL;
16008 swapchain_create_info.flags = 0;
16009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16010 "specified as NULL");
16011
16012 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16013 pass = (err != VK_SUCCESS);
16014 ASSERT_TRUE(pass);
16015 m_errorMonitor->VerifyFound();
16016
16017 // TODO: Enhance swapchain layer so that
16018 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16019
16020 // Next, call with a queue family index that's too large:
16021 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16022 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16023 swapchain_create_info.queueFamilyIndexCount = 2;
16024 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16026 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16027 pass = (err != VK_SUCCESS);
16028 ASSERT_TRUE(pass);
16029 m_errorMonitor->VerifyFound();
16030
16031 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16032 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16033 swapchain_create_info.queueFamilyIndexCount = 1;
16034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16035 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16036 "pCreateInfo->pQueueFamilyIndices).");
16037 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16038 pass = (err != VK_SUCCESS);
16039 ASSERT_TRUE(pass);
16040 m_errorMonitor->VerifyFound();
16041
16042 // Next, call with an invalid imageSharingMode:
16043 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16044 swapchain_create_info.queueFamilyIndexCount = 1;
16045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16046 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16047 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16048 pass = (err != VK_SUCCESS);
16049 ASSERT_TRUE(pass);
16050 m_errorMonitor->VerifyFound();
16051 // Fix for the future:
16052 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16053 // SUPPORTED
16054 swapchain_create_info.queueFamilyIndexCount = 0;
16055 queueFamilyIndex[0] = 0;
16056 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16057
16058 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16059 // Get the images from a swapchain:
16060 // Acquire an image from a swapchain:
16061 // Present an image to a swapchain:
16062 // Destroy the swapchain:
16063
16064 // TODOs:
16065 //
16066 // - Try destroying the device without first destroying the swapchain
16067 //
16068 // - Try destroying the device without first destroying the surface
16069 //
16070 // - Try destroying the surface without first destroying the swapchain
16071
16072 // Destroy the surface:
16073 vkDestroySurfaceKHR(instance(), surface, NULL);
16074
16075 // Tear down the window:
16076 xcb_destroy_window(connection, xcb_window);
16077 xcb_disconnect(connection);
16078
16079#else // VK_USE_PLATFORM_XCB_KHR
16080 return;
16081#endif // VK_USE_PLATFORM_XCB_KHR
16082}
Chris Forbes09368e42016-10-13 11:59:22 +130016083#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016084
16085//
16086// POSITIVE VALIDATION TESTS
16087//
16088// These tests do not expect to encounter ANY validation errors pass only if this is true
16089
Tobin Ehlise0006882016-11-03 10:14:28 -060016090TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
16091 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
16092 "by a transition in the primary.");
16093 VkResult err;
16094 m_errorMonitor->ExpectSuccess();
16095 ASSERT_NO_FATAL_FAILURE(InitState());
16096 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16097 // Allocate a secondary and primary cmd buffer
16098 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16099 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16100 command_buffer_allocate_info.commandPool = m_commandPool;
16101 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16102 command_buffer_allocate_info.commandBufferCount = 1;
16103
16104 VkCommandBuffer secondary_command_buffer;
16105 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16106 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16107 VkCommandBuffer primary_command_buffer;
16108 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16109 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16110 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16111 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16112 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16113 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16114 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16115
16116 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16117 ASSERT_VK_SUCCESS(err);
16118 VkImageObj image(m_device);
16119 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16120 ASSERT_TRUE(image.initialized());
16121 VkImageMemoryBarrier img_barrier = {};
16122 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16123 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16124 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16125 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16126 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16127 img_barrier.image = image.handle();
16128 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16129 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16130 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16131 img_barrier.subresourceRange.baseArrayLayer = 0;
16132 img_barrier.subresourceRange.baseMipLevel = 0;
16133 img_barrier.subresourceRange.layerCount = 1;
16134 img_barrier.subresourceRange.levelCount = 1;
16135 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16136 0, nullptr, 1, &img_barrier);
16137 err = vkEndCommandBuffer(secondary_command_buffer);
16138 ASSERT_VK_SUCCESS(err);
16139
16140 // Now update primary cmd buffer to execute secondary and transitions image
16141 command_buffer_begin_info.pInheritanceInfo = nullptr;
16142 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16143 ASSERT_VK_SUCCESS(err);
16144 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16145 VkImageMemoryBarrier img_barrier2 = {};
16146 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16147 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16148 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16149 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16150 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16151 img_barrier2.image = image.handle();
16152 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16153 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16154 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16155 img_barrier2.subresourceRange.baseArrayLayer = 0;
16156 img_barrier2.subresourceRange.baseMipLevel = 0;
16157 img_barrier2.subresourceRange.layerCount = 1;
16158 img_barrier2.subresourceRange.levelCount = 1;
16159 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16160 nullptr, 1, &img_barrier2);
16161 err = vkEndCommandBuffer(primary_command_buffer);
16162 ASSERT_VK_SUCCESS(err);
16163 VkSubmitInfo submit_info = {};
16164 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16165 submit_info.commandBufferCount = 1;
16166 submit_info.pCommandBuffers = &primary_command_buffer;
16167 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16168 ASSERT_VK_SUCCESS(err);
16169 m_errorMonitor->VerifyNotFound();
16170 err = vkDeviceWaitIdle(m_device->device());
16171 ASSERT_VK_SUCCESS(err);
16172 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16173 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16174}
16175
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016176// This is a positive test. No failures are expected.
16177TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16178 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16179 "is ignoring VkWriteDescriptorSet members that are not "
16180 "related to the descriptor type specified by "
16181 "VkWriteDescriptorSet::descriptorType. Correct "
16182 "validation behavior will result in the test running to "
16183 "completion without validation errors.");
16184
16185 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16186
16187 ASSERT_NO_FATAL_FAILURE(InitState());
16188
16189 // Image Case
16190 {
16191 m_errorMonitor->ExpectSuccess();
16192
16193 VkImage image;
16194 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16195 const int32_t tex_width = 32;
16196 const int32_t tex_height = 32;
16197 VkImageCreateInfo image_create_info = {};
16198 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16199 image_create_info.pNext = NULL;
16200 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16201 image_create_info.format = tex_format;
16202 image_create_info.extent.width = tex_width;
16203 image_create_info.extent.height = tex_height;
16204 image_create_info.extent.depth = 1;
16205 image_create_info.mipLevels = 1;
16206 image_create_info.arrayLayers = 1;
16207 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16208 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16209 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16210 image_create_info.flags = 0;
16211 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16212 ASSERT_VK_SUCCESS(err);
16213
16214 VkMemoryRequirements memory_reqs;
16215 VkDeviceMemory image_memory;
16216 bool pass;
16217 VkMemoryAllocateInfo memory_info = {};
16218 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16219 memory_info.pNext = NULL;
16220 memory_info.allocationSize = 0;
16221 memory_info.memoryTypeIndex = 0;
16222 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16223 memory_info.allocationSize = memory_reqs.size;
16224 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16225 ASSERT_TRUE(pass);
16226 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16227 ASSERT_VK_SUCCESS(err);
16228 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16229 ASSERT_VK_SUCCESS(err);
16230
16231 VkImageViewCreateInfo image_view_create_info = {};
16232 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16233 image_view_create_info.image = image;
16234 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16235 image_view_create_info.format = tex_format;
16236 image_view_create_info.subresourceRange.layerCount = 1;
16237 image_view_create_info.subresourceRange.baseMipLevel = 0;
16238 image_view_create_info.subresourceRange.levelCount = 1;
16239 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16240
16241 VkImageView view;
16242 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16243 ASSERT_VK_SUCCESS(err);
16244
16245 VkDescriptorPoolSize ds_type_count = {};
16246 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16247 ds_type_count.descriptorCount = 1;
16248
16249 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16250 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16251 ds_pool_ci.pNext = NULL;
16252 ds_pool_ci.maxSets = 1;
16253 ds_pool_ci.poolSizeCount = 1;
16254 ds_pool_ci.pPoolSizes = &ds_type_count;
16255
16256 VkDescriptorPool ds_pool;
16257 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16258 ASSERT_VK_SUCCESS(err);
16259
16260 VkDescriptorSetLayoutBinding dsl_binding = {};
16261 dsl_binding.binding = 0;
16262 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16263 dsl_binding.descriptorCount = 1;
16264 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16265 dsl_binding.pImmutableSamplers = NULL;
16266
16267 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16268 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16269 ds_layout_ci.pNext = NULL;
16270 ds_layout_ci.bindingCount = 1;
16271 ds_layout_ci.pBindings = &dsl_binding;
16272 VkDescriptorSetLayout ds_layout;
16273 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16274 ASSERT_VK_SUCCESS(err);
16275
16276 VkDescriptorSet descriptor_set;
16277 VkDescriptorSetAllocateInfo alloc_info = {};
16278 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16279 alloc_info.descriptorSetCount = 1;
16280 alloc_info.descriptorPool = ds_pool;
16281 alloc_info.pSetLayouts = &ds_layout;
16282 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16283 ASSERT_VK_SUCCESS(err);
16284
16285 VkDescriptorImageInfo image_info = {};
16286 image_info.imageView = view;
16287 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16288
16289 VkWriteDescriptorSet descriptor_write;
16290 memset(&descriptor_write, 0, sizeof(descriptor_write));
16291 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16292 descriptor_write.dstSet = descriptor_set;
16293 descriptor_write.dstBinding = 0;
16294 descriptor_write.descriptorCount = 1;
16295 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16296 descriptor_write.pImageInfo = &image_info;
16297
16298 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16299 // be
16300 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16301 // This will most likely produce a crash if the parameter_validation
16302 // layer
16303 // does not correctly ignore pBufferInfo.
16304 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16305 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16306
16307 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16308
16309 m_errorMonitor->VerifyNotFound();
16310
16311 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16312 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16313 vkDestroyImageView(m_device->device(), view, NULL);
16314 vkDestroyImage(m_device->device(), image, NULL);
16315 vkFreeMemory(m_device->device(), image_memory, NULL);
16316 }
16317
16318 // Buffer Case
16319 {
16320 m_errorMonitor->ExpectSuccess();
16321
16322 VkBuffer buffer;
16323 uint32_t queue_family_index = 0;
16324 VkBufferCreateInfo buffer_create_info = {};
16325 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16326 buffer_create_info.size = 1024;
16327 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16328 buffer_create_info.queueFamilyIndexCount = 1;
16329 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16330
16331 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16332 ASSERT_VK_SUCCESS(err);
16333
16334 VkMemoryRequirements memory_reqs;
16335 VkDeviceMemory buffer_memory;
16336 bool pass;
16337 VkMemoryAllocateInfo memory_info = {};
16338 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16339 memory_info.pNext = NULL;
16340 memory_info.allocationSize = 0;
16341 memory_info.memoryTypeIndex = 0;
16342
16343 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16344 memory_info.allocationSize = memory_reqs.size;
16345 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16346 ASSERT_TRUE(pass);
16347
16348 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16349 ASSERT_VK_SUCCESS(err);
16350 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16351 ASSERT_VK_SUCCESS(err);
16352
16353 VkDescriptorPoolSize ds_type_count = {};
16354 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16355 ds_type_count.descriptorCount = 1;
16356
16357 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16358 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16359 ds_pool_ci.pNext = NULL;
16360 ds_pool_ci.maxSets = 1;
16361 ds_pool_ci.poolSizeCount = 1;
16362 ds_pool_ci.pPoolSizes = &ds_type_count;
16363
16364 VkDescriptorPool ds_pool;
16365 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16366 ASSERT_VK_SUCCESS(err);
16367
16368 VkDescriptorSetLayoutBinding dsl_binding = {};
16369 dsl_binding.binding = 0;
16370 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16371 dsl_binding.descriptorCount = 1;
16372 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16373 dsl_binding.pImmutableSamplers = NULL;
16374
16375 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16376 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16377 ds_layout_ci.pNext = NULL;
16378 ds_layout_ci.bindingCount = 1;
16379 ds_layout_ci.pBindings = &dsl_binding;
16380 VkDescriptorSetLayout ds_layout;
16381 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16382 ASSERT_VK_SUCCESS(err);
16383
16384 VkDescriptorSet descriptor_set;
16385 VkDescriptorSetAllocateInfo alloc_info = {};
16386 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16387 alloc_info.descriptorSetCount = 1;
16388 alloc_info.descriptorPool = ds_pool;
16389 alloc_info.pSetLayouts = &ds_layout;
16390 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16391 ASSERT_VK_SUCCESS(err);
16392
16393 VkDescriptorBufferInfo buffer_info = {};
16394 buffer_info.buffer = buffer;
16395 buffer_info.offset = 0;
16396 buffer_info.range = 1024;
16397
16398 VkWriteDescriptorSet descriptor_write;
16399 memset(&descriptor_write, 0, sizeof(descriptor_write));
16400 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16401 descriptor_write.dstSet = descriptor_set;
16402 descriptor_write.dstBinding = 0;
16403 descriptor_write.descriptorCount = 1;
16404 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16405 descriptor_write.pBufferInfo = &buffer_info;
16406
16407 // Set pImageInfo and pTexelBufferView to invalid values, which should
16408 // be
16409 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16410 // This will most likely produce a crash if the parameter_validation
16411 // layer
16412 // does not correctly ignore pImageInfo.
16413 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16414 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16415
16416 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16417
16418 m_errorMonitor->VerifyNotFound();
16419
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016420 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16421 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16422 vkDestroyBuffer(m_device->device(), buffer, NULL);
16423 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16424 }
16425
16426 // Texel Buffer Case
16427 {
16428 m_errorMonitor->ExpectSuccess();
16429
16430 VkBuffer buffer;
16431 uint32_t queue_family_index = 0;
16432 VkBufferCreateInfo buffer_create_info = {};
16433 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16434 buffer_create_info.size = 1024;
16435 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16436 buffer_create_info.queueFamilyIndexCount = 1;
16437 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16438
16439 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16440 ASSERT_VK_SUCCESS(err);
16441
16442 VkMemoryRequirements memory_reqs;
16443 VkDeviceMemory buffer_memory;
16444 bool pass;
16445 VkMemoryAllocateInfo memory_info = {};
16446 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16447 memory_info.pNext = NULL;
16448 memory_info.allocationSize = 0;
16449 memory_info.memoryTypeIndex = 0;
16450
16451 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16452 memory_info.allocationSize = memory_reqs.size;
16453 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16454 ASSERT_TRUE(pass);
16455
16456 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16457 ASSERT_VK_SUCCESS(err);
16458 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16459 ASSERT_VK_SUCCESS(err);
16460
16461 VkBufferViewCreateInfo buff_view_ci = {};
16462 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16463 buff_view_ci.buffer = buffer;
16464 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16465 buff_view_ci.range = VK_WHOLE_SIZE;
16466 VkBufferView buffer_view;
16467 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16468
16469 VkDescriptorPoolSize ds_type_count = {};
16470 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16471 ds_type_count.descriptorCount = 1;
16472
16473 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16474 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16475 ds_pool_ci.pNext = NULL;
16476 ds_pool_ci.maxSets = 1;
16477 ds_pool_ci.poolSizeCount = 1;
16478 ds_pool_ci.pPoolSizes = &ds_type_count;
16479
16480 VkDescriptorPool ds_pool;
16481 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16482 ASSERT_VK_SUCCESS(err);
16483
16484 VkDescriptorSetLayoutBinding dsl_binding = {};
16485 dsl_binding.binding = 0;
16486 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16487 dsl_binding.descriptorCount = 1;
16488 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16489 dsl_binding.pImmutableSamplers = NULL;
16490
16491 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16492 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16493 ds_layout_ci.pNext = NULL;
16494 ds_layout_ci.bindingCount = 1;
16495 ds_layout_ci.pBindings = &dsl_binding;
16496 VkDescriptorSetLayout ds_layout;
16497 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16498 ASSERT_VK_SUCCESS(err);
16499
16500 VkDescriptorSet descriptor_set;
16501 VkDescriptorSetAllocateInfo alloc_info = {};
16502 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16503 alloc_info.descriptorSetCount = 1;
16504 alloc_info.descriptorPool = ds_pool;
16505 alloc_info.pSetLayouts = &ds_layout;
16506 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16507 ASSERT_VK_SUCCESS(err);
16508
16509 VkWriteDescriptorSet descriptor_write;
16510 memset(&descriptor_write, 0, sizeof(descriptor_write));
16511 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16512 descriptor_write.dstSet = descriptor_set;
16513 descriptor_write.dstBinding = 0;
16514 descriptor_write.descriptorCount = 1;
16515 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16516 descriptor_write.pTexelBufferView = &buffer_view;
16517
16518 // Set pImageInfo and pBufferInfo to invalid values, which should be
16519 // ignored for descriptorType ==
16520 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16521 // This will most likely produce a crash if the parameter_validation
16522 // layer
16523 // does not correctly ignore pImageInfo and pBufferInfo.
16524 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16525 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16526
16527 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16528
16529 m_errorMonitor->VerifyNotFound();
16530
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016531 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16532 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16533 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16534 vkDestroyBuffer(m_device->device(), buffer, NULL);
16535 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16536 }
16537}
16538
Tobin Ehlisf7428442016-10-25 07:58:24 -060016539TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16540 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16541
16542 ASSERT_NO_FATAL_FAILURE(InitState());
16543 // Create layout where two binding #s are "1"
16544 static const uint32_t NUM_BINDINGS = 3;
16545 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16546 dsl_binding[0].binding = 1;
16547 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16548 dsl_binding[0].descriptorCount = 1;
16549 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16550 dsl_binding[0].pImmutableSamplers = NULL;
16551 dsl_binding[1].binding = 0;
16552 dsl_binding[1].descriptorCount = 1;
16553 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16554 dsl_binding[1].descriptorCount = 1;
16555 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16556 dsl_binding[1].pImmutableSamplers = NULL;
16557 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16558 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16559 dsl_binding[2].descriptorCount = 1;
16560 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16561 dsl_binding[2].pImmutableSamplers = NULL;
16562
16563 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16564 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16565 ds_layout_ci.pNext = NULL;
16566 ds_layout_ci.bindingCount = NUM_BINDINGS;
16567 ds_layout_ci.pBindings = dsl_binding;
16568 VkDescriptorSetLayout ds_layout;
16569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16570 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16571 m_errorMonitor->VerifyFound();
16572}
16573
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016574TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016575 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16576
16577 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016578
16579 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016580
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016581 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16582
16583 {
16584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16585 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16586 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16587 m_errorMonitor->VerifyFound();
16588 }
16589
16590 {
16591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16592 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16593 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16594 m_errorMonitor->VerifyFound();
16595 }
16596
16597 {
16598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16599 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16600 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16601 m_errorMonitor->VerifyFound();
16602 }
16603
16604 {
16605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16606 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16607 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16608 m_errorMonitor->VerifyFound();
16609 }
16610
16611 {
16612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16613 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16614 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16615 m_errorMonitor->VerifyFound();
16616 }
16617
16618 {
16619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16620 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16621 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16622 m_errorMonitor->VerifyFound();
16623 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016624
16625 {
16626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16627 VkRect2D scissor = {{-1, 0}, {16, 16}};
16628 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16629 m_errorMonitor->VerifyFound();
16630 }
16631
16632 {
16633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16634 VkRect2D scissor = {{0, -2}, {16, 16}};
16635 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16636 m_errorMonitor->VerifyFound();
16637 }
16638
16639 {
16640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16641 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16642 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16643 m_errorMonitor->VerifyFound();
16644 }
16645
16646 {
16647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16648 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16649 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16650 m_errorMonitor->VerifyFound();
16651 }
16652
16653 EndCommandBuffer();
16654}
16655
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016656// This is a positive test. No failures are expected.
16657TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16658 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16659 VkResult err;
16660
16661 ASSERT_NO_FATAL_FAILURE(InitState());
16662 m_errorMonitor->ExpectSuccess();
16663 VkDescriptorPoolSize ds_type_count = {};
16664 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16665 ds_type_count.descriptorCount = 2;
16666
16667 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16668 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16669 ds_pool_ci.pNext = NULL;
16670 ds_pool_ci.maxSets = 1;
16671 ds_pool_ci.poolSizeCount = 1;
16672 ds_pool_ci.pPoolSizes = &ds_type_count;
16673
16674 VkDescriptorPool ds_pool;
16675 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16676 ASSERT_VK_SUCCESS(err);
16677
16678 // Create layout with two uniform buffer descriptors w/ empty binding between them
16679 static const uint32_t NUM_BINDINGS = 3;
16680 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16681 dsl_binding[0].binding = 0;
16682 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16683 dsl_binding[0].descriptorCount = 1;
16684 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16685 dsl_binding[0].pImmutableSamplers = NULL;
16686 dsl_binding[1].binding = 1;
16687 dsl_binding[1].descriptorCount = 0; // empty binding
16688 dsl_binding[2].binding = 2;
16689 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16690 dsl_binding[2].descriptorCount = 1;
16691 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16692 dsl_binding[2].pImmutableSamplers = NULL;
16693
16694 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16695 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16696 ds_layout_ci.pNext = NULL;
16697 ds_layout_ci.bindingCount = NUM_BINDINGS;
16698 ds_layout_ci.pBindings = dsl_binding;
16699 VkDescriptorSetLayout ds_layout;
16700 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16701 ASSERT_VK_SUCCESS(err);
16702
16703 VkDescriptorSet descriptor_set = {};
16704 VkDescriptorSetAllocateInfo alloc_info = {};
16705 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16706 alloc_info.descriptorSetCount = 1;
16707 alloc_info.descriptorPool = ds_pool;
16708 alloc_info.pSetLayouts = &ds_layout;
16709 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16710 ASSERT_VK_SUCCESS(err);
16711
16712 // Create a buffer to be used for update
16713 VkBufferCreateInfo buff_ci = {};
16714 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16715 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16716 buff_ci.size = 256;
16717 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16718 VkBuffer buffer;
16719 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16720 ASSERT_VK_SUCCESS(err);
16721 // Have to bind memory to buffer before descriptor update
16722 VkMemoryAllocateInfo mem_alloc = {};
16723 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16724 mem_alloc.pNext = NULL;
16725 mem_alloc.allocationSize = 512; // one allocation for both buffers
16726 mem_alloc.memoryTypeIndex = 0;
16727
16728 VkMemoryRequirements mem_reqs;
16729 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16730 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16731 if (!pass) {
16732 vkDestroyBuffer(m_device->device(), buffer, NULL);
16733 return;
16734 }
16735
16736 VkDeviceMemory mem;
16737 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16738 ASSERT_VK_SUCCESS(err);
16739 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16740 ASSERT_VK_SUCCESS(err);
16741
16742 // Only update the descriptor at binding 2
16743 VkDescriptorBufferInfo buff_info = {};
16744 buff_info.buffer = buffer;
16745 buff_info.offset = 0;
16746 buff_info.range = VK_WHOLE_SIZE;
16747 VkWriteDescriptorSet descriptor_write = {};
16748 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16749 descriptor_write.dstBinding = 2;
16750 descriptor_write.descriptorCount = 1;
16751 descriptor_write.pTexelBufferView = nullptr;
16752 descriptor_write.pBufferInfo = &buff_info;
16753 descriptor_write.pImageInfo = nullptr;
16754 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16755 descriptor_write.dstSet = descriptor_set;
16756
16757 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16758
16759 m_errorMonitor->VerifyNotFound();
16760 // Cleanup
16761 vkFreeMemory(m_device->device(), mem, NULL);
16762 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16763 vkDestroyBuffer(m_device->device(), buffer, NULL);
16764 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16765}
16766
16767// This is a positive test. No failures are expected.
16768TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16769 VkResult err;
16770 bool pass;
16771
16772 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16773 "the buffer, create an image, and bind the same memory to "
16774 "it");
16775
16776 m_errorMonitor->ExpectSuccess();
16777
16778 ASSERT_NO_FATAL_FAILURE(InitState());
16779
16780 VkBuffer buffer;
16781 VkImage image;
16782 VkDeviceMemory mem;
16783 VkMemoryRequirements mem_reqs;
16784
16785 VkBufferCreateInfo buf_info = {};
16786 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16787 buf_info.pNext = NULL;
16788 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16789 buf_info.size = 256;
16790 buf_info.queueFamilyIndexCount = 0;
16791 buf_info.pQueueFamilyIndices = NULL;
16792 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16793 buf_info.flags = 0;
16794 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16795 ASSERT_VK_SUCCESS(err);
16796
16797 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16798
16799 VkMemoryAllocateInfo alloc_info = {};
16800 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16801 alloc_info.pNext = NULL;
16802 alloc_info.memoryTypeIndex = 0;
16803
16804 // Ensure memory is big enough for both bindings
16805 alloc_info.allocationSize = 0x10000;
16806
16807 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16808 if (!pass) {
16809 vkDestroyBuffer(m_device->device(), buffer, NULL);
16810 return;
16811 }
16812
16813 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16814 ASSERT_VK_SUCCESS(err);
16815
16816 uint8_t *pData;
16817 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16818 ASSERT_VK_SUCCESS(err);
16819
16820 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16821
16822 vkUnmapMemory(m_device->device(), mem);
16823
16824 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16825 ASSERT_VK_SUCCESS(err);
16826
16827 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16828 // memory. In fact, it was never used by the GPU.
16829 // Just be be sure, wait for idle.
16830 vkDestroyBuffer(m_device->device(), buffer, NULL);
16831 vkDeviceWaitIdle(m_device->device());
16832
16833 VkImageCreateInfo image_create_info = {};
16834 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16835 image_create_info.pNext = NULL;
16836 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16837 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16838 image_create_info.extent.width = 64;
16839 image_create_info.extent.height = 64;
16840 image_create_info.extent.depth = 1;
16841 image_create_info.mipLevels = 1;
16842 image_create_info.arrayLayers = 1;
16843 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16844 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16845 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16846 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16847 image_create_info.queueFamilyIndexCount = 0;
16848 image_create_info.pQueueFamilyIndices = NULL;
16849 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16850 image_create_info.flags = 0;
16851
16852 VkMemoryAllocateInfo mem_alloc = {};
16853 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16854 mem_alloc.pNext = NULL;
16855 mem_alloc.allocationSize = 0;
16856 mem_alloc.memoryTypeIndex = 0;
16857
16858 /* Create a mappable image. It will be the texture if linear images are ok
16859 * to be textures or it will be the staging image if they are not.
16860 */
16861 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16862 ASSERT_VK_SUCCESS(err);
16863
16864 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16865
16866 mem_alloc.allocationSize = mem_reqs.size;
16867
16868 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16869 if (!pass) {
16870 vkDestroyImage(m_device->device(), image, NULL);
16871 return;
16872 }
16873
16874 // VALIDATION FAILURE:
16875 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16876 ASSERT_VK_SUCCESS(err);
16877
16878 m_errorMonitor->VerifyNotFound();
16879
16880 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016881 vkDestroyImage(m_device->device(), image, NULL);
16882}
16883
Tobin Ehlis953e8392016-11-17 10:54:13 -070016884TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16885 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16886 // We previously had a bug where dynamic offset of inactive bindings was still being used
16887 VkResult err;
16888 m_errorMonitor->ExpectSuccess();
16889
16890 ASSERT_NO_FATAL_FAILURE(InitState());
16891 ASSERT_NO_FATAL_FAILURE(InitViewport());
16892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16893
16894 VkDescriptorPoolSize ds_type_count = {};
16895 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16896 ds_type_count.descriptorCount = 3;
16897
16898 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16899 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16900 ds_pool_ci.pNext = NULL;
16901 ds_pool_ci.maxSets = 1;
16902 ds_pool_ci.poolSizeCount = 1;
16903 ds_pool_ci.pPoolSizes = &ds_type_count;
16904
16905 VkDescriptorPool ds_pool;
16906 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16907 ASSERT_VK_SUCCESS(err);
16908
16909 const uint32_t BINDING_COUNT = 3;
16910 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016911 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016912 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16913 dsl_binding[0].descriptorCount = 1;
16914 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16915 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016916 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016917 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16918 dsl_binding[1].descriptorCount = 1;
16919 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16920 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016921 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016922 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16923 dsl_binding[2].descriptorCount = 1;
16924 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16925 dsl_binding[2].pImmutableSamplers = NULL;
16926
16927 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16928 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16929 ds_layout_ci.pNext = NULL;
16930 ds_layout_ci.bindingCount = BINDING_COUNT;
16931 ds_layout_ci.pBindings = dsl_binding;
16932 VkDescriptorSetLayout ds_layout;
16933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16934 ASSERT_VK_SUCCESS(err);
16935
16936 VkDescriptorSet descriptor_set;
16937 VkDescriptorSetAllocateInfo alloc_info = {};
16938 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16939 alloc_info.descriptorSetCount = 1;
16940 alloc_info.descriptorPool = ds_pool;
16941 alloc_info.pSetLayouts = &ds_layout;
16942 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16943 ASSERT_VK_SUCCESS(err);
16944
16945 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16946 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16947 pipeline_layout_ci.pNext = NULL;
16948 pipeline_layout_ci.setLayoutCount = 1;
16949 pipeline_layout_ci.pSetLayouts = &ds_layout;
16950
16951 VkPipelineLayout pipeline_layout;
16952 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16953 ASSERT_VK_SUCCESS(err);
16954
16955 // Create two buffers to update the descriptors with
16956 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16957 uint32_t qfi = 0;
16958 VkBufferCreateInfo buffCI = {};
16959 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16960 buffCI.size = 2048;
16961 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16962 buffCI.queueFamilyIndexCount = 1;
16963 buffCI.pQueueFamilyIndices = &qfi;
16964
16965 VkBuffer dyub1;
16966 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16967 ASSERT_VK_SUCCESS(err);
16968 // buffer2
16969 buffCI.size = 1024;
16970 VkBuffer dyub2;
16971 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16972 ASSERT_VK_SUCCESS(err);
16973 // Allocate memory and bind to buffers
16974 VkMemoryAllocateInfo mem_alloc[2] = {};
16975 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16976 mem_alloc[0].pNext = NULL;
16977 mem_alloc[0].memoryTypeIndex = 0;
16978 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16979 mem_alloc[1].pNext = NULL;
16980 mem_alloc[1].memoryTypeIndex = 0;
16981
16982 VkMemoryRequirements mem_reqs1;
16983 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16984 VkMemoryRequirements mem_reqs2;
16985 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16986 mem_alloc[0].allocationSize = mem_reqs1.size;
16987 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16988 mem_alloc[1].allocationSize = mem_reqs2.size;
16989 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16990 if (!pass) {
16991 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16992 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16993 return;
16994 }
16995
16996 VkDeviceMemory mem1;
16997 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16998 ASSERT_VK_SUCCESS(err);
16999 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17000 ASSERT_VK_SUCCESS(err);
17001 VkDeviceMemory mem2;
17002 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17003 ASSERT_VK_SUCCESS(err);
17004 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17005 ASSERT_VK_SUCCESS(err);
17006 // Update descriptors
17007 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17008 buff_info[0].buffer = dyub1;
17009 buff_info[0].offset = 0;
17010 buff_info[0].range = 256;
17011 buff_info[1].buffer = dyub1;
17012 buff_info[1].offset = 256;
17013 buff_info[1].range = 512;
17014 buff_info[2].buffer = dyub2;
17015 buff_info[2].offset = 0;
17016 buff_info[2].range = 512;
17017
17018 VkWriteDescriptorSet descriptor_write;
17019 memset(&descriptor_write, 0, sizeof(descriptor_write));
17020 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17021 descriptor_write.dstSet = descriptor_set;
17022 descriptor_write.dstBinding = 0;
17023 descriptor_write.descriptorCount = BINDING_COUNT;
17024 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17025 descriptor_write.pBufferInfo = buff_info;
17026
17027 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17028
17029 BeginCommandBuffer();
17030
17031 // Create PSO to be used for draw-time errors below
17032 char const *vsSource = "#version 450\n"
17033 "\n"
17034 "out gl_PerVertex { \n"
17035 " vec4 gl_Position;\n"
17036 "};\n"
17037 "void main(){\n"
17038 " gl_Position = vec4(1);\n"
17039 "}\n";
17040 char const *fsSource = "#version 450\n"
17041 "\n"
17042 "layout(location=0) out vec4 x;\n"
17043 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17044 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17045 "void main(){\n"
17046 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17047 "}\n";
17048 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17049 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17050 VkPipelineObj pipe(m_device);
17051 pipe.SetViewport(m_viewports);
17052 pipe.SetScissor(m_scissors);
17053 pipe.AddShader(&vs);
17054 pipe.AddShader(&fs);
17055 pipe.AddColorAttachment();
17056 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17057
17058 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17059 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17060 // we used to have a bug in this case.
17061 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17062 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17063 &descriptor_set, BINDING_COUNT, dyn_off);
17064 Draw(1, 0, 0, 0);
17065 m_errorMonitor->VerifyNotFound();
17066
17067 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17068 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17069 vkFreeMemory(m_device->device(), mem1, NULL);
17070 vkFreeMemory(m_device->device(), mem2, NULL);
17071
17072 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17073 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17074 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17075}
17076
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017077TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
17078
17079 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
17080 "mapping while using VK_WHOLE_SIZE does not cause access "
17081 "violations");
17082 VkResult err;
17083 uint8_t *pData;
17084 ASSERT_NO_FATAL_FAILURE(InitState());
17085
17086 VkDeviceMemory mem;
17087 VkMemoryRequirements mem_reqs;
17088 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017089 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017090 VkMemoryAllocateInfo alloc_info = {};
17091 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17092 alloc_info.pNext = NULL;
17093 alloc_info.memoryTypeIndex = 0;
17094
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017095 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017096 alloc_info.allocationSize = allocation_size;
17097
17098 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17099 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
17100 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17101 if (!pass) {
17102 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17103 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17104 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17105 if (!pass) {
17106 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17107 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17108 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17109 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17110 if (!pass) {
17111 return;
17112 }
17113 }
17114 }
17115
17116 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17117 ASSERT_VK_SUCCESS(err);
17118
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017119 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017120 m_errorMonitor->ExpectSuccess();
17121 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17122 ASSERT_VK_SUCCESS(err);
17123 VkMappedMemoryRange mmr = {};
17124 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17125 mmr.memory = mem;
17126 mmr.offset = 0;
17127 mmr.size = VK_WHOLE_SIZE;
17128 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17129 ASSERT_VK_SUCCESS(err);
17130 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17131 ASSERT_VK_SUCCESS(err);
17132 m_errorMonitor->VerifyNotFound();
17133 vkUnmapMemory(m_device->device(), mem);
17134
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017135 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017136 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017137 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017138 ASSERT_VK_SUCCESS(err);
17139 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17140 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017141 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017142 mmr.size = VK_WHOLE_SIZE;
17143 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17144 ASSERT_VK_SUCCESS(err);
17145 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17146 ASSERT_VK_SUCCESS(err);
17147 m_errorMonitor->VerifyNotFound();
17148 vkUnmapMemory(m_device->device(), mem);
17149
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017150 // Map with offset and size
17151 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017152 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017153 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017154 ASSERT_VK_SUCCESS(err);
17155 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17156 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017157 mmr.offset = 4 * atom_size;
17158 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017159 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17160 ASSERT_VK_SUCCESS(err);
17161 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17162 ASSERT_VK_SUCCESS(err);
17163 m_errorMonitor->VerifyNotFound();
17164 vkUnmapMemory(m_device->device(), mem);
17165
17166 // Map without offset and flush WHOLE_SIZE with two separate offsets
17167 m_errorMonitor->ExpectSuccess();
17168 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17169 ASSERT_VK_SUCCESS(err);
17170 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17171 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017172 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017173 mmr.size = VK_WHOLE_SIZE;
17174 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17175 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017176 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017177 mmr.size = VK_WHOLE_SIZE;
17178 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17179 ASSERT_VK_SUCCESS(err);
17180 m_errorMonitor->VerifyNotFound();
17181 vkUnmapMemory(m_device->device(), mem);
17182
17183 vkFreeMemory(m_device->device(), mem, NULL);
17184}
17185
17186// This is a positive test. We used to expect error in this case but spec now allows it
17187TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17188 m_errorMonitor->ExpectSuccess();
17189 vk_testing::Fence testFence;
17190 VkFenceCreateInfo fenceInfo = {};
17191 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17192 fenceInfo.pNext = NULL;
17193
17194 ASSERT_NO_FATAL_FAILURE(InitState());
17195 testFence.init(*m_device, fenceInfo);
17196 VkFence fences[1] = { testFence.handle() };
17197 VkResult result = vkResetFences(m_device->device(), 1, fences);
17198 ASSERT_VK_SUCCESS(result);
17199
17200 m_errorMonitor->VerifyNotFound();
17201}
17202
17203TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17204 m_errorMonitor->ExpectSuccess();
17205
17206 ASSERT_NO_FATAL_FAILURE(InitState());
17207 VkResult err;
17208
17209 // Record (empty!) command buffer that can be submitted multiple times
17210 // simultaneously.
17211 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17212 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17213 m_commandBuffer->BeginCommandBuffer(&cbbi);
17214 m_commandBuffer->EndCommandBuffer();
17215
17216 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17217 VkFence fence;
17218 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17219 ASSERT_VK_SUCCESS(err);
17220
17221 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17222 VkSemaphore s1, s2;
17223 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17224 ASSERT_VK_SUCCESS(err);
17225 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17226 ASSERT_VK_SUCCESS(err);
17227
17228 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17229 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17230 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17231 ASSERT_VK_SUCCESS(err);
17232
17233 // Submit CB again, signaling s2.
17234 si.pSignalSemaphores = &s2;
17235 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17236 ASSERT_VK_SUCCESS(err);
17237
17238 // Wait for fence.
17239 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17240 ASSERT_VK_SUCCESS(err);
17241
17242 // CB is still in flight from second submission, but semaphore s1 is no
17243 // longer in flight. delete it.
17244 vkDestroySemaphore(m_device->device(), s1, nullptr);
17245
17246 m_errorMonitor->VerifyNotFound();
17247
17248 // Force device idle and clean up remaining objects
17249 vkDeviceWaitIdle(m_device->device());
17250 vkDestroySemaphore(m_device->device(), s2, nullptr);
17251 vkDestroyFence(m_device->device(), fence, nullptr);
17252}
17253
17254TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17255 m_errorMonitor->ExpectSuccess();
17256
17257 ASSERT_NO_FATAL_FAILURE(InitState());
17258 VkResult err;
17259
17260 // A fence created signaled
17261 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17262 VkFence f1;
17263 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17264 ASSERT_VK_SUCCESS(err);
17265
17266 // A fence created not
17267 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17268 VkFence f2;
17269 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17270 ASSERT_VK_SUCCESS(err);
17271
17272 // Submit the unsignaled fence
17273 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17274 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17275
17276 // Wait on both fences, with signaled first.
17277 VkFence fences[] = { f1, f2 };
17278 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17279
17280 // Should have both retired!
17281 vkDestroyFence(m_device->device(), f1, nullptr);
17282 vkDestroyFence(m_device->device(), f2, nullptr);
17283
17284 m_errorMonitor->VerifyNotFound();
17285}
17286
17287TEST_F(VkPositiveLayerTest, ValidUsage) {
17288 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17289 "doesn't generate validation errors");
17290
17291 ASSERT_NO_FATAL_FAILURE(InitState());
17292
17293 m_errorMonitor->ExpectSuccess();
17294 // Verify that we can create a view with usage INPUT_ATTACHMENT
17295 VkImageObj image(m_device);
17296 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17297 ASSERT_TRUE(image.initialized());
17298 VkImageView imageView;
17299 VkImageViewCreateInfo ivci = {};
17300 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17301 ivci.image = image.handle();
17302 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17303 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17304 ivci.subresourceRange.layerCount = 1;
17305 ivci.subresourceRange.baseMipLevel = 0;
17306 ivci.subresourceRange.levelCount = 1;
17307 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17308
17309 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17310 m_errorMonitor->VerifyNotFound();
17311 vkDestroyImageView(m_device->device(), imageView, NULL);
17312}
17313
17314// This is a positive test. No failures are expected.
17315TEST_F(VkPositiveLayerTest, BindSparse) {
17316 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17317 "and then free the memory");
17318
17319 ASSERT_NO_FATAL_FAILURE(InitState());
17320
17321 auto index = m_device->graphics_queue_node_index_;
17322 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17323 return;
17324
17325 m_errorMonitor->ExpectSuccess();
17326
17327 VkImage image;
17328 VkImageCreateInfo image_create_info = {};
17329 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17330 image_create_info.pNext = NULL;
17331 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17332 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17333 image_create_info.extent.width = 64;
17334 image_create_info.extent.height = 64;
17335 image_create_info.extent.depth = 1;
17336 image_create_info.mipLevels = 1;
17337 image_create_info.arrayLayers = 1;
17338 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17339 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17340 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17341 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17342 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17343 ASSERT_VK_SUCCESS(err);
17344
17345 VkMemoryRequirements memory_reqs;
17346 VkDeviceMemory memory_one, memory_two;
17347 bool pass;
17348 VkMemoryAllocateInfo memory_info = {};
17349 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17350 memory_info.pNext = NULL;
17351 memory_info.allocationSize = 0;
17352 memory_info.memoryTypeIndex = 0;
17353 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17354 // Find an image big enough to allow sparse mapping of 2 memory regions
17355 // Increase the image size until it is at least twice the
17356 // size of the required alignment, to ensure we can bind both
17357 // allocated memory blocks to the image on aligned offsets.
17358 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17359 vkDestroyImage(m_device->device(), image, nullptr);
17360 image_create_info.extent.width *= 2;
17361 image_create_info.extent.height *= 2;
17362 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17363 ASSERT_VK_SUCCESS(err);
17364 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17365 }
17366 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17367 // at the end of the first
17368 memory_info.allocationSize = memory_reqs.alignment;
17369 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17370 ASSERT_TRUE(pass);
17371 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17372 ASSERT_VK_SUCCESS(err);
17373 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17374 ASSERT_VK_SUCCESS(err);
17375 VkSparseMemoryBind binds[2];
17376 binds[0].flags = 0;
17377 binds[0].memory = memory_one;
17378 binds[0].memoryOffset = 0;
17379 binds[0].resourceOffset = 0;
17380 binds[0].size = memory_info.allocationSize;
17381 binds[1].flags = 0;
17382 binds[1].memory = memory_two;
17383 binds[1].memoryOffset = 0;
17384 binds[1].resourceOffset = memory_info.allocationSize;
17385 binds[1].size = memory_info.allocationSize;
17386
17387 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17388 opaqueBindInfo.image = image;
17389 opaqueBindInfo.bindCount = 2;
17390 opaqueBindInfo.pBinds = binds;
17391
17392 VkFence fence = VK_NULL_HANDLE;
17393 VkBindSparseInfo bindSparseInfo = {};
17394 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17395 bindSparseInfo.imageOpaqueBindCount = 1;
17396 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17397
17398 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17399 vkQueueWaitIdle(m_device->m_queue);
17400 vkDestroyImage(m_device->device(), image, NULL);
17401 vkFreeMemory(m_device->device(), memory_one, NULL);
17402 vkFreeMemory(m_device->device(), memory_two, NULL);
17403 m_errorMonitor->VerifyNotFound();
17404}
17405
17406TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17407 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17408 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17409 "the command buffer has prior knowledge of that "
17410 "attachment's layout.");
17411
17412 m_errorMonitor->ExpectSuccess();
17413
17414 ASSERT_NO_FATAL_FAILURE(InitState());
17415
17416 // A renderpass with one color attachment.
17417 VkAttachmentDescription attachment = { 0,
17418 VK_FORMAT_R8G8B8A8_UNORM,
17419 VK_SAMPLE_COUNT_1_BIT,
17420 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17421 VK_ATTACHMENT_STORE_OP_STORE,
17422 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17423 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17424 VK_IMAGE_LAYOUT_UNDEFINED,
17425 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17426
17427 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17428
17429 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17430
17431 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17432
17433 VkRenderPass rp;
17434 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17435 ASSERT_VK_SUCCESS(err);
17436
17437 // A compatible framebuffer.
17438 VkImageObj image(m_device);
17439 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17440 ASSERT_TRUE(image.initialized());
17441
17442 VkImageViewCreateInfo ivci = {
17443 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17444 nullptr,
17445 0,
17446 image.handle(),
17447 VK_IMAGE_VIEW_TYPE_2D,
17448 VK_FORMAT_R8G8B8A8_UNORM,
17449 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17450 VK_COMPONENT_SWIZZLE_IDENTITY },
17451 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17452 };
17453 VkImageView view;
17454 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17455 ASSERT_VK_SUCCESS(err);
17456
17457 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17458 VkFramebuffer fb;
17459 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17460 ASSERT_VK_SUCCESS(err);
17461
17462 // Record a single command buffer which uses this renderpass twice. The
17463 // bug is triggered at the beginning of the second renderpass, when the
17464 // command buffer already has a layout recorded for the attachment.
17465 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17466 BeginCommandBuffer();
17467 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17468 vkCmdEndRenderPass(m_commandBuffer->handle());
17469 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17470
17471 m_errorMonitor->VerifyNotFound();
17472
17473 vkCmdEndRenderPass(m_commandBuffer->handle());
17474 EndCommandBuffer();
17475
17476 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17477 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17478 vkDestroyImageView(m_device->device(), view, nullptr);
17479}
17480
17481TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17482 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17483 "command buffer, bind them together, then destroy "
17484 "command pool and framebuffer and verify there are no "
17485 "errors.");
17486
17487 m_errorMonitor->ExpectSuccess();
17488
17489 ASSERT_NO_FATAL_FAILURE(InitState());
17490
17491 // A renderpass with one color attachment.
17492 VkAttachmentDescription attachment = { 0,
17493 VK_FORMAT_R8G8B8A8_UNORM,
17494 VK_SAMPLE_COUNT_1_BIT,
17495 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17496 VK_ATTACHMENT_STORE_OP_STORE,
17497 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17498 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17499 VK_IMAGE_LAYOUT_UNDEFINED,
17500 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17501
17502 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17503
17504 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17505
17506 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17507
17508 VkRenderPass rp;
17509 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17510 ASSERT_VK_SUCCESS(err);
17511
17512 // A compatible framebuffer.
17513 VkImageObj image(m_device);
17514 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17515 ASSERT_TRUE(image.initialized());
17516
17517 VkImageViewCreateInfo ivci = {
17518 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17519 nullptr,
17520 0,
17521 image.handle(),
17522 VK_IMAGE_VIEW_TYPE_2D,
17523 VK_FORMAT_R8G8B8A8_UNORM,
17524 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17525 VK_COMPONENT_SWIZZLE_IDENTITY },
17526 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17527 };
17528 VkImageView view;
17529 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17530 ASSERT_VK_SUCCESS(err);
17531
17532 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17533 VkFramebuffer fb;
17534 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17535 ASSERT_VK_SUCCESS(err);
17536
17537 // Explicitly create a command buffer to bind the FB to so that we can then
17538 // destroy the command pool in order to implicitly free command buffer
17539 VkCommandPool command_pool;
17540 VkCommandPoolCreateInfo pool_create_info{};
17541 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17542 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17543 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17544 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17545
17546 VkCommandBuffer command_buffer;
17547 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17548 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17549 command_buffer_allocate_info.commandPool = command_pool;
17550 command_buffer_allocate_info.commandBufferCount = 1;
17551 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17552 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17553
17554 // Begin our cmd buffer with renderpass using our framebuffer
17555 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17556 VkCommandBufferBeginInfo begin_info{};
17557 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17558 vkBeginCommandBuffer(command_buffer, &begin_info);
17559
17560 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17561 vkCmdEndRenderPass(command_buffer);
17562 vkEndCommandBuffer(command_buffer);
17563 vkDestroyImageView(m_device->device(), view, nullptr);
17564 // Destroy command pool to implicitly free command buffer
17565 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17566 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17567 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17568 m_errorMonitor->VerifyNotFound();
17569}
17570
17571TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17572 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17573 "transitions for the first subpass");
17574
17575 m_errorMonitor->ExpectSuccess();
17576
17577 ASSERT_NO_FATAL_FAILURE(InitState());
17578
17579 // A renderpass with one color attachment.
17580 VkAttachmentDescription attachment = { 0,
17581 VK_FORMAT_R8G8B8A8_UNORM,
17582 VK_SAMPLE_COUNT_1_BIT,
17583 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17584 VK_ATTACHMENT_STORE_OP_STORE,
17585 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17586 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17587 VK_IMAGE_LAYOUT_UNDEFINED,
17588 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17589
17590 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17591
17592 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17593
17594 VkSubpassDependency dep = { 0,
17595 0,
17596 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17597 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17598 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17599 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17600 VK_DEPENDENCY_BY_REGION_BIT };
17601
17602 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17603
17604 VkResult err;
17605 VkRenderPass rp;
17606 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17607 ASSERT_VK_SUCCESS(err);
17608
17609 // A compatible framebuffer.
17610 VkImageObj image(m_device);
17611 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17612 ASSERT_TRUE(image.initialized());
17613
17614 VkImageViewCreateInfo ivci = {
17615 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17616 nullptr,
17617 0,
17618 image.handle(),
17619 VK_IMAGE_VIEW_TYPE_2D,
17620 VK_FORMAT_R8G8B8A8_UNORM,
17621 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17622 VK_COMPONENT_SWIZZLE_IDENTITY },
17623 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17624 };
17625 VkImageView view;
17626 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17627 ASSERT_VK_SUCCESS(err);
17628
17629 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17630 VkFramebuffer fb;
17631 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17632 ASSERT_VK_SUCCESS(err);
17633
17634 // Record a single command buffer which issues a pipeline barrier w/
17635 // image memory barrier for the attachment. This detects the previously
17636 // missing tracking of the subpass layout by throwing a validation error
17637 // if it doesn't occur.
17638 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17639 BeginCommandBuffer();
17640 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17641
17642 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17643 nullptr,
17644 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17645 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17646 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17647 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17648 VK_QUEUE_FAMILY_IGNORED,
17649 VK_QUEUE_FAMILY_IGNORED,
17650 image.handle(),
17651 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17652 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17653 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17654 &imb);
17655
17656 vkCmdEndRenderPass(m_commandBuffer->handle());
17657 m_errorMonitor->VerifyNotFound();
17658 EndCommandBuffer();
17659
17660 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17661 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17662 vkDestroyImageView(m_device->device(), view, nullptr);
17663}
17664
17665TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17666 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17667 "is used as a depth/stencil framebuffer attachment, the "
17668 "aspectMask is ignored and both depth and stencil image "
17669 "subresources are used.");
17670
17671 VkFormatProperties format_properties;
17672 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17673 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17674 return;
17675 }
17676
17677 m_errorMonitor->ExpectSuccess();
17678
17679 ASSERT_NO_FATAL_FAILURE(InitState());
17680
17681 VkAttachmentDescription attachment = { 0,
17682 VK_FORMAT_D32_SFLOAT_S8_UINT,
17683 VK_SAMPLE_COUNT_1_BIT,
17684 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17685 VK_ATTACHMENT_STORE_OP_STORE,
17686 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17687 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17688 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17689 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17690
17691 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17692
17693 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17694
17695 VkSubpassDependency dep = { 0,
17696 0,
17697 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17698 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17699 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17700 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17701 VK_DEPENDENCY_BY_REGION_BIT};
17702
17703 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17704
17705 VkResult err;
17706 VkRenderPass rp;
17707 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17708 ASSERT_VK_SUCCESS(err);
17709
17710 VkImageObj image(m_device);
17711 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17712 0x26, // usage
17713 VK_IMAGE_TILING_OPTIMAL, 0);
17714 ASSERT_TRUE(image.initialized());
17715 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17716
17717 VkImageViewCreateInfo ivci = {
17718 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17719 nullptr,
17720 0,
17721 image.handle(),
17722 VK_IMAGE_VIEW_TYPE_2D,
17723 VK_FORMAT_D32_SFLOAT_S8_UINT,
17724 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17725 { 0x2, 0, 1, 0, 1 },
17726 };
17727 VkImageView view;
17728 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17729 ASSERT_VK_SUCCESS(err);
17730
17731 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17732 VkFramebuffer fb;
17733 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17734 ASSERT_VK_SUCCESS(err);
17735
17736 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17737 BeginCommandBuffer();
17738 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17739
17740 VkImageMemoryBarrier imb = {};
17741 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17742 imb.pNext = nullptr;
17743 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17744 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17745 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17746 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17747 imb.srcQueueFamilyIndex = 0;
17748 imb.dstQueueFamilyIndex = 0;
17749 imb.image = image.handle();
17750 imb.subresourceRange.aspectMask = 0x6;
17751 imb.subresourceRange.baseMipLevel = 0;
17752 imb.subresourceRange.levelCount = 0x1;
17753 imb.subresourceRange.baseArrayLayer = 0;
17754 imb.subresourceRange.layerCount = 0x1;
17755
17756 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17757 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17758 &imb);
17759
17760 vkCmdEndRenderPass(m_commandBuffer->handle());
17761 EndCommandBuffer();
17762 QueueCommandBuffer(false);
17763 m_errorMonitor->VerifyNotFound();
17764
17765 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17766 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17767 vkDestroyImageView(m_device->device(), view, nullptr);
17768}
17769
17770TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17771 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17772 "errors, when an attachment reference is "
17773 "VK_ATTACHMENT_UNUSED");
17774
17775 m_errorMonitor->ExpectSuccess();
17776
17777 ASSERT_NO_FATAL_FAILURE(InitState());
17778
17779 // A renderpass with no attachments
17780 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17781
17782 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17783
17784 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17785
17786 VkRenderPass rp;
17787 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17788 ASSERT_VK_SUCCESS(err);
17789
17790 // A compatible framebuffer.
17791 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17792 VkFramebuffer fb;
17793 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17794 ASSERT_VK_SUCCESS(err);
17795
17796 // Record a command buffer which just begins and ends the renderpass. The
17797 // bug manifests in BeginRenderPass.
17798 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17799 BeginCommandBuffer();
17800 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17801 vkCmdEndRenderPass(m_commandBuffer->handle());
17802 m_errorMonitor->VerifyNotFound();
17803 EndCommandBuffer();
17804
17805 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17806 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17807}
17808
17809// This is a positive test. No errors are expected.
17810TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17811 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17812 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17813 VkResult result = VK_SUCCESS;
17814 VkImageFormatProperties formatProps;
17815 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17816 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17817 &formatProps);
17818 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17819 return;
17820 }
17821
17822 ASSERT_NO_FATAL_FAILURE(InitState());
17823 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17824 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17825 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17826 VkAttachmentDescription att = {};
17827 VkAttachmentReference ref = {};
17828 att.format = depth_stencil_fmt;
17829 att.samples = VK_SAMPLE_COUNT_1_BIT;
17830 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17831 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17832 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17833 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17834 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17835 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17836
17837 VkClearValue clear;
17838 clear.depthStencil.depth = 1.0;
17839 clear.depthStencil.stencil = 0;
17840 ref.attachment = 0;
17841 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17842
17843 VkSubpassDescription subpass = {};
17844 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17845 subpass.flags = 0;
17846 subpass.inputAttachmentCount = 0;
17847 subpass.pInputAttachments = NULL;
17848 subpass.colorAttachmentCount = 0;
17849 subpass.pColorAttachments = NULL;
17850 subpass.pResolveAttachments = NULL;
17851 subpass.pDepthStencilAttachment = &ref;
17852 subpass.preserveAttachmentCount = 0;
17853 subpass.pPreserveAttachments = NULL;
17854
17855 VkRenderPass rp;
17856 VkRenderPassCreateInfo rp_info = {};
17857 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17858 rp_info.attachmentCount = 1;
17859 rp_info.pAttachments = &att;
17860 rp_info.subpassCount = 1;
17861 rp_info.pSubpasses = &subpass;
17862 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17863 ASSERT_VK_SUCCESS(result);
17864
17865 VkImageView *depthView = m_depthStencil->BindInfo();
17866 VkFramebufferCreateInfo fb_info = {};
17867 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17868 fb_info.pNext = NULL;
17869 fb_info.renderPass = rp;
17870 fb_info.attachmentCount = 1;
17871 fb_info.pAttachments = depthView;
17872 fb_info.width = 100;
17873 fb_info.height = 100;
17874 fb_info.layers = 1;
17875 VkFramebuffer fb;
17876 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17877 ASSERT_VK_SUCCESS(result);
17878
17879 VkRenderPassBeginInfo rpbinfo = {};
17880 rpbinfo.clearValueCount = 1;
17881 rpbinfo.pClearValues = &clear;
17882 rpbinfo.pNext = NULL;
17883 rpbinfo.renderPass = rp;
17884 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17885 rpbinfo.renderArea.extent.width = 100;
17886 rpbinfo.renderArea.extent.height = 100;
17887 rpbinfo.renderArea.offset.x = 0;
17888 rpbinfo.renderArea.offset.y = 0;
17889 rpbinfo.framebuffer = fb;
17890
17891 VkFence fence = {};
17892 VkFenceCreateInfo fence_ci = {};
17893 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17894 fence_ci.pNext = nullptr;
17895 fence_ci.flags = 0;
17896 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17897 ASSERT_VK_SUCCESS(result);
17898
17899 m_commandBuffer->BeginCommandBuffer();
17900 m_commandBuffer->BeginRenderPass(rpbinfo);
17901 m_commandBuffer->EndRenderPass();
17902 m_commandBuffer->EndCommandBuffer();
17903 m_commandBuffer->QueueCommandBuffer(fence);
17904
17905 VkImageObj destImage(m_device);
17906 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17907 VK_IMAGE_TILING_OPTIMAL, 0);
17908 VkImageMemoryBarrier barrier = {};
17909 VkImageSubresourceRange range;
17910 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17911 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17912 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17913 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17914 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17915 barrier.image = m_depthStencil->handle();
17916 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17917 range.baseMipLevel = 0;
17918 range.levelCount = 1;
17919 range.baseArrayLayer = 0;
17920 range.layerCount = 1;
17921 barrier.subresourceRange = range;
17922 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17923 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17924 cmdbuf.BeginCommandBuffer();
17925 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17926 &barrier);
17927 barrier.srcAccessMask = 0;
17928 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17929 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17930 barrier.image = destImage.handle();
17931 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17932 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17933 &barrier);
17934 VkImageCopy cregion;
17935 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17936 cregion.srcSubresource.mipLevel = 0;
17937 cregion.srcSubresource.baseArrayLayer = 0;
17938 cregion.srcSubresource.layerCount = 1;
17939 cregion.srcOffset.x = 0;
17940 cregion.srcOffset.y = 0;
17941 cregion.srcOffset.z = 0;
17942 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17943 cregion.dstSubresource.mipLevel = 0;
17944 cregion.dstSubresource.baseArrayLayer = 0;
17945 cregion.dstSubresource.layerCount = 1;
17946 cregion.dstOffset.x = 0;
17947 cregion.dstOffset.y = 0;
17948 cregion.dstOffset.z = 0;
17949 cregion.extent.width = 100;
17950 cregion.extent.height = 100;
17951 cregion.extent.depth = 1;
17952 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17953 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17954 cmdbuf.EndCommandBuffer();
17955
17956 VkSubmitInfo submit_info;
17957 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17958 submit_info.pNext = NULL;
17959 submit_info.waitSemaphoreCount = 0;
17960 submit_info.pWaitSemaphores = NULL;
17961 submit_info.pWaitDstStageMask = NULL;
17962 submit_info.commandBufferCount = 1;
17963 submit_info.pCommandBuffers = &cmdbuf.handle();
17964 submit_info.signalSemaphoreCount = 0;
17965 submit_info.pSignalSemaphores = NULL;
17966
17967 m_errorMonitor->ExpectSuccess();
17968 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17969 m_errorMonitor->VerifyNotFound();
17970
17971 vkQueueWaitIdle(m_device->m_queue);
17972 vkDestroyFence(m_device->device(), fence, nullptr);
17973 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17974 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17975}
17976
17977// This is a positive test. No errors should be generated.
17978TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17979 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17980
17981 m_errorMonitor->ExpectSuccess();
17982 ASSERT_NO_FATAL_FAILURE(InitState());
17983
17984 VkEvent event;
17985 VkEventCreateInfo event_create_info{};
17986 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17987 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17988
17989 VkCommandPool command_pool;
17990 VkCommandPoolCreateInfo pool_create_info{};
17991 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17992 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17993 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17994 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17995
17996 VkCommandBuffer command_buffer;
17997 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17998 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17999 command_buffer_allocate_info.commandPool = command_pool;
18000 command_buffer_allocate_info.commandBufferCount = 1;
18001 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18002 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18003
18004 VkQueue queue = VK_NULL_HANDLE;
18005 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18006
18007 {
18008 VkCommandBufferBeginInfo begin_info{};
18009 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18010 vkBeginCommandBuffer(command_buffer, &begin_info);
18011
18012 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
18013 nullptr, 0, nullptr);
18014 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18015 vkEndCommandBuffer(command_buffer);
18016 }
18017 {
18018 VkSubmitInfo submit_info{};
18019 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18020 submit_info.commandBufferCount = 1;
18021 submit_info.pCommandBuffers = &command_buffer;
18022 submit_info.signalSemaphoreCount = 0;
18023 submit_info.pSignalSemaphores = nullptr;
18024 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18025 }
18026 { vkSetEvent(m_device->device(), event); }
18027
18028 vkQueueWaitIdle(queue);
18029
18030 vkDestroyEvent(m_device->device(), event, nullptr);
18031 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18032 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18033
18034 m_errorMonitor->VerifyNotFound();
18035}
18036// This is a positive test. No errors should be generated.
18037TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18038 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18039
18040 ASSERT_NO_FATAL_FAILURE(InitState());
18041 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18042 return;
18043
18044 m_errorMonitor->ExpectSuccess();
18045
18046 VkQueryPool query_pool;
18047 VkQueryPoolCreateInfo query_pool_create_info{};
18048 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18049 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18050 query_pool_create_info.queryCount = 1;
18051 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18052
18053 VkCommandPool command_pool;
18054 VkCommandPoolCreateInfo pool_create_info{};
18055 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18056 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18057 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18058 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18059
18060 VkCommandBuffer command_buffer;
18061 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18062 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18063 command_buffer_allocate_info.commandPool = command_pool;
18064 command_buffer_allocate_info.commandBufferCount = 1;
18065 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18066 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18067
18068 VkCommandBuffer secondary_command_buffer;
18069 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18070 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18071
18072 VkQueue queue = VK_NULL_HANDLE;
18073 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18074
18075 uint32_t qfi = 0;
18076 VkBufferCreateInfo buff_create_info = {};
18077 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18078 buff_create_info.size = 1024;
18079 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18080 buff_create_info.queueFamilyIndexCount = 1;
18081 buff_create_info.pQueueFamilyIndices = &qfi;
18082
18083 VkResult err;
18084 VkBuffer buffer;
18085 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18086 ASSERT_VK_SUCCESS(err);
18087 VkMemoryAllocateInfo mem_alloc = {};
18088 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18089 mem_alloc.pNext = NULL;
18090 mem_alloc.allocationSize = 1024;
18091 mem_alloc.memoryTypeIndex = 0;
18092
18093 VkMemoryRequirements memReqs;
18094 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18095 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18096 if (!pass) {
18097 vkDestroyBuffer(m_device->device(), buffer, NULL);
18098 return;
18099 }
18100
18101 VkDeviceMemory mem;
18102 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18103 ASSERT_VK_SUCCESS(err);
18104 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18105 ASSERT_VK_SUCCESS(err);
18106
18107 VkCommandBufferInheritanceInfo hinfo = {};
18108 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18109 hinfo.renderPass = VK_NULL_HANDLE;
18110 hinfo.subpass = 0;
18111 hinfo.framebuffer = VK_NULL_HANDLE;
18112 hinfo.occlusionQueryEnable = VK_FALSE;
18113 hinfo.queryFlags = 0;
18114 hinfo.pipelineStatistics = 0;
18115
18116 {
18117 VkCommandBufferBeginInfo begin_info{};
18118 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18119 begin_info.pInheritanceInfo = &hinfo;
18120 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18121
18122 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18123 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18124
18125 vkEndCommandBuffer(secondary_command_buffer);
18126
18127 begin_info.pInheritanceInfo = nullptr;
18128 vkBeginCommandBuffer(command_buffer, &begin_info);
18129
18130 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18131 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18132
18133 vkEndCommandBuffer(command_buffer);
18134 }
18135 {
18136 VkSubmitInfo submit_info{};
18137 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18138 submit_info.commandBufferCount = 1;
18139 submit_info.pCommandBuffers = &command_buffer;
18140 submit_info.signalSemaphoreCount = 0;
18141 submit_info.pSignalSemaphores = nullptr;
18142 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18143 }
18144
18145 vkQueueWaitIdle(queue);
18146
18147 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18148 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18149 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18150 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18151 vkDestroyBuffer(m_device->device(), buffer, NULL);
18152 vkFreeMemory(m_device->device(), mem, NULL);
18153
18154 m_errorMonitor->VerifyNotFound();
18155}
18156
18157// This is a positive test. No errors should be generated.
18158TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18159 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18160
18161 ASSERT_NO_FATAL_FAILURE(InitState());
18162 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18163 return;
18164
18165 m_errorMonitor->ExpectSuccess();
18166
18167 VkQueryPool query_pool;
18168 VkQueryPoolCreateInfo query_pool_create_info{};
18169 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18170 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18171 query_pool_create_info.queryCount = 1;
18172 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18173
18174 VkCommandPool command_pool;
18175 VkCommandPoolCreateInfo pool_create_info{};
18176 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18177 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18178 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18179 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18180
18181 VkCommandBuffer command_buffer[2];
18182 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18183 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18184 command_buffer_allocate_info.commandPool = command_pool;
18185 command_buffer_allocate_info.commandBufferCount = 2;
18186 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18187 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18188
18189 VkQueue queue = VK_NULL_HANDLE;
18190 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18191
18192 uint32_t qfi = 0;
18193 VkBufferCreateInfo buff_create_info = {};
18194 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18195 buff_create_info.size = 1024;
18196 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18197 buff_create_info.queueFamilyIndexCount = 1;
18198 buff_create_info.pQueueFamilyIndices = &qfi;
18199
18200 VkResult err;
18201 VkBuffer buffer;
18202 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18203 ASSERT_VK_SUCCESS(err);
18204 VkMemoryAllocateInfo mem_alloc = {};
18205 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18206 mem_alloc.pNext = NULL;
18207 mem_alloc.allocationSize = 1024;
18208 mem_alloc.memoryTypeIndex = 0;
18209
18210 VkMemoryRequirements memReqs;
18211 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18212 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18213 if (!pass) {
18214 vkDestroyBuffer(m_device->device(), buffer, NULL);
18215 return;
18216 }
18217
18218 VkDeviceMemory mem;
18219 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18220 ASSERT_VK_SUCCESS(err);
18221 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18222 ASSERT_VK_SUCCESS(err);
18223
18224 {
18225 VkCommandBufferBeginInfo begin_info{};
18226 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18227 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18228
18229 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18230 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18231
18232 vkEndCommandBuffer(command_buffer[0]);
18233
18234 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18235
18236 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18237
18238 vkEndCommandBuffer(command_buffer[1]);
18239 }
18240 {
18241 VkSubmitInfo submit_info{};
18242 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18243 submit_info.commandBufferCount = 2;
18244 submit_info.pCommandBuffers = command_buffer;
18245 submit_info.signalSemaphoreCount = 0;
18246 submit_info.pSignalSemaphores = nullptr;
18247 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18248 }
18249
18250 vkQueueWaitIdle(queue);
18251
18252 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18253 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18254 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18255 vkDestroyBuffer(m_device->device(), buffer, NULL);
18256 vkFreeMemory(m_device->device(), mem, NULL);
18257
18258 m_errorMonitor->VerifyNotFound();
18259}
18260
Tony Barbourc46924f2016-11-04 11:49:52 -060018261TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018262 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18263
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018264 ASSERT_NO_FATAL_FAILURE(InitState());
18265 VkEvent event;
18266 VkEventCreateInfo event_create_info{};
18267 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18268 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18269
18270 VkCommandPool command_pool;
18271 VkCommandPoolCreateInfo pool_create_info{};
18272 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18273 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18274 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18275 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18276
18277 VkCommandBuffer command_buffer;
18278 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18279 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18280 command_buffer_allocate_info.commandPool = command_pool;
18281 command_buffer_allocate_info.commandBufferCount = 1;
18282 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18283 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18284
18285 VkQueue queue = VK_NULL_HANDLE;
18286 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18287
18288 {
18289 VkCommandBufferBeginInfo begin_info{};
18290 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18291 vkBeginCommandBuffer(command_buffer, &begin_info);
18292
18293 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018294 vkEndCommandBuffer(command_buffer);
18295 }
18296 {
18297 VkSubmitInfo submit_info{};
18298 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18299 submit_info.commandBufferCount = 1;
18300 submit_info.pCommandBuffers = &command_buffer;
18301 submit_info.signalSemaphoreCount = 0;
18302 submit_info.pSignalSemaphores = nullptr;
18303 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18304 }
18305 {
18306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18307 "command buffer.");
18308 vkSetEvent(m_device->device(), event);
18309 m_errorMonitor->VerifyFound();
18310 }
18311
18312 vkQueueWaitIdle(queue);
18313
18314 vkDestroyEvent(m_device->device(), event, nullptr);
18315 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18316 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18317}
18318
18319// This is a positive test. No errors should be generated.
18320TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18321 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18322 "run through a Submit & WaitForFences cycle 3 times. This "
18323 "previously revealed a bug so running this positive test "
18324 "to prevent a regression.");
18325 m_errorMonitor->ExpectSuccess();
18326
18327 ASSERT_NO_FATAL_FAILURE(InitState());
18328 VkQueue queue = VK_NULL_HANDLE;
18329 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18330
18331 static const uint32_t NUM_OBJECTS = 2;
18332 static const uint32_t NUM_FRAMES = 3;
18333 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18334 VkFence fences[NUM_OBJECTS] = {};
18335
18336 VkCommandPool cmd_pool;
18337 VkCommandPoolCreateInfo cmd_pool_ci = {};
18338 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18339 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18340 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18341 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18342 ASSERT_VK_SUCCESS(err);
18343
18344 VkCommandBufferAllocateInfo cmd_buf_info = {};
18345 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18346 cmd_buf_info.commandPool = cmd_pool;
18347 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18348 cmd_buf_info.commandBufferCount = 1;
18349
18350 VkFenceCreateInfo fence_ci = {};
18351 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18352 fence_ci.pNext = nullptr;
18353 fence_ci.flags = 0;
18354
18355 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18356 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18357 ASSERT_VK_SUCCESS(err);
18358 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18359 ASSERT_VK_SUCCESS(err);
18360 }
18361
18362 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18363 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18364 // Create empty cmd buffer
18365 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18366 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18367
18368 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18369 ASSERT_VK_SUCCESS(err);
18370 err = vkEndCommandBuffer(cmd_buffers[obj]);
18371 ASSERT_VK_SUCCESS(err);
18372
18373 VkSubmitInfo submit_info = {};
18374 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18375 submit_info.commandBufferCount = 1;
18376 submit_info.pCommandBuffers = &cmd_buffers[obj];
18377 // Submit cmd buffer and wait for fence
18378 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18379 ASSERT_VK_SUCCESS(err);
18380 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18381 ASSERT_VK_SUCCESS(err);
18382 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18383 ASSERT_VK_SUCCESS(err);
18384 }
18385 }
18386 m_errorMonitor->VerifyNotFound();
18387 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18388 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18389 vkDestroyFence(m_device->device(), fences[i], nullptr);
18390 }
18391}
18392// This is a positive test. No errors should be generated.
18393TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18394
18395 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18396 "submitted on separate queues followed by a QueueWaitIdle.");
18397
18398 ASSERT_NO_FATAL_FAILURE(InitState());
18399 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18400 return;
18401
18402 m_errorMonitor->ExpectSuccess();
18403
18404 VkSemaphore semaphore;
18405 VkSemaphoreCreateInfo semaphore_create_info{};
18406 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18407 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18408
18409 VkCommandPool command_pool;
18410 VkCommandPoolCreateInfo pool_create_info{};
18411 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18412 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18413 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18414 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18415
18416 VkCommandBuffer command_buffer[2];
18417 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18418 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18419 command_buffer_allocate_info.commandPool = command_pool;
18420 command_buffer_allocate_info.commandBufferCount = 2;
18421 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18422 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18423
18424 VkQueue queue = VK_NULL_HANDLE;
18425 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18426
18427 {
18428 VkCommandBufferBeginInfo begin_info{};
18429 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18430 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18431
18432 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18433 nullptr, 0, nullptr, 0, nullptr);
18434
18435 VkViewport viewport{};
18436 viewport.maxDepth = 1.0f;
18437 viewport.minDepth = 0.0f;
18438 viewport.width = 512;
18439 viewport.height = 512;
18440 viewport.x = 0;
18441 viewport.y = 0;
18442 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18443 vkEndCommandBuffer(command_buffer[0]);
18444 }
18445 {
18446 VkCommandBufferBeginInfo begin_info{};
18447 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18448 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18449
18450 VkViewport viewport{};
18451 viewport.maxDepth = 1.0f;
18452 viewport.minDepth = 0.0f;
18453 viewport.width = 512;
18454 viewport.height = 512;
18455 viewport.x = 0;
18456 viewport.y = 0;
18457 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18458 vkEndCommandBuffer(command_buffer[1]);
18459 }
18460 {
18461 VkSubmitInfo submit_info{};
18462 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18463 submit_info.commandBufferCount = 1;
18464 submit_info.pCommandBuffers = &command_buffer[0];
18465 submit_info.signalSemaphoreCount = 1;
18466 submit_info.pSignalSemaphores = &semaphore;
18467 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18468 }
18469 {
18470 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18471 VkSubmitInfo submit_info{};
18472 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18473 submit_info.commandBufferCount = 1;
18474 submit_info.pCommandBuffers = &command_buffer[1];
18475 submit_info.waitSemaphoreCount = 1;
18476 submit_info.pWaitSemaphores = &semaphore;
18477 submit_info.pWaitDstStageMask = flags;
18478 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18479 }
18480
18481 vkQueueWaitIdle(m_device->m_queue);
18482
18483 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18484 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18485 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18486
18487 m_errorMonitor->VerifyNotFound();
18488}
18489
18490// This is a positive test. No errors should be generated.
18491TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18492
18493 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18494 "submitted on separate queues, the second having a fence"
18495 "followed by a QueueWaitIdle.");
18496
18497 ASSERT_NO_FATAL_FAILURE(InitState());
18498 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18499 return;
18500
18501 m_errorMonitor->ExpectSuccess();
18502
18503 VkFence fence;
18504 VkFenceCreateInfo fence_create_info{};
18505 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18506 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18507
18508 VkSemaphore semaphore;
18509 VkSemaphoreCreateInfo semaphore_create_info{};
18510 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18511 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18512
18513 VkCommandPool command_pool;
18514 VkCommandPoolCreateInfo pool_create_info{};
18515 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18516 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18517 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18518 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18519
18520 VkCommandBuffer command_buffer[2];
18521 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18522 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18523 command_buffer_allocate_info.commandPool = command_pool;
18524 command_buffer_allocate_info.commandBufferCount = 2;
18525 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18526 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18527
18528 VkQueue queue = VK_NULL_HANDLE;
18529 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18530
18531 {
18532 VkCommandBufferBeginInfo begin_info{};
18533 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18534 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18535
18536 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18537 nullptr, 0, nullptr, 0, nullptr);
18538
18539 VkViewport viewport{};
18540 viewport.maxDepth = 1.0f;
18541 viewport.minDepth = 0.0f;
18542 viewport.width = 512;
18543 viewport.height = 512;
18544 viewport.x = 0;
18545 viewport.y = 0;
18546 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18547 vkEndCommandBuffer(command_buffer[0]);
18548 }
18549 {
18550 VkCommandBufferBeginInfo begin_info{};
18551 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18552 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18553
18554 VkViewport viewport{};
18555 viewport.maxDepth = 1.0f;
18556 viewport.minDepth = 0.0f;
18557 viewport.width = 512;
18558 viewport.height = 512;
18559 viewport.x = 0;
18560 viewport.y = 0;
18561 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18562 vkEndCommandBuffer(command_buffer[1]);
18563 }
18564 {
18565 VkSubmitInfo submit_info{};
18566 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18567 submit_info.commandBufferCount = 1;
18568 submit_info.pCommandBuffers = &command_buffer[0];
18569 submit_info.signalSemaphoreCount = 1;
18570 submit_info.pSignalSemaphores = &semaphore;
18571 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18572 }
18573 {
18574 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18575 VkSubmitInfo submit_info{};
18576 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18577 submit_info.commandBufferCount = 1;
18578 submit_info.pCommandBuffers = &command_buffer[1];
18579 submit_info.waitSemaphoreCount = 1;
18580 submit_info.pWaitSemaphores = &semaphore;
18581 submit_info.pWaitDstStageMask = flags;
18582 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18583 }
18584
18585 vkQueueWaitIdle(m_device->m_queue);
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
18595// This is a positive test. No errors should be generated.
18596TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18597
18598 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18599 "submitted on separate queues, the second having a fence"
18600 "followed by two consecutive WaitForFences calls on the same fence.");
18601
18602 ASSERT_NO_FATAL_FAILURE(InitState());
18603 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18604 return;
18605
18606 m_errorMonitor->ExpectSuccess();
18607
18608 VkFence fence;
18609 VkFenceCreateInfo fence_create_info{};
18610 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18611 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18612
18613 VkSemaphore semaphore;
18614 VkSemaphoreCreateInfo semaphore_create_info{};
18615 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18616 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18617
18618 VkCommandPool command_pool;
18619 VkCommandPoolCreateInfo pool_create_info{};
18620 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18621 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18622 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18623 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18624
18625 VkCommandBuffer command_buffer[2];
18626 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18627 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18628 command_buffer_allocate_info.commandPool = command_pool;
18629 command_buffer_allocate_info.commandBufferCount = 2;
18630 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18631 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18632
18633 VkQueue queue = VK_NULL_HANDLE;
18634 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18635
18636 {
18637 VkCommandBufferBeginInfo begin_info{};
18638 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18639 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18640
18641 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18642 nullptr, 0, nullptr, 0, nullptr);
18643
18644 VkViewport viewport{};
18645 viewport.maxDepth = 1.0f;
18646 viewport.minDepth = 0.0f;
18647 viewport.width = 512;
18648 viewport.height = 512;
18649 viewport.x = 0;
18650 viewport.y = 0;
18651 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18652 vkEndCommandBuffer(command_buffer[0]);
18653 }
18654 {
18655 VkCommandBufferBeginInfo begin_info{};
18656 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18657 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18658
18659 VkViewport viewport{};
18660 viewport.maxDepth = 1.0f;
18661 viewport.minDepth = 0.0f;
18662 viewport.width = 512;
18663 viewport.height = 512;
18664 viewport.x = 0;
18665 viewport.y = 0;
18666 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18667 vkEndCommandBuffer(command_buffer[1]);
18668 }
18669 {
18670 VkSubmitInfo submit_info{};
18671 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18672 submit_info.commandBufferCount = 1;
18673 submit_info.pCommandBuffers = &command_buffer[0];
18674 submit_info.signalSemaphoreCount = 1;
18675 submit_info.pSignalSemaphores = &semaphore;
18676 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18677 }
18678 {
18679 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18680 VkSubmitInfo submit_info{};
18681 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18682 submit_info.commandBufferCount = 1;
18683 submit_info.pCommandBuffers = &command_buffer[1];
18684 submit_info.waitSemaphoreCount = 1;
18685 submit_info.pWaitSemaphores = &semaphore;
18686 submit_info.pWaitDstStageMask = flags;
18687 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18688 }
18689
18690 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18691 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18692
18693 vkDestroyFence(m_device->device(), fence, nullptr);
18694 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18695 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18696 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18697
18698 m_errorMonitor->VerifyNotFound();
18699}
18700
18701TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18702
18703 ASSERT_NO_FATAL_FAILURE(InitState());
18704 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18705 printf("Test requires two queues, skipping\n");
18706 return;
18707 }
18708
18709 VkResult err;
18710
18711 m_errorMonitor->ExpectSuccess();
18712
18713 VkQueue q0 = m_device->m_queue;
18714 VkQueue q1 = nullptr;
18715 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18716 ASSERT_NE(q1, nullptr);
18717
18718 // An (empty) command buffer. We must have work in the first submission --
18719 // the layer treats unfenced work differently from fenced work.
18720 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18721 VkCommandPool pool;
18722 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18723 ASSERT_VK_SUCCESS(err);
18724 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18725 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18726 VkCommandBuffer cb;
18727 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18728 ASSERT_VK_SUCCESS(err);
18729 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18730 err = vkBeginCommandBuffer(cb, &cbbi);
18731 ASSERT_VK_SUCCESS(err);
18732 err = vkEndCommandBuffer(cb);
18733 ASSERT_VK_SUCCESS(err);
18734
18735 // A semaphore
18736 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18737 VkSemaphore s;
18738 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18739 ASSERT_VK_SUCCESS(err);
18740
18741 // First submission, to q0
18742 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18743
18744 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18745 ASSERT_VK_SUCCESS(err);
18746
18747 // Second submission, to q1, waiting on s
18748 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18749 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18750
18751 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18752 ASSERT_VK_SUCCESS(err);
18753
18754 // Wait for q0 idle
18755 err = vkQueueWaitIdle(q0);
18756 ASSERT_VK_SUCCESS(err);
18757
18758 // Command buffer should have been completed (it was on q0); reset the pool.
18759 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18760
18761 m_errorMonitor->VerifyNotFound();
18762
18763 // Force device completely idle and clean up resources
18764 vkDeviceWaitIdle(m_device->device());
18765 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18766 vkDestroySemaphore(m_device->device(), s, nullptr);
18767}
18768
18769// This is a positive test. No errors should be generated.
18770TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18771
18772 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18773 "submitted on separate queues, the second having a fence, "
18774 "followed by a WaitForFences call.");
18775
18776 ASSERT_NO_FATAL_FAILURE(InitState());
18777 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18778 return;
18779
18780 m_errorMonitor->ExpectSuccess();
18781
18782 ASSERT_NO_FATAL_FAILURE(InitState());
18783 VkFence fence;
18784 VkFenceCreateInfo fence_create_info{};
18785 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18786 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18787
18788 VkSemaphore semaphore;
18789 VkSemaphoreCreateInfo semaphore_create_info{};
18790 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18791 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18792
18793 VkCommandPool command_pool;
18794 VkCommandPoolCreateInfo pool_create_info{};
18795 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18796 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18797 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18798 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18799
18800 VkCommandBuffer command_buffer[2];
18801 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18802 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18803 command_buffer_allocate_info.commandPool = command_pool;
18804 command_buffer_allocate_info.commandBufferCount = 2;
18805 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18806 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18807
18808 VkQueue queue = VK_NULL_HANDLE;
18809 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18810
18811 {
18812 VkCommandBufferBeginInfo begin_info{};
18813 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18814 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18815
18816 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18817 nullptr, 0, nullptr, 0, nullptr);
18818
18819 VkViewport viewport{};
18820 viewport.maxDepth = 1.0f;
18821 viewport.minDepth = 0.0f;
18822 viewport.width = 512;
18823 viewport.height = 512;
18824 viewport.x = 0;
18825 viewport.y = 0;
18826 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18827 vkEndCommandBuffer(command_buffer[0]);
18828 }
18829 {
18830 VkCommandBufferBeginInfo begin_info{};
18831 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18832 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18833
18834 VkViewport viewport{};
18835 viewport.maxDepth = 1.0f;
18836 viewport.minDepth = 0.0f;
18837 viewport.width = 512;
18838 viewport.height = 512;
18839 viewport.x = 0;
18840 viewport.y = 0;
18841 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18842 vkEndCommandBuffer(command_buffer[1]);
18843 }
18844 {
18845 VkSubmitInfo submit_info{};
18846 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18847 submit_info.commandBufferCount = 1;
18848 submit_info.pCommandBuffers = &command_buffer[0];
18849 submit_info.signalSemaphoreCount = 1;
18850 submit_info.pSignalSemaphores = &semaphore;
18851 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18852 }
18853 {
18854 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18855 VkSubmitInfo submit_info{};
18856 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18857 submit_info.commandBufferCount = 1;
18858 submit_info.pCommandBuffers = &command_buffer[1];
18859 submit_info.waitSemaphoreCount = 1;
18860 submit_info.pWaitSemaphores = &semaphore;
18861 submit_info.pWaitDstStageMask = flags;
18862 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18863 }
18864
18865 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18866
18867 vkDestroyFence(m_device->device(), fence, nullptr);
18868 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18869 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18870 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18871
18872 m_errorMonitor->VerifyNotFound();
18873}
18874
18875// This is a positive test. No errors should be generated.
18876TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18877
18878 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18879 "on the same queue, sharing a signal/wait semaphore, the "
18880 "second having a fence, "
18881 "followed by a WaitForFences call.");
18882
18883 m_errorMonitor->ExpectSuccess();
18884
18885 ASSERT_NO_FATAL_FAILURE(InitState());
18886 VkFence fence;
18887 VkFenceCreateInfo fence_create_info{};
18888 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18889 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18890
18891 VkSemaphore semaphore;
18892 VkSemaphoreCreateInfo semaphore_create_info{};
18893 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18894 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18895
18896 VkCommandPool command_pool;
18897 VkCommandPoolCreateInfo pool_create_info{};
18898 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18899 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18900 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18901 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18902
18903 VkCommandBuffer command_buffer[2];
18904 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18905 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18906 command_buffer_allocate_info.commandPool = command_pool;
18907 command_buffer_allocate_info.commandBufferCount = 2;
18908 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18909 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18910
18911 {
18912 VkCommandBufferBeginInfo begin_info{};
18913 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18914 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18915
18916 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18917 nullptr, 0, nullptr, 0, nullptr);
18918
18919 VkViewport viewport{};
18920 viewport.maxDepth = 1.0f;
18921 viewport.minDepth = 0.0f;
18922 viewport.width = 512;
18923 viewport.height = 512;
18924 viewport.x = 0;
18925 viewport.y = 0;
18926 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18927 vkEndCommandBuffer(command_buffer[0]);
18928 }
18929 {
18930 VkCommandBufferBeginInfo begin_info{};
18931 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18932 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18933
18934 VkViewport viewport{};
18935 viewport.maxDepth = 1.0f;
18936 viewport.minDepth = 0.0f;
18937 viewport.width = 512;
18938 viewport.height = 512;
18939 viewport.x = 0;
18940 viewport.y = 0;
18941 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18942 vkEndCommandBuffer(command_buffer[1]);
18943 }
18944 {
18945 VkSubmitInfo submit_info{};
18946 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18947 submit_info.commandBufferCount = 1;
18948 submit_info.pCommandBuffers = &command_buffer[0];
18949 submit_info.signalSemaphoreCount = 1;
18950 submit_info.pSignalSemaphores = &semaphore;
18951 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18952 }
18953 {
18954 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18955 VkSubmitInfo submit_info{};
18956 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18957 submit_info.commandBufferCount = 1;
18958 submit_info.pCommandBuffers = &command_buffer[1];
18959 submit_info.waitSemaphoreCount = 1;
18960 submit_info.pWaitSemaphores = &semaphore;
18961 submit_info.pWaitDstStageMask = flags;
18962 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18963 }
18964
18965 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18966
18967 vkDestroyFence(m_device->device(), fence, nullptr);
18968 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18969 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18970 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18971
18972 m_errorMonitor->VerifyNotFound();
18973}
18974
18975// This is a positive test. No errors should be generated.
18976TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18977
18978 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18979 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18980 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18981
18982 m_errorMonitor->ExpectSuccess();
18983
18984 ASSERT_NO_FATAL_FAILURE(InitState());
18985 VkFence fence;
18986 VkFenceCreateInfo fence_create_info{};
18987 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18988 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18989
18990 VkCommandPool command_pool;
18991 VkCommandPoolCreateInfo pool_create_info{};
18992 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18993 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18994 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18995 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18996
18997 VkCommandBuffer command_buffer[2];
18998 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18999 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19000 command_buffer_allocate_info.commandPool = command_pool;
19001 command_buffer_allocate_info.commandBufferCount = 2;
19002 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19003 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19004
19005 {
19006 VkCommandBufferBeginInfo begin_info{};
19007 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19008 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19009
19010 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19011 nullptr, 0, nullptr, 0, nullptr);
19012
19013 VkViewport viewport{};
19014 viewport.maxDepth = 1.0f;
19015 viewport.minDepth = 0.0f;
19016 viewport.width = 512;
19017 viewport.height = 512;
19018 viewport.x = 0;
19019 viewport.y = 0;
19020 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19021 vkEndCommandBuffer(command_buffer[0]);
19022 }
19023 {
19024 VkCommandBufferBeginInfo begin_info{};
19025 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19026 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19027
19028 VkViewport viewport{};
19029 viewport.maxDepth = 1.0f;
19030 viewport.minDepth = 0.0f;
19031 viewport.width = 512;
19032 viewport.height = 512;
19033 viewport.x = 0;
19034 viewport.y = 0;
19035 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19036 vkEndCommandBuffer(command_buffer[1]);
19037 }
19038 {
19039 VkSubmitInfo submit_info{};
19040 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19041 submit_info.commandBufferCount = 1;
19042 submit_info.pCommandBuffers = &command_buffer[0];
19043 submit_info.signalSemaphoreCount = 0;
19044 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19045 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19046 }
19047 {
19048 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19049 VkSubmitInfo submit_info{};
19050 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19051 submit_info.commandBufferCount = 1;
19052 submit_info.pCommandBuffers = &command_buffer[1];
19053 submit_info.waitSemaphoreCount = 0;
19054 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19055 submit_info.pWaitDstStageMask = flags;
19056 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19057 }
19058
19059 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19060
19061 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19062 ASSERT_VK_SUCCESS(err);
19063
19064 vkDestroyFence(m_device->device(), fence, nullptr);
19065 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19066 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19067
19068 m_errorMonitor->VerifyNotFound();
19069}
19070
19071// This is a positive test. No errors should be generated.
19072TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
19073
19074 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19075 "on the same queue, the second having a fence, followed "
19076 "by a WaitForFences call.");
19077
19078 m_errorMonitor->ExpectSuccess();
19079
19080 ASSERT_NO_FATAL_FAILURE(InitState());
19081 VkFence fence;
19082 VkFenceCreateInfo fence_create_info{};
19083 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19084 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19085
19086 VkCommandPool command_pool;
19087 VkCommandPoolCreateInfo pool_create_info{};
19088 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19089 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19090 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19091 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19092
19093 VkCommandBuffer command_buffer[2];
19094 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19095 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19096 command_buffer_allocate_info.commandPool = command_pool;
19097 command_buffer_allocate_info.commandBufferCount = 2;
19098 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19099 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19100
19101 {
19102 VkCommandBufferBeginInfo begin_info{};
19103 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19104 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19105
19106 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19107 nullptr, 0, nullptr, 0, nullptr);
19108
19109 VkViewport viewport{};
19110 viewport.maxDepth = 1.0f;
19111 viewport.minDepth = 0.0f;
19112 viewport.width = 512;
19113 viewport.height = 512;
19114 viewport.x = 0;
19115 viewport.y = 0;
19116 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19117 vkEndCommandBuffer(command_buffer[0]);
19118 }
19119 {
19120 VkCommandBufferBeginInfo begin_info{};
19121 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19122 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19123
19124 VkViewport viewport{};
19125 viewport.maxDepth = 1.0f;
19126 viewport.minDepth = 0.0f;
19127 viewport.width = 512;
19128 viewport.height = 512;
19129 viewport.x = 0;
19130 viewport.y = 0;
19131 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19132 vkEndCommandBuffer(command_buffer[1]);
19133 }
19134 {
19135 VkSubmitInfo submit_info{};
19136 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19137 submit_info.commandBufferCount = 1;
19138 submit_info.pCommandBuffers = &command_buffer[0];
19139 submit_info.signalSemaphoreCount = 0;
19140 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19141 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19142 }
19143 {
19144 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19145 VkSubmitInfo submit_info{};
19146 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19147 submit_info.commandBufferCount = 1;
19148 submit_info.pCommandBuffers = &command_buffer[1];
19149 submit_info.waitSemaphoreCount = 0;
19150 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19151 submit_info.pWaitDstStageMask = flags;
19152 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19153 }
19154
19155 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19156
19157 vkDestroyFence(m_device->device(), fence, nullptr);
19158 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19159 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19160
19161 m_errorMonitor->VerifyNotFound();
19162}
19163
19164// This is a positive test. No errors should be generated.
19165TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19166
19167 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19168 "QueueSubmit call followed by a WaitForFences call.");
19169 ASSERT_NO_FATAL_FAILURE(InitState());
19170
19171 m_errorMonitor->ExpectSuccess();
19172
19173 VkFence fence;
19174 VkFenceCreateInfo fence_create_info{};
19175 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19176 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19177
19178 VkSemaphore semaphore;
19179 VkSemaphoreCreateInfo semaphore_create_info{};
19180 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19181 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19182
19183 VkCommandPool command_pool;
19184 VkCommandPoolCreateInfo pool_create_info{};
19185 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19186 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19187 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19188 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19189
19190 VkCommandBuffer command_buffer[2];
19191 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19192 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19193 command_buffer_allocate_info.commandPool = command_pool;
19194 command_buffer_allocate_info.commandBufferCount = 2;
19195 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19196 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19197
19198 {
19199 VkCommandBufferBeginInfo begin_info{};
19200 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19201 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19202
19203 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19204 nullptr, 0, nullptr, 0, nullptr);
19205
19206 VkViewport viewport{};
19207 viewport.maxDepth = 1.0f;
19208 viewport.minDepth = 0.0f;
19209 viewport.width = 512;
19210 viewport.height = 512;
19211 viewport.x = 0;
19212 viewport.y = 0;
19213 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19214 vkEndCommandBuffer(command_buffer[0]);
19215 }
19216 {
19217 VkCommandBufferBeginInfo begin_info{};
19218 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19219 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19220
19221 VkViewport viewport{};
19222 viewport.maxDepth = 1.0f;
19223 viewport.minDepth = 0.0f;
19224 viewport.width = 512;
19225 viewport.height = 512;
19226 viewport.x = 0;
19227 viewport.y = 0;
19228 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19229 vkEndCommandBuffer(command_buffer[1]);
19230 }
19231 {
19232 VkSubmitInfo submit_info[2];
19233 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19234
19235 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19236 submit_info[0].pNext = NULL;
19237 submit_info[0].commandBufferCount = 1;
19238 submit_info[0].pCommandBuffers = &command_buffer[0];
19239 submit_info[0].signalSemaphoreCount = 1;
19240 submit_info[0].pSignalSemaphores = &semaphore;
19241 submit_info[0].waitSemaphoreCount = 0;
19242 submit_info[0].pWaitSemaphores = NULL;
19243 submit_info[0].pWaitDstStageMask = 0;
19244
19245 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19246 submit_info[1].pNext = NULL;
19247 submit_info[1].commandBufferCount = 1;
19248 submit_info[1].pCommandBuffers = &command_buffer[1];
19249 submit_info[1].waitSemaphoreCount = 1;
19250 submit_info[1].pWaitSemaphores = &semaphore;
19251 submit_info[1].pWaitDstStageMask = flags;
19252 submit_info[1].signalSemaphoreCount = 0;
19253 submit_info[1].pSignalSemaphores = NULL;
19254 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19255 }
19256
19257 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19258
19259 vkDestroyFence(m_device->device(), fence, nullptr);
19260 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19261 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19262 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19263
19264 m_errorMonitor->VerifyNotFound();
19265}
19266
19267TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19268 m_errorMonitor->ExpectSuccess();
19269
19270 ASSERT_NO_FATAL_FAILURE(InitState());
19271 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19272
19273 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
19274 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
19275
19276 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19277 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19278 m_errorMonitor->VerifyNotFound();
19279 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19280 m_errorMonitor->VerifyNotFound();
19281 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19282 m_errorMonitor->VerifyNotFound();
19283
19284 m_commandBuffer->EndCommandBuffer();
19285 m_errorMonitor->VerifyNotFound();
19286}
19287
19288TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19289 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19290 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19291 "has a valid layout, and a second subpass then uses a "
19292 "valid *READ_ONLY* layout.");
19293 m_errorMonitor->ExpectSuccess();
19294 ASSERT_NO_FATAL_FAILURE(InitState());
19295
19296 VkAttachmentReference attach[2] = {};
19297 attach[0].attachment = 0;
19298 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19299 attach[1].attachment = 0;
19300 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19301 VkSubpassDescription subpasses[2] = {};
19302 // First subpass clears DS attach on load
19303 subpasses[0].pDepthStencilAttachment = &attach[0];
19304 // 2nd subpass reads in DS as input attachment
19305 subpasses[1].inputAttachmentCount = 1;
19306 subpasses[1].pInputAttachments = &attach[1];
19307 VkAttachmentDescription attach_desc = {};
19308 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19309 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19310 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19311 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19312 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19313 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19314 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19315 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19316 VkRenderPassCreateInfo rpci = {};
19317 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19318 rpci.attachmentCount = 1;
19319 rpci.pAttachments = &attach_desc;
19320 rpci.subpassCount = 2;
19321 rpci.pSubpasses = subpasses;
19322
19323 // Now create RenderPass and verify no errors
19324 VkRenderPass rp;
19325 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19326 m_errorMonitor->VerifyNotFound();
19327
19328 vkDestroyRenderPass(m_device->device(), rp, NULL);
19329}
19330
19331TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19332 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19333 "as vertex attributes");
19334 m_errorMonitor->ExpectSuccess();
19335
19336 ASSERT_NO_FATAL_FAILURE(InitState());
19337 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19338
19339 VkVertexInputBindingDescription input_binding;
19340 memset(&input_binding, 0, sizeof(input_binding));
19341
19342 VkVertexInputAttributeDescription input_attribs[2];
19343 memset(input_attribs, 0, sizeof(input_attribs));
19344
19345 for (int i = 0; i < 2; i++) {
19346 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19347 input_attribs[i].location = i;
19348 }
19349
19350 char const *vsSource = "#version 450\n"
19351 "\n"
19352 "layout(location=0) in mat2x4 x;\n"
19353 "out gl_PerVertex {\n"
19354 " vec4 gl_Position;\n"
19355 "};\n"
19356 "void main(){\n"
19357 " gl_Position = x[0] + x[1];\n"
19358 "}\n";
19359 char const *fsSource = "#version 450\n"
19360 "\n"
19361 "layout(location=0) out vec4 color;\n"
19362 "void main(){\n"
19363 " color = vec4(1);\n"
19364 "}\n";
19365
19366 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19367 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19368
19369 VkPipelineObj pipe(m_device);
19370 pipe.AddColorAttachment();
19371 pipe.AddShader(&vs);
19372 pipe.AddShader(&fs);
19373
19374 pipe.AddVertexInputBindings(&input_binding, 1);
19375 pipe.AddVertexInputAttribs(input_attribs, 2);
19376
19377 VkDescriptorSetObj descriptorSet(m_device);
19378 descriptorSet.AppendDummy();
19379 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19380
19381 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19382
19383 /* expect success */
19384 m_errorMonitor->VerifyNotFound();
19385}
19386
19387TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19388 m_errorMonitor->ExpectSuccess();
19389
19390 ASSERT_NO_FATAL_FAILURE(InitState());
19391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19392
19393 VkVertexInputBindingDescription input_binding;
19394 memset(&input_binding, 0, sizeof(input_binding));
19395
19396 VkVertexInputAttributeDescription input_attribs[2];
19397 memset(input_attribs, 0, sizeof(input_attribs));
19398
19399 for (int i = 0; i < 2; i++) {
19400 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19401 input_attribs[i].location = i;
19402 }
19403
19404 char const *vsSource = "#version 450\n"
19405 "\n"
19406 "layout(location=0) in vec4 x[2];\n"
19407 "out gl_PerVertex {\n"
19408 " vec4 gl_Position;\n"
19409 "};\n"
19410 "void main(){\n"
19411 " gl_Position = x[0] + x[1];\n"
19412 "}\n";
19413 char const *fsSource = "#version 450\n"
19414 "\n"
19415 "layout(location=0) out vec4 color;\n"
19416 "void main(){\n"
19417 " color = vec4(1);\n"
19418 "}\n";
19419
19420 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19421 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19422
19423 VkPipelineObj pipe(m_device);
19424 pipe.AddColorAttachment();
19425 pipe.AddShader(&vs);
19426 pipe.AddShader(&fs);
19427
19428 pipe.AddVertexInputBindings(&input_binding, 1);
19429 pipe.AddVertexInputAttribs(input_attribs, 2);
19430
19431 VkDescriptorSetObj descriptorSet(m_device);
19432 descriptorSet.AppendDummy();
19433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19434
19435 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19436
19437 m_errorMonitor->VerifyNotFound();
19438}
19439
19440TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19441 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19442 "through multiple vertex shader inputs, each consuming a different "
19443 "subset of the components.");
19444 m_errorMonitor->ExpectSuccess();
19445
19446 ASSERT_NO_FATAL_FAILURE(InitState());
19447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19448
19449 VkVertexInputBindingDescription input_binding;
19450 memset(&input_binding, 0, sizeof(input_binding));
19451
19452 VkVertexInputAttributeDescription input_attribs[3];
19453 memset(input_attribs, 0, sizeof(input_attribs));
19454
19455 for (int i = 0; i < 3; i++) {
19456 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19457 input_attribs[i].location = i;
19458 }
19459
19460 char const *vsSource = "#version 450\n"
19461 "\n"
19462 "layout(location=0) in vec4 x;\n"
19463 "layout(location=1) in vec3 y1;\n"
19464 "layout(location=1, component=3) in float y2;\n"
19465 "layout(location=2) in vec4 z;\n"
19466 "out gl_PerVertex {\n"
19467 " vec4 gl_Position;\n"
19468 "};\n"
19469 "void main(){\n"
19470 " gl_Position = x + vec4(y1, y2) + z;\n"
19471 "}\n";
19472 char const *fsSource = "#version 450\n"
19473 "\n"
19474 "layout(location=0) out vec4 color;\n"
19475 "void main(){\n"
19476 " color = vec4(1);\n"
19477 "}\n";
19478
19479 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19480 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19481
19482 VkPipelineObj pipe(m_device);
19483 pipe.AddColorAttachment();
19484 pipe.AddShader(&vs);
19485 pipe.AddShader(&fs);
19486
19487 pipe.AddVertexInputBindings(&input_binding, 1);
19488 pipe.AddVertexInputAttribs(input_attribs, 3);
19489
19490 VkDescriptorSetObj descriptorSet(m_device);
19491 descriptorSet.AppendDummy();
19492 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19493
19494 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19495
19496 m_errorMonitor->VerifyNotFound();
19497}
19498
19499TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19500 m_errorMonitor->ExpectSuccess();
19501
19502 ASSERT_NO_FATAL_FAILURE(InitState());
19503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19504
19505 char const *vsSource = "#version 450\n"
19506 "out gl_PerVertex {\n"
19507 " vec4 gl_Position;\n"
19508 "};\n"
19509 "void main(){\n"
19510 " gl_Position = vec4(0);\n"
19511 "}\n";
19512 char const *fsSource = "#version 450\n"
19513 "\n"
19514 "layout(location=0) out vec4 color;\n"
19515 "void main(){\n"
19516 " color = vec4(1);\n"
19517 "}\n";
19518
19519 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19520 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19521
19522 VkPipelineObj pipe(m_device);
19523 pipe.AddColorAttachment();
19524 pipe.AddShader(&vs);
19525 pipe.AddShader(&fs);
19526
19527 VkDescriptorSetObj descriptorSet(m_device);
19528 descriptorSet.AppendDummy();
19529 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19530
19531 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19532
19533 m_errorMonitor->VerifyNotFound();
19534}
19535
19536TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19537 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19538 "set out in 14.1.3: fundamental type must match, and producer side must "
19539 "have at least as many components");
19540 m_errorMonitor->ExpectSuccess();
19541
19542 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19543
19544 ASSERT_NO_FATAL_FAILURE(InitState());
19545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19546
19547 char const *vsSource = "#version 450\n"
19548 "out gl_PerVertex {\n"
19549 " vec4 gl_Position;\n"
19550 "};\n"
19551 "layout(location=0) out vec3 x;\n"
19552 "layout(location=1) out ivec3 y;\n"
19553 "layout(location=2) out vec3 z;\n"
19554 "void main(){\n"
19555 " gl_Position = vec4(0);\n"
19556 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19557 "}\n";
19558 char const *fsSource = "#version 450\n"
19559 "\n"
19560 "layout(location=0) out vec4 color;\n"
19561 "layout(location=0) in float x;\n"
19562 "layout(location=1) flat in int y;\n"
19563 "layout(location=2) in vec2 z;\n"
19564 "void main(){\n"
19565 " color = vec4(1 + x + y + z.x);\n"
19566 "}\n";
19567
19568 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19569 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19570
19571 VkPipelineObj pipe(m_device);
19572 pipe.AddColorAttachment();
19573 pipe.AddShader(&vs);
19574 pipe.AddShader(&fs);
19575
19576 VkDescriptorSetObj descriptorSet(m_device);
19577 descriptorSet.AppendDummy();
19578 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19579
19580 VkResult err = VK_SUCCESS;
19581 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19582 ASSERT_VK_SUCCESS(err);
19583
19584 m_errorMonitor->VerifyNotFound();
19585}
19586
19587TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19588 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19589 "passed between the TCS and TES stages");
19590 m_errorMonitor->ExpectSuccess();
19591
19592 ASSERT_NO_FATAL_FAILURE(InitState());
19593 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19594
19595 if (!m_device->phy().features().tessellationShader) {
19596 printf("Device does not support tessellation shaders; skipped.\n");
19597 return;
19598 }
19599
19600 char const *vsSource = "#version 450\n"
19601 "void main(){}\n";
19602 char const *tcsSource = "#version 450\n"
19603 "layout(location=0) out int x[];\n"
19604 "layout(vertices=3) out;\n"
19605 "void main(){\n"
19606 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19607 " gl_TessLevelInner[0] = 1;\n"
19608 " x[gl_InvocationID] = gl_InvocationID;\n"
19609 "}\n";
19610 char const *tesSource = "#version 450\n"
19611 "layout(triangles, equal_spacing, cw) in;\n"
19612 "layout(location=0) in int x[];\n"
19613 "out gl_PerVertex { vec4 gl_Position; };\n"
19614 "void main(){\n"
19615 " gl_Position.xyz = gl_TessCoord;\n"
19616 " gl_Position.w = x[0] + x[1] + x[2];\n"
19617 "}\n";
19618 char const *fsSource = "#version 450\n"
19619 "layout(location=0) out vec4 color;\n"
19620 "void main(){\n"
19621 " color = vec4(1);\n"
19622 "}\n";
19623
19624 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19625 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19626 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19627 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19628
19629 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19630 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19631
19632 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19633
19634 VkPipelineObj pipe(m_device);
19635 pipe.SetInputAssembly(&iasci);
19636 pipe.SetTessellation(&tsci);
19637 pipe.AddColorAttachment();
19638 pipe.AddShader(&vs);
19639 pipe.AddShader(&tcs);
19640 pipe.AddShader(&tes);
19641 pipe.AddShader(&fs);
19642
19643 VkDescriptorSetObj descriptorSet(m_device);
19644 descriptorSet.AppendDummy();
19645 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19646
19647 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19648
19649 m_errorMonitor->VerifyNotFound();
19650}
19651
19652TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19653 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19654 "interface block passed into the geometry shader. This "
19655 "is interesting because the 'extra' array level is not "
19656 "present on the member type, but on the block instance.");
19657 m_errorMonitor->ExpectSuccess();
19658
19659 ASSERT_NO_FATAL_FAILURE(InitState());
19660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19661
19662 if (!m_device->phy().features().geometryShader) {
19663 printf("Device does not support geometry shaders; skipped.\n");
19664 return;
19665 }
19666
19667 char const *vsSource = "#version 450\n"
19668 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19669 "void main(){\n"
19670 " vs_out.x = vec4(1);\n"
19671 "}\n";
19672 char const *gsSource = "#version 450\n"
19673 "layout(triangles) in;\n"
19674 "layout(triangle_strip, max_vertices=3) out;\n"
19675 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19676 "out gl_PerVertex { vec4 gl_Position; };\n"
19677 "void main() {\n"
19678 " gl_Position = gs_in[0].x;\n"
19679 " EmitVertex();\n"
19680 "}\n";
19681 char const *fsSource = "#version 450\n"
19682 "layout(location=0) out vec4 color;\n"
19683 "void main(){\n"
19684 " color = vec4(1);\n"
19685 "}\n";
19686
19687 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19688 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19689 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19690
19691 VkPipelineObj pipe(m_device);
19692 pipe.AddColorAttachment();
19693 pipe.AddShader(&vs);
19694 pipe.AddShader(&gs);
19695 pipe.AddShader(&fs);
19696
19697 VkDescriptorSetObj descriptorSet(m_device);
19698 descriptorSet.AppendDummy();
19699 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19700
19701 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19702
19703 m_errorMonitor->VerifyNotFound();
19704}
19705
19706TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19707 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19708 "attributes. This is interesting because they consume multiple "
19709 "locations.");
19710 m_errorMonitor->ExpectSuccess();
19711
19712 ASSERT_NO_FATAL_FAILURE(InitState());
19713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19714
19715 if (!m_device->phy().features().shaderFloat64) {
19716 printf("Device does not support 64bit vertex attributes; skipped.\n");
19717 return;
19718 }
19719
19720 VkVertexInputBindingDescription input_bindings[1];
19721 memset(input_bindings, 0, sizeof(input_bindings));
19722
19723 VkVertexInputAttributeDescription input_attribs[4];
19724 memset(input_attribs, 0, sizeof(input_attribs));
19725 input_attribs[0].location = 0;
19726 input_attribs[0].offset = 0;
19727 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19728 input_attribs[1].location = 2;
19729 input_attribs[1].offset = 32;
19730 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19731 input_attribs[2].location = 4;
19732 input_attribs[2].offset = 64;
19733 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19734 input_attribs[3].location = 6;
19735 input_attribs[3].offset = 96;
19736 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19737
19738 char const *vsSource = "#version 450\n"
19739 "\n"
19740 "layout(location=0) in dmat4 x;\n"
19741 "out gl_PerVertex {\n"
19742 " vec4 gl_Position;\n"
19743 "};\n"
19744 "void main(){\n"
19745 " gl_Position = vec4(x[0][0]);\n"
19746 "}\n";
19747 char const *fsSource = "#version 450\n"
19748 "\n"
19749 "layout(location=0) out vec4 color;\n"
19750 "void main(){\n"
19751 " color = vec4(1);\n"
19752 "}\n";
19753
19754 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19755 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19756
19757 VkPipelineObj pipe(m_device);
19758 pipe.AddColorAttachment();
19759 pipe.AddShader(&vs);
19760 pipe.AddShader(&fs);
19761
19762 pipe.AddVertexInputBindings(input_bindings, 1);
19763 pipe.AddVertexInputAttribs(input_attribs, 4);
19764
19765 VkDescriptorSetObj descriptorSet(m_device);
19766 descriptorSet.AppendDummy();
19767 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19768
19769 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19770
19771 m_errorMonitor->VerifyNotFound();
19772}
19773
19774TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19775 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19776 m_errorMonitor->ExpectSuccess();
19777
19778 ASSERT_NO_FATAL_FAILURE(InitState());
19779
19780 char const *vsSource = "#version 450\n"
19781 "\n"
19782 "out gl_PerVertex {\n"
19783 " vec4 gl_Position;\n"
19784 "};\n"
19785 "void main(){\n"
19786 " gl_Position = vec4(1);\n"
19787 "}\n";
19788 char const *fsSource = "#version 450\n"
19789 "\n"
19790 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19791 "layout(location=0) out vec4 color;\n"
19792 "void main() {\n"
19793 " color = subpassLoad(x);\n"
19794 "}\n";
19795
19796 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19797 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19798
19799 VkPipelineObj pipe(m_device);
19800 pipe.AddShader(&vs);
19801 pipe.AddShader(&fs);
19802 pipe.AddColorAttachment();
19803 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19804
19805 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19806 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19807 VkDescriptorSetLayout dsl;
19808 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19809 ASSERT_VK_SUCCESS(err);
19810
19811 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19812 VkPipelineLayout pl;
19813 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19814 ASSERT_VK_SUCCESS(err);
19815
19816 VkAttachmentDescription descs[2] = {
19817 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19818 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19819 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19820 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19821 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19822 };
19823 VkAttachmentReference color = {
19824 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19825 };
19826 VkAttachmentReference input = {
19827 1, VK_IMAGE_LAYOUT_GENERAL,
19828 };
19829
19830 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19831
19832 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19833 VkRenderPass rp;
19834 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19835 ASSERT_VK_SUCCESS(err);
19836
19837 // should be OK. would go wrong here if it's going to...
19838 pipe.CreateVKPipeline(pl, rp);
19839
19840 m_errorMonitor->VerifyNotFound();
19841
19842 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19843 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19844 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19845}
19846
19847TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19848 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19849 "descriptor-backed resource which is not provided, but the shader does not "
19850 "statically use it. This is interesting because it requires compute pipelines "
19851 "to have a proper descriptor use walk, which they didn't for some time.");
19852 m_errorMonitor->ExpectSuccess();
19853
19854 ASSERT_NO_FATAL_FAILURE(InitState());
19855
19856 char const *csSource = "#version 450\n"
19857 "\n"
19858 "layout(local_size_x=1) in;\n"
19859 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19860 "void main(){\n"
19861 " // x is not used.\n"
19862 "}\n";
19863
19864 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19865
19866 VkDescriptorSetObj descriptorSet(m_device);
19867 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19868
19869 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19870 nullptr,
19871 0,
19872 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19873 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19874 descriptorSet.GetPipelineLayout(),
19875 VK_NULL_HANDLE,
19876 -1 };
19877
19878 VkPipeline pipe;
19879 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19880
19881 m_errorMonitor->VerifyNotFound();
19882
19883 if (err == VK_SUCCESS) {
19884 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19885 }
19886}
19887
19888TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19889 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19890 "sampler portion of a combined image + sampler");
19891 m_errorMonitor->ExpectSuccess();
19892
19893 ASSERT_NO_FATAL_FAILURE(InitState());
19894
19895 VkDescriptorSetLayoutBinding bindings[] = {
19896 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19897 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19898 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19899 };
19900 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19901 VkDescriptorSetLayout dsl;
19902 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19903 ASSERT_VK_SUCCESS(err);
19904
19905 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19906 VkPipelineLayout pl;
19907 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19908 ASSERT_VK_SUCCESS(err);
19909
19910 char const *csSource = "#version 450\n"
19911 "\n"
19912 "layout(local_size_x=1) in;\n"
19913 "layout(set=0, binding=0) uniform sampler s;\n"
19914 "layout(set=0, binding=1) uniform texture2D t;\n"
19915 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19916 "void main() {\n"
19917 " x = texture(sampler2D(t, s), vec2(0));\n"
19918 "}\n";
19919 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19920
19921 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19922 nullptr,
19923 0,
19924 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19925 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19926 pl,
19927 VK_NULL_HANDLE,
19928 -1 };
19929
19930 VkPipeline pipe;
19931 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19932
19933 m_errorMonitor->VerifyNotFound();
19934
19935 if (err == VK_SUCCESS) {
19936 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19937 }
19938
19939 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19940 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19941}
19942
19943TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19944 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19945 "image portion of a combined image + sampler");
19946 m_errorMonitor->ExpectSuccess();
19947
19948 ASSERT_NO_FATAL_FAILURE(InitState());
19949
19950 VkDescriptorSetLayoutBinding bindings[] = {
19951 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19952 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19953 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19954 };
19955 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19956 VkDescriptorSetLayout dsl;
19957 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19958 ASSERT_VK_SUCCESS(err);
19959
19960 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19961 VkPipelineLayout pl;
19962 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19963 ASSERT_VK_SUCCESS(err);
19964
19965 char const *csSource = "#version 450\n"
19966 "\n"
19967 "layout(local_size_x=1) in;\n"
19968 "layout(set=0, binding=0) uniform texture2D t;\n"
19969 "layout(set=0, binding=1) uniform sampler s;\n"
19970 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19971 "void main() {\n"
19972 " x = texture(sampler2D(t, s), vec2(0));\n"
19973 "}\n";
19974 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19975
19976 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19977 nullptr,
19978 0,
19979 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19980 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19981 pl,
19982 VK_NULL_HANDLE,
19983 -1 };
19984
19985 VkPipeline pipe;
19986 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19987
19988 m_errorMonitor->VerifyNotFound();
19989
19990 if (err == VK_SUCCESS) {
19991 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19992 }
19993
19994 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19995 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19996}
19997
19998TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19999 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
20000 "both the sampler and the image of a combined image+sampler "
20001 "but via separate variables");
20002 m_errorMonitor->ExpectSuccess();
20003
20004 ASSERT_NO_FATAL_FAILURE(InitState());
20005
20006 VkDescriptorSetLayoutBinding bindings[] = {
20007 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20008 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20009 };
20010 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
20011 VkDescriptorSetLayout dsl;
20012 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20013 ASSERT_VK_SUCCESS(err);
20014
20015 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20016 VkPipelineLayout pl;
20017 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20018 ASSERT_VK_SUCCESS(err);
20019
20020 char const *csSource = "#version 450\n"
20021 "\n"
20022 "layout(local_size_x=1) in;\n"
20023 "layout(set=0, binding=0) uniform texture2D t;\n"
20024 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20025 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20026 "void main() {\n"
20027 " x = texture(sampler2D(t, s), vec2(0));\n"
20028 "}\n";
20029 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20030
20031 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20032 nullptr,
20033 0,
20034 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20035 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20036 pl,
20037 VK_NULL_HANDLE,
20038 -1 };
20039
20040 VkPipeline pipe;
20041 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20042
20043 m_errorMonitor->VerifyNotFound();
20044
20045 if (err == VK_SUCCESS) {
20046 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20047 }
20048
20049 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20050 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20051}
20052
20053TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20054 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20055
20056 ASSERT_NO_FATAL_FAILURE(InitState());
20057
20058 // Positive test to check parameter_validation and unique_objects support
20059 // for NV_dedicated_allocation
20060 uint32_t extension_count = 0;
20061 bool supports_nv_dedicated_allocation = false;
20062 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20063 ASSERT_VK_SUCCESS(err);
20064
20065 if (extension_count > 0) {
20066 std::vector<VkExtensionProperties> available_extensions(extension_count);
20067
20068 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20069 ASSERT_VK_SUCCESS(err);
20070
20071 for (const auto &extension_props : available_extensions) {
20072 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20073 supports_nv_dedicated_allocation = true;
20074 }
20075 }
20076 }
20077
20078 if (supports_nv_dedicated_allocation) {
20079 m_errorMonitor->ExpectSuccess();
20080
20081 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20082 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20083 dedicated_buffer_create_info.pNext = nullptr;
20084 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20085
20086 uint32_t queue_family_index = 0;
20087 VkBufferCreateInfo buffer_create_info = {};
20088 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20089 buffer_create_info.pNext = &dedicated_buffer_create_info;
20090 buffer_create_info.size = 1024;
20091 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20092 buffer_create_info.queueFamilyIndexCount = 1;
20093 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20094
20095 VkBuffer buffer;
20096 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20097 ASSERT_VK_SUCCESS(err);
20098
20099 VkMemoryRequirements memory_reqs;
20100 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20101
20102 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20103 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20104 dedicated_memory_info.pNext = nullptr;
20105 dedicated_memory_info.buffer = buffer;
20106 dedicated_memory_info.image = VK_NULL_HANDLE;
20107
20108 VkMemoryAllocateInfo memory_info = {};
20109 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20110 memory_info.pNext = &dedicated_memory_info;
20111 memory_info.allocationSize = memory_reqs.size;
20112
20113 bool pass;
20114 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20115 ASSERT_TRUE(pass);
20116
20117 VkDeviceMemory buffer_memory;
20118 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20119 ASSERT_VK_SUCCESS(err);
20120
20121 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20122 ASSERT_VK_SUCCESS(err);
20123
20124 vkDestroyBuffer(m_device->device(), buffer, NULL);
20125 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20126
20127 m_errorMonitor->VerifyNotFound();
20128 }
20129}
20130
20131TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20132 VkResult err;
20133
20134 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20135
20136 ASSERT_NO_FATAL_FAILURE(InitState());
20137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20138
20139 std::vector<const char *> device_extension_names;
20140 auto features = m_device->phy().features();
20141 // Artificially disable support for non-solid fill modes
20142 features.fillModeNonSolid = false;
20143 // The sacrificial device object
20144 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20145
20146 VkRenderpassObj render_pass(&test_device);
20147
20148 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20149 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20150 pipeline_layout_ci.setLayoutCount = 0;
20151 pipeline_layout_ci.pSetLayouts = NULL;
20152
20153 VkPipelineLayout pipeline_layout;
20154 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20155 ASSERT_VK_SUCCESS(err);
20156
20157 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20158 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20159 rs_ci.pNext = nullptr;
20160 rs_ci.lineWidth = 1.0f;
20161 rs_ci.rasterizerDiscardEnable = true;
20162
20163 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20164 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20165
20166 // Set polygonMode=FILL. No error is expected
20167 m_errorMonitor->ExpectSuccess();
20168 {
20169 VkPipelineObj pipe(&test_device);
20170 pipe.AddShader(&vs);
20171 pipe.AddShader(&fs);
20172 pipe.AddColorAttachment();
20173 // Set polygonMode to a good value
20174 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20175 pipe.SetRasterization(&rs_ci);
20176 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20177 }
20178 m_errorMonitor->VerifyNotFound();
20179
20180 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20181}
20182
20183TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20184 VkResult err;
20185 ASSERT_NO_FATAL_FAILURE(InitState());
20186 ASSERT_NO_FATAL_FAILURE(InitViewport());
20187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20188
20189 VkPipelineLayout pipeline_layout;
20190 VkPushConstantRange pc_range = {};
20191 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20192 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20193 pipeline_layout_ci.pushConstantRangeCount = 1;
20194 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20195
20196 //
20197 // Check for invalid push constant ranges in pipeline layouts.
20198 //
20199 struct PipelineLayoutTestCase {
20200 VkPushConstantRange const range;
20201 char const *msg;
20202 };
20203
20204 // Check for overlapping ranges
20205 const uint32_t ranges_per_test = 5;
20206 struct OverlappingRangeTestCase {
20207 VkPushConstantRange const ranges[ranges_per_test];
20208 char const *msg;
20209 };
20210
20211 // Run some positive tests to make sure overlap checking in the layer is OK
20212 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20213 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20214 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20215 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20216 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20217 "" },
20218 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20219 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20220 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20221 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20222 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20223 "" } } };
20224 for (const auto &iter : overlapping_range_tests_pos) {
20225 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20226 m_errorMonitor->ExpectSuccess();
20227 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20228 m_errorMonitor->VerifyNotFound();
20229 if (VK_SUCCESS == err) {
20230 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20231 }
20232 }
20233
20234 //
20235 // CmdPushConstants tests
20236 //
20237 const uint8_t dummy_values[100] = {};
20238
20239 BeginCommandBuffer();
20240
20241 // positive overlapping range tests with cmd
20242 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20243 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20244 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20245 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20246 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20247 } };
20248
20249 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20250 const VkPushConstantRange pc_range4[] = {
20251 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20252 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20253 };
20254
20255 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20256 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20257 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20258 ASSERT_VK_SUCCESS(err);
20259 for (const auto &iter : cmd_overlap_tests_pos) {
20260 m_errorMonitor->ExpectSuccess();
20261 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20262 iter.range.size, dummy_values);
20263 m_errorMonitor->VerifyNotFound();
20264 }
20265 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20266
20267 EndCommandBuffer();
20268}
20269
20270
20271
20272
20273
20274
20275
20276#if 0 // A few devices have issues with this test so disabling for now
20277TEST_F(VkPositiveLayerTest, LongFenceChain)
20278{
20279 m_errorMonitor->ExpectSuccess();
20280
20281 ASSERT_NO_FATAL_FAILURE(InitState());
20282 VkResult err;
20283
20284 std::vector<VkFence> fences;
20285
20286 const int chainLength = 32768;
20287
20288 for (int i = 0; i < chainLength; i++) {
20289 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20290 VkFence fence;
20291 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20292 ASSERT_VK_SUCCESS(err);
20293
20294 fences.push_back(fence);
20295
20296 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20297 0, nullptr, 0, nullptr };
20298 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20299 ASSERT_VK_SUCCESS(err);
20300
20301 }
20302
20303 // BOOM, stack overflow.
20304 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20305
20306 for (auto fence : fences)
20307 vkDestroyFence(m_device->device(), fence, nullptr);
20308
20309 m_errorMonitor->VerifyNotFound();
20310}
20311#endif
20312
20313
Cody Northrop1242dfd2016-07-13 17:24:59 -060020314#if defined(ANDROID) && defined(VALIDATION_APK)
20315static bool initialized = false;
20316static bool active = false;
20317
20318// Convert Intents to argv
20319// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020320std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020321 std::vector<std::string> args;
20322 JavaVM &vm = *app.activity->vm;
20323 JNIEnv *p_env;
20324 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20325 return args;
20326
20327 JNIEnv &env = *p_env;
20328 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020329 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020330 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020331 jmethodID get_string_extra_method =
20332 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020333 jvalue get_string_extra_args;
20334 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020335 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020336
20337 std::string args_str;
20338 if (extra_str) {
20339 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20340 args_str = extra_utf;
20341 env.ReleaseStringUTFChars(extra_str, extra_utf);
20342 env.DeleteLocalRef(extra_str);
20343 }
20344
20345 env.DeleteLocalRef(get_string_extra_args.l);
20346 env.DeleteLocalRef(intent);
20347 vm.DetachCurrentThread();
20348
20349 // split args_str
20350 std::stringstream ss(args_str);
20351 std::string arg;
20352 while (std::getline(ss, arg, ' ')) {
20353 if (!arg.empty())
20354 args.push_back(arg);
20355 }
20356
20357 return args;
20358}
20359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020360static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020361
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020362static void processCommand(struct android_app *app, int32_t cmd) {
20363 switch (cmd) {
20364 case APP_CMD_INIT_WINDOW: {
20365 if (app->window) {
20366 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020367 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020368 break;
20369 }
20370 case APP_CMD_GAINED_FOCUS: {
20371 active = true;
20372 break;
20373 }
20374 case APP_CMD_LOST_FOCUS: {
20375 active = false;
20376 break;
20377 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020378 }
20379}
20380
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020381void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020382 app_dummy();
20383
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020384 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020385
20386 int vulkanSupport = InitVulkan();
20387 if (vulkanSupport == 0) {
20388 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20389 return;
20390 }
20391
20392 app->onAppCmd = processCommand;
20393 app->onInputEvent = processInput;
20394
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020395 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020396 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020397 struct android_poll_source *source;
20398 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020399 if (source) {
20400 source->process(app, source);
20401 }
20402
20403 if (app->destroyRequested != 0) {
20404 VkTestFramework::Finish();
20405 return;
20406 }
20407 }
20408
20409 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020410 // Use the following key to send arguments to gtest, i.e.
20411 // --es args "--gtest_filter=-VkLayerTest.foo"
20412 const char key[] = "args";
20413 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020414
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020415 std::string filter = "";
20416 if (args.size() > 0) {
20417 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20418 filter += args[0];
20419 } else {
20420 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20421 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020423 int argc = 2;
20424 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20425 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020426
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020427 // Route output to files until we can override the gtest output
20428 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20429 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020430
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020431 ::testing::InitGoogleTest(&argc, argv);
20432 VkTestFramework::InitArgs(&argc, argv);
20433 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020434
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020435 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020436
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020437 if (result != 0) {
20438 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20439 } else {
20440 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20441 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020443 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020445 fclose(stdout);
20446 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020448 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020450 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020451 }
20452 }
20453}
20454#endif
20455
Tony Barbour300a6082015-04-07 13:44:53 -060020456int main(int argc, char **argv) {
20457 int result;
20458
Cody Northrop8e54a402016-03-08 22:25:52 -070020459#ifdef ANDROID
20460 int vulkanSupport = InitVulkan();
20461 if (vulkanSupport == 0)
20462 return 1;
20463#endif
20464
Tony Barbour300a6082015-04-07 13:44:53 -060020465 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020466 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020467
20468 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20469
20470 result = RUN_ALL_TESTS();
20471
Tony Barbour6918cd52015-04-09 12:58:51 -060020472 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020473 return result;
20474}