blob: d3dc8c2f2504b09414328cc42b0791238a262229 [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;
175 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600176 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600177 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600178 m_msgFound = VK_TRUE;
179 result = VK_TRUE;
180 // We only want one match for each expected error so remove from set here
181 // 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 -0600182 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600183 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186 for (auto desired_id : m_desired_message_ids) {
187 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
188 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
189 // Return true to avoid calling layers/driver with this error.
190 result = VK_TRUE;
191 } else if (desired_id == message_code) {
192 // Double-check that the string matches the error enum
193 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
194 found_expected = true;
195 result = VK_TRUE;
196 m_msgFound = VK_TRUE;
197 m_desired_message_ids.erase(desired_id);
198 break;
199 } else {
200 // Treat this message as a regular unexpected error, but print a warning jic
201 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
202 errorString.c_str(), desired_id, validation_error_map[desired_id]);
203 }
204 }
205 }
206
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600207 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200208 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600209 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600210 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600211 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600212 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600213 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600214
Karl Schultz6addd812016-02-02 17:17:23 -0700215 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600217 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
218
Karl Schultz6addd812016-02-02 17:17:23 -0700219 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600220
Karl Schultz6addd812016-02-02 17:17:23 -0700221 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600222
Karl Schultz6addd812016-02-02 17:17:23 -0700223 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600224 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600225 if (otherMsgs.size()) {
226 cout << "Other error messages logged for this test were:" << endl;
227 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
228 cout << " " << *iter << endl;
229 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600230 }
231 }
232
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600233 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200234
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600235 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
236 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
237 m_msgFlags = message_flag_mask;
238 // Match ANY message matching specified type
239 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200240 }
241
242 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600243 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200244 if (!DesiredMsgFound()) {
245 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600246 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600247 FAIL() << "Did not receive expected error '" << desired_msg << "'";
248 }
Tony Barbour59b42282016-11-03 13:31:28 -0600249 for (auto desired_id : m_desired_message_ids) {
250 FAIL() << "Did not receive expected error '" << desired_id << "'";
251 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200252 }
253 }
254
255 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600256 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200257 if (DesiredMsgFound()) {
258 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600259 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600260 FAIL() << "Expected to succeed but got error: " << msg;
261 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262 }
263 }
264
Karl Schultz6addd812016-02-02 17:17:23 -0700265 private:
266 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600267 std::unordered_set<uint32_t>m_desired_message_ids;
268 std::unordered_set<string> m_desired_message_strings;
269 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700270 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600271 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700272 bool *m_bailout;
273 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600274};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500275
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600276static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
277 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
278 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
280 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600281 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600282 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600283 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600284}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500285
Karl Schultz6addd812016-02-02 17:17:23 -0700286class VkLayerTest : public VkRenderFramework {
287 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800288 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
289 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600290 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
291 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700292 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
294 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700295 }
Tony Barbour300a6082015-04-07 13:44:53 -0600296
Tony Barbourfe3351b2015-07-28 10:17:20 -0600297 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800299 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600300 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
301 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700302 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700304 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700306 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600307 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
308 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
309 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700310 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
311 }
312 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
313 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
314 }
315
316 protected:
317 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600318 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600319
320 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600321 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600322 std::vector<const char *> instance_extension_names;
323 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600324
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700325 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600326 /*
327 * Since CreateDbgMsgCallback is an instance level extension call
328 * any extension / layer that utilizes that feature also needs
329 * to be enabled at create instance time.
330 */
Karl Schultz6addd812016-02-02 17:17:23 -0700331 // Use Threading layer first to protect others from
332 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700333 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600334 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800335 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700336 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800337 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600338 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700339 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600340
Ian Elliott2c1daf52016-05-12 09:41:46 -0600341 if (m_enableWSI) {
342 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
343 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
344#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
345#if defined(VK_USE_PLATFORM_ANDROID_KHR)
346 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
347#endif // VK_USE_PLATFORM_ANDROID_KHR
348#if defined(VK_USE_PLATFORM_MIR_KHR)
349 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_MIR_KHR
351#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
352 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_WAYLAND_KHR
354#if defined(VK_USE_PLATFORM_WIN32_KHR)
355 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WIN32_KHR
357#endif // NEED_TO_TEST_THIS_ON_PLATFORM
358#if defined(VK_USE_PLATFORM_XCB_KHR)
359 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
360#elif defined(VK_USE_PLATFORM_XLIB_KHR)
361 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
362#endif // VK_USE_PLATFORM_XLIB_KHR
363 }
364
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600366 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800367 this->app_info.pApplicationName = "layer_tests";
368 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pEngineName = "unittest";
370 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600371 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600372
Tony Barbour15524c32015-04-29 17:34:29 -0600373 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600374 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600375 }
376
377 virtual void TearDown() {
378 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600379 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600380 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600381 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600382
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600383 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600384};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385
Karl Schultz6addd812016-02-02 17:17:23 -0700386VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600387 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600388
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600390
391 /*
392 * For render test all drawing happens in a single render pass
393 * on a single command buffer.
394 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200395 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800396 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600397 }
398
399 return result;
400}
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600404
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200405 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800406 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200407 }
Tony Barbour300a6082015-04-07 13:44:53 -0600408
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600410
411 return result;
412}
413
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600414void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500415 // Create identity matrix
416 int i;
417 struct vktriangle_vs_uniform data;
418
419 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700420 glm::mat4 View = glm::mat4(1.0f);
421 glm::mat4 Model = glm::mat4(1.0f);
422 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700424 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425
426 memcpy(&data.mvp, &MVP[0][0], matrixSize);
427
Karl Schultz6addd812016-02-02 17:17:23 -0700428 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600429 {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 -0500430 };
431
Karl Schultz6addd812016-02-02 17:17:23 -0700432 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 data.position[i][0] = tri_data[i].posX;
434 data.position[i][1] = tri_data[i].posY;
435 data.position[i][2] = tri_data[i].posZ;
436 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700437 data.color[i][0] = tri_data[i].r;
438 data.color[i][1] = tri_data[i].g;
439 data.color[i][2] = tri_data[i].b;
440 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441 }
442
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 ASSERT_NO_FATAL_FAILURE(InitViewport());
444
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200445 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
446 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Karl Schultz6addd812016-02-02 17:17:23 -0700448 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600449 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
451 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800452 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 pipelineobj.AddShader(&vs);
454 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 if (failMask & BsoFailLineWidth) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600458 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600459 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
460 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBias) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600464 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600465 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600466 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600467 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600468 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 }
Karl Schultz6addd812016-02-02 17:17:23 -0700470 // Viewport and scissors must stay in synch or other errors will occur than
471 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 if (failMask & BsoFailViewport) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
474 }
475 if (failMask & BsoFailScissor) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
477 }
478 if (failMask & BsoFailBlend) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 VkPipelineColorBlendAttachmentState att_state = {};
481 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
482 att_state.blendEnable = VK_TRUE;
483 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600484 }
485 if (failMask & BsoFailDepthBounds) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
487 }
488 if (failMask & BsoFailStencilReadMask) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
490 }
491 if (failMask & BsoFailStencilWriteMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
493 }
494 if (failMask & BsoFailStencilReference) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
496 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497
498 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600502 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
Tony Barbourfe3351b2015-07-28 10:17:20 -0600504 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500505
506 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600507 if (failMask & BsoFailIndexBuffer) {
508 // Use DrawIndexed w/o an index buffer bound
509 DrawIndexed(3, 1, 0, 0, 0);
510 } else {
511 Draw(3, 1, 0, 0);
512 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513
Mark Muellerd4914412016-06-13 17:52:06 -0600514 if (failMask & BsoFailCmdClearAttachments) {
515 VkClearAttachment color_attachment = {};
516 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
517 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
518 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
519
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600521 }
522
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600524 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525
Tony Barbourfe3351b2015-07-28 10:17:20 -0600526 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500527}
528
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600529void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
530 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600534 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535 }
536
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700538 // Make sure depthWriteEnable is set so that Depth fail test will work
539 // correctly
540 // Make sure stencilTestEnable is set so that Stencil fail test will work
541 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600542 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800543 stencil.failOp = VK_STENCIL_OP_KEEP;
544 stencil.passOp = VK_STENCIL_OP_KEEP;
545 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
546 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600547
548 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
549 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600550 ds_ci.pNext = NULL;
551 ds_ci.depthTestEnable = VK_FALSE;
552 ds_ci.depthWriteEnable = VK_TRUE;
553 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
554 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600555 if (failMask & BsoFailDepthBounds) {
556 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600557 ds_ci.maxDepthBounds = 0.0f;
558 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600559 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600560 ds_ci.stencilTestEnable = VK_TRUE;
561 ds_ci.front = stencil;
562 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600563
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600564 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600565 pipelineobj.SetViewport(m_viewports);
566 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800567 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600568 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600569 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 commandBuffer->BindPipeline(pipelineobj);
571 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500572}
573
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600574class VkPositiveLayerTest : public VkLayerTest {
575 public:
576 protected:
577};
578
Ian Elliott2c1daf52016-05-12 09:41:46 -0600579class VkWsiEnabledLayerTest : public VkLayerTest {
580 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 protected:
582 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600583};
584
Mark Muellerdfe37552016-07-07 14:47:42 -0600585class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600587 enum eTestEnFlags {
588 eDoubleDelete,
589 eInvalidDeviceOffset,
590 eInvalidMemoryOffset,
591 eBindNullBuffer,
592 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600593 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 };
595
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600596 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
599 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 return true;
601 }
602 VkDeviceSize offset_limit = 0;
603 if (eInvalidMemoryOffset == aTestFlag) {
604 VkBuffer vulkanBuffer;
605 VkBufferCreateInfo buffer_create_info = {};
606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
607 buffer_create_info.size = 32;
608 buffer_create_info.usage = aBufferUsage;
609
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600611 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
615 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
617 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600618 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600620 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 }
623 if (eOffsetAlignment < offset_limit) {
624 return true;
625 }
626 return false;
627 }
628
629 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
631 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 if (eBindNullBuffer == aTestFlag) {
634 VulkanMemory = 0;
635 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
636 } else {
637 VkBufferCreateInfo buffer_create_info = {};
638 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
639 buffer_create_info.size = 32;
640 buffer_create_info.usage = aBufferUsage;
641
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600643
644 CreateCurrent = true;
645
646 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600647 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600648
649 VkMemoryAllocateInfo memory_allocate_info = {};
650 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
651 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
653 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 if (!pass) {
655 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
656 return;
657 }
658
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600659 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600660 AllocateCurrent = true;
661 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
663 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 BoundCurrent = true;
665
666 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
667 }
668 }
669
670 ~VkBufferTest() {
671 if (CreateCurrent) {
672 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
673 }
674 if (AllocateCurrent) {
675 if (InvalidDeleteEn) {
676 union {
677 VkDeviceMemory device_memory;
678 unsigned long long index_access;
679 } bad_index;
680
681 bad_index.device_memory = VulkanMemory;
682 bad_index.index_access++;
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 }
686 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
687 }
688 }
689
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600690 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600691
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600693
694 void TestDoubleDestroy() {
695 // Destroy the buffer but leave the flag set, which will cause
696 // the buffer to be destroyed again in the destructor.
697 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600701 bool AllocateCurrent;
702 bool BoundCurrent;
703 bool CreateCurrent;
704 bool InvalidDeleteEn;
705
706 VkBuffer VulkanBuffer;
707 VkDevice VulkanDevice;
708 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600709};
710
711class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 public:
713 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600714 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600716 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
718 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 BindIdGenerator++; // NB: This can wrap w/misuse
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
722 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
725 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
726 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
727 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
728 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729
730 unsigned i = 0;
731 do {
732 VertexInputAttributeDescription[i].binding = BindId;
733 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
735 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600736 i++;
737 } while (AttributeCount < i);
738
739 i = 0;
740 do {
741 VertexInputBindingDescription[i].binding = BindId;
742 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600743 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 i++;
745 } while (BindingCount < i);
746 }
747
748 ~VkVerticesObj() {
749 if (VertexInputAttributeDescription) {
750 delete[] VertexInputAttributeDescription;
751 }
752 if (VertexInputBindingDescription) {
753 delete[] VertexInputBindingDescription;
754 }
755 }
756
757 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
759 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600760 return true;
761 }
762
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 VkDeviceSize *offsetList;
765 unsigned offsetCount;
766
767 if (aOffsetCount) {
768 offsetList = aOffsetList;
769 offsetCount = aOffsetCount;
770 } else {
771 offsetList = new VkDeviceSize[1]();
772 offsetCount = 1;
773 }
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600776 BoundCurrent = true;
777
778 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600779 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600780 }
781 }
782
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600783 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600784 static uint32_t BindIdGenerator;
785
786 bool BoundCurrent;
787 unsigned AttributeCount;
788 unsigned BindingCount;
789 uint32_t BindId;
790
791 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
792 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
793 VkVertexInputBindingDescription *VertexInputBindingDescription;
794 VkConstantBufferObj VulkanMemoryBuffer;
795};
796
797uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500798// ********************************************************************************************************************
799// ********************************************************************************************************************
800// ********************************************************************************************************************
801// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600802#if PARAMETER_VALIDATION_TESTS
803TEST_F(VkLayerTest, RequiredParameter) {
804 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
805 "pointer, array, and array count parameters");
806
807 ASSERT_NO_FATAL_FAILURE(InitState());
808
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600810 // Specify NULL for a pointer to a handle
811 // Expected to trigger an error with
812 // parameter_validation::validate_required_pointer
813 vkGetPhysicalDeviceFeatures(gpu(), NULL);
814 m_errorMonitor->VerifyFound();
815
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
817 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600818 // Specify NULL for pointer to array count
819 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600820 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify 0 for a required array count
825 // Expected to trigger an error with parameter_validation::validate_array
826 VkViewport view_port = {};
827 m_commandBuffer->SetViewport(0, 0, &view_port);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for a required array
832 // Expected to trigger an error with parameter_validation::validate_array
833 m_commandBuffer->SetViewport(0, 1, NULL);
834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify VK_NULL_HANDLE for a required handle
838 // Expected to trigger an error with
839 // parameter_validation::validate_required_handle
840 vkUnmapMemory(device(), VK_NULL_HANDLE);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845 // Specify VK_NULL_HANDLE for a required handle array entry
846 // Expected to trigger an error with
847 // parameter_validation::validate_required_handle_array
848 VkFence fence = VK_NULL_HANDLE;
849 vkResetFences(device(), 1, &fence);
850 m_errorMonitor->VerifyFound();
851
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600853 // Specify NULL for a required struct pointer
854 // Expected to trigger an error with
855 // parameter_validation::validate_struct_type
856 VkDeviceMemory memory = VK_NULL_HANDLE;
857 vkAllocateMemory(device(), NULL, NULL, &memory);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required VkFlags parameter
862 // Expected to trigger an error with parameter_validation::validate_flags
863 m_commandBuffer->SetStencilReference(0, 0);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 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 -0600867 // Specify 0 for a required VkFlags array entry
868 // Expected to trigger an error with
869 // parameter_validation::validate_flags_array
870 VkSemaphore semaphore = VK_NULL_HANDLE;
871 VkPipelineStageFlags stageFlags = 0;
872 VkSubmitInfo submitInfo = {};
873 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
874 submitInfo.waitSemaphoreCount = 1;
875 submitInfo.pWaitSemaphores = &semaphore;
876 submitInfo.pWaitDstStageMask = &stageFlags;
877 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600880
Dustin Gravesfce74c02016-05-10 11:42:58 -0600881TEST_F(VkLayerTest, ReservedParameter) {
882 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
883
884 ASSERT_NO_FATAL_FAILURE(InitState());
885
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600887 // Specify 0 for a reserved VkFlags parameter
888 // Expected to trigger an error with
889 // parameter_validation::validate_reserved_flags
890 VkEvent event_handle = VK_NULL_HANDLE;
891 VkEventCreateInfo event_info = {};
892 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
893 event_info.flags = 1;
894 vkCreateEvent(device(), &event_info, NULL, &event_handle);
895 m_errorMonitor->VerifyFound();
896}
897
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600898TEST_F(VkLayerTest, InvalidStructSType) {
899 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
900 "structure's sType field");
901
902 ASSERT_NO_FATAL_FAILURE(InitState());
903
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600905 // Zero struct memory, effectively setting sType to
906 // VK_STRUCTURE_TYPE_APPLICATION_INFO
907 // Expected to trigger an error with
908 // parameter_validation::validate_struct_type
909 VkMemoryAllocateInfo alloc_info = {};
910 VkDeviceMemory memory = VK_NULL_HANDLE;
911 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
912 m_errorMonitor->VerifyFound();
913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915 // Zero struct memory, effectively setting sType to
916 // VK_STRUCTURE_TYPE_APPLICATION_INFO
917 // Expected to trigger an error with
918 // parameter_validation::validate_struct_type_array
919 VkSubmitInfo submit_info = {};
920 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
921 m_errorMonitor->VerifyFound();
922}
923
924TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600925 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600926
927 ASSERT_NO_FATAL_FAILURE(InitState());
928
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600930 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600931 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600932 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600933 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600934 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600935 // Zero-initialization will provide the correct sType
936 VkApplicationInfo app_info = {};
937 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
938 event_alloc_info.pNext = &app_info;
939 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
940 m_errorMonitor->VerifyFound();
941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
943 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
945 // a function that has allowed pNext structure types and specify
946 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600947 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600949 VkMemoryAllocateInfo memory_alloc_info = {};
950 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
951 memory_alloc_info.pNext = &app_info;
952 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600954}
Dustin Graves5d33d532016-05-09 16:21:12 -0600955
956TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959 ASSERT_NO_FATAL_FAILURE(InitState());
960
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
962 "range of the core VkFormat "
963 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 // Specify an invalid VkFormat value
965 // Expected to trigger an error with
966 // parameter_validation::validate_ranged_enum
967 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600968 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600969 m_errorMonitor->VerifyFound();
970
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 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 -0600972 // Specify an invalid VkFlags bitmask value
973 // Expected to trigger an error with parameter_validation::validate_flags
974 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
976 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600977 m_errorMonitor->VerifyFound();
978
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 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 -0600980 // Specify an invalid VkFlags array entry
981 // Expected to trigger an error with
982 // parameter_validation::validate_flags_array
983 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600984 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 VkSubmitInfo submit_info = {};
986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
987 submit_info.waitSemaphoreCount = 1;
988 submit_info.pWaitSemaphores = &semaphore;
989 submit_info.pWaitDstStageMask = &stage_flags;
990 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkBool32 value
995 // Expected to trigger a warning with
996 // parameter_validation::validate_bool32
997 VkSampler sampler = VK_NULL_HANDLE;
998 VkSamplerCreateInfo sampler_info = {};
999 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1000 sampler_info.pNext = NULL;
1001 sampler_info.magFilter = VK_FILTER_NEAREST;
1002 sampler_info.minFilter = VK_FILTER_NEAREST;
1003 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1004 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1005 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1006 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1007 sampler_info.mipLodBias = 1.0;
1008 sampler_info.maxAnisotropy = 1;
1009 sampler_info.compareEnable = VK_FALSE;
1010 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1011 sampler_info.minLod = 1.0;
1012 sampler_info.maxLod = 1.0;
1013 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1014 sampler_info.unnormalizedCoordinates = VK_FALSE;
1015 // Not VK_TRUE or VK_FALSE
1016 sampler_info.anisotropyEnable = 3;
1017 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1018 m_errorMonitor->VerifyFound();
1019}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001020
1021TEST_F(VkLayerTest, FailedReturnValue) {
1022 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001026 // Find an unsupported image format
1027 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1028 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1029 VkFormat format = static_cast<VkFormat>(f);
1030 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001031 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001032 unsupported = format;
1033 break;
1034 }
1035 }
1036
1037 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1039 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Specify an unsupported VkFormat value to generate a
1041 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1042 // Expected to trigger a warning from
1043 // parameter_validation::validate_result
1044 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1046 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1048 m_errorMonitor->VerifyFound();
1049 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001050}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001051
1052TEST_F(VkLayerTest, UpdateBufferAlignment) {
1053 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001054 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001055
1056 ASSERT_NO_FATAL_FAILURE(InitState());
1057
1058 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1059 vk_testing::Buffer buffer;
1060 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1061
1062 BeginCommandBuffer();
1063 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1066 m_errorMonitor->VerifyFound();
1067
1068 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Introduce failure by using dataSize that is < 0
1074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1077 m_errorMonitor->VerifyFound();
1078
1079 // Introduce failure by using dataSize that is > 65536
1080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001081 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001082 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1083 m_errorMonitor->VerifyFound();
1084
1085 EndCommandBuffer();
1086}
1087
1088TEST_F(VkLayerTest, FillBufferAlignment) {
1089 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1090
1091 ASSERT_NO_FATAL_FAILURE(InitState());
1092
1093 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1094 vk_testing::Buffer buffer;
1095 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1096
1097 BeginCommandBuffer();
1098
1099 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1107 m_errorMonitor->VerifyFound();
1108
1109 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1112 m_errorMonitor->VerifyFound();
1113
1114 EndCommandBuffer();
1115}
Dustin Graves40f35822016-06-23 11:12:53 -06001116
Cortd889ff92016-07-27 09:51:27 -07001117TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1118 VkResult err;
1119
1120 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001122
1123 ASSERT_NO_FATAL_FAILURE(InitState());
1124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1125
1126 std::vector<const char *> device_extension_names;
1127 auto features = m_device->phy().features();
1128 // Artificially disable support for non-solid fill modes
1129 features.fillModeNonSolid = false;
1130 // The sacrificial device object
1131 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1132
1133 VkRenderpassObj render_pass(&test_device);
1134
1135 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1136 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1137 pipeline_layout_ci.setLayoutCount = 0;
1138 pipeline_layout_ci.pSetLayouts = NULL;
1139
1140 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001141 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001142 ASSERT_VK_SUCCESS(err);
1143
1144 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1145 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1146 rs_ci.pNext = nullptr;
1147 rs_ci.lineWidth = 1.0f;
1148 rs_ci.rasterizerDiscardEnable = true;
1149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1151 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001152
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001153 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1155 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001156 {
1157 VkPipelineObj pipe(&test_device);
1158 pipe.AddShader(&vs);
1159 pipe.AddShader(&fs);
1160 pipe.AddColorAttachment();
1161 // Introduce failure by setting unsupported polygon mode
1162 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1163 pipe.SetRasterization(&rs_ci);
1164 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1165 }
1166 m_errorMonitor->VerifyFound();
1167
1168 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1170 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001171 {
1172 VkPipelineObj pipe(&test_device);
1173 pipe.AddShader(&vs);
1174 pipe.AddShader(&fs);
1175 pipe.AddColorAttachment();
1176 // Introduce failure by setting unsupported polygon mode
1177 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1178 pipe.SetRasterization(&rs_ci);
1179 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1180 }
1181 m_errorMonitor->VerifyFound();
1182
Cortd889ff92016-07-27 09:51:27 -07001183 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1184}
1185
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001186#endif // PARAMETER_VALIDATION_TESTS
1187
Tobin Ehlis0788f522015-05-26 16:11:58 -06001188#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001189#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001190TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001191{
1192 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001193 VkFenceCreateInfo fenceInfo = {};
1194 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1195 fenceInfo.pNext = NULL;
1196 fenceInfo.flags = 0;
1197
Mike Weiblencce7ec72016-10-17 19:33:05 -06001198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001199
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001200 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001201
1202 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1203 vk_testing::Buffer buffer;
1204 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001205
Tony Barbourfe3351b2015-07-28 10:17:20 -06001206 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001207 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001208 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001209
1210 testFence.init(*m_device, fenceInfo);
1211
1212 // Bypass framework since it does the waits automatically
1213 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001214 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1216 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001217 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001218 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001219 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001221 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001222 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001223 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001224
1225 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226 ASSERT_VK_SUCCESS( err );
1227
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001229 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001231 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232}
1233
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235{
1236 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001237 VkFenceCreateInfo fenceInfo = {};
1238 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1239 fenceInfo.pNext = NULL;
1240 fenceInfo.flags = 0;
1241
Mike Weiblencce7ec72016-10-17 19:33:05 -06001242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001243
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001244 ASSERT_NO_FATAL_FAILURE(InitState());
1245 ASSERT_NO_FATAL_FAILURE(InitViewport());
1246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1247
Tony Barbourfe3351b2015-07-28 10:17:20 -06001248 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001249 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001250 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251
1252 testFence.init(*m_device, fenceInfo);
1253
1254 // Bypass framework since it does the waits automatically
1255 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001256 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1258 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001261 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001264 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001265 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001266
1267 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268 ASSERT_VK_SUCCESS( err );
1269
Jon Ashburnf19916e2016-01-11 13:12:43 -07001270 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001271 VkCommandBufferBeginInfo info = {};
1272 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1273 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001274 info.renderPass = VK_NULL_HANDLE;
1275 info.subpass = 0;
1276 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001277 info.occlusionQueryEnable = VK_FALSE;
1278 info.queryFlags = 0;
1279 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001280
1281 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001282 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001284 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001285}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001286#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287
Tobin Ehlisf11be982016-05-11 13:52:53 -06001288TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1289 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1290 "buffer and image to memory such that they will alias.");
1291 VkResult err;
1292 bool pass;
1293 ASSERT_NO_FATAL_FAILURE(InitState());
1294
Tobin Ehlis077ded32016-05-12 17:39:13 -06001295 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001296 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001297 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001298 VkDeviceMemory mem; // buffer will be bound first
1299 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001300 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001301
1302 VkBufferCreateInfo buf_info = {};
1303 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1304 buf_info.pNext = NULL;
1305 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1306 buf_info.size = 256;
1307 buf_info.queueFamilyIndexCount = 0;
1308 buf_info.pQueueFamilyIndices = NULL;
1309 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1310 buf_info.flags = 0;
1311 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlis077ded32016-05-12 17:39:13 -06001314 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001315
1316 VkImageCreateInfo image_create_info = {};
1317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1318 image_create_info.pNext = NULL;
1319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1320 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1321 image_create_info.extent.width = 64;
1322 image_create_info.extent.height = 64;
1323 image_create_info.extent.depth = 1;
1324 image_create_info.mipLevels = 1;
1325 image_create_info.arrayLayers = 1;
1326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001327 // Image tiling must be optimal to trigger error when aliasing linear buffer
1328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001329 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1330 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1331 image_create_info.queueFamilyIndexCount = 0;
1332 image_create_info.pQueueFamilyIndices = NULL;
1333 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1334 image_create_info.flags = 0;
1335
Tobin Ehlisf11be982016-05-11 13:52:53 -06001336 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1337 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001338 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1339 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1342
1343 VkMemoryAllocateInfo alloc_info = {};
1344 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1345 alloc_info.pNext = NULL;
1346 alloc_info.memoryTypeIndex = 0;
1347 // Ensure memory is big enough for both bindings
1348 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001349 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1350 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001351 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001352 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001353 vkDestroyImage(m_device->device(), image, NULL);
1354 return;
1355 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1357 ASSERT_VK_SUCCESS(err);
1358 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1359 ASSERT_VK_SUCCESS(err);
1360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001362 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1364 m_errorMonitor->VerifyFound();
1365
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001366 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001367 // aliasing buffer2
1368 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1369 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001370 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1371 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001372 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001373 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001375 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 m_errorMonitor->VerifyFound();
1377
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001379 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001381 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 vkFreeMemory(m_device->device(), mem, NULL);
1383 vkFreeMemory(m_device->device(), mem_img, NULL);
1384}
1385
Tobin Ehlis35372522016-05-12 08:32:31 -06001386TEST_F(VkLayerTest, InvalidMemoryMapping) {
1387 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1388 VkResult err;
1389 bool pass;
1390 ASSERT_NO_FATAL_FAILURE(InitState());
1391
1392 VkBuffer buffer;
1393 VkDeviceMemory mem;
1394 VkMemoryRequirements mem_reqs;
1395
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001396 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1397
Tobin Ehlis35372522016-05-12 08:32:31 -06001398 VkBufferCreateInfo buf_info = {};
1399 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1400 buf_info.pNext = NULL;
1401 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1402 buf_info.size = 256;
1403 buf_info.queueFamilyIndexCount = 0;
1404 buf_info.pQueueFamilyIndices = NULL;
1405 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1406 buf_info.flags = 0;
1407 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1408 ASSERT_VK_SUCCESS(err);
1409
1410 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1411 VkMemoryAllocateInfo alloc_info = {};
1412 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1413 alloc_info.pNext = NULL;
1414 alloc_info.memoryTypeIndex = 0;
1415
1416 // Ensure memory is big enough for both bindings
1417 static const VkDeviceSize allocation_size = 0x10000;
1418 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001419 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 -06001420 if (!pass) {
1421 vkDestroyBuffer(m_device->device(), buffer, NULL);
1422 return;
1423 }
1424 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1425 ASSERT_VK_SUCCESS(err);
1426
1427 uint8_t *pData;
1428 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001429 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 -06001430 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1431 m_errorMonitor->VerifyFound();
1432 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001433 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001434 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1436 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1437 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001438 m_errorMonitor->VerifyFound();
1439
1440 // Unmap the memory to avoid re-map error
1441 vkUnmapMemory(m_device->device(), mem);
1442 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1444 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1445 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001446 m_errorMonitor->VerifyFound();
1447 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1449 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001450 m_errorMonitor->VerifyFound();
1451 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001453 vkUnmapMemory(m_device->device(), mem);
1454 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001455
Tobin Ehlis35372522016-05-12 08:32:31 -06001456 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001457 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001458 ASSERT_VK_SUCCESS(err);
1459 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001460 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001462 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001464 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1465 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001466
Tobin Ehlis35372522016-05-12 08:32:31 -06001467 // Now flush range that oversteps mapped range
1468 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001469 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001471 mmr.offset = atom_size;
1472 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1474 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1475 m_errorMonitor->VerifyFound();
1476
1477 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1478 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001479 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001481 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001482 mmr.size = VK_WHOLE_SIZE;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1485 m_errorMonitor->VerifyFound();
1486
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001487 // Some platforms have an atomsize of 1 which makes the test meaningless
1488 if (atom_size > 3) {
1489 // Now with an offset NOT a multiple of the device limit
1490 vkUnmapMemory(m_device->device(), mem);
1491 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1492 ASSERT_VK_SUCCESS(err);
1493 mmr.offset = 3; // Not a multiple of atom_size
1494 mmr.size = VK_WHOLE_SIZE;
1495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1496 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1497 m_errorMonitor->VerifyFound();
1498
1499 // Now with a size NOT a multiple of the device limit
1500 vkUnmapMemory(m_device->device(), mem);
1501 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1502 ASSERT_VK_SUCCESS(err);
1503 mmr.offset = atom_size;
1504 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1506 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1507 m_errorMonitor->VerifyFound();
1508 }
1509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001510 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1511 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001512 if (!pass) {
1513 vkFreeMemory(m_device->device(), mem, NULL);
1514 vkDestroyBuffer(m_device->device(), buffer, NULL);
1515 return;
1516 }
1517 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1518 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1519
1520 vkDestroyBuffer(m_device->device(), buffer, NULL);
1521 vkFreeMemory(m_device->device(), mem, NULL);
1522}
1523
Ian Elliott1c32c772016-04-28 14:47:13 -06001524TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1525 VkResult err;
1526 bool pass;
1527
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001528 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1529 // following declaration (which is temporarily being moved below):
1530 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001531 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001532 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001533 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001534 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001535 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001536 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001537
1538 ASSERT_NO_FATAL_FAILURE(InitState());
1539
Ian Elliott3f06ce52016-04-29 14:46:21 -06001540#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1541#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1542 // Use the functions from the VK_KHR_android_surface extension without
1543 // enabling that extension:
1544
1545 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001546 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1548 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001549 pass = (err != VK_SUCCESS);
1550 ASSERT_TRUE(pass);
1551 m_errorMonitor->VerifyFound();
1552#endif // VK_USE_PLATFORM_ANDROID_KHR
1553
Ian Elliott3f06ce52016-04-29 14:46:21 -06001554#if defined(VK_USE_PLATFORM_MIR_KHR)
1555 // Use the functions from the VK_KHR_mir_surface extension without enabling
1556 // that extension:
1557
1558 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001559 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001561 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1562 pass = (err != VK_SUCCESS);
1563 ASSERT_TRUE(pass);
1564 m_errorMonitor->VerifyFound();
1565
1566 // Tell whether an mir_connection supports presentation:
1567 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1569 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001570 m_errorMonitor->VerifyFound();
1571#endif // VK_USE_PLATFORM_MIR_KHR
1572
Ian Elliott3f06ce52016-04-29 14:46:21 -06001573#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1574 // Use the functions from the VK_KHR_wayland_surface extension without
1575 // enabling that extension:
1576
1577 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001578 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1580 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001581 pass = (err != VK_SUCCESS);
1582 ASSERT_TRUE(pass);
1583 m_errorMonitor->VerifyFound();
1584
1585 // Tell whether an wayland_display supports presentation:
1586 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1588 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001589 m_errorMonitor->VerifyFound();
1590#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001591#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001592
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001594 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1595 // TO NON-LINUX PLATFORMS:
1596 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001597 // Use the functions from the VK_KHR_win32_surface extension without
1598 // enabling that extension:
1599
1600 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001601 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1603 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001604 pass = (err != VK_SUCCESS);
1605 ASSERT_TRUE(pass);
1606 m_errorMonitor->VerifyFound();
1607
1608 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001610 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001611 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001612// Set this (for now, until all platforms are supported and tested):
1613#define NEED_TO_TEST_THIS_ON_PLATFORM
1614#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001615#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001616 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1617 // TO NON-LINUX PLATFORMS:
1618 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001619#endif
1620#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001621 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1622 // that extension:
1623
1624 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001625 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001627 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1628 pass = (err != VK_SUCCESS);
1629 ASSERT_TRUE(pass);
1630 m_errorMonitor->VerifyFound();
1631
1632 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001633 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001634 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1636 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001637 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001638// Set this (for now, until all platforms are supported and tested):
1639#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001640#endif // VK_USE_PLATFORM_XCB_KHR
1641
Ian Elliott12630812016-04-29 14:35:43 -06001642#if defined(VK_USE_PLATFORM_XLIB_KHR)
1643 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1644 // that extension:
1645
1646 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001647 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001649 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1650 pass = (err != VK_SUCCESS);
1651 ASSERT_TRUE(pass);
1652 m_errorMonitor->VerifyFound();
1653
1654 // Tell whether an Xlib VisualID supports presentation:
1655 Display *dpy = NULL;
1656 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001658 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1659 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001660// Set this (for now, until all platforms are supported and tested):
1661#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001662#endif // VK_USE_PLATFORM_XLIB_KHR
1663
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664// Use the functions from the VK_KHR_surface extension without enabling
1665// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001666
Ian Elliott489eec02016-05-05 14:12:44 -06001667#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001668 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001670 vkDestroySurfaceKHR(instance(), surface, NULL);
1671 m_errorMonitor->VerifyFound();
1672
1673 // Check if surface supports presentation:
1674 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001676 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1677 pass = (err != VK_SUCCESS);
1678 ASSERT_TRUE(pass);
1679 m_errorMonitor->VerifyFound();
1680
1681 // Check surface capabilities:
1682 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1684 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001685 pass = (err != VK_SUCCESS);
1686 ASSERT_TRUE(pass);
1687 m_errorMonitor->VerifyFound();
1688
1689 // Check surface formats:
1690 uint32_t format_count = 0;
1691 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1693 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001694 pass = (err != VK_SUCCESS);
1695 ASSERT_TRUE(pass);
1696 m_errorMonitor->VerifyFound();
1697
1698 // Check surface present modes:
1699 uint32_t present_mode_count = 0;
1700 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1702 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001703 pass = (err != VK_SUCCESS);
1704 ASSERT_TRUE(pass);
1705 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001706#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001707
Ian Elliott1c32c772016-04-28 14:47:13 -06001708 // Use the functions from the VK_KHR_swapchain extension without enabling
1709 // that extension:
1710
1711 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001713 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1714 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001715 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001716 pass = (err != VK_SUCCESS);
1717 ASSERT_TRUE(pass);
1718 m_errorMonitor->VerifyFound();
1719
1720 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1722 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001723 pass = (err != VK_SUCCESS);
1724 ASSERT_TRUE(pass);
1725 m_errorMonitor->VerifyFound();
1726
Chris Forbeseb7d5502016-09-13 18:19:21 +12001727 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1728 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1729 VkFence fence;
1730 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1731
Ian Elliott1c32c772016-04-28 14:47:13 -06001732 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001734 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001735 pass = (err != VK_SUCCESS);
1736 ASSERT_TRUE(pass);
1737 m_errorMonitor->VerifyFound();
1738
Chris Forbeseb7d5502016-09-13 18:19:21 +12001739 vkDestroyFence(m_device->device(), fence, nullptr);
1740
Ian Elliott1c32c772016-04-28 14:47:13 -06001741 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001742 //
1743 // NOTE: Currently can't test this because a real swapchain is needed (as
1744 // opposed to the fake one we created) in order for the layer to lookup the
1745 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001746
1747 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001749 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1750 m_errorMonitor->VerifyFound();
1751}
1752
Karl Schultz6addd812016-02-02 17:17:23 -07001753TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1754 VkResult err;
1755 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001756
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1758 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001759
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001760 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001761
1762 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001763 VkImage image;
1764 VkDeviceMemory mem;
1765 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001766
Karl Schultz6addd812016-02-02 17:17:23 -07001767 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1768 const int32_t tex_width = 32;
1769 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001770
Tony Barboureb254902015-07-15 12:50:33 -06001771 VkImageCreateInfo image_create_info = {};
1772 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001773 image_create_info.pNext = NULL;
1774 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1775 image_create_info.format = tex_format;
1776 image_create_info.extent.width = tex_width;
1777 image_create_info.extent.height = tex_height;
1778 image_create_info.extent.depth = 1;
1779 image_create_info.mipLevels = 1;
1780 image_create_info.arrayLayers = 1;
1781 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1782 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1783 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1784 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001785 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001786
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001787 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001788 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001789 mem_alloc.pNext = NULL;
1790 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001791
Chia-I Wuf7458c52015-10-26 21:10:41 +08001792 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001793 ASSERT_VK_SUCCESS(err);
1794
Karl Schultz6addd812016-02-02 17:17:23 -07001795 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001796
Mark Lobodzinski23065352015-05-29 09:32:35 -05001797 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001798
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001799 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 -07001800 if (!pass) { // If we can't find any unmappable memory this test doesn't
1801 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001802 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001803 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001804 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001805
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001806 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001807 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001808 ASSERT_VK_SUCCESS(err);
1809
1810 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001811 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001812 ASSERT_VK_SUCCESS(err);
1813
1814 // Map memory as if to initialize the image
1815 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001816 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001817
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001818 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001819
Chia-I Wuf7458c52015-10-26 21:10:41 +08001820 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001821 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001822}
1823
Karl Schultz6addd812016-02-02 17:17:23 -07001824TEST_F(VkLayerTest, RebindMemory) {
1825 VkResult err;
1826 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001827
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001829
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001830 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001831
1832 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001833 VkImage image;
1834 VkDeviceMemory mem1;
1835 VkDeviceMemory mem2;
1836 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001837
Karl Schultz6addd812016-02-02 17:17:23 -07001838 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1839 const int32_t tex_width = 32;
1840 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001841
Tony Barboureb254902015-07-15 12:50:33 -06001842 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001843 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1844 image_create_info.pNext = NULL;
1845 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1846 image_create_info.format = tex_format;
1847 image_create_info.extent.width = tex_width;
1848 image_create_info.extent.height = tex_height;
1849 image_create_info.extent.depth = 1;
1850 image_create_info.mipLevels = 1;
1851 image_create_info.arrayLayers = 1;
1852 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1853 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1854 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1855 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001856
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001857 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001858 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1859 mem_alloc.pNext = NULL;
1860 mem_alloc.allocationSize = 0;
1861 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001862
Karl Schultz6addd812016-02-02 17:17:23 -07001863 // Introduce failure, do NOT set memProps to
1864 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001865 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001866 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001867 ASSERT_VK_SUCCESS(err);
1868
Karl Schultz6addd812016-02-02 17:17:23 -07001869 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001870
1871 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001872 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001873 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001874
1875 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001876 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001877 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001878 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001879 ASSERT_VK_SUCCESS(err);
1880
1881 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001882 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001883 ASSERT_VK_SUCCESS(err);
1884
Karl Schultz6addd812016-02-02 17:17:23 -07001885 // Introduce validation failure, try to bind a different memory object to
1886 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001887 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001888
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001889 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001890
Chia-I Wuf7458c52015-10-26 21:10:41 +08001891 vkDestroyImage(m_device->device(), image, NULL);
1892 vkFreeMemory(m_device->device(), mem1, NULL);
1893 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001894}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001895
Karl Schultz6addd812016-02-02 17:17:23 -07001896TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001897 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001898
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1900 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001901
1902 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001903 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1904 fenceInfo.pNext = NULL;
1905 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001906
Tony Barbour300a6082015-04-07 13:44:53 -06001907 ASSERT_NO_FATAL_FAILURE(InitState());
1908 ASSERT_NO_FATAL_FAILURE(InitViewport());
1909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1910
Tony Barbourfe3351b2015-07-28 10:17:20 -06001911 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001912 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001913 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001914
1915 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001916
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001917 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001918 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1919 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001920 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001921 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001922 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001923 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001924 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001925 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001926 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001927
1928 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001929 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001930
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001931 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001932}
Chris Forbes4e44c912016-06-16 10:20:00 +12001933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001934TEST_F(VkLayerTest, InvalidUsageBits) {
1935 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1936 "Initialize buffer with wrong usage then perform copy expecting errors "
1937 "from both the image and the buffer (2 calls)");
1938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001939
1940 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001941 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001942 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001943 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001944 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001945
Tony Barbourf92621a2016-05-02 14:28:12 -06001946 VkImageView dsv;
1947 VkImageViewCreateInfo dsvci = {};
1948 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1949 dsvci.image = image.handle();
1950 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1951 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1952 dsvci.subresourceRange.layerCount = 1;
1953 dsvci.subresourceRange.baseMipLevel = 0;
1954 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001955 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001956
Tony Barbourf92621a2016-05-02 14:28:12 -06001957 // Create a view with depth / stencil aspect for image with different usage
1958 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001959
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001960 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001961
1962 // Initialize buffer with TRANSFER_DST usage
1963 vk_testing::Buffer buffer;
1964 VkMemoryPropertyFlags reqs = 0;
1965 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1966 VkBufferImageCopy region = {};
1967 region.bufferRowLength = 128;
1968 region.bufferImageHeight = 128;
1969 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1970 region.imageSubresource.layerCount = 1;
1971 region.imageExtent.height = 16;
1972 region.imageExtent.width = 16;
1973 region.imageExtent.depth = 1;
1974
Tony Barbourf92621a2016-05-02 14:28:12 -06001975 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1976 // TRANSFER_DST
1977 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001978
Chris Forbesda581202016-10-06 18:25:26 +13001979 // two separate errors from this call:
1980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001983 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1984 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001985 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001986}
Tony Barbour75d79f02016-08-30 09:39:07 -06001987
Tony Barbour75d79f02016-08-30 09:39:07 -06001988
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001989#endif // MEM_TRACKER_TESTS
1990
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001991#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001992
1993TEST_F(VkLayerTest, LeakAnObject) {
1994 VkResult err;
1995
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001996 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001997
1998 // Note that we have to create a new device since destroying the
1999 // framework's device causes Teardown() to fail and just calling Teardown
2000 // will destroy the errorMonitor.
2001
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002003
2004 ASSERT_NO_FATAL_FAILURE(InitState());
2005
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002006 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002007 std::vector<VkDeviceQueueCreateInfo> queue_info;
2008 queue_info.reserve(queue_props.size());
2009 std::vector<std::vector<float>> queue_priorities;
2010 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2011 VkDeviceQueueCreateInfo qi = {};
2012 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2013 qi.pNext = NULL;
2014 qi.queueFamilyIndex = i;
2015 qi.queueCount = queue_props[i].queueCount;
2016 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2017 qi.pQueuePriorities = queue_priorities[i].data();
2018 queue_info.push_back(qi);
2019 }
2020
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002021 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002022
2023 // The sacrificial device object
2024 VkDevice testDevice;
2025 VkDeviceCreateInfo device_create_info = {};
2026 auto features = m_device->phy().features();
2027 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2028 device_create_info.pNext = NULL;
2029 device_create_info.queueCreateInfoCount = queue_info.size();
2030 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002031 device_create_info.enabledLayerCount = 0;
2032 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002033 device_create_info.pEnabledFeatures = &features;
2034 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2035 ASSERT_VK_SUCCESS(err);
2036
2037 VkFence fence;
2038 VkFenceCreateInfo fence_create_info = {};
2039 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2040 fence_create_info.pNext = NULL;
2041 fence_create_info.flags = 0;
2042 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2043 ASSERT_VK_SUCCESS(err);
2044
2045 // Induce failure by not calling vkDestroyFence
2046 vkDestroyDevice(testDevice, NULL);
2047 m_errorMonitor->VerifyFound();
2048}
2049
2050TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2051
2052 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2053 "attempt to delete them from another.");
2054
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002056
Cody Northropc31a84f2016-08-22 10:41:47 -06002057 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002058 VkCommandPool command_pool_one;
2059 VkCommandPool command_pool_two;
2060
2061 VkCommandPoolCreateInfo pool_create_info{};
2062 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2063 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2064 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2065
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002066 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002067
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002068 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002069
2070 VkCommandBuffer command_buffer[9];
2071 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002072 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002073 command_buffer_allocate_info.commandPool = command_pool_one;
2074 command_buffer_allocate_info.commandBufferCount = 9;
2075 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002076 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002077
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002078 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002079
2080 m_errorMonitor->VerifyFound();
2081
2082 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2083 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2084}
2085
2086TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2087 VkResult err;
2088
2089 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002090 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002091
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002093
2094 ASSERT_NO_FATAL_FAILURE(InitState());
2095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2096
2097 VkDescriptorPoolSize ds_type_count = {};
2098 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2099 ds_type_count.descriptorCount = 1;
2100
2101 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2102 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2103 ds_pool_ci.pNext = NULL;
2104 ds_pool_ci.flags = 0;
2105 ds_pool_ci.maxSets = 1;
2106 ds_pool_ci.poolSizeCount = 1;
2107 ds_pool_ci.pPoolSizes = &ds_type_count;
2108
2109 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002110 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002111 ASSERT_VK_SUCCESS(err);
2112
2113 // Create a second descriptor pool
2114 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002115 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002116 ASSERT_VK_SUCCESS(err);
2117
2118 VkDescriptorSetLayoutBinding dsl_binding = {};
2119 dsl_binding.binding = 0;
2120 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2121 dsl_binding.descriptorCount = 1;
2122 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2123 dsl_binding.pImmutableSamplers = NULL;
2124
2125 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2126 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2127 ds_layout_ci.pNext = NULL;
2128 ds_layout_ci.bindingCount = 1;
2129 ds_layout_ci.pBindings = &dsl_binding;
2130
2131 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002132 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002133 ASSERT_VK_SUCCESS(err);
2134
2135 VkDescriptorSet descriptorSet;
2136 VkDescriptorSetAllocateInfo alloc_info = {};
2137 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2138 alloc_info.descriptorSetCount = 1;
2139 alloc_info.descriptorPool = ds_pool_one;
2140 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002141 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002142 ASSERT_VK_SUCCESS(err);
2143
2144 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2145
2146 m_errorMonitor->VerifyFound();
2147
2148 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2149 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2150 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2151}
2152
2153TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002155
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002157
2158 ASSERT_NO_FATAL_FAILURE(InitState());
2159
2160 // Pass bogus handle into GetImageMemoryRequirements
2161 VkMemoryRequirements mem_reqs;
2162 uint64_t fakeImageHandle = 0xCADECADE;
2163 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2164
2165 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2166
2167 m_errorMonitor->VerifyFound();
2168}
2169
Karl Schultz6addd812016-02-02 17:17:23 -07002170TEST_F(VkLayerTest, PipelineNotBound) {
2171 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002172
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002173 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002176
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002177 ASSERT_NO_FATAL_FAILURE(InitState());
2178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002179
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002180 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002181 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2182 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002183
2184 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002185 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2186 ds_pool_ci.pNext = NULL;
2187 ds_pool_ci.maxSets = 1;
2188 ds_pool_ci.poolSizeCount = 1;
2189 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002190
2191 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002192 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002193 ASSERT_VK_SUCCESS(err);
2194
2195 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002196 dsl_binding.binding = 0;
2197 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2198 dsl_binding.descriptorCount = 1;
2199 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2200 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002201
2202 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002203 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2204 ds_layout_ci.pNext = NULL;
2205 ds_layout_ci.bindingCount = 1;
2206 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002207
2208 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002209 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002210 ASSERT_VK_SUCCESS(err);
2211
2212 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002213 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002214 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002215 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002216 alloc_info.descriptorPool = ds_pool;
2217 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002218 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002219 ASSERT_VK_SUCCESS(err);
2220
2221 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002222 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2223 pipeline_layout_ci.pNext = NULL;
2224 pipeline_layout_ci.setLayoutCount = 1;
2225 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002226
2227 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002229 ASSERT_VK_SUCCESS(err);
2230
Mark Youngad779052016-01-06 14:26:04 -07002231 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002232
2233 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002234 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002235
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002236 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002237
Chia-I Wuf7458c52015-10-26 21:10:41 +08002238 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2239 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2240 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002241}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002242
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002243TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2244 VkResult err;
2245
2246 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2247 "during bind[Buffer|Image]Memory time");
2248
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002249 ASSERT_NO_FATAL_FAILURE(InitState());
2250
2251 // Create an image, allocate memory, set a bad typeIndex and then try to
2252 // bind it
2253 VkImage image;
2254 VkDeviceMemory mem;
2255 VkMemoryRequirements mem_reqs;
2256 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2257 const int32_t tex_width = 32;
2258 const int32_t tex_height = 32;
2259
2260 VkImageCreateInfo image_create_info = {};
2261 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2262 image_create_info.pNext = NULL;
2263 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2264 image_create_info.format = tex_format;
2265 image_create_info.extent.width = tex_width;
2266 image_create_info.extent.height = tex_height;
2267 image_create_info.extent.depth = 1;
2268 image_create_info.mipLevels = 1;
2269 image_create_info.arrayLayers = 1;
2270 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2271 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2272 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2273 image_create_info.flags = 0;
2274
2275 VkMemoryAllocateInfo mem_alloc = {};
2276 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2277 mem_alloc.pNext = NULL;
2278 mem_alloc.allocationSize = 0;
2279 mem_alloc.memoryTypeIndex = 0;
2280
2281 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2282 ASSERT_VK_SUCCESS(err);
2283
2284 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2285 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002286
2287 // Introduce Failure, select invalid TypeIndex
2288 VkPhysicalDeviceMemoryProperties memory_info;
2289
2290 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2291 unsigned int i;
2292 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2293 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2294 mem_alloc.memoryTypeIndex = i;
2295 break;
2296 }
2297 }
2298 if (i >= memory_info.memoryTypeCount) {
2299 printf("No invalid memory type index could be found; skipped.\n");
2300 vkDestroyImage(m_device->device(), image, NULL);
2301 return;
2302 }
2303
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002304 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 -06002305
2306 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2307 ASSERT_VK_SUCCESS(err);
2308
2309 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2310 (void)err;
2311
2312 m_errorMonitor->VerifyFound();
2313
2314 vkDestroyImage(m_device->device(), image, NULL);
2315 vkFreeMemory(m_device->device(), mem, NULL);
2316}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002317
Karl Schultz6addd812016-02-02 17:17:23 -07002318TEST_F(VkLayerTest, BindInvalidMemory) {
2319 VkResult err;
2320 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002321
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002323
Tobin Ehlisec598302015-09-15 15:02:17 -06002324 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002325
2326 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002327 VkImage image;
2328 VkDeviceMemory mem;
2329 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002330
Karl Schultz6addd812016-02-02 17:17:23 -07002331 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2332 const int32_t tex_width = 32;
2333 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002334
2335 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002336 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2337 image_create_info.pNext = NULL;
2338 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2339 image_create_info.format = tex_format;
2340 image_create_info.extent.width = tex_width;
2341 image_create_info.extent.height = tex_height;
2342 image_create_info.extent.depth = 1;
2343 image_create_info.mipLevels = 1;
2344 image_create_info.arrayLayers = 1;
2345 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2346 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2347 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2348 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002349
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002350 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002351 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2352 mem_alloc.pNext = NULL;
2353 mem_alloc.allocationSize = 0;
2354 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002355
Chia-I Wuf7458c52015-10-26 21:10:41 +08002356 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002357 ASSERT_VK_SUCCESS(err);
2358
Karl Schultz6addd812016-02-02 17:17:23 -07002359 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002360
2361 mem_alloc.allocationSize = mem_reqs.size;
2362
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002363 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002364 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002365
2366 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002367 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002368 ASSERT_VK_SUCCESS(err);
2369
2370 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002371 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002372
2373 // Try to bind free memory that has been freed
2374 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2375 // This may very well return an error.
2376 (void)err;
2377
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002378 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002379
Chia-I Wuf7458c52015-10-26 21:10:41 +08002380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002381}
2382
Karl Schultz6addd812016-02-02 17:17:23 -07002383TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2384 VkResult err;
2385 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002388
Tobin Ehlisec598302015-09-15 15:02:17 -06002389 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002390
Karl Schultz6addd812016-02-02 17:17:23 -07002391 // Create an image object, allocate memory, destroy the object and then try
2392 // to bind it
2393 VkImage image;
2394 VkDeviceMemory mem;
2395 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002396
Karl Schultz6addd812016-02-02 17:17:23 -07002397 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2398 const int32_t tex_width = 32;
2399 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002400
2401 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002402 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2403 image_create_info.pNext = NULL;
2404 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2405 image_create_info.format = tex_format;
2406 image_create_info.extent.width = tex_width;
2407 image_create_info.extent.height = tex_height;
2408 image_create_info.extent.depth = 1;
2409 image_create_info.mipLevels = 1;
2410 image_create_info.arrayLayers = 1;
2411 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2412 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2413 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2414 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002415
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002416 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002417 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2418 mem_alloc.pNext = NULL;
2419 mem_alloc.allocationSize = 0;
2420 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002421
Chia-I Wuf7458c52015-10-26 21:10:41 +08002422 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002423 ASSERT_VK_SUCCESS(err);
2424
Karl Schultz6addd812016-02-02 17:17:23 -07002425 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002426
2427 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002428 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002429 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002430
2431 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002432 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002433 ASSERT_VK_SUCCESS(err);
2434
2435 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002436 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002437 ASSERT_VK_SUCCESS(err);
2438
2439 // Now Try to bind memory to this destroyed object
2440 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2441 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002442 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002443
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002444 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002445
Chia-I Wuf7458c52015-10-26 21:10:41 +08002446 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002447}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002448
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002449#endif // OBJ_TRACKER_TESTS
2450
Tobin Ehlis0788f522015-05-26 16:11:58 -06002451#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002452
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002453TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2454 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2455
2456 ASSERT_NO_FATAL_FAILURE(InitState());
2457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2458
2459 VkVertexInputBindingDescription input_binding;
2460 memset(&input_binding, 0, sizeof(input_binding));
2461
2462 VkVertexInputAttributeDescription input_attribs;
2463 memset(&input_attribs, 0, sizeof(input_attribs));
2464
2465 // Pick a really bad format for this purpose and make sure it should fail
2466 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2467 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2468 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2469 printf("Format unsuitable for test; skipped.\n");
2470 return;
2471 }
2472
2473 input_attribs.location = 0;
2474 char const *vsSource = "#version 450\n"
2475 "\n"
2476 "out gl_PerVertex {\n"
2477 " vec4 gl_Position;\n"
2478 "};\n"
2479 "void main(){\n"
2480 " gl_Position = vec4(1);\n"
2481 "}\n";
2482 char const *fsSource = "#version 450\n"
2483 "\n"
2484 "layout(location=0) out vec4 color;\n"
2485 "void main(){\n"
2486 " color = vec4(1);\n"
2487 "}\n";
2488
2489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2490 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2491 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2492
2493 VkPipelineObj pipe(m_device);
2494 pipe.AddColorAttachment();
2495 pipe.AddShader(&vs);
2496 pipe.AddShader(&fs);
2497
2498 pipe.AddVertexInputBindings(&input_binding, 1);
2499 pipe.AddVertexInputAttribs(&input_attribs, 1);
2500
2501 VkDescriptorSetObj descriptorSet(m_device);
2502 descriptorSet.AppendDummy();
2503 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2504
2505 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2506
2507 m_errorMonitor->VerifyFound();
2508}
2509
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002510TEST_F(VkLayerTest, ImageSampleCounts) {
2511
2512 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2513 "validation errors.");
2514 ASSERT_NO_FATAL_FAILURE(InitState());
2515
2516 VkMemoryPropertyFlags reqs = 0;
2517 VkImageCreateInfo image_create_info = {};
2518 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2519 image_create_info.pNext = NULL;
2520 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2521 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2522 image_create_info.extent.width = 256;
2523 image_create_info.extent.height = 256;
2524 image_create_info.extent.depth = 1;
2525 image_create_info.mipLevels = 1;
2526 image_create_info.arrayLayers = 1;
2527 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2528 image_create_info.flags = 0;
2529
2530 VkImageBlit blit_region = {};
2531 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2532 blit_region.srcSubresource.baseArrayLayer = 0;
2533 blit_region.srcSubresource.layerCount = 1;
2534 blit_region.srcSubresource.mipLevel = 0;
2535 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2536 blit_region.dstSubresource.baseArrayLayer = 0;
2537 blit_region.dstSubresource.layerCount = 1;
2538 blit_region.dstSubresource.mipLevel = 0;
2539
2540 // Create two images, the source with sampleCount = 2, and attempt to blit
2541 // between them
2542 {
2543 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002544 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002545 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002546 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002547 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002549 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002550 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002551 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2553 "of VK_SAMPLE_COUNT_2_BIT but "
2554 "must be VK_SAMPLE_COUNT_1_BIT");
2555 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2556 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002557 m_errorMonitor->VerifyFound();
2558 m_commandBuffer->EndCommandBuffer();
2559 }
2560
2561 // Create two images, the dest with sampleCount = 4, and attempt to blit
2562 // between them
2563 {
2564 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002565 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002566 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002567 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002568 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002569 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002570 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002571 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002572 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2574 "of VK_SAMPLE_COUNT_4_BIT but "
2575 "must be VK_SAMPLE_COUNT_1_BIT");
2576 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2577 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002578 m_errorMonitor->VerifyFound();
2579 m_commandBuffer->EndCommandBuffer();
2580 }
2581
2582 VkBufferImageCopy copy_region = {};
2583 copy_region.bufferRowLength = 128;
2584 copy_region.bufferImageHeight = 128;
2585 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2586 copy_region.imageSubresource.layerCount = 1;
2587 copy_region.imageExtent.height = 64;
2588 copy_region.imageExtent.width = 64;
2589 copy_region.imageExtent.depth = 1;
2590
2591 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2592 // buffer to image
2593 {
2594 vk_testing::Buffer src_buffer;
2595 VkMemoryPropertyFlags reqs = 0;
2596 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2597 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002598 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002599 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2603 "of VK_SAMPLE_COUNT_8_BIT but "
2604 "must be VK_SAMPLE_COUNT_1_BIT");
2605 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2606 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002607 m_errorMonitor->VerifyFound();
2608 m_commandBuffer->EndCommandBuffer();
2609 }
2610
2611 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2612 // image to buffer
2613 {
2614 vk_testing::Buffer dst_buffer;
2615 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2616 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002617 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002618 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002619 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002620 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2622 "of VK_SAMPLE_COUNT_2_BIT but "
2623 "must be VK_SAMPLE_COUNT_1_BIT");
2624 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002625 dst_buffer.handle(), 1, &copy_region);
2626 m_errorMonitor->VerifyFound();
2627 m_commandBuffer->EndCommandBuffer();
2628 }
2629}
2630
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002631TEST_F(VkLayerTest, BlitImageFormats) {
2632
2633 // Image blit with mismatched formats
2634 const char * expected_message =
2635 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2636 " the other one must also have signed/unsigned integer format";
2637
2638 ASSERT_NO_FATAL_FAILURE(InitState());
2639
2640 VkImageObj src_image(m_device);
2641 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2642 VkImageObj dst_image(m_device);
2643 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2644 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002645 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 -06002646
2647 VkImageBlit blitRegion = {};
2648 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2649 blitRegion.srcSubresource.baseArrayLayer = 0;
2650 blitRegion.srcSubresource.layerCount = 1;
2651 blitRegion.srcSubresource.mipLevel = 0;
2652 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2653 blitRegion.dstSubresource.baseArrayLayer = 0;
2654 blitRegion.dstSubresource.layerCount = 1;
2655 blitRegion.dstSubresource.mipLevel = 0;
2656
2657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2658
2659 // Unsigned int vs not an int
2660 BeginCommandBuffer();
2661 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2662 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2663
2664 m_errorMonitor->VerifyFound();
2665
2666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2667
2668 // Unsigned int vs signed int
2669 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2670 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2671
2672 m_errorMonitor->VerifyFound();
2673
2674 EndCommandBuffer();
2675}
2676
2677
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002678TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2679 VkResult err;
2680 bool pass;
2681
2682 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2683 ASSERT_NO_FATAL_FAILURE(InitState());
2684
2685 // If w/d/h granularity is 1, test is not meaningful
2686 // TODO: When virtual device limits are available, create a set of limits for this test that
2687 // will always have a granularity of > 1 for w, h, and d
2688 auto index = m_device->graphics_queue_node_index_;
2689 auto queue_family_properties = m_device->phy().queue_properties();
2690
2691 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2692 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2693 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2694 return;
2695 }
2696
2697 // Create two images of different types and try to copy between them
2698 VkImage srcImage;
2699 VkImage dstImage;
2700 VkDeviceMemory srcMem;
2701 VkDeviceMemory destMem;
2702 VkMemoryRequirements memReqs;
2703
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002704 VkImageCreateInfo image_create_info = {};
2705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2706 image_create_info.pNext = NULL;
2707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2708 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2709 image_create_info.extent.width = 32;
2710 image_create_info.extent.height = 32;
2711 image_create_info.extent.depth = 1;
2712 image_create_info.mipLevels = 1;
2713 image_create_info.arrayLayers = 4;
2714 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2715 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2716 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2717 image_create_info.flags = 0;
2718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002719 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002720 ASSERT_VK_SUCCESS(err);
2721
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002722 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002723 ASSERT_VK_SUCCESS(err);
2724
2725 // Allocate memory
2726 VkMemoryAllocateInfo memAlloc = {};
2727 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2728 memAlloc.pNext = NULL;
2729 memAlloc.allocationSize = 0;
2730 memAlloc.memoryTypeIndex = 0;
2731
2732 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2733 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002734 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002735 ASSERT_TRUE(pass);
2736 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2737 ASSERT_VK_SUCCESS(err);
2738
2739 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2740 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002741 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002742 ASSERT_VK_SUCCESS(err);
2743 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2744 ASSERT_VK_SUCCESS(err);
2745
2746 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2747 ASSERT_VK_SUCCESS(err);
2748 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2749 ASSERT_VK_SUCCESS(err);
2750
2751 BeginCommandBuffer();
2752 VkImageCopy copyRegion;
2753 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2754 copyRegion.srcSubresource.mipLevel = 0;
2755 copyRegion.srcSubresource.baseArrayLayer = 0;
2756 copyRegion.srcSubresource.layerCount = 1;
2757 copyRegion.srcOffset.x = 0;
2758 copyRegion.srcOffset.y = 0;
2759 copyRegion.srcOffset.z = 0;
2760 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2761 copyRegion.dstSubresource.mipLevel = 0;
2762 copyRegion.dstSubresource.baseArrayLayer = 0;
2763 copyRegion.dstSubresource.layerCount = 1;
2764 copyRegion.dstOffset.x = 0;
2765 copyRegion.dstOffset.y = 0;
2766 copyRegion.dstOffset.z = 0;
2767 copyRegion.extent.width = 1;
2768 copyRegion.extent.height = 1;
2769 copyRegion.extent.depth = 1;
2770
2771 // Introduce failure by setting srcOffset to a bad granularity value
2772 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2774 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002775 m_errorMonitor->VerifyFound();
2776
2777 // Introduce failure by setting extent to a bad granularity value
2778 copyRegion.srcOffset.y = 0;
2779 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2781 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002782 m_errorMonitor->VerifyFound();
2783
2784 // Now do some buffer/image copies
2785 vk_testing::Buffer buffer;
2786 VkMemoryPropertyFlags reqs = 0;
2787 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2788 VkBufferImageCopy region = {};
2789 region.bufferOffset = 0;
2790 region.bufferRowLength = 3;
2791 region.bufferImageHeight = 128;
2792 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2793 region.imageSubresource.layerCount = 1;
2794 region.imageExtent.height = 16;
2795 region.imageExtent.width = 16;
2796 region.imageExtent.depth = 1;
2797 region.imageOffset.x = 0;
2798 region.imageOffset.y = 0;
2799 region.imageOffset.z = 0;
2800
2801 // Introduce failure by setting bufferRowLength to a bad granularity value
2802 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2804 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2805 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002806 m_errorMonitor->VerifyFound();
2807 region.bufferRowLength = 128;
2808
2809 // Introduce failure by setting bufferOffset to a bad granularity value
2810 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2812 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2813 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002814 m_errorMonitor->VerifyFound();
2815 region.bufferOffset = 0;
2816
2817 // Introduce failure by setting bufferImageHeight to a bad granularity value
2818 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2820 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2821 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002822 m_errorMonitor->VerifyFound();
2823 region.bufferImageHeight = 128;
2824
2825 // Introduce failure by setting imageExtent to a bad granularity value
2826 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2828 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2829 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002830 m_errorMonitor->VerifyFound();
2831 region.imageExtent.width = 16;
2832
2833 // Introduce failure by setting imageOffset to a bad granularity value
2834 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2836 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2837 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002838 m_errorMonitor->VerifyFound();
2839
2840 EndCommandBuffer();
2841
2842 vkDestroyImage(m_device->device(), srcImage, NULL);
2843 vkDestroyImage(m_device->device(), dstImage, NULL);
2844 vkFreeMemory(m_device->device(), srcMem, NULL);
2845 vkFreeMemory(m_device->device(), destMem, NULL);
2846}
2847
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002848TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002849 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2850 "attempt to submit them on a queue created in a different "
2851 "queue family.");
2852
Cody Northropc31a84f2016-08-22 10:41:47 -06002853 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002854 // This test is meaningless unless we have multiple queue families
2855 auto queue_family_properties = m_device->phy().queue_properties();
2856 if (queue_family_properties.size() < 2) {
2857 return;
2858 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002860 // Get safe index of another queue family
2861 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2862 ASSERT_NO_FATAL_FAILURE(InitState());
2863 // Create a second queue using a different queue family
2864 VkQueue other_queue;
2865 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2866
2867 // Record an empty cmd buffer
2868 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2869 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2870 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2871 vkEndCommandBuffer(m_commandBuffer->handle());
2872
2873 // And submit on the wrong queue
2874 VkSubmitInfo submit_info = {};
2875 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2876 submit_info.commandBufferCount = 1;
2877 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002878 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002879
2880 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002881}
2882
Chris Forbes4c24a922016-11-16 08:59:10 +13002883TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2884 ASSERT_NO_FATAL_FAILURE(InitState());
2885
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002886 // There are no attachments, but refer to attachment 0.
2887 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002888 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002889 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2890 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002891 };
2892
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002893 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2894 nullptr,
2895 0,
2896 0,
2897 nullptr,
2898 1,
2899 subpasses,
2900 0,
2901 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002902 VkRenderPass rp;
2903
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002904 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002906 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002907 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2908 m_errorMonitor->VerifyFound();
2909}
2910
Chris Forbesa58c4522016-09-28 15:19:39 +13002911TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2912 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2913 ASSERT_NO_FATAL_FAILURE(InitState());
2914
2915 // A renderpass with two subpasses, both writing the same attachment.
2916 VkAttachmentDescription attach[] = {
2917 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2918 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2919 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2920 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2921 },
2922 };
2923 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2924 VkSubpassDescription subpasses[] = {
2925 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2926 1, &ref, nullptr, nullptr, 0, nullptr },
2927 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2928 1, &ref, nullptr, nullptr, 0, nullptr },
2929 };
2930 VkSubpassDependency dep = {
2931 0, 1,
2932 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2933 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2934 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2935 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2936 VK_DEPENDENCY_BY_REGION_BIT
2937 };
2938 VkRenderPassCreateInfo rpci = {
2939 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2940 0, 1, attach, 2, subpasses, 1, &dep
2941 };
2942 VkRenderPass rp;
2943 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2944 ASSERT_VK_SUCCESS(err);
2945
2946 VkImageObj image(m_device);
2947 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2948 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2949 VK_IMAGE_TILING_OPTIMAL, 0);
2950 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2951
2952 VkFramebufferCreateInfo fbci = {
2953 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2954 0, rp, 1, &imageView, 32, 32, 1
2955 };
2956 VkFramebuffer fb;
2957 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2958 ASSERT_VK_SUCCESS(err);
2959
2960 char const *vsSource =
2961 "#version 450\n"
2962 "void main() { gl_Position = vec4(1); }\n";
2963 char const *fsSource =
2964 "#version 450\n"
2965 "layout(location=0) out vec4 color;\n"
2966 "void main() { color = vec4(1); }\n";
2967
2968 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2969 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2970 VkPipelineObj pipe(m_device);
2971 pipe.AddColorAttachment();
2972 pipe.AddShader(&vs);
2973 pipe.AddShader(&fs);
2974 VkViewport view_port = {};
2975 m_viewports.push_back(view_port);
2976 pipe.SetViewport(m_viewports);
2977 VkRect2D rect = {};
2978 m_scissors.push_back(rect);
2979 pipe.SetScissor(m_scissors);
2980
2981 VkPipelineLayoutCreateInfo plci = {
2982 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2983 0, 0, nullptr, 0, nullptr
2984 };
2985 VkPipelineLayout pl;
2986 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2987 ASSERT_VK_SUCCESS(err);
2988 pipe.CreateVKPipeline(pl, rp);
2989
2990 BeginCommandBuffer();
2991
2992 VkRenderPassBeginInfo rpbi = {
2993 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2994 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2995 };
2996
2997 // subtest 1: bind in the wrong subpass
2998 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2999 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3001 "built for subpass 0 but used in subpass 1");
3002 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3003 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3004 m_errorMonitor->VerifyFound();
3005
3006 vkCmdEndRenderPass(m_commandBuffer->handle());
3007
3008 // subtest 2: bind in correct subpass, then transition to next subpass
3009 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3010 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3011 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3013 "built for subpass 0 but used in subpass 1");
3014 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3015 m_errorMonitor->VerifyFound();
3016
3017 vkCmdEndRenderPass(m_commandBuffer->handle());
3018
3019 EndCommandBuffer();
3020
3021 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3022 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3023 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3024}
3025
Tony Barbour4e919972016-08-09 13:27:40 -06003026TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3027 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3028 "with extent outside of framebuffer");
3029 ASSERT_NO_FATAL_FAILURE(InitState());
3030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3033 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003034
3035 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3036 m_renderPassBeginInfo.renderArea.extent.width = 257;
3037 m_renderPassBeginInfo.renderArea.extent.height = 257;
3038 BeginCommandBuffer();
3039 m_errorMonitor->VerifyFound();
3040}
3041
3042TEST_F(VkLayerTest, DisabledIndependentBlend) {
3043 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3044 "blend and then specifying different blend states for two "
3045 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003046 VkPhysicalDeviceFeatures features = {};
3047 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003048 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3051 "Invalid Pipeline CreateInfo: If independent blend feature not "
3052 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003053
Cody Northropc31a84f2016-08-22 10:41:47 -06003054 VkDescriptorSetObj descriptorSet(m_device);
3055 descriptorSet.AppendDummy();
3056 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003057
Cody Northropc31a84f2016-08-22 10:41:47 -06003058 VkPipelineObj pipeline(m_device);
3059 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003060 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003061 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003062
Cody Northropc31a84f2016-08-22 10:41:47 -06003063 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3064 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3065 att_state1.blendEnable = VK_TRUE;
3066 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3067 att_state2.blendEnable = VK_FALSE;
3068 pipeline.AddColorAttachment(0, &att_state1);
3069 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003070 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003071 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003072}
3073
3074TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3075 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3076 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003077 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003078
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3080 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003081
3082 // Create a renderPass with a single color attachment
3083 VkAttachmentReference attach = {};
3084 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3085 VkSubpassDescription subpass = {};
3086 VkRenderPassCreateInfo rpci = {};
3087 rpci.subpassCount = 1;
3088 rpci.pSubpasses = &subpass;
3089 rpci.attachmentCount = 1;
3090 VkAttachmentDescription attach_desc = {};
3091 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3092 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3093 rpci.pAttachments = &attach_desc;
3094 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3095 VkRenderPass rp;
3096 subpass.pDepthStencilAttachment = &attach;
3097 subpass.pColorAttachments = NULL;
3098 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3099 m_errorMonitor->VerifyFound();
3100}
3101
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003102TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3103 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3104 "attachment reference of VK_ATTACHMENT_UNUSED");
3105
3106 ASSERT_NO_FATAL_FAILURE(InitState());
3107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3108
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003110
3111 VkAttachmentReference color_attach = {};
3112 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3113 color_attach.attachment = 0;
3114 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3115 VkSubpassDescription subpass = {};
3116 subpass.colorAttachmentCount = 1;
3117 subpass.pColorAttachments = &color_attach;
3118 subpass.preserveAttachmentCount = 1;
3119 subpass.pPreserveAttachments = &preserve_attachment;
3120
3121 VkRenderPassCreateInfo rpci = {};
3122 rpci.subpassCount = 1;
3123 rpci.pSubpasses = &subpass;
3124 rpci.attachmentCount = 1;
3125 VkAttachmentDescription attach_desc = {};
3126 attach_desc.format = VK_FORMAT_UNDEFINED;
3127 rpci.pAttachments = &attach_desc;
3128 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3129 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003130 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003131
3132 m_errorMonitor->VerifyFound();
3133
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003134 if (result == VK_SUCCESS) {
3135 vkDestroyRenderPass(m_device->device(), rp, NULL);
3136 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003137}
3138
Chris Forbesc5389742016-06-29 11:49:23 +12003139TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003140 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3141 "when the source of a subpass multisample resolve "
3142 "does not have multiple samples.");
3143
Chris Forbesc5389742016-06-29 11:49:23 +12003144 ASSERT_NO_FATAL_FAILURE(InitState());
3145
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3147 "Subpass 0 requests multisample resolve from attachment 0 which has "
3148 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003149
3150 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003151 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3152 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3153 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3154 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3155 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3156 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003157 };
3158
3159 VkAttachmentReference color = {
3160 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3161 };
3162
3163 VkAttachmentReference resolve = {
3164 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3165 };
3166
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003167 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003170
3171 VkRenderPass rp;
3172 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3173
3174 m_errorMonitor->VerifyFound();
3175
3176 if (err == VK_SUCCESS)
3177 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3178}
3179
3180TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003181 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3182 "when a subpass multisample resolve operation is "
3183 "requested, and the destination of that resolve has "
3184 "multiple samples.");
3185
Chris Forbesc5389742016-06-29 11:49:23 +12003186 ASSERT_NO_FATAL_FAILURE(InitState());
3187
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3189 "Subpass 0 requests multisample resolve into attachment 1, which "
3190 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003191
3192 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003193 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3194 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3195 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3196 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3197 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3198 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003199 };
3200
3201 VkAttachmentReference color = {
3202 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3203 };
3204
3205 VkAttachmentReference resolve = {
3206 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3207 };
3208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003209 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003211 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003212
3213 VkRenderPass rp;
3214 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3215
3216 m_errorMonitor->VerifyFound();
3217
3218 if (err == VK_SUCCESS)
3219 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3220}
3221
Chris Forbes3f128ef2016-06-29 14:58:53 +12003222TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003223 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3224 "when the color and depth attachments used by a subpass "
3225 "have inconsistent sample counts");
3226
Chris Forbes3f128ef2016-06-29 14:58:53 +12003227 ASSERT_NO_FATAL_FAILURE(InitState());
3228
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3230 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003231
3232 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003233 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3234 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3235 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3236 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3237 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3238 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003239 };
3240
3241 VkAttachmentReference color[] = {
3242 {
3243 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3244 },
3245 {
3246 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3247 },
3248 };
3249
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003250 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003251
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003252 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003253
3254 VkRenderPass rp;
3255 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3256
3257 m_errorMonitor->VerifyFound();
3258
3259 if (err == VK_SUCCESS)
3260 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3261}
3262
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003263TEST_F(VkLayerTest, FramebufferCreateErrors) {
3264 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003265 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003266 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003267 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3268 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3269 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3270 " 6. Framebuffer attachment where dimensions don't match\n"
3271 " 7. Framebuffer attachment w/o identity swizzle\n"
3272 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003273
3274 ASSERT_NO_FATAL_FAILURE(InitState());
3275 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3276
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3278 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3279 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003280
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003281 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003282 VkAttachmentReference attach = {};
3283 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3284 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003285 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003286 VkRenderPassCreateInfo rpci = {};
3287 rpci.subpassCount = 1;
3288 rpci.pSubpasses = &subpass;
3289 rpci.attachmentCount = 1;
3290 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003291 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003292 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003293 rpci.pAttachments = &attach_desc;
3294 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3295 VkRenderPass rp;
3296 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3297 ASSERT_VK_SUCCESS(err);
3298
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003299 VkImageView ivs[2];
3300 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3301 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003302 VkFramebufferCreateInfo fb_info = {};
3303 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3304 fb_info.pNext = NULL;
3305 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003306 // Set mis-matching attachmentCount
3307 fb_info.attachmentCount = 2;
3308 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003309 fb_info.width = 100;
3310 fb_info.height = 100;
3311 fb_info.layers = 1;
3312
3313 VkFramebuffer fb;
3314 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3315
3316 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003317 if (err == VK_SUCCESS) {
3318 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3319 }
3320 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003321
3322 // Create a renderPass with a depth-stencil attachment created with
3323 // IMAGE_USAGE_COLOR_ATTACHMENT
3324 // Add our color attachment to pDepthStencilAttachment
3325 subpass.pDepthStencilAttachment = &attach;
3326 subpass.pColorAttachments = NULL;
3327 VkRenderPass rp_ds;
3328 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3329 ASSERT_VK_SUCCESS(err);
3330 // Set correct attachment count, but attachment has COLOR usage bit set
3331 fb_info.attachmentCount = 1;
3332 fb_info.renderPass = rp_ds;
3333
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003335 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3336
3337 m_errorMonitor->VerifyFound();
3338 if (err == VK_SUCCESS) {
3339 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3340 }
3341 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003342
3343 // Create new renderpass with alternate attachment format from fb
3344 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3345 subpass.pDepthStencilAttachment = NULL;
3346 subpass.pColorAttachments = &attach;
3347 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3348 ASSERT_VK_SUCCESS(err);
3349
3350 // Cause error due to mis-matched formats between rp & fb
3351 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3352 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3354 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003355 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3356
3357 m_errorMonitor->VerifyFound();
3358 if (err == VK_SUCCESS) {
3359 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3360 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003361 vkDestroyRenderPass(m_device->device(), rp, NULL);
3362
3363 // Create new renderpass with alternate sample count from fb
3364 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3365 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3366 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3367 ASSERT_VK_SUCCESS(err);
3368
3369 // Cause error due to mis-matched sample count between rp & fb
3370 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3372 "that do not match the "
3373 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003374 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3375
3376 m_errorMonitor->VerifyFound();
3377 if (err == VK_SUCCESS) {
3378 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3379 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003380
3381 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003382
3383 // Create a custom imageView with non-1 mip levels
3384 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003385 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 -06003386 ASSERT_TRUE(image.initialized());
3387
3388 VkImageView view;
3389 VkImageViewCreateInfo ivci = {};
3390 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3391 ivci.image = image.handle();
3392 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3393 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3394 ivci.subresourceRange.layerCount = 1;
3395 ivci.subresourceRange.baseMipLevel = 0;
3396 // Set level count 2 (only 1 is allowed for FB attachment)
3397 ivci.subresourceRange.levelCount = 2;
3398 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3399 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3400 ASSERT_VK_SUCCESS(err);
3401 // Re-create renderpass to have matching sample count
3402 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3403 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3404 ASSERT_VK_SUCCESS(err);
3405
3406 fb_info.renderPass = rp;
3407 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003409 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3410
3411 m_errorMonitor->VerifyFound();
3412 if (err == VK_SUCCESS) {
3413 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3414 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003415 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003416 // Update view to original color buffer and grow FB dimensions too big
3417 fb_info.pAttachments = ivs;
3418 fb_info.height = 1024;
3419 fb_info.width = 1024;
3420 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3422 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003423 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3424
3425 m_errorMonitor->VerifyFound();
3426 if (err == VK_SUCCESS) {
3427 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3428 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003429 // Create view attachment with non-identity swizzle
3430 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3431 ivci.image = image.handle();
3432 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3433 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3434 ivci.subresourceRange.layerCount = 1;
3435 ivci.subresourceRange.baseMipLevel = 0;
3436 ivci.subresourceRange.levelCount = 1;
3437 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3438 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3439 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3440 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3441 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3442 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3443 ASSERT_VK_SUCCESS(err);
3444
3445 fb_info.pAttachments = &view;
3446 fb_info.height = 100;
3447 fb_info.width = 100;
3448 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3450 "framebuffer attachments must have "
3451 "been created with the identity "
3452 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003453 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3454
3455 m_errorMonitor->VerifyFound();
3456 if (err == VK_SUCCESS) {
3457 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3458 }
3459 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003460 // Request fb that exceeds max dimensions
3461 // reset attachment to color attachment
3462 fb_info.pAttachments = ivs;
3463 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3464 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3465 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3467 "dimensions exceed physical device "
3468 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003469 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3470
3471 m_errorMonitor->VerifyFound();
3472 if (err == VK_SUCCESS) {
3473 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3474 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003475
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003476 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003477}
3478
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003479TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003480 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3481 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003482
Cody Northropc31a84f2016-08-22 10:41:47 -06003483 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003484 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3486 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003487 m_errorMonitor->VerifyFound();
3488}
3489
3490TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003491 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3492 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003493
Cody Northropc31a84f2016-08-22 10:41:47 -06003494 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003495 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3497 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003498 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003499}
3500
3501TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003502 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3503 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003504
Cody Northropc31a84f2016-08-22 10:41:47 -06003505 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003506 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003507 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 -06003508 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003509 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003510}
3511
3512TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003513 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3514 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003515
Cody Northropc31a84f2016-08-22 10:41:47 -06003516 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003517 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003518 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 -06003519 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003520 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003521}
3522
Cortd713fe82016-07-27 09:51:27 -07003523TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003524 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3525 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003526
3527 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003528 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3530 "Dynamic blend constants state not set for this command buffer");
3531 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003532 m_errorMonitor->VerifyFound();
3533}
3534
3535TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003536 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3537 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003538
3539 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003540 if (!m_device->phy().features().depthBounds) {
3541 printf("Device does not support depthBounds test; skipped.\n");
3542 return;
3543 }
3544 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3546 "Dynamic depth bounds state not set for this command buffer");
3547 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003548 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003549}
3550
3551TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003552 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3553 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003554
3555 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003556 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3558 "Dynamic stencil read mask state not set for this command buffer");
3559 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003560 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003561}
3562
3563TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003564 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3565 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003566
3567 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003568 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3570 "Dynamic stencil write mask state not set for this command buffer");
3571 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003572 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003573}
3574
3575TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003576 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3577 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003578
3579 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003580 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3582 "Dynamic stencil reference state not set for this command buffer");
3583 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003584 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003585}
3586
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003587TEST_F(VkLayerTest, IndexBufferNotBound) {
3588 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003589
3590 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3592 "Index buffer object not bound to this command buffer when Indexed ");
3593 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003594 m_errorMonitor->VerifyFound();
3595}
3596
Karl Schultz6addd812016-02-02 17:17:23 -07003597TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3599 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3600 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003601
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003602 ASSERT_NO_FATAL_FAILURE(InitState());
3603 ASSERT_NO_FATAL_FAILURE(InitViewport());
3604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3605
Karl Schultz6addd812016-02-02 17:17:23 -07003606 // We luck out b/c by default the framework creates CB w/ the
3607 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003608 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003609 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003610 EndCommandBuffer();
3611
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003612 // Bypass framework since it does the waits automatically
3613 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003614 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003615 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3616 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003617 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003618 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003619 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003620 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003621 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003622 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003623 submit_info.pSignalSemaphores = NULL;
3624
Chris Forbes40028e22016-06-13 09:59:34 +12003625 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003626 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003627 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003628
Karl Schultz6addd812016-02-02 17:17:23 -07003629 // Cause validation error by re-submitting cmd buffer that should only be
3630 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003631 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003632 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003633
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003634 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003635}
3636
Karl Schultz6addd812016-02-02 17:17:23 -07003637TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003638 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003639 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003640
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3642 "type "
3643 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003644
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003645 ASSERT_NO_FATAL_FAILURE(InitState());
3646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003647
Karl Schultz6addd812016-02-02 17:17:23 -07003648 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3649 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003650 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003651 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3652 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003653
3654 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003655 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3656 ds_pool_ci.pNext = NULL;
3657 ds_pool_ci.flags = 0;
3658 ds_pool_ci.maxSets = 1;
3659 ds_pool_ci.poolSizeCount = 1;
3660 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003661
3662 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003663 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003664 ASSERT_VK_SUCCESS(err);
3665
3666 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003667 dsl_binding.binding = 0;
3668 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3669 dsl_binding.descriptorCount = 1;
3670 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3671 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003672
3673 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003674 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3675 ds_layout_ci.pNext = NULL;
3676 ds_layout_ci.bindingCount = 1;
3677 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003678
3679 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003680 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003681 ASSERT_VK_SUCCESS(err);
3682
3683 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003684 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003685 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003686 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003687 alloc_info.descriptorPool = ds_pool;
3688 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003689 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003690
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003691 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003692
Chia-I Wuf7458c52015-10-26 21:10:41 +08003693 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3694 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003695}
3696
Karl Schultz6addd812016-02-02 17:17:23 -07003697TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3698 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003699
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3701 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3702 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003703
Tobin Ehlise735c692015-10-08 13:13:50 -06003704 ASSERT_NO_FATAL_FAILURE(InitState());
3705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003706
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003707 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003708 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3709 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003710
3711 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003712 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3713 ds_pool_ci.pNext = NULL;
3714 ds_pool_ci.maxSets = 1;
3715 ds_pool_ci.poolSizeCount = 1;
3716 ds_pool_ci.flags = 0;
3717 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3718 // app can only call vkResetDescriptorPool on this pool.;
3719 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003720
3721 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003722 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003723 ASSERT_VK_SUCCESS(err);
3724
3725 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003726 dsl_binding.binding = 0;
3727 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3728 dsl_binding.descriptorCount = 1;
3729 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3730 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003731
3732 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003733 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3734 ds_layout_ci.pNext = NULL;
3735 ds_layout_ci.bindingCount = 1;
3736 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003737
3738 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003739 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003740 ASSERT_VK_SUCCESS(err);
3741
3742 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003743 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003744 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003745 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003746 alloc_info.descriptorPool = ds_pool;
3747 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003748 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003749 ASSERT_VK_SUCCESS(err);
3750
3751 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003752 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003753
Chia-I Wuf7458c52015-10-26 21:10:41 +08003754 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3755 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003756}
3757
Karl Schultz6addd812016-02-02 17:17:23 -07003758TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003759 // Attempt to clear Descriptor Pool with bad object.
3760 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003761
3762 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003764 uint64_t fake_pool_handle = 0xbaad6001;
3765 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3766 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003767 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003768}
3769
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003770TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003771 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3772 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003773 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003774 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003775
3776 uint64_t fake_set_handle = 0xbaad6001;
3777 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003778 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003780
3781 ASSERT_NO_FATAL_FAILURE(InitState());
3782
3783 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3784 layout_bindings[0].binding = 0;
3785 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3786 layout_bindings[0].descriptorCount = 1;
3787 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3788 layout_bindings[0].pImmutableSamplers = NULL;
3789
3790 VkDescriptorSetLayout descriptor_set_layout;
3791 VkDescriptorSetLayoutCreateInfo dslci = {};
3792 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3793 dslci.pNext = NULL;
3794 dslci.bindingCount = 1;
3795 dslci.pBindings = layout_bindings;
3796 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003797 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003798
3799 VkPipelineLayout pipeline_layout;
3800 VkPipelineLayoutCreateInfo plci = {};
3801 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3802 plci.pNext = NULL;
3803 plci.setLayoutCount = 1;
3804 plci.pSetLayouts = &descriptor_set_layout;
3805 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003806 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003807
3808 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003809 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3810 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003811 m_errorMonitor->VerifyFound();
3812 EndCommandBuffer();
3813 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3814 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003815}
3816
Karl Schultz6addd812016-02-02 17:17:23 -07003817TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003818 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3819 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003820 uint64_t fake_layout_handle = 0xbaad6001;
3821 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003823 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003824 VkPipelineLayout pipeline_layout;
3825 VkPipelineLayoutCreateInfo plci = {};
3826 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3827 plci.pNext = NULL;
3828 plci.setLayoutCount = 1;
3829 plci.pSetLayouts = &bad_layout;
3830 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3831
3832 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003833}
3834
Mark Muellerd4914412016-06-13 17:52:06 -06003835TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3836 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3837 "1) A uniform buffer update must have a valid buffer index."
3838 "2) When using an array of descriptors in a single WriteDescriptor,"
3839 " the descriptor types and stageflags must all be the same."
3840 "3) Immutable Sampler state must match across descriptors");
3841
3842 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003843 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3844 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3845 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3846 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3847 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003848
Mark Muellerd4914412016-06-13 17:52:06 -06003849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3850
3851 ASSERT_NO_FATAL_FAILURE(InitState());
3852 VkDescriptorPoolSize ds_type_count[4] = {};
3853 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3854 ds_type_count[0].descriptorCount = 1;
3855 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3856 ds_type_count[1].descriptorCount = 1;
3857 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3858 ds_type_count[2].descriptorCount = 1;
3859 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3860 ds_type_count[3].descriptorCount = 1;
3861
3862 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3863 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3864 ds_pool_ci.maxSets = 1;
3865 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3866 ds_pool_ci.pPoolSizes = ds_type_count;
3867
3868 VkDescriptorPool ds_pool;
3869 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3870 ASSERT_VK_SUCCESS(err);
3871
Mark Muellerb9896722016-06-16 09:54:29 -06003872 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003873 layout_binding[0].binding = 0;
3874 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3875 layout_binding[0].descriptorCount = 1;
3876 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3877 layout_binding[0].pImmutableSamplers = NULL;
3878
3879 layout_binding[1].binding = 1;
3880 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3881 layout_binding[1].descriptorCount = 1;
3882 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3883 layout_binding[1].pImmutableSamplers = NULL;
3884
3885 VkSamplerCreateInfo sampler_ci = {};
3886 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3887 sampler_ci.pNext = NULL;
3888 sampler_ci.magFilter = VK_FILTER_NEAREST;
3889 sampler_ci.minFilter = VK_FILTER_NEAREST;
3890 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3891 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3892 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3893 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3894 sampler_ci.mipLodBias = 1.0;
3895 sampler_ci.anisotropyEnable = VK_FALSE;
3896 sampler_ci.maxAnisotropy = 1;
3897 sampler_ci.compareEnable = VK_FALSE;
3898 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3899 sampler_ci.minLod = 1.0;
3900 sampler_ci.maxLod = 1.0;
3901 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3902 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3903 VkSampler sampler;
3904
3905 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3906 ASSERT_VK_SUCCESS(err);
3907
3908 layout_binding[2].binding = 2;
3909 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3910 layout_binding[2].descriptorCount = 1;
3911 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3912 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3913
Mark Muellerd4914412016-06-13 17:52:06 -06003914 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3915 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3916 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3917 ds_layout_ci.pBindings = layout_binding;
3918 VkDescriptorSetLayout ds_layout;
3919 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3920 ASSERT_VK_SUCCESS(err);
3921
3922 VkDescriptorSetAllocateInfo alloc_info = {};
3923 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3924 alloc_info.descriptorSetCount = 1;
3925 alloc_info.descriptorPool = ds_pool;
3926 alloc_info.pSetLayouts = &ds_layout;
3927 VkDescriptorSet descriptorSet;
3928 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3929 ASSERT_VK_SUCCESS(err);
3930
3931 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3932 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3933 pipeline_layout_ci.pNext = NULL;
3934 pipeline_layout_ci.setLayoutCount = 1;
3935 pipeline_layout_ci.pSetLayouts = &ds_layout;
3936
3937 VkPipelineLayout pipeline_layout;
3938 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3939 ASSERT_VK_SUCCESS(err);
3940
Mark Mueller5c838ce2016-06-16 09:54:29 -06003941 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003942 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3943 descriptor_write.dstSet = descriptorSet;
3944 descriptor_write.dstBinding = 0;
3945 descriptor_write.descriptorCount = 1;
3946 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3947
Mark Mueller5c838ce2016-06-16 09:54:29 -06003948 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003949 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3950 m_errorMonitor->VerifyFound();
3951
3952 // Create a buffer to update the descriptor with
3953 uint32_t qfi = 0;
3954 VkBufferCreateInfo buffCI = {};
3955 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3956 buffCI.size = 1024;
3957 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3958 buffCI.queueFamilyIndexCount = 1;
3959 buffCI.pQueueFamilyIndices = &qfi;
3960
3961 VkBuffer dyub;
3962 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3963 ASSERT_VK_SUCCESS(err);
3964 VkDescriptorBufferInfo buffInfo = {};
3965 buffInfo.buffer = dyub;
3966 buffInfo.offset = 0;
3967 buffInfo.range = 1024;
3968
3969 descriptor_write.pBufferInfo = &buffInfo;
3970 descriptor_write.descriptorCount = 2;
3971
Mark Mueller5c838ce2016-06-16 09:54:29 -06003972 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3974 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3975 m_errorMonitor->VerifyFound();
3976
Mark Mueller5c838ce2016-06-16 09:54:29 -06003977 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3978 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003979 descriptor_write.dstBinding = 1;
3980 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003981
Mark Mueller5c838ce2016-06-16 09:54:29 -06003982 // Make pImageInfo index non-null to avoid complaints of it missing
3983 VkDescriptorImageInfo imageInfo = {};
3984 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3985 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3987 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3988 m_errorMonitor->VerifyFound();
3989
Mark Muellerd4914412016-06-13 17:52:06 -06003990 vkDestroyBuffer(m_device->device(), dyub, NULL);
3991 vkDestroySampler(m_device->device(), sampler, NULL);
3992 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3993 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3994 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3995}
3996
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003997TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
3998 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
3999 "due to a buffer dependency being destroyed.");
4000 ASSERT_NO_FATAL_FAILURE(InitState());
4001
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004002 VkBuffer buffer;
4003 VkDeviceMemory mem;
4004 VkMemoryRequirements mem_reqs;
4005
4006 VkBufferCreateInfo buf_info = {};
4007 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004008 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004009 buf_info.size = 256;
4010 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4011 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4012 ASSERT_VK_SUCCESS(err);
4013
4014 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4015
4016 VkMemoryAllocateInfo alloc_info = {};
4017 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4018 alloc_info.allocationSize = 256;
4019 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004020 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 -06004021 if (!pass) {
4022 vkDestroyBuffer(m_device->device(), buffer, NULL);
4023 return;
4024 }
4025 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4026 ASSERT_VK_SUCCESS(err);
4027
4028 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4029 ASSERT_VK_SUCCESS(err);
4030
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004031 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004032 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004033 m_commandBuffer->EndCommandBuffer();
4034
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004036 // Destroy buffer dependency prior to submit to cause ERROR
4037 vkDestroyBuffer(m_device->device(), buffer, NULL);
4038
4039 VkSubmitInfo submit_info = {};
4040 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4041 submit_info.commandBufferCount = 1;
4042 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4043 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4044
4045 m_errorMonitor->VerifyFound();
4046 vkFreeMemory(m_device->handle(), mem, NULL);
4047}
4048
Tobin Ehlisea413442016-09-28 10:23:59 -06004049TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4050 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4051
4052 ASSERT_NO_FATAL_FAILURE(InitState());
4053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4054
4055 VkDescriptorPoolSize ds_type_count;
4056 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4057 ds_type_count.descriptorCount = 1;
4058
4059 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4060 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4061 ds_pool_ci.maxSets = 1;
4062 ds_pool_ci.poolSizeCount = 1;
4063 ds_pool_ci.pPoolSizes = &ds_type_count;
4064
4065 VkDescriptorPool ds_pool;
4066 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4067 ASSERT_VK_SUCCESS(err);
4068
4069 VkDescriptorSetLayoutBinding layout_binding;
4070 layout_binding.binding = 0;
4071 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4072 layout_binding.descriptorCount = 1;
4073 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4074 layout_binding.pImmutableSamplers = NULL;
4075
4076 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4077 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4078 ds_layout_ci.bindingCount = 1;
4079 ds_layout_ci.pBindings = &layout_binding;
4080 VkDescriptorSetLayout ds_layout;
4081 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4082 ASSERT_VK_SUCCESS(err);
4083
4084 VkDescriptorSetAllocateInfo alloc_info = {};
4085 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4086 alloc_info.descriptorSetCount = 1;
4087 alloc_info.descriptorPool = ds_pool;
4088 alloc_info.pSetLayouts = &ds_layout;
4089 VkDescriptorSet descriptor_set;
4090 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4091 ASSERT_VK_SUCCESS(err);
4092
4093 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4094 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4095 pipeline_layout_ci.pNext = NULL;
4096 pipeline_layout_ci.setLayoutCount = 1;
4097 pipeline_layout_ci.pSetLayouts = &ds_layout;
4098
4099 VkPipelineLayout pipeline_layout;
4100 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4101 ASSERT_VK_SUCCESS(err);
4102
4103 VkBuffer buffer;
4104 uint32_t queue_family_index = 0;
4105 VkBufferCreateInfo buffer_create_info = {};
4106 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4107 buffer_create_info.size = 1024;
4108 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4109 buffer_create_info.queueFamilyIndexCount = 1;
4110 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4111
4112 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4113 ASSERT_VK_SUCCESS(err);
4114
4115 VkMemoryRequirements memory_reqs;
4116 VkDeviceMemory buffer_memory;
4117
4118 VkMemoryAllocateInfo memory_info = {};
4119 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4120 memory_info.allocationSize = 0;
4121 memory_info.memoryTypeIndex = 0;
4122
4123 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4124 memory_info.allocationSize = memory_reqs.size;
4125 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4126 ASSERT_TRUE(pass);
4127
4128 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4129 ASSERT_VK_SUCCESS(err);
4130 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4131 ASSERT_VK_SUCCESS(err);
4132
4133 VkBufferView view;
4134 VkBufferViewCreateInfo bvci = {};
4135 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4136 bvci.buffer = buffer;
4137 bvci.format = VK_FORMAT_R8_UNORM;
4138 bvci.range = VK_WHOLE_SIZE;
4139
4140 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4141 ASSERT_VK_SUCCESS(err);
4142
4143 VkWriteDescriptorSet descriptor_write = {};
4144 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4145 descriptor_write.dstSet = descriptor_set;
4146 descriptor_write.dstBinding = 0;
4147 descriptor_write.descriptorCount = 1;
4148 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4149 descriptor_write.pTexelBufferView = &view;
4150
4151 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4152
4153 char const *vsSource = "#version 450\n"
4154 "\n"
4155 "out gl_PerVertex { \n"
4156 " vec4 gl_Position;\n"
4157 "};\n"
4158 "void main(){\n"
4159 " gl_Position = vec4(1);\n"
4160 "}\n";
4161 char const *fsSource = "#version 450\n"
4162 "\n"
4163 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4164 "layout(location=0) out vec4 x;\n"
4165 "void main(){\n"
4166 " x = imageLoad(s, 0);\n"
4167 "}\n";
4168 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4169 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4170 VkPipelineObj pipe(m_device);
4171 pipe.AddShader(&vs);
4172 pipe.AddShader(&fs);
4173 pipe.AddColorAttachment();
4174 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4175
4176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4178
4179 BeginCommandBuffer();
4180 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4181 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4182 VkRect2D scissor = {{0, 0}, {16, 16}};
4183 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4184 // Bind pipeline to cmd buffer
4185 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4186 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4187 &descriptor_set, 0, nullptr);
4188 Draw(1, 0, 0, 0);
4189 EndCommandBuffer();
4190
4191 // Delete BufferView in order to invalidate cmd buffer
4192 vkDestroyBufferView(m_device->device(), view, NULL);
4193 // Now attempt submit of cmd buffer
4194 VkSubmitInfo submit_info = {};
4195 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4196 submit_info.commandBufferCount = 1;
4197 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4198 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4199 m_errorMonitor->VerifyFound();
4200
4201 // Clean-up
4202 vkDestroyBuffer(m_device->device(), buffer, NULL);
4203 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4204 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4205 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4206 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4207}
4208
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004209TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4210 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4211 "due to an image dependency being destroyed.");
4212 ASSERT_NO_FATAL_FAILURE(InitState());
4213
4214 VkImage image;
4215 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4216 VkImageCreateInfo image_create_info = {};
4217 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4218 image_create_info.pNext = NULL;
4219 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4220 image_create_info.format = tex_format;
4221 image_create_info.extent.width = 32;
4222 image_create_info.extent.height = 32;
4223 image_create_info.extent.depth = 1;
4224 image_create_info.mipLevels = 1;
4225 image_create_info.arrayLayers = 1;
4226 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4227 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004228 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004229 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004230 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004231 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004232 // Have to bind memory to image before recording cmd in cmd buffer using it
4233 VkMemoryRequirements mem_reqs;
4234 VkDeviceMemory image_mem;
4235 bool pass;
4236 VkMemoryAllocateInfo mem_alloc = {};
4237 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4238 mem_alloc.pNext = NULL;
4239 mem_alloc.memoryTypeIndex = 0;
4240 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4241 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004242 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004243 ASSERT_TRUE(pass);
4244 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4245 ASSERT_VK_SUCCESS(err);
4246 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4247 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004248
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004249 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004250 VkClearColorValue ccv;
4251 ccv.float32[0] = 1.0f;
4252 ccv.float32[1] = 1.0f;
4253 ccv.float32[2] = 1.0f;
4254 ccv.float32[3] = 1.0f;
4255 VkImageSubresourceRange isr = {};
4256 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004257 isr.baseArrayLayer = 0;
4258 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004259 isr.layerCount = 1;
4260 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004261 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004262 m_commandBuffer->EndCommandBuffer();
4263
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004265 // Destroy image dependency prior to submit to cause ERROR
4266 vkDestroyImage(m_device->device(), image, NULL);
4267
4268 VkSubmitInfo submit_info = {};
4269 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4270 submit_info.commandBufferCount = 1;
4271 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4272 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4273
4274 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004275 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004276}
4277
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004278TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4279 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4280 "due to a framebuffer image dependency being destroyed.");
4281 VkFormatProperties format_properties;
4282 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004283 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4284 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004285 return;
4286 }
4287
4288 ASSERT_NO_FATAL_FAILURE(InitState());
4289 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4290
4291 VkImageCreateInfo image_ci = {};
4292 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4293 image_ci.pNext = NULL;
4294 image_ci.imageType = VK_IMAGE_TYPE_2D;
4295 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4296 image_ci.extent.width = 32;
4297 image_ci.extent.height = 32;
4298 image_ci.extent.depth = 1;
4299 image_ci.mipLevels = 1;
4300 image_ci.arrayLayers = 1;
4301 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4302 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004303 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004304 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4305 image_ci.flags = 0;
4306 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004307 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004308
4309 VkMemoryRequirements memory_reqs;
4310 VkDeviceMemory image_memory;
4311 bool pass;
4312 VkMemoryAllocateInfo memory_info = {};
4313 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4314 memory_info.pNext = NULL;
4315 memory_info.allocationSize = 0;
4316 memory_info.memoryTypeIndex = 0;
4317 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4318 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004319 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004320 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004321 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004322 ASSERT_VK_SUCCESS(err);
4323 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4324 ASSERT_VK_SUCCESS(err);
4325
4326 VkImageViewCreateInfo ivci = {
4327 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4328 nullptr,
4329 0,
4330 image,
4331 VK_IMAGE_VIEW_TYPE_2D,
4332 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004333 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004334 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4335 };
4336 VkImageView view;
4337 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4338 ASSERT_VK_SUCCESS(err);
4339
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004340 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004341 VkFramebuffer fb;
4342 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4343 ASSERT_VK_SUCCESS(err);
4344
4345 // Just use default renderpass with our framebuffer
4346 m_renderPassBeginInfo.framebuffer = fb;
4347 // Create Null cmd buffer for submit
4348 BeginCommandBuffer();
4349 EndCommandBuffer();
4350 // Destroy image attached to framebuffer to invalidate cmd buffer
4351 vkDestroyImage(m_device->device(), image, NULL);
4352 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004354 QueueCommandBuffer(false);
4355 m_errorMonitor->VerifyFound();
4356
4357 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4358 vkDestroyImageView(m_device->device(), view, nullptr);
4359 vkFreeMemory(m_device->device(), image_memory, nullptr);
4360}
4361
Tobin Ehlisb329f992016-10-12 13:20:29 -06004362TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4363 TEST_DESCRIPTION("Delete in-use framebuffer.");
4364 VkFormatProperties format_properties;
4365 VkResult err = VK_SUCCESS;
4366 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4367
4368 ASSERT_NO_FATAL_FAILURE(InitState());
4369 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4370
4371 VkImageObj image(m_device);
4372 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4373 ASSERT_TRUE(image.initialized());
4374 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4375
4376 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4377 VkFramebuffer fb;
4378 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4379 ASSERT_VK_SUCCESS(err);
4380
4381 // Just use default renderpass with our framebuffer
4382 m_renderPassBeginInfo.framebuffer = fb;
4383 // Create Null cmd buffer for submit
4384 BeginCommandBuffer();
4385 EndCommandBuffer();
4386 // Submit cmd buffer to put it in-flight
4387 VkSubmitInfo submit_info = {};
4388 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4389 submit_info.commandBufferCount = 1;
4390 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4391 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4392 // Destroy framebuffer while in-flight
4393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4394 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4395 m_errorMonitor->VerifyFound();
4396 // Wait for queue to complete so we can safely destroy everything
4397 vkQueueWaitIdle(m_device->m_queue);
4398 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4399}
4400
Tobin Ehlis88becd72016-09-21 14:33:41 -06004401TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4402 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4403 VkFormatProperties format_properties;
4404 VkResult err = VK_SUCCESS;
4405 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004406
4407 ASSERT_NO_FATAL_FAILURE(InitState());
4408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4409
4410 VkImageCreateInfo image_ci = {};
4411 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4412 image_ci.pNext = NULL;
4413 image_ci.imageType = VK_IMAGE_TYPE_2D;
4414 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4415 image_ci.extent.width = 256;
4416 image_ci.extent.height = 256;
4417 image_ci.extent.depth = 1;
4418 image_ci.mipLevels = 1;
4419 image_ci.arrayLayers = 1;
4420 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4421 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004422 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004423 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4424 image_ci.flags = 0;
4425 VkImage image;
4426 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4427
4428 VkMemoryRequirements memory_reqs;
4429 VkDeviceMemory image_memory;
4430 bool pass;
4431 VkMemoryAllocateInfo memory_info = {};
4432 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4433 memory_info.pNext = NULL;
4434 memory_info.allocationSize = 0;
4435 memory_info.memoryTypeIndex = 0;
4436 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4437 memory_info.allocationSize = memory_reqs.size;
4438 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4439 ASSERT_TRUE(pass);
4440 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4441 ASSERT_VK_SUCCESS(err);
4442 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4443 ASSERT_VK_SUCCESS(err);
4444
4445 VkImageViewCreateInfo ivci = {
4446 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4447 nullptr,
4448 0,
4449 image,
4450 VK_IMAGE_VIEW_TYPE_2D,
4451 VK_FORMAT_B8G8R8A8_UNORM,
4452 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4453 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4454 };
4455 VkImageView view;
4456 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4457 ASSERT_VK_SUCCESS(err);
4458
4459 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4460 VkFramebuffer fb;
4461 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4462 ASSERT_VK_SUCCESS(err);
4463
4464 // Just use default renderpass with our framebuffer
4465 m_renderPassBeginInfo.framebuffer = fb;
4466 // Create Null cmd buffer for submit
4467 BeginCommandBuffer();
4468 EndCommandBuffer();
4469 // Submit cmd buffer to put it (and attached imageView) in-flight
4470 VkSubmitInfo submit_info = {};
4471 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4472 submit_info.commandBufferCount = 1;
4473 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4474 // Submit cmd buffer to put framebuffer and children in-flight
4475 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4476 // Destroy image attached to framebuffer while in-flight
4477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4478 vkDestroyImage(m_device->device(), image, NULL);
4479 m_errorMonitor->VerifyFound();
4480 // Wait for queue to complete so we can safely destroy image and other objects
4481 vkQueueWaitIdle(m_device->m_queue);
4482 vkDestroyImage(m_device->device(), image, NULL);
4483 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4484 vkDestroyImageView(m_device->device(), view, nullptr);
4485 vkFreeMemory(m_device->device(), image_memory, nullptr);
4486}
4487
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004488TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4489 TEST_DESCRIPTION("Delete in-use renderPass.");
4490
4491 ASSERT_NO_FATAL_FAILURE(InitState());
4492 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4493
4494 // Create simple renderpass
4495 VkAttachmentReference attach = {};
4496 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4497 VkSubpassDescription subpass = {};
4498 subpass.pColorAttachments = &attach;
4499 VkRenderPassCreateInfo rpci = {};
4500 rpci.subpassCount = 1;
4501 rpci.pSubpasses = &subpass;
4502 rpci.attachmentCount = 1;
4503 VkAttachmentDescription attach_desc = {};
4504 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4505 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4506 rpci.pAttachments = &attach_desc;
4507 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4508 VkRenderPass rp;
4509 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4510 ASSERT_VK_SUCCESS(err);
4511
4512 // Create a pipeline that uses the given renderpass
4513 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4514 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4515
4516 VkPipelineLayout pipeline_layout;
4517 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4518 ASSERT_VK_SUCCESS(err);
4519
4520 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4521 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4522 vp_state_ci.viewportCount = 1;
4523 VkViewport vp = {}; // Just need dummy vp to point to
4524 vp_state_ci.pViewports = &vp;
4525 vp_state_ci.scissorCount = 1;
4526 VkRect2D scissors = {}; // Dummy scissors to point to
4527 vp_state_ci.pScissors = &scissors;
4528
4529 VkPipelineShaderStageCreateInfo shaderStages[2];
4530 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4531
4532 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4533 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4534 // but add it to be able to run on more devices
4535 shaderStages[0] = vs.GetStageCreateInfo();
4536 shaderStages[1] = fs.GetStageCreateInfo();
4537
4538 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4539 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4540
4541 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4542 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4543 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4544
4545 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4546 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4547 rs_ci.rasterizerDiscardEnable = true;
4548 rs_ci.lineWidth = 1.0f;
4549
4550 VkPipelineColorBlendAttachmentState att = {};
4551 att.blendEnable = VK_FALSE;
4552 att.colorWriteMask = 0xf;
4553
4554 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4555 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4556 cb_ci.attachmentCount = 1;
4557 cb_ci.pAttachments = &att;
4558
4559 VkGraphicsPipelineCreateInfo gp_ci = {};
4560 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4561 gp_ci.stageCount = 2;
4562 gp_ci.pStages = shaderStages;
4563 gp_ci.pVertexInputState = &vi_ci;
4564 gp_ci.pInputAssemblyState = &ia_ci;
4565 gp_ci.pViewportState = &vp_state_ci;
4566 gp_ci.pRasterizationState = &rs_ci;
4567 gp_ci.pColorBlendState = &cb_ci;
4568 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4569 gp_ci.layout = pipeline_layout;
4570 gp_ci.renderPass = rp;
4571
4572 VkPipelineCacheCreateInfo pc_ci = {};
4573 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4574
4575 VkPipeline pipeline;
4576 VkPipelineCache pipe_cache;
4577 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4578 ASSERT_VK_SUCCESS(err);
4579
4580 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4581 ASSERT_VK_SUCCESS(err);
4582 // Bind pipeline to cmd buffer, will also bind renderpass
4583 m_commandBuffer->BeginCommandBuffer();
4584 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4585 m_commandBuffer->EndCommandBuffer();
4586
4587 VkSubmitInfo submit_info = {};
4588 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4589 submit_info.commandBufferCount = 1;
4590 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4591 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4592
4593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4594 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4595 m_errorMonitor->VerifyFound();
4596
4597 // Wait for queue to complete so we can safely destroy everything
4598 vkQueueWaitIdle(m_device->m_queue);
4599 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4600 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4601 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4602 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4603}
4604
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004605TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004606 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004607 ASSERT_NO_FATAL_FAILURE(InitState());
4608
4609 VkImage image;
4610 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4611 VkImageCreateInfo image_create_info = {};
4612 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4613 image_create_info.pNext = NULL;
4614 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4615 image_create_info.format = tex_format;
4616 image_create_info.extent.width = 32;
4617 image_create_info.extent.height = 32;
4618 image_create_info.extent.depth = 1;
4619 image_create_info.mipLevels = 1;
4620 image_create_info.arrayLayers = 1;
4621 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4622 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004623 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004624 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004625 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004626 ASSERT_VK_SUCCESS(err);
4627 // Have to bind memory to image before recording cmd in cmd buffer using it
4628 VkMemoryRequirements mem_reqs;
4629 VkDeviceMemory image_mem;
4630 bool pass;
4631 VkMemoryAllocateInfo mem_alloc = {};
4632 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4633 mem_alloc.pNext = NULL;
4634 mem_alloc.memoryTypeIndex = 0;
4635 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4636 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004637 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004638 ASSERT_TRUE(pass);
4639 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4640 ASSERT_VK_SUCCESS(err);
4641
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004642 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004644 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004645
4646 m_commandBuffer->BeginCommandBuffer();
4647 VkClearColorValue ccv;
4648 ccv.float32[0] = 1.0f;
4649 ccv.float32[1] = 1.0f;
4650 ccv.float32[2] = 1.0f;
4651 ccv.float32[3] = 1.0f;
4652 VkImageSubresourceRange isr = {};
4653 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4654 isr.baseArrayLayer = 0;
4655 isr.baseMipLevel = 0;
4656 isr.layerCount = 1;
4657 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004658 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004659 m_commandBuffer->EndCommandBuffer();
4660
4661 m_errorMonitor->VerifyFound();
4662 vkDestroyImage(m_device->device(), image, NULL);
4663 vkFreeMemory(m_device->device(), image_mem, nullptr);
4664}
4665
4666TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004667 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004668 ASSERT_NO_FATAL_FAILURE(InitState());
4669
4670 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004671 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 -06004672 VK_IMAGE_TILING_OPTIMAL, 0);
4673 ASSERT_TRUE(image.initialized());
4674
4675 VkBuffer buffer;
4676 VkDeviceMemory mem;
4677 VkMemoryRequirements mem_reqs;
4678
4679 VkBufferCreateInfo buf_info = {};
4680 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004681 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004682 buf_info.size = 256;
4683 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4684 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4685 ASSERT_VK_SUCCESS(err);
4686
4687 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4688
4689 VkMemoryAllocateInfo alloc_info = {};
4690 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4691 alloc_info.allocationSize = 256;
4692 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004693 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 -06004694 if (!pass) {
4695 vkDestroyBuffer(m_device->device(), buffer, NULL);
4696 return;
4697 }
4698 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4699 ASSERT_VK_SUCCESS(err);
4700
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004701 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004703 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004704 VkBufferImageCopy region = {};
4705 region.bufferRowLength = 128;
4706 region.bufferImageHeight = 128;
4707 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4708
4709 region.imageSubresource.layerCount = 1;
4710 region.imageExtent.height = 4;
4711 region.imageExtent.width = 4;
4712 region.imageExtent.depth = 1;
4713 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004714 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4715 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004716 m_commandBuffer->EndCommandBuffer();
4717
4718 m_errorMonitor->VerifyFound();
4719
4720 vkDestroyBuffer(m_device->device(), buffer, NULL);
4721 vkFreeMemory(m_device->handle(), mem, NULL);
4722}
4723
Tobin Ehlis85940f52016-07-07 16:57:21 -06004724TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4725 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4726 "due to an event dependency being destroyed.");
4727 ASSERT_NO_FATAL_FAILURE(InitState());
4728
4729 VkEvent event;
4730 VkEventCreateInfo evci = {};
4731 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4732 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4733 ASSERT_VK_SUCCESS(result);
4734
4735 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004736 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004737 m_commandBuffer->EndCommandBuffer();
4738
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004740 // Destroy event dependency prior to submit to cause ERROR
4741 vkDestroyEvent(m_device->device(), event, NULL);
4742
4743 VkSubmitInfo submit_info = {};
4744 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4745 submit_info.commandBufferCount = 1;
4746 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4747 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4748
4749 m_errorMonitor->VerifyFound();
4750}
4751
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004752TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4753 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4754 "due to a query pool dependency being destroyed.");
4755 ASSERT_NO_FATAL_FAILURE(InitState());
4756
4757 VkQueryPool query_pool;
4758 VkQueryPoolCreateInfo qpci{};
4759 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4760 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4761 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004762 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004763 ASSERT_VK_SUCCESS(result);
4764
4765 m_commandBuffer->BeginCommandBuffer();
4766 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4767 m_commandBuffer->EndCommandBuffer();
4768
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004770 // Destroy query pool dependency prior to submit to cause ERROR
4771 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4772
4773 VkSubmitInfo submit_info = {};
4774 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4775 submit_info.commandBufferCount = 1;
4776 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4777 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4778
4779 m_errorMonitor->VerifyFound();
4780}
4781
Tobin Ehlis24130d92016-07-08 15:50:53 -06004782TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4783 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4784 "due to a pipeline dependency being destroyed.");
4785 ASSERT_NO_FATAL_FAILURE(InitState());
4786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4787
4788 VkResult err;
4789
4790 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4791 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4792
4793 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004794 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004795 ASSERT_VK_SUCCESS(err);
4796
4797 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4798 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4799 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004800 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004801 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004802 vp_state_ci.scissorCount = 1;
4803 VkRect2D scissors = {}; // Dummy scissors to point to
4804 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004805
4806 VkPipelineShaderStageCreateInfo shaderStages[2];
4807 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4808
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004809 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4810 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4811 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004812 shaderStages[0] = vs.GetStageCreateInfo();
4813 shaderStages[1] = fs.GetStageCreateInfo();
4814
4815 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4816 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4817
4818 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4819 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4820 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4821
4822 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4823 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004824 rs_ci.rasterizerDiscardEnable = true;
4825 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004826
4827 VkPipelineColorBlendAttachmentState att = {};
4828 att.blendEnable = VK_FALSE;
4829 att.colorWriteMask = 0xf;
4830
4831 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4832 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4833 cb_ci.attachmentCount = 1;
4834 cb_ci.pAttachments = &att;
4835
4836 VkGraphicsPipelineCreateInfo gp_ci = {};
4837 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4838 gp_ci.stageCount = 2;
4839 gp_ci.pStages = shaderStages;
4840 gp_ci.pVertexInputState = &vi_ci;
4841 gp_ci.pInputAssemblyState = &ia_ci;
4842 gp_ci.pViewportState = &vp_state_ci;
4843 gp_ci.pRasterizationState = &rs_ci;
4844 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004845 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4846 gp_ci.layout = pipeline_layout;
4847 gp_ci.renderPass = renderPass();
4848
4849 VkPipelineCacheCreateInfo pc_ci = {};
4850 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4851
4852 VkPipeline pipeline;
4853 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004854 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004855 ASSERT_VK_SUCCESS(err);
4856
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004857 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004858 ASSERT_VK_SUCCESS(err);
4859
4860 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004861 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004862 m_commandBuffer->EndCommandBuffer();
4863 // Now destroy pipeline in order to cause error when submitting
4864 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4865
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004867
4868 VkSubmitInfo submit_info = {};
4869 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4870 submit_info.commandBufferCount = 1;
4871 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4872 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4873
4874 m_errorMonitor->VerifyFound();
4875 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4876 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4877}
4878
Tobin Ehlis31289162016-08-17 14:57:58 -06004879TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4880 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4881 "due to a bound descriptor set with a buffer dependency "
4882 "being destroyed.");
4883 ASSERT_NO_FATAL_FAILURE(InitState());
4884 ASSERT_NO_FATAL_FAILURE(InitViewport());
4885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4886
4887 VkDescriptorPoolSize ds_type_count = {};
4888 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4889 ds_type_count.descriptorCount = 1;
4890
4891 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4892 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4893 ds_pool_ci.pNext = NULL;
4894 ds_pool_ci.maxSets = 1;
4895 ds_pool_ci.poolSizeCount = 1;
4896 ds_pool_ci.pPoolSizes = &ds_type_count;
4897
4898 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004899 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004900 ASSERT_VK_SUCCESS(err);
4901
4902 VkDescriptorSetLayoutBinding dsl_binding = {};
4903 dsl_binding.binding = 0;
4904 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4905 dsl_binding.descriptorCount = 1;
4906 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4907 dsl_binding.pImmutableSamplers = NULL;
4908
4909 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4910 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4911 ds_layout_ci.pNext = NULL;
4912 ds_layout_ci.bindingCount = 1;
4913 ds_layout_ci.pBindings = &dsl_binding;
4914 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004915 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004916 ASSERT_VK_SUCCESS(err);
4917
4918 VkDescriptorSet descriptorSet;
4919 VkDescriptorSetAllocateInfo alloc_info = {};
4920 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4921 alloc_info.descriptorSetCount = 1;
4922 alloc_info.descriptorPool = ds_pool;
4923 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004924 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004925 ASSERT_VK_SUCCESS(err);
4926
4927 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4928 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4929 pipeline_layout_ci.pNext = NULL;
4930 pipeline_layout_ci.setLayoutCount = 1;
4931 pipeline_layout_ci.pSetLayouts = &ds_layout;
4932
4933 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004934 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004935 ASSERT_VK_SUCCESS(err);
4936
4937 // Create a buffer to update the descriptor with
4938 uint32_t qfi = 0;
4939 VkBufferCreateInfo buffCI = {};
4940 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4941 buffCI.size = 1024;
4942 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4943 buffCI.queueFamilyIndexCount = 1;
4944 buffCI.pQueueFamilyIndices = &qfi;
4945
4946 VkBuffer buffer;
4947 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4948 ASSERT_VK_SUCCESS(err);
4949 // Allocate memory and bind to buffer so we can make it to the appropriate
4950 // error
4951 VkMemoryAllocateInfo mem_alloc = {};
4952 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4953 mem_alloc.pNext = NULL;
4954 mem_alloc.allocationSize = 1024;
4955 mem_alloc.memoryTypeIndex = 0;
4956
4957 VkMemoryRequirements memReqs;
4958 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004959 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004960 if (!pass) {
4961 vkDestroyBuffer(m_device->device(), buffer, NULL);
4962 return;
4963 }
4964
4965 VkDeviceMemory mem;
4966 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4967 ASSERT_VK_SUCCESS(err);
4968 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4969 ASSERT_VK_SUCCESS(err);
4970 // Correctly update descriptor to avoid "NOT_UPDATED" error
4971 VkDescriptorBufferInfo buffInfo = {};
4972 buffInfo.buffer = buffer;
4973 buffInfo.offset = 0;
4974 buffInfo.range = 1024;
4975
4976 VkWriteDescriptorSet descriptor_write;
4977 memset(&descriptor_write, 0, sizeof(descriptor_write));
4978 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4979 descriptor_write.dstSet = descriptorSet;
4980 descriptor_write.dstBinding = 0;
4981 descriptor_write.descriptorCount = 1;
4982 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4983 descriptor_write.pBufferInfo = &buffInfo;
4984
4985 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4986
4987 // Create PSO to be used for draw-time errors below
4988 char const *vsSource = "#version 450\n"
4989 "\n"
4990 "out gl_PerVertex { \n"
4991 " vec4 gl_Position;\n"
4992 "};\n"
4993 "void main(){\n"
4994 " gl_Position = vec4(1);\n"
4995 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004996 char const *fsSource = "#version 450\n"
4997 "\n"
4998 "layout(location=0) out vec4 x;\n"
4999 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5000 "void main(){\n"
5001 " x = vec4(bar.y);\n"
5002 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005003 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5004 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5005 VkPipelineObj pipe(m_device);
5006 pipe.AddShader(&vs);
5007 pipe.AddShader(&fs);
5008 pipe.AddColorAttachment();
5009 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5010
5011 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005012 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5013 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5014 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005015 Draw(1, 0, 0, 0);
5016 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005018 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5019 vkDestroyBuffer(m_device->device(), buffer, NULL);
5020 // Attempt to submit cmd buffer
5021 VkSubmitInfo submit_info = {};
5022 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5023 submit_info.commandBufferCount = 1;
5024 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5025 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5026 m_errorMonitor->VerifyFound();
5027 // Cleanup
5028 vkFreeMemory(m_device->device(), mem, NULL);
5029
5030 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5031 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5032 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5033}
5034
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005035TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5036 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5037 "due to a bound descriptor sets with a combined image "
5038 "sampler having their image, sampler, and descriptor set "
5039 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005040 "submit associated cmd buffers. Attempt to destroy a "
5041 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005042 ASSERT_NO_FATAL_FAILURE(InitState());
5043 ASSERT_NO_FATAL_FAILURE(InitViewport());
5044 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5045
5046 VkDescriptorPoolSize ds_type_count = {};
5047 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5048 ds_type_count.descriptorCount = 1;
5049
5050 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5051 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5052 ds_pool_ci.pNext = NULL;
5053 ds_pool_ci.maxSets = 1;
5054 ds_pool_ci.poolSizeCount = 1;
5055 ds_pool_ci.pPoolSizes = &ds_type_count;
5056
5057 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005058 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005059 ASSERT_VK_SUCCESS(err);
5060
5061 VkDescriptorSetLayoutBinding dsl_binding = {};
5062 dsl_binding.binding = 0;
5063 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5064 dsl_binding.descriptorCount = 1;
5065 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5066 dsl_binding.pImmutableSamplers = NULL;
5067
5068 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5069 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5070 ds_layout_ci.pNext = NULL;
5071 ds_layout_ci.bindingCount = 1;
5072 ds_layout_ci.pBindings = &dsl_binding;
5073 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005074 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005075 ASSERT_VK_SUCCESS(err);
5076
5077 VkDescriptorSet descriptorSet;
5078 VkDescriptorSetAllocateInfo alloc_info = {};
5079 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5080 alloc_info.descriptorSetCount = 1;
5081 alloc_info.descriptorPool = ds_pool;
5082 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005083 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005084 ASSERT_VK_SUCCESS(err);
5085
5086 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5087 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5088 pipeline_layout_ci.pNext = NULL;
5089 pipeline_layout_ci.setLayoutCount = 1;
5090 pipeline_layout_ci.pSetLayouts = &ds_layout;
5091
5092 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005093 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005094 ASSERT_VK_SUCCESS(err);
5095
5096 // Create images to update the descriptor with
5097 VkImage image;
5098 VkImage image2;
5099 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5100 const int32_t tex_width = 32;
5101 const int32_t tex_height = 32;
5102 VkImageCreateInfo image_create_info = {};
5103 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5104 image_create_info.pNext = NULL;
5105 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5106 image_create_info.format = tex_format;
5107 image_create_info.extent.width = tex_width;
5108 image_create_info.extent.height = tex_height;
5109 image_create_info.extent.depth = 1;
5110 image_create_info.mipLevels = 1;
5111 image_create_info.arrayLayers = 1;
5112 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5113 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5114 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5115 image_create_info.flags = 0;
5116 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5117 ASSERT_VK_SUCCESS(err);
5118 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5119 ASSERT_VK_SUCCESS(err);
5120
5121 VkMemoryRequirements memory_reqs;
5122 VkDeviceMemory image_memory;
5123 bool pass;
5124 VkMemoryAllocateInfo memory_info = {};
5125 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5126 memory_info.pNext = NULL;
5127 memory_info.allocationSize = 0;
5128 memory_info.memoryTypeIndex = 0;
5129 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5130 // Allocate enough memory for both images
5131 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005132 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005133 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005134 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005135 ASSERT_VK_SUCCESS(err);
5136 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5137 ASSERT_VK_SUCCESS(err);
5138 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005139 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005140 ASSERT_VK_SUCCESS(err);
5141
5142 VkImageViewCreateInfo image_view_create_info = {};
5143 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5144 image_view_create_info.image = image;
5145 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5146 image_view_create_info.format = tex_format;
5147 image_view_create_info.subresourceRange.layerCount = 1;
5148 image_view_create_info.subresourceRange.baseMipLevel = 0;
5149 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005150 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005151
5152 VkImageView view;
5153 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005154 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005155 ASSERT_VK_SUCCESS(err);
5156 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005157 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005158 ASSERT_VK_SUCCESS(err);
5159 // Create Samplers
5160 VkSamplerCreateInfo sampler_ci = {};
5161 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5162 sampler_ci.pNext = NULL;
5163 sampler_ci.magFilter = VK_FILTER_NEAREST;
5164 sampler_ci.minFilter = VK_FILTER_NEAREST;
5165 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5166 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5167 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5168 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5169 sampler_ci.mipLodBias = 1.0;
5170 sampler_ci.anisotropyEnable = VK_FALSE;
5171 sampler_ci.maxAnisotropy = 1;
5172 sampler_ci.compareEnable = VK_FALSE;
5173 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5174 sampler_ci.minLod = 1.0;
5175 sampler_ci.maxLod = 1.0;
5176 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5177 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5178 VkSampler sampler;
5179 VkSampler sampler2;
5180 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5181 ASSERT_VK_SUCCESS(err);
5182 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5183 ASSERT_VK_SUCCESS(err);
5184 // Update descriptor with image and sampler
5185 VkDescriptorImageInfo img_info = {};
5186 img_info.sampler = sampler;
5187 img_info.imageView = view;
5188 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5189
5190 VkWriteDescriptorSet descriptor_write;
5191 memset(&descriptor_write, 0, sizeof(descriptor_write));
5192 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5193 descriptor_write.dstSet = descriptorSet;
5194 descriptor_write.dstBinding = 0;
5195 descriptor_write.descriptorCount = 1;
5196 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5197 descriptor_write.pImageInfo = &img_info;
5198
5199 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5200
5201 // Create PSO to be used for draw-time errors below
5202 char const *vsSource = "#version 450\n"
5203 "\n"
5204 "out gl_PerVertex { \n"
5205 " vec4 gl_Position;\n"
5206 "};\n"
5207 "void main(){\n"
5208 " gl_Position = vec4(1);\n"
5209 "}\n";
5210 char const *fsSource = "#version 450\n"
5211 "\n"
5212 "layout(set=0, binding=0) uniform sampler2D s;\n"
5213 "layout(location=0) out vec4 x;\n"
5214 "void main(){\n"
5215 " x = texture(s, vec2(1));\n"
5216 "}\n";
5217 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5218 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5219 VkPipelineObj pipe(m_device);
5220 pipe.AddShader(&vs);
5221 pipe.AddShader(&fs);
5222 pipe.AddColorAttachment();
5223 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5224
5225 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005227 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005228 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5229 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5230 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005231 Draw(1, 0, 0, 0);
5232 EndCommandBuffer();
5233 // Destroy sampler invalidates the cmd buffer, causing error on submit
5234 vkDestroySampler(m_device->device(), sampler, NULL);
5235 // Attempt to submit cmd buffer
5236 VkSubmitInfo submit_info = {};
5237 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5238 submit_info.commandBufferCount = 1;
5239 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5240 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5241 m_errorMonitor->VerifyFound();
5242 // Now re-update descriptor with valid sampler and delete image
5243 img_info.sampler = sampler2;
5244 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005246 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005247 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5248 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5249 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005250 Draw(1, 0, 0, 0);
5251 EndCommandBuffer();
5252 // Destroy image invalidates the cmd buffer, causing error on submit
5253 vkDestroyImage(m_device->device(), image, NULL);
5254 // Attempt to submit cmd buffer
5255 submit_info = {};
5256 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5257 submit_info.commandBufferCount = 1;
5258 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5259 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5260 m_errorMonitor->VerifyFound();
5261 // Now update descriptor to be valid, but then free descriptor
5262 img_info.imageView = view2;
5263 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005265 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005266 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5267 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5268 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005269 Draw(1, 0, 0, 0);
5270 EndCommandBuffer();
5271 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005273 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005274 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005275 // Attempt to submit cmd buffer
5276 submit_info = {};
5277 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5278 submit_info.commandBufferCount = 1;
5279 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5280 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5281 m_errorMonitor->VerifyFound();
5282 // Cleanup
5283 vkFreeMemory(m_device->device(), image_memory, NULL);
5284 vkDestroySampler(m_device->device(), sampler2, NULL);
5285 vkDestroyImage(m_device->device(), image2, NULL);
5286 vkDestroyImageView(m_device->device(), view, NULL);
5287 vkDestroyImageView(m_device->device(), view2, NULL);
5288 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5289 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5290 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5291}
5292
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005293TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5294 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5295 ASSERT_NO_FATAL_FAILURE(InitState());
5296 ASSERT_NO_FATAL_FAILURE(InitViewport());
5297 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5298
5299 VkDescriptorPoolSize ds_type_count = {};
5300 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5301 ds_type_count.descriptorCount = 1;
5302
5303 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5304 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5305 ds_pool_ci.pNext = NULL;
5306 ds_pool_ci.maxSets = 1;
5307 ds_pool_ci.poolSizeCount = 1;
5308 ds_pool_ci.pPoolSizes = &ds_type_count;
5309
5310 VkDescriptorPool ds_pool;
5311 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5312 ASSERT_VK_SUCCESS(err);
5313
5314 VkDescriptorSetLayoutBinding dsl_binding = {};
5315 dsl_binding.binding = 0;
5316 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5317 dsl_binding.descriptorCount = 1;
5318 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5319 dsl_binding.pImmutableSamplers = NULL;
5320
5321 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5322 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5323 ds_layout_ci.pNext = NULL;
5324 ds_layout_ci.bindingCount = 1;
5325 ds_layout_ci.pBindings = &dsl_binding;
5326 VkDescriptorSetLayout ds_layout;
5327 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5328 ASSERT_VK_SUCCESS(err);
5329
5330 VkDescriptorSet descriptor_set;
5331 VkDescriptorSetAllocateInfo alloc_info = {};
5332 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5333 alloc_info.descriptorSetCount = 1;
5334 alloc_info.descriptorPool = ds_pool;
5335 alloc_info.pSetLayouts = &ds_layout;
5336 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5337 ASSERT_VK_SUCCESS(err);
5338
5339 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5340 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5341 pipeline_layout_ci.pNext = NULL;
5342 pipeline_layout_ci.setLayoutCount = 1;
5343 pipeline_layout_ci.pSetLayouts = &ds_layout;
5344
5345 VkPipelineLayout pipeline_layout;
5346 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5347 ASSERT_VK_SUCCESS(err);
5348
5349 // Create image to update the descriptor with
5350 VkImageObj image(m_device);
5351 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5352 ASSERT_TRUE(image.initialized());
5353
5354 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5355 // Create Sampler
5356 VkSamplerCreateInfo sampler_ci = {};
5357 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5358 sampler_ci.pNext = NULL;
5359 sampler_ci.magFilter = VK_FILTER_NEAREST;
5360 sampler_ci.minFilter = VK_FILTER_NEAREST;
5361 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5362 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5363 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5364 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5365 sampler_ci.mipLodBias = 1.0;
5366 sampler_ci.anisotropyEnable = VK_FALSE;
5367 sampler_ci.maxAnisotropy = 1;
5368 sampler_ci.compareEnable = VK_FALSE;
5369 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5370 sampler_ci.minLod = 1.0;
5371 sampler_ci.maxLod = 1.0;
5372 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5373 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5374 VkSampler sampler;
5375 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5376 ASSERT_VK_SUCCESS(err);
5377 // Update descriptor with image and sampler
5378 VkDescriptorImageInfo img_info = {};
5379 img_info.sampler = sampler;
5380 img_info.imageView = view;
5381 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5382
5383 VkWriteDescriptorSet descriptor_write;
5384 memset(&descriptor_write, 0, sizeof(descriptor_write));
5385 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5386 descriptor_write.dstSet = descriptor_set;
5387 descriptor_write.dstBinding = 0;
5388 descriptor_write.descriptorCount = 1;
5389 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5390 descriptor_write.pImageInfo = &img_info;
5391
5392 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5393
5394 // Create PSO to be used for draw-time errors below
5395 char const *vsSource = "#version 450\n"
5396 "\n"
5397 "out gl_PerVertex { \n"
5398 " vec4 gl_Position;\n"
5399 "};\n"
5400 "void main(){\n"
5401 " gl_Position = vec4(1);\n"
5402 "}\n";
5403 char const *fsSource = "#version 450\n"
5404 "\n"
5405 "layout(set=0, binding=0) uniform sampler2D s;\n"
5406 "layout(location=0) out vec4 x;\n"
5407 "void main(){\n"
5408 " x = texture(s, vec2(1));\n"
5409 "}\n";
5410 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5411 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5412 VkPipelineObj pipe(m_device);
5413 pipe.AddShader(&vs);
5414 pipe.AddShader(&fs);
5415 pipe.AddColorAttachment();
5416 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5417
5418 BeginCommandBuffer();
5419 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5420 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5421 &descriptor_set, 0, NULL);
5422 Draw(1, 0, 0, 0);
5423 EndCommandBuffer();
5424 // Submit cmd buffer to put pool in-flight
5425 VkSubmitInfo submit_info = {};
5426 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5427 submit_info.commandBufferCount = 1;
5428 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5429 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5430 // Destroy pool while in-flight, causing error
5431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5432 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5433 m_errorMonitor->VerifyFound();
5434 vkQueueWaitIdle(m_device->m_queue);
5435 // Cleanup
5436 vkDestroySampler(m_device->device(), sampler, NULL);
5437 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5438 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5439 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5440}
5441
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005442TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5443 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5444 ASSERT_NO_FATAL_FAILURE(InitState());
5445 ASSERT_NO_FATAL_FAILURE(InitViewport());
5446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5447
5448 VkDescriptorPoolSize ds_type_count = {};
5449 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5450 ds_type_count.descriptorCount = 1;
5451
5452 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5453 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5454 ds_pool_ci.pNext = NULL;
5455 ds_pool_ci.maxSets = 1;
5456 ds_pool_ci.poolSizeCount = 1;
5457 ds_pool_ci.pPoolSizes = &ds_type_count;
5458
5459 VkDescriptorPool ds_pool;
5460 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5461 ASSERT_VK_SUCCESS(err);
5462
5463 VkDescriptorSetLayoutBinding dsl_binding = {};
5464 dsl_binding.binding = 0;
5465 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5466 dsl_binding.descriptorCount = 1;
5467 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5468 dsl_binding.pImmutableSamplers = NULL;
5469
5470 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5471 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5472 ds_layout_ci.pNext = NULL;
5473 ds_layout_ci.bindingCount = 1;
5474 ds_layout_ci.pBindings = &dsl_binding;
5475 VkDescriptorSetLayout ds_layout;
5476 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5477 ASSERT_VK_SUCCESS(err);
5478
5479 VkDescriptorSet descriptorSet;
5480 VkDescriptorSetAllocateInfo alloc_info = {};
5481 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5482 alloc_info.descriptorSetCount = 1;
5483 alloc_info.descriptorPool = ds_pool;
5484 alloc_info.pSetLayouts = &ds_layout;
5485 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5486 ASSERT_VK_SUCCESS(err);
5487
5488 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5489 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5490 pipeline_layout_ci.pNext = NULL;
5491 pipeline_layout_ci.setLayoutCount = 1;
5492 pipeline_layout_ci.pSetLayouts = &ds_layout;
5493
5494 VkPipelineLayout pipeline_layout;
5495 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5496 ASSERT_VK_SUCCESS(err);
5497
5498 // Create images to update the descriptor with
5499 VkImage image;
5500 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5501 const int32_t tex_width = 32;
5502 const int32_t tex_height = 32;
5503 VkImageCreateInfo image_create_info = {};
5504 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5505 image_create_info.pNext = NULL;
5506 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5507 image_create_info.format = tex_format;
5508 image_create_info.extent.width = tex_width;
5509 image_create_info.extent.height = tex_height;
5510 image_create_info.extent.depth = 1;
5511 image_create_info.mipLevels = 1;
5512 image_create_info.arrayLayers = 1;
5513 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5514 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5515 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5516 image_create_info.flags = 0;
5517 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5518 ASSERT_VK_SUCCESS(err);
5519 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5520 VkMemoryRequirements memory_reqs;
5521 VkDeviceMemory image_memory;
5522 bool pass;
5523 VkMemoryAllocateInfo memory_info = {};
5524 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5525 memory_info.pNext = NULL;
5526 memory_info.allocationSize = 0;
5527 memory_info.memoryTypeIndex = 0;
5528 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5529 // Allocate enough memory for image
5530 memory_info.allocationSize = memory_reqs.size;
5531 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5532 ASSERT_TRUE(pass);
5533 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5534 ASSERT_VK_SUCCESS(err);
5535 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5536 ASSERT_VK_SUCCESS(err);
5537
5538 VkImageViewCreateInfo image_view_create_info = {};
5539 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5540 image_view_create_info.image = image;
5541 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5542 image_view_create_info.format = tex_format;
5543 image_view_create_info.subresourceRange.layerCount = 1;
5544 image_view_create_info.subresourceRange.baseMipLevel = 0;
5545 image_view_create_info.subresourceRange.levelCount = 1;
5546 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5547
5548 VkImageView view;
5549 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5550 ASSERT_VK_SUCCESS(err);
5551 // Create Samplers
5552 VkSamplerCreateInfo sampler_ci = {};
5553 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5554 sampler_ci.pNext = NULL;
5555 sampler_ci.magFilter = VK_FILTER_NEAREST;
5556 sampler_ci.minFilter = VK_FILTER_NEAREST;
5557 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5558 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5559 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5560 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5561 sampler_ci.mipLodBias = 1.0;
5562 sampler_ci.anisotropyEnable = VK_FALSE;
5563 sampler_ci.maxAnisotropy = 1;
5564 sampler_ci.compareEnable = VK_FALSE;
5565 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5566 sampler_ci.minLod = 1.0;
5567 sampler_ci.maxLod = 1.0;
5568 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5569 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5570 VkSampler sampler;
5571 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5572 ASSERT_VK_SUCCESS(err);
5573 // Update descriptor with image and sampler
5574 VkDescriptorImageInfo img_info = {};
5575 img_info.sampler = sampler;
5576 img_info.imageView = view;
5577 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5578
5579 VkWriteDescriptorSet descriptor_write;
5580 memset(&descriptor_write, 0, sizeof(descriptor_write));
5581 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5582 descriptor_write.dstSet = descriptorSet;
5583 descriptor_write.dstBinding = 0;
5584 descriptor_write.descriptorCount = 1;
5585 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5586 descriptor_write.pImageInfo = &img_info;
5587 // Break memory binding and attempt update
5588 vkFreeMemory(m_device->device(), image_memory, nullptr);
5589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005590 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5592 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5593 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5594 m_errorMonitor->VerifyFound();
5595 // Cleanup
5596 vkDestroyImage(m_device->device(), image, NULL);
5597 vkDestroySampler(m_device->device(), sampler, NULL);
5598 vkDestroyImageView(m_device->device(), view, NULL);
5599 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5600 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5601 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5602}
5603
Karl Schultz6addd812016-02-02 17:17:23 -07005604TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005605 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5606 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005607 // Create a valid cmd buffer
5608 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005609 uint64_t fake_pipeline_handle = 0xbaad6001;
5610 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005611 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005612 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5613
5614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005615 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005616 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005617 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005618
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005619 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005620 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 -06005621 Draw(1, 0, 0, 0);
5622 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005623
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005624 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005625 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 +12005626 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005627 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5628 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005629}
5630
Karl Schultz6addd812016-02-02 17:17:23 -07005631TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005632 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005633 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005634
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005636
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005637 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005638 ASSERT_NO_FATAL_FAILURE(InitViewport());
5639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005640 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005641 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5642 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005643
5644 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005645 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5646 ds_pool_ci.pNext = NULL;
5647 ds_pool_ci.maxSets = 1;
5648 ds_pool_ci.poolSizeCount = 1;
5649 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005650
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005651 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005652 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005653 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005654
Tony Barboureb254902015-07-15 12:50:33 -06005655 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005656 dsl_binding.binding = 0;
5657 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5658 dsl_binding.descriptorCount = 1;
5659 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5660 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005661
Tony Barboureb254902015-07-15 12:50:33 -06005662 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005663 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5664 ds_layout_ci.pNext = NULL;
5665 ds_layout_ci.bindingCount = 1;
5666 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005667 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005668 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005669 ASSERT_VK_SUCCESS(err);
5670
5671 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005672 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005673 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005674 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005675 alloc_info.descriptorPool = ds_pool;
5676 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005677 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005678 ASSERT_VK_SUCCESS(err);
5679
Tony Barboureb254902015-07-15 12:50:33 -06005680 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005681 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5682 pipeline_layout_ci.pNext = NULL;
5683 pipeline_layout_ci.setLayoutCount = 1;
5684 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005685
5686 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005687 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005688 ASSERT_VK_SUCCESS(err);
5689
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005690 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005691 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005692 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005693 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005694
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005695 VkPipelineObj pipe(m_device);
5696 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005697 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005698 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005699 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005700
5701 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005702 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5703 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5704 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005705
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005706 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005707
Chia-I Wuf7458c52015-10-26 21:10:41 +08005708 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5709 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5710 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005711}
5712
Karl Schultz6addd812016-02-02 17:17:23 -07005713TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005714 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005715 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5718 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005719
5720 ASSERT_NO_FATAL_FAILURE(InitState());
5721 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005722 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5723 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005724
5725 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005726 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5727 ds_pool_ci.pNext = NULL;
5728 ds_pool_ci.maxSets = 1;
5729 ds_pool_ci.poolSizeCount = 1;
5730 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005731
5732 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005733 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005734 ASSERT_VK_SUCCESS(err);
5735
5736 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005737 dsl_binding.binding = 0;
5738 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5739 dsl_binding.descriptorCount = 1;
5740 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5741 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005742
5743 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005744 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5745 ds_layout_ci.pNext = NULL;
5746 ds_layout_ci.bindingCount = 1;
5747 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005748 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005749 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005750 ASSERT_VK_SUCCESS(err);
5751
5752 VkDescriptorSet descriptorSet;
5753 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005754 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005755 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005756 alloc_info.descriptorPool = ds_pool;
5757 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005758 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005759 ASSERT_VK_SUCCESS(err);
5760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005761 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005762 VkWriteDescriptorSet descriptor_write;
5763 memset(&descriptor_write, 0, sizeof(descriptor_write));
5764 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5765 descriptor_write.dstSet = descriptorSet;
5766 descriptor_write.dstBinding = 0;
5767 descriptor_write.descriptorCount = 1;
5768 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5769 descriptor_write.pTexelBufferView = &view;
5770
5771 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5772
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005773 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005774
5775 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5776 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5777}
5778
Mark Youngd339ba32016-05-30 13:28:35 -06005779TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005780 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 -06005781
5782 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005784 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005785
5786 ASSERT_NO_FATAL_FAILURE(InitState());
5787
5788 // Create a buffer with no bound memory and then attempt to create
5789 // a buffer view.
5790 VkBufferCreateInfo buff_ci = {};
5791 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005792 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005793 buff_ci.size = 256;
5794 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5795 VkBuffer buffer;
5796 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5797 ASSERT_VK_SUCCESS(err);
5798
5799 VkBufferViewCreateInfo buff_view_ci = {};
5800 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5801 buff_view_ci.buffer = buffer;
5802 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5803 buff_view_ci.range = VK_WHOLE_SIZE;
5804 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005805 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005806
5807 m_errorMonitor->VerifyFound();
5808 vkDestroyBuffer(m_device->device(), buffer, NULL);
5809 // If last error is success, it still created the view, so delete it.
5810 if (err == VK_SUCCESS) {
5811 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5812 }
5813}
5814
Karl Schultz6addd812016-02-02 17:17:23 -07005815TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5816 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5817 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005818 // 1. No dynamicOffset supplied
5819 // 2. Too many dynamicOffsets supplied
5820 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005821 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5823 "0 dynamicOffsets are left in "
5824 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005825
5826 ASSERT_NO_FATAL_FAILURE(InitState());
5827 ASSERT_NO_FATAL_FAILURE(InitViewport());
5828 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5829
5830 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005831 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5832 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005833
5834 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005835 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5836 ds_pool_ci.pNext = NULL;
5837 ds_pool_ci.maxSets = 1;
5838 ds_pool_ci.poolSizeCount = 1;
5839 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005840
5841 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005842 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005843 ASSERT_VK_SUCCESS(err);
5844
5845 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005846 dsl_binding.binding = 0;
5847 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5848 dsl_binding.descriptorCount = 1;
5849 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5850 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005851
5852 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005853 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5854 ds_layout_ci.pNext = NULL;
5855 ds_layout_ci.bindingCount = 1;
5856 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005857 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005858 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005859 ASSERT_VK_SUCCESS(err);
5860
5861 VkDescriptorSet descriptorSet;
5862 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005863 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005864 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005865 alloc_info.descriptorPool = ds_pool;
5866 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005867 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005868 ASSERT_VK_SUCCESS(err);
5869
5870 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005871 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5872 pipeline_layout_ci.pNext = NULL;
5873 pipeline_layout_ci.setLayoutCount = 1;
5874 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005875
5876 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005877 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005878 ASSERT_VK_SUCCESS(err);
5879
5880 // Create a buffer to update the descriptor with
5881 uint32_t qfi = 0;
5882 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005883 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5884 buffCI.size = 1024;
5885 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5886 buffCI.queueFamilyIndexCount = 1;
5887 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005888
5889 VkBuffer dyub;
5890 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5891 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005892 // Allocate memory and bind to buffer so we can make it to the appropriate
5893 // error
5894 VkMemoryAllocateInfo mem_alloc = {};
5895 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5896 mem_alloc.pNext = NULL;
5897 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005898 mem_alloc.memoryTypeIndex = 0;
5899
5900 VkMemoryRequirements memReqs;
5901 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005902 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005903 if (!pass) {
5904 vkDestroyBuffer(m_device->device(), dyub, NULL);
5905 return;
5906 }
5907
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005908 VkDeviceMemory mem;
5909 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5910 ASSERT_VK_SUCCESS(err);
5911 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5912 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005913 // Correctly update descriptor to avoid "NOT_UPDATED" error
5914 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005915 buffInfo.buffer = dyub;
5916 buffInfo.offset = 0;
5917 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005918
5919 VkWriteDescriptorSet descriptor_write;
5920 memset(&descriptor_write, 0, sizeof(descriptor_write));
5921 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5922 descriptor_write.dstSet = descriptorSet;
5923 descriptor_write.dstBinding = 0;
5924 descriptor_write.descriptorCount = 1;
5925 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5926 descriptor_write.pBufferInfo = &buffInfo;
5927
5928 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5929
5930 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005931 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5932 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005933 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005934 uint32_t pDynOff[2] = {512, 756};
5935 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5937 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5938 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5939 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005940 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005941 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5943 "offset 0 and range 1024 that "
5944 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005945 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005946 char const *vsSource = "#version 450\n"
5947 "\n"
5948 "out gl_PerVertex { \n"
5949 " vec4 gl_Position;\n"
5950 "};\n"
5951 "void main(){\n"
5952 " gl_Position = vec4(1);\n"
5953 "}\n";
5954 char const *fsSource = "#version 450\n"
5955 "\n"
5956 "layout(location=0) out vec4 x;\n"
5957 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5958 "void main(){\n"
5959 " x = vec4(bar.y);\n"
5960 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005961 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5962 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5963 VkPipelineObj pipe(m_device);
5964 pipe.AddShader(&vs);
5965 pipe.AddShader(&fs);
5966 pipe.AddColorAttachment();
5967 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005969 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005970 // This update should succeed, but offset size of 512 will overstep buffer
5971 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005972 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5973 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005974 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005975 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005976
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005977 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005978 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005979
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005980 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005981 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005982 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5983}
5984
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005985TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5986 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5987 "that doesn't have memory bound");
5988 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005990 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5992 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005993
5994 ASSERT_NO_FATAL_FAILURE(InitState());
5995 ASSERT_NO_FATAL_FAILURE(InitViewport());
5996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5997
5998 VkDescriptorPoolSize ds_type_count = {};
5999 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6000 ds_type_count.descriptorCount = 1;
6001
6002 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6003 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6004 ds_pool_ci.pNext = NULL;
6005 ds_pool_ci.maxSets = 1;
6006 ds_pool_ci.poolSizeCount = 1;
6007 ds_pool_ci.pPoolSizes = &ds_type_count;
6008
6009 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006010 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006011 ASSERT_VK_SUCCESS(err);
6012
6013 VkDescriptorSetLayoutBinding dsl_binding = {};
6014 dsl_binding.binding = 0;
6015 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6016 dsl_binding.descriptorCount = 1;
6017 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6018 dsl_binding.pImmutableSamplers = NULL;
6019
6020 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6021 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6022 ds_layout_ci.pNext = NULL;
6023 ds_layout_ci.bindingCount = 1;
6024 ds_layout_ci.pBindings = &dsl_binding;
6025 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006026 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006027 ASSERT_VK_SUCCESS(err);
6028
6029 VkDescriptorSet descriptorSet;
6030 VkDescriptorSetAllocateInfo alloc_info = {};
6031 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6032 alloc_info.descriptorSetCount = 1;
6033 alloc_info.descriptorPool = ds_pool;
6034 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006035 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006036 ASSERT_VK_SUCCESS(err);
6037
6038 // Create a buffer to update the descriptor with
6039 uint32_t qfi = 0;
6040 VkBufferCreateInfo buffCI = {};
6041 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6042 buffCI.size = 1024;
6043 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6044 buffCI.queueFamilyIndexCount = 1;
6045 buffCI.pQueueFamilyIndices = &qfi;
6046
6047 VkBuffer dyub;
6048 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6049 ASSERT_VK_SUCCESS(err);
6050
6051 // Attempt to update descriptor without binding memory to it
6052 VkDescriptorBufferInfo buffInfo = {};
6053 buffInfo.buffer = dyub;
6054 buffInfo.offset = 0;
6055 buffInfo.range = 1024;
6056
6057 VkWriteDescriptorSet descriptor_write;
6058 memset(&descriptor_write, 0, sizeof(descriptor_write));
6059 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6060 descriptor_write.dstSet = descriptorSet;
6061 descriptor_write.dstBinding = 0;
6062 descriptor_write.descriptorCount = 1;
6063 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6064 descriptor_write.pBufferInfo = &buffInfo;
6065
6066 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6067 m_errorMonitor->VerifyFound();
6068
6069 vkDestroyBuffer(m_device->device(), dyub, NULL);
6070 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6071 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6072}
6073
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006074TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006075 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006076 ASSERT_NO_FATAL_FAILURE(InitState());
6077 ASSERT_NO_FATAL_FAILURE(InitViewport());
6078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6079
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006080 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006081 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006082 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6083 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6084 pipeline_layout_ci.pushConstantRangeCount = 1;
6085 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6086
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006087 //
6088 // Check for invalid push constant ranges in pipeline layouts.
6089 //
6090 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006091 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006092 char const *msg;
6093 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006094
Karl Schultzc81037d2016-05-12 08:11:23 -06006095 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6096 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6097 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6098 "vkCreatePipelineLayout() call has push constants index 0 with "
6099 "size 0."},
6100 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6101 "vkCreatePipelineLayout() call has push constants index 0 with "
6102 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006103 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006104 "vkCreatePipelineLayout() call has push constants index 0 with "
6105 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006106 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006107 "vkCreatePipelineLayout() call has push constants index 0 with "
6108 "size 0."},
6109 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6110 "vkCreatePipelineLayout() call has push constants index 0 with "
6111 "offset 1. Offset must"},
6112 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6113 "vkCreatePipelineLayout() call has push constants index 0 "
6114 "with offset "},
6115 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6116 "vkCreatePipelineLayout() call has push constants "
6117 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006118 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006119 "vkCreatePipelineLayout() call has push constants index 0 "
6120 "with offset "},
6121 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6122 "vkCreatePipelineLayout() call has push "
6123 "constants index 0 with offset "},
6124 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6125 "vkCreatePipelineLayout() call has push "
6126 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006127 }};
6128
6129 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006130 for (const auto &iter : range_tests) {
6131 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6133 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006134 m_errorMonitor->VerifyFound();
6135 if (VK_SUCCESS == err) {
6136 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6137 }
6138 }
6139
6140 // Check for invalid stage flag
6141 pc_range.offset = 0;
6142 pc_range.size = 16;
6143 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006144 m_errorMonitor->SetDesiredFailureMsg(
6145 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6146 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006147 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006148 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006149 if (VK_SUCCESS == err) {
6150 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6151 }
6152
6153 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006154 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006155 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006156 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006157 char const *msg;
6158 };
6159
Karl Schultzc81037d2016-05-12 08:11:23 -06006160 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006161 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6162 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6163 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6164 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6165 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006166 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006167 {
6168 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6169 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6170 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6171 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6172 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006173 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006174 },
6175 {
6176 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6177 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6178 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6179 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6180 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006181 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006182 },
6183 {
6184 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6185 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6186 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6187 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6188 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006189 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006190 },
6191 {
6192 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6193 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6194 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6195 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6196 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006197 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006198 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006199
Karl Schultzc81037d2016-05-12 08:11:23 -06006200 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006201 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006202 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6204 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006205 m_errorMonitor->VerifyFound();
6206 if (VK_SUCCESS == err) {
6207 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6208 }
6209 }
6210
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006211 //
6212 // CmdPushConstants tests
6213 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006214 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006215
6216 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006217 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6218 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006219 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6220 "vkCmdPushConstants() call has push constants with size 1. Size "
6221 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006222 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006223 "vkCmdPushConstants() call has push constants with size 1. Size "
6224 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006225 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006226 "vkCmdPushConstants() call has push constants with offset 1. "
6227 "Offset must be a multiple of 4."},
6228 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6229 "vkCmdPushConstants() call has push constants with offset 1. "
6230 "Offset must be a multiple of 4."},
6231 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6232 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6233 "0x1 not within flag-matching ranges in pipeline layout"},
6234 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6235 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6236 "0x1 not within flag-matching ranges in pipeline layout"},
6237 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6238 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6239 "0x1 not within flag-matching ranges in pipeline layout"},
6240 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6241 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6242 "0x1 not within flag-matching ranges in pipeline layout"},
6243 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6244 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6245 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006246 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006247 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6248 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006249 }};
6250
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006251 BeginCommandBuffer();
6252
6253 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006254 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006255 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006256 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006257 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006258 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006259 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006260 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006261 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6263 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006264 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006265 m_errorMonitor->VerifyFound();
6266 }
6267
6268 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006270 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006271 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006272 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006273
Karl Schultzc81037d2016-05-12 08:11:23 -06006274 // overlapping range tests with cmd
6275 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6276 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6277 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6278 "0x1 not within flag-matching ranges in pipeline layout"},
6279 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6280 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6281 "0x1 not within flag-matching ranges in pipeline layout"},
6282 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6283 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6284 "0x1 not within flag-matching ranges in pipeline layout"},
6285 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006286 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006287 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006288 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6289 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006290 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006291 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006292 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006293 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006294 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006295 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6297 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006298 iter.range.size, dummy_values);
6299 m_errorMonitor->VerifyFound();
6300 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006301 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6302
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006303 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006304}
6305
Karl Schultz6addd812016-02-02 17:17:23 -07006306TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006307 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006308 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006309
6310 ASSERT_NO_FATAL_FAILURE(InitState());
6311 ASSERT_NO_FATAL_FAILURE(InitViewport());
6312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6313
Mike Stroyanb8a61002016-06-20 16:00:28 -06006314 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6315 VkImageTiling tiling;
6316 VkFormatProperties format_properties;
6317 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006318 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006319 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006320 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006321 tiling = VK_IMAGE_TILING_OPTIMAL;
6322 } else {
6323 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6324 "skipped.\n");
6325 return;
6326 }
6327
Tobin Ehlis559c6382015-11-05 09:52:49 -07006328 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6329 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006330 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6331 ds_type_count[0].descriptorCount = 10;
6332 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6333 ds_type_count[1].descriptorCount = 2;
6334 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6335 ds_type_count[2].descriptorCount = 2;
6336 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6337 ds_type_count[3].descriptorCount = 5;
6338 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6339 // type
6340 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6341 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6342 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006343
6344 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006345 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6346 ds_pool_ci.pNext = NULL;
6347 ds_pool_ci.maxSets = 5;
6348 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6349 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006350
6351 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006352 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006353 ASSERT_VK_SUCCESS(err);
6354
6355 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6356 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006357 dsl_binding[0].binding = 0;
6358 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6359 dsl_binding[0].descriptorCount = 5;
6360 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6361 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006362
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006363 // Create layout identical to set0 layout but w/ different stageFlags
6364 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006365 dsl_fs_stage_only.binding = 0;
6366 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6367 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006368 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6369 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006370 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006371 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006372 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6373 ds_layout_ci.pNext = NULL;
6374 ds_layout_ci.bindingCount = 1;
6375 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006376 static const uint32_t NUM_LAYOUTS = 4;
6377 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006378 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006379 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6380 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006381 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006382 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006383 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006384 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006385 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006386 dsl_binding[0].binding = 0;
6387 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006388 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006389 dsl_binding[1].binding = 1;
6390 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6391 dsl_binding[1].descriptorCount = 2;
6392 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6393 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006394 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006395 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006396 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006397 ASSERT_VK_SUCCESS(err);
6398 dsl_binding[0].binding = 0;
6399 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006400 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006401 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006402 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006403 ASSERT_VK_SUCCESS(err);
6404 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006405 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006406 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006407 ASSERT_VK_SUCCESS(err);
6408
6409 static const uint32_t NUM_SETS = 4;
6410 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6411 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006412 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006413 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006414 alloc_info.descriptorPool = ds_pool;
6415 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006416 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006417 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006418 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006419 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006420 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006421 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006422 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006423
6424 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006425 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6426 pipeline_layout_ci.pNext = NULL;
6427 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6428 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006429
6430 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006431 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006432 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006433 // Create pipelineLayout with only one setLayout
6434 pipeline_layout_ci.setLayoutCount = 1;
6435 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006436 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006437 ASSERT_VK_SUCCESS(err);
6438 // Create pipelineLayout with 2 descriptor setLayout at index 0
6439 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6440 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006441 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006442 ASSERT_VK_SUCCESS(err);
6443 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6444 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6445 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006446 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006447 ASSERT_VK_SUCCESS(err);
6448 // Create pipelineLayout with UB type, but stageFlags for FS only
6449 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6450 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006451 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006452 ASSERT_VK_SUCCESS(err);
6453 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6454 VkDescriptorSetLayout pl_bad_s0[2] = {};
6455 pl_bad_s0[0] = ds_layout_fs_only;
6456 pl_bad_s0[1] = ds_layout[1];
6457 pipeline_layout_ci.setLayoutCount = 2;
6458 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6459 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006460 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006461 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006462
6463 // Create a buffer to update the descriptor with
6464 uint32_t qfi = 0;
6465 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006466 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6467 buffCI.size = 1024;
6468 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6469 buffCI.queueFamilyIndexCount = 1;
6470 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006471
6472 VkBuffer dyub;
6473 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6474 ASSERT_VK_SUCCESS(err);
6475 // Correctly update descriptor to avoid "NOT_UPDATED" error
6476 static const uint32_t NUM_BUFFS = 5;
6477 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006478 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006479 buffInfo[i].buffer = dyub;
6480 buffInfo[i].offset = 0;
6481 buffInfo[i].range = 1024;
6482 }
Karl Schultz6addd812016-02-02 17:17:23 -07006483 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006484 const int32_t tex_width = 32;
6485 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006486 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006487 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6488 image_create_info.pNext = NULL;
6489 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6490 image_create_info.format = tex_format;
6491 image_create_info.extent.width = tex_width;
6492 image_create_info.extent.height = tex_height;
6493 image_create_info.extent.depth = 1;
6494 image_create_info.mipLevels = 1;
6495 image_create_info.arrayLayers = 1;
6496 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006497 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006498 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006499 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006500 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6501 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006502
Karl Schultz6addd812016-02-02 17:17:23 -07006503 VkMemoryRequirements memReqs;
6504 VkDeviceMemory imageMem;
6505 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006506 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006507 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6508 memAlloc.pNext = NULL;
6509 memAlloc.allocationSize = 0;
6510 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006511 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6512 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006513 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006514 ASSERT_TRUE(pass);
6515 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6516 ASSERT_VK_SUCCESS(err);
6517 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6518 ASSERT_VK_SUCCESS(err);
6519
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006520 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006521 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6522 image_view_create_info.image = image;
6523 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6524 image_view_create_info.format = tex_format;
6525 image_view_create_info.subresourceRange.layerCount = 1;
6526 image_view_create_info.subresourceRange.baseMipLevel = 0;
6527 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006528 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006529
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006530 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006531 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006532 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006533 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006534 imageInfo[0].imageView = view;
6535 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6536 imageInfo[1].imageView = view;
6537 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006538 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006539 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006540 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006541 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006542
6543 static const uint32_t NUM_SET_UPDATES = 3;
6544 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6545 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6546 descriptor_write[0].dstSet = descriptorSet[0];
6547 descriptor_write[0].dstBinding = 0;
6548 descriptor_write[0].descriptorCount = 5;
6549 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6550 descriptor_write[0].pBufferInfo = buffInfo;
6551 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6552 descriptor_write[1].dstSet = descriptorSet[1];
6553 descriptor_write[1].dstBinding = 0;
6554 descriptor_write[1].descriptorCount = 2;
6555 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6556 descriptor_write[1].pImageInfo = imageInfo;
6557 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6558 descriptor_write[2].dstSet = descriptorSet[1];
6559 descriptor_write[2].dstBinding = 1;
6560 descriptor_write[2].descriptorCount = 2;
6561 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006562 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006563
6564 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006565
Tobin Ehlis88452832015-12-03 09:40:56 -07006566 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006567 char const *vsSource = "#version 450\n"
6568 "\n"
6569 "out gl_PerVertex {\n"
6570 " vec4 gl_Position;\n"
6571 "};\n"
6572 "void main(){\n"
6573 " gl_Position = vec4(1);\n"
6574 "}\n";
6575 char const *fsSource = "#version 450\n"
6576 "\n"
6577 "layout(location=0) out vec4 x;\n"
6578 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6579 "void main(){\n"
6580 " x = vec4(bar.y);\n"
6581 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006584 VkPipelineObj pipe(m_device);
6585 pipe.AddShader(&vs);
6586 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006587 pipe.AddColorAttachment();
6588 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006589
6590 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006591
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006592 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006593 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6594 // of PSO
6595 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6596 // cmd_pipeline.c
6597 // due to the fact that cmd_alloc_dset_data() has not been called in
6598 // cmd_bind_graphics_pipeline()
6599 // TODO : Want to cause various binding incompatibility issues here to test
6600 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006601 // First cause various verify_layout_compatibility() fails
6602 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006603 // verify_set_layout_compatibility fail cases:
6604 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6606 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6607 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006608 m_errorMonitor->VerifyFound();
6609
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006610 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6612 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6613 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006614 m_errorMonitor->VerifyFound();
6615
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006616 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006617 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6618 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6620 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6621 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006622 m_errorMonitor->VerifyFound();
6623
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006624 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6625 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6627 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6628 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006629 m_errorMonitor->VerifyFound();
6630
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006631 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6632 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6634 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6635 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6636 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006637 m_errorMonitor->VerifyFound();
6638
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006639 // Cause INFO messages due to disturbing previously bound Sets
6640 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006641 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6642 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006643 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6645 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6646 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006647 m_errorMonitor->VerifyFound();
6648
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006649 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6650 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006651 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6653 "any subsequent sets were disturbed ");
6654 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6655 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006656 m_errorMonitor->VerifyFound();
6657
Tobin Ehlis10fad692016-07-07 12:00:36 -06006658 // Now that we're done actively using the pipelineLayout that gfx pipeline
6659 // was created with, we should be able to delete it. Do that now to verify
6660 // that validation obeys pipelineLayout lifetime
6661 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6662
Tobin Ehlis88452832015-12-03 09:40:56 -07006663 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006664 // 1. Error due to not binding required set (we actually use same code as
6665 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006666 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6667 &descriptorSet[0], 0, NULL);
6668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6669 &descriptorSet[1], 0, NULL);
6670 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 -07006671 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006672 m_errorMonitor->VerifyFound();
6673
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006674 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006675 // 2. Error due to bound set not being compatible with PSO's
6676 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006677 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6678 &descriptorSet[0], 0, NULL);
6679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006680 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006681 m_errorMonitor->VerifyFound();
6682
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006683 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006684 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6686 }
6687 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006688 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006689 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6690 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006691 vkFreeMemory(m_device->device(), imageMem, NULL);
6692 vkDestroyImage(m_device->device(), image, NULL);
6693 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006694}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006695
Karl Schultz6addd812016-02-02 17:17:23 -07006696TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006697
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6699 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006700
6701 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006702 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006703 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006704 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006705
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006706 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006707}
6708
Karl Schultz6addd812016-02-02 17:17:23 -07006709TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6710 VkResult err;
6711 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006712
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006714
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006715 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006716
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006717 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006718 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006719 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006720 cmd.commandPool = m_commandPool;
6721 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006722 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006723
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006724 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006725 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006726
6727 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006728 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006729 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006730 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006731 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006732 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 -07006733 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006734
6735 // The error should be caught by validation of the BeginCommandBuffer call
6736 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6737
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006738 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006739 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006740}
6741
Karl Schultz6addd812016-02-02 17:17:23 -07006742TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006743 // Cause error due to Begin while recording CB
6744 // Then cause 2 errors for attempting to reset CB w/o having
6745 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6746 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006748
6749 ASSERT_NO_FATAL_FAILURE(InitState());
6750
6751 // Calls AllocateCommandBuffers
6752 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6753
Karl Schultz6addd812016-02-02 17:17:23 -07006754 // Force the failure by setting the Renderpass and Framebuffer fields with
6755 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006756 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006757 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006758 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6759 cmd_buf_info.pNext = NULL;
6760 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006761 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006762
6763 // Begin CB to transition to recording state
6764 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6765 // Can't re-begin. This should trigger error
6766 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006767 m_errorMonitor->VerifyFound();
6768
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006770 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6771 // Reset attempt will trigger error due to incorrect CommandPool state
6772 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006773 m_errorMonitor->VerifyFound();
6774
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006776 // Transition CB to RECORDED state
6777 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6778 // Now attempting to Begin will implicitly reset, which triggers error
6779 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006780 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006781}
6782
Karl Schultz6addd812016-02-02 17:17:23 -07006783TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006784 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006785 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006786
Mike Weiblencce7ec72016-10-17 19:33:05 -06006787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006788
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006789 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006791
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006792 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006793 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6794 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006795
6796 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006797 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6798 ds_pool_ci.pNext = NULL;
6799 ds_pool_ci.maxSets = 1;
6800 ds_pool_ci.poolSizeCount = 1;
6801 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006802
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006803 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006804 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006805 ASSERT_VK_SUCCESS(err);
6806
Tony Barboureb254902015-07-15 12:50:33 -06006807 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006808 dsl_binding.binding = 0;
6809 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6810 dsl_binding.descriptorCount = 1;
6811 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6812 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006813
Tony Barboureb254902015-07-15 12:50:33 -06006814 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006815 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6816 ds_layout_ci.pNext = NULL;
6817 ds_layout_ci.bindingCount = 1;
6818 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006819
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006820 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006821 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006822 ASSERT_VK_SUCCESS(err);
6823
6824 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006825 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006826 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006827 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006828 alloc_info.descriptorPool = ds_pool;
6829 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006830 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006831 ASSERT_VK_SUCCESS(err);
6832
Tony Barboureb254902015-07-15 12:50:33 -06006833 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006834 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6835 pipeline_layout_ci.setLayoutCount = 1;
6836 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006837
6838 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006839 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006840 ASSERT_VK_SUCCESS(err);
6841
Tobin Ehlise68360f2015-10-01 11:15:13 -06006842 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006843 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006844
6845 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006846 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6847 vp_state_ci.scissorCount = 1;
6848 vp_state_ci.pScissors = &sc;
6849 vp_state_ci.viewportCount = 1;
6850 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006851
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006852 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6853 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6854 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6855 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6856 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6857 rs_state_ci.depthClampEnable = VK_FALSE;
6858 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6859 rs_state_ci.depthBiasEnable = VK_FALSE;
6860
Tony Barboureb254902015-07-15 12:50:33 -06006861 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006862 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6863 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006864 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006865 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6866 gp_ci.layout = pipeline_layout;
6867 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006868
6869 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006870 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6871 pc_ci.initialDataSize = 0;
6872 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006873
6874 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006875 VkPipelineCache pipelineCache;
6876
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006877 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006878 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006879 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006880
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006881 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006882
Chia-I Wuf7458c52015-10-26 21:10:41 +08006883 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6884 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6885 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6886 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006887}
Tobin Ehlis912df022015-09-17 08:46:18 -06006888/*// TODO : This test should be good, but needs Tess support in compiler to run
6889TEST_F(VkLayerTest, InvalidPatchControlPoints)
6890{
6891 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006892 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006893
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006895 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6896primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006897
Tobin Ehlis912df022015-09-17 08:46:18 -06006898 ASSERT_NO_FATAL_FAILURE(InitState());
6899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006900
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006901 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006902 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006903 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006904
6905 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6906 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6907 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006908 ds_pool_ci.poolSizeCount = 1;
6909 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006910
6911 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006912 err = vkCreateDescriptorPool(m_device->device(),
6913VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006914 ASSERT_VK_SUCCESS(err);
6915
6916 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006917 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006918 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006919 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006920 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6921 dsl_binding.pImmutableSamplers = NULL;
6922
6923 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006924 ds_layout_ci.sType =
6925VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006926 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006927 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006928 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006929
6930 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006931 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6932&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006933 ASSERT_VK_SUCCESS(err);
6934
6935 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006936 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6937VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006938 ASSERT_VK_SUCCESS(err);
6939
6940 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006941 pipeline_layout_ci.sType =
6942VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006943 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006944 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006945 pipeline_layout_ci.pSetLayouts = &ds_layout;
6946
6947 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006948 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6949&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006950 ASSERT_VK_SUCCESS(err);
6951
6952 VkPipelineShaderStageCreateInfo shaderStages[3];
6953 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6954
Karl Schultz6addd812016-02-02 17:17:23 -07006955 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6956this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006957 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006958 VkShaderObj
6959tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6960this);
6961 VkShaderObj
6962te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6963this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006964
Karl Schultz6addd812016-02-02 17:17:23 -07006965 shaderStages[0].sType =
6966VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006967 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006968 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006969 shaderStages[1].sType =
6970VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006971 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006972 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006973 shaderStages[2].sType =
6974VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006975 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006976 shaderStages[2].shader = te.handle();
6977
6978 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006979 iaCI.sType =
6980VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006981 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006982
6983 VkPipelineTessellationStateCreateInfo tsCI = {};
6984 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6985 tsCI.patchControlPoints = 0; // This will cause an error
6986
6987 VkGraphicsPipelineCreateInfo gp_ci = {};
6988 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6989 gp_ci.pNext = NULL;
6990 gp_ci.stageCount = 3;
6991 gp_ci.pStages = shaderStages;
6992 gp_ci.pVertexInputState = NULL;
6993 gp_ci.pInputAssemblyState = &iaCI;
6994 gp_ci.pTessellationState = &tsCI;
6995 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006996 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006997 gp_ci.pMultisampleState = NULL;
6998 gp_ci.pDepthStencilState = NULL;
6999 gp_ci.pColorBlendState = NULL;
7000 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7001 gp_ci.layout = pipeline_layout;
7002 gp_ci.renderPass = renderPass();
7003
7004 VkPipelineCacheCreateInfo pc_ci = {};
7005 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7006 pc_ci.pNext = NULL;
7007 pc_ci.initialSize = 0;
7008 pc_ci.initialData = 0;
7009 pc_ci.maxSize = 0;
7010
7011 VkPipeline pipeline;
7012 VkPipelineCache pipelineCache;
7013
Karl Schultz6addd812016-02-02 17:17:23 -07007014 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7015&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007016 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007017 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7018&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007019
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007020 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007021
Chia-I Wuf7458c52015-10-26 21:10:41 +08007022 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7023 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7024 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7025 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007026}
7027*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007028// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007029TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007030 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7033 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007034
Tobin Ehlise68360f2015-10-01 11:15:13 -06007035 ASSERT_NO_FATAL_FAILURE(InitState());
7036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007037
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007038 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007039 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7040 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007041
7042 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007043 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7044 ds_pool_ci.maxSets = 1;
7045 ds_pool_ci.poolSizeCount = 1;
7046 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007047
7048 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007049 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007050 ASSERT_VK_SUCCESS(err);
7051
7052 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007053 dsl_binding.binding = 0;
7054 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7055 dsl_binding.descriptorCount = 1;
7056 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007057
7058 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007059 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7060 ds_layout_ci.bindingCount = 1;
7061 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007062
7063 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007064 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007065 ASSERT_VK_SUCCESS(err);
7066
7067 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007068 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007069 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007070 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007071 alloc_info.descriptorPool = ds_pool;
7072 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007073 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007074 ASSERT_VK_SUCCESS(err);
7075
7076 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007077 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7078 pipeline_layout_ci.setLayoutCount = 1;
7079 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007080
7081 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007082 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007083 ASSERT_VK_SUCCESS(err);
7084
7085 VkViewport vp = {}; // Just need dummy vp to point to
7086
7087 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007088 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7089 vp_state_ci.scissorCount = 0;
7090 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7091 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007092
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007093 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7094 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7095 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7096 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7097 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7098 rs_state_ci.depthClampEnable = VK_FALSE;
7099 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7100 rs_state_ci.depthBiasEnable = VK_FALSE;
7101
Cody Northropeb3a6c12015-10-05 14:44:45 -06007102 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007103 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007104
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007105 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7106 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7107 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007108 shaderStages[0] = vs.GetStageCreateInfo();
7109 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007110
7111 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007112 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7113 gp_ci.stageCount = 2;
7114 gp_ci.pStages = shaderStages;
7115 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007116 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007117 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7118 gp_ci.layout = pipeline_layout;
7119 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007120
7121 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007122 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007123
7124 VkPipeline pipeline;
7125 VkPipelineCache pipelineCache;
7126
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007127 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007128 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007129 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007130
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007131 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007132
Chia-I Wuf7458c52015-10-26 21:10:41 +08007133 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7134 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7135 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7136 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007137}
Karl Schultz6addd812016-02-02 17:17:23 -07007138// Don't set viewport state in PSO. This is an error b/c we always need this
7139// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007140// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007141TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007142 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007143 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007144
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007146
Tobin Ehlise68360f2015-10-01 11:15:13 -06007147 ASSERT_NO_FATAL_FAILURE(InitState());
7148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007149
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007150 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007151 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7152 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007153
7154 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007155 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7156 ds_pool_ci.maxSets = 1;
7157 ds_pool_ci.poolSizeCount = 1;
7158 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007159
7160 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007161 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007162 ASSERT_VK_SUCCESS(err);
7163
7164 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007165 dsl_binding.binding = 0;
7166 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7167 dsl_binding.descriptorCount = 1;
7168 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007169
7170 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007171 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7172 ds_layout_ci.bindingCount = 1;
7173 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007174
7175 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007176 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007177 ASSERT_VK_SUCCESS(err);
7178
7179 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007180 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007181 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007182 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007183 alloc_info.descriptorPool = ds_pool;
7184 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007185 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007186 ASSERT_VK_SUCCESS(err);
7187
7188 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007189 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7190 pipeline_layout_ci.setLayoutCount = 1;
7191 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007192
7193 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007194 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007195 ASSERT_VK_SUCCESS(err);
7196
7197 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7198 // Set scissor as dynamic to avoid second error
7199 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007200 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7201 dyn_state_ci.dynamicStateCount = 1;
7202 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007203
Cody Northropeb3a6c12015-10-05 14:44:45 -06007204 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007205 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007206
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007207 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7208 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7209 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007210 shaderStages[0] = vs.GetStageCreateInfo();
7211 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007212
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007213 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7214 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7215 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7216 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7217 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7218 rs_state_ci.depthClampEnable = VK_FALSE;
7219 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7220 rs_state_ci.depthBiasEnable = VK_FALSE;
7221
Tobin Ehlise68360f2015-10-01 11:15:13 -06007222 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007223 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7224 gp_ci.stageCount = 2;
7225 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007226 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007227 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7228 // should cause validation error
7229 gp_ci.pDynamicState = &dyn_state_ci;
7230 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7231 gp_ci.layout = pipeline_layout;
7232 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007233
7234 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007235 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007236
7237 VkPipeline pipeline;
7238 VkPipelineCache pipelineCache;
7239
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007240 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007241 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007242 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007243
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007244 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007245
Chia-I Wuf7458c52015-10-26 21:10:41 +08007246 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7247 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7248 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7249 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007250}
7251// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007252// Then run second test where dynamic scissor count doesn't match PSO scissor
7253// count
7254TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7255 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7258 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007259
Tobin Ehlise68360f2015-10-01 11:15:13 -06007260 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007261
7262 if (!m_device->phy().features().multiViewport) {
7263 printf("Device does not support multiple viewports/scissors; skipped.\n");
7264 return;
7265 }
7266
Tobin Ehlise68360f2015-10-01 11:15:13 -06007267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007268
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007269 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007270 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7271 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007272
7273 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007274 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7275 ds_pool_ci.maxSets = 1;
7276 ds_pool_ci.poolSizeCount = 1;
7277 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007278
7279 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007280 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007281 ASSERT_VK_SUCCESS(err);
7282
7283 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007284 dsl_binding.binding = 0;
7285 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7286 dsl_binding.descriptorCount = 1;
7287 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007288
7289 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007290 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7291 ds_layout_ci.bindingCount = 1;
7292 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007293
7294 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007295 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007296 ASSERT_VK_SUCCESS(err);
7297
7298 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007299 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007300 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007301 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007302 alloc_info.descriptorPool = ds_pool;
7303 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007304 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007305 ASSERT_VK_SUCCESS(err);
7306
7307 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007308 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7309 pipeline_layout_ci.setLayoutCount = 1;
7310 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007311
7312 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007313 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007314 ASSERT_VK_SUCCESS(err);
7315
7316 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007317 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7318 vp_state_ci.viewportCount = 1;
7319 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7320 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007321 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007322
7323 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7324 // Set scissor as dynamic to avoid that error
7325 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007326 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7327 dyn_state_ci.dynamicStateCount = 1;
7328 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007329
Cody Northropeb3a6c12015-10-05 14:44:45 -06007330 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007331 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007332
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007333 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7334 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7335 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007336 shaderStages[0] = vs.GetStageCreateInfo();
7337 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007338
Cody Northropf6622dc2015-10-06 10:33:21 -06007339 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7340 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7341 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007342 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007343 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007344 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007345 vi_ci.pVertexAttributeDescriptions = nullptr;
7346
7347 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7348 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7349 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7350
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007351 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007352 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007353 rs_ci.pNext = nullptr;
7354
Mark Youngc89c6312016-03-31 16:03:20 -06007355 VkPipelineColorBlendAttachmentState att = {};
7356 att.blendEnable = VK_FALSE;
7357 att.colorWriteMask = 0xf;
7358
Cody Northropf6622dc2015-10-06 10:33:21 -06007359 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7360 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7361 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007362 cb_ci.attachmentCount = 1;
7363 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007364
Tobin Ehlise68360f2015-10-01 11:15:13 -06007365 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007366 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7367 gp_ci.stageCount = 2;
7368 gp_ci.pStages = shaderStages;
7369 gp_ci.pVertexInputState = &vi_ci;
7370 gp_ci.pInputAssemblyState = &ia_ci;
7371 gp_ci.pViewportState = &vp_state_ci;
7372 gp_ci.pRasterizationState = &rs_ci;
7373 gp_ci.pColorBlendState = &cb_ci;
7374 gp_ci.pDynamicState = &dyn_state_ci;
7375 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7376 gp_ci.layout = pipeline_layout;
7377 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007378
7379 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007380 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007381
7382 VkPipeline pipeline;
7383 VkPipelineCache pipelineCache;
7384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007385 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007386 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007387 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007388
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007389 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007390
Tobin Ehlisd332f282015-10-02 11:00:56 -06007391 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007392 // First need to successfully create the PSO from above by setting
7393 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007394 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 -07007395
7396 VkViewport vp = {}; // Just need dummy vp to point to
7397 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007398 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007399 ASSERT_VK_SUCCESS(err);
7400 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007401 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007402 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007403 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007404 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007405 Draw(1, 0, 0, 0);
7406
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007407 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007408
7409 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7410 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7411 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7412 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007413 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007414}
7415// Create PSO w/o non-zero scissorCount but no scissor data
7416// Then run second test where dynamic viewportCount doesn't match PSO
7417// viewportCount
7418TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7419 VkResult err;
7420
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
Karl Schultz6addd812016-02-02 17:17:23 -07007422
7423 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007424
7425 if (!m_device->phy().features().multiViewport) {
7426 printf("Device does not support multiple viewports/scissors; skipped.\n");
7427 return;
7428 }
7429
Karl Schultz6addd812016-02-02 17:17:23 -07007430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7431
7432 VkDescriptorPoolSize ds_type_count = {};
7433 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7434 ds_type_count.descriptorCount = 1;
7435
7436 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7437 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7438 ds_pool_ci.maxSets = 1;
7439 ds_pool_ci.poolSizeCount = 1;
7440 ds_pool_ci.pPoolSizes = &ds_type_count;
7441
7442 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007443 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007444 ASSERT_VK_SUCCESS(err);
7445
7446 VkDescriptorSetLayoutBinding dsl_binding = {};
7447 dsl_binding.binding = 0;
7448 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7449 dsl_binding.descriptorCount = 1;
7450 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7451
7452 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7453 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7454 ds_layout_ci.bindingCount = 1;
7455 ds_layout_ci.pBindings = &dsl_binding;
7456
7457 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007459 ASSERT_VK_SUCCESS(err);
7460
7461 VkDescriptorSet descriptorSet;
7462 VkDescriptorSetAllocateInfo alloc_info = {};
7463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7464 alloc_info.descriptorSetCount = 1;
7465 alloc_info.descriptorPool = ds_pool;
7466 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007468 ASSERT_VK_SUCCESS(err);
7469
7470 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7471 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7472 pipeline_layout_ci.setLayoutCount = 1;
7473 pipeline_layout_ci.pSetLayouts = &ds_layout;
7474
7475 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007476 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007477 ASSERT_VK_SUCCESS(err);
7478
7479 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7480 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7481 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007482 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007483 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007484 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007485
7486 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7487 // Set scissor as dynamic to avoid that error
7488 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7489 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7490 dyn_state_ci.dynamicStateCount = 1;
7491 dyn_state_ci.pDynamicStates = &vp_state;
7492
7493 VkPipelineShaderStageCreateInfo shaderStages[2];
7494 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7495
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007496 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7497 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7498 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007499 shaderStages[0] = vs.GetStageCreateInfo();
7500 shaderStages[1] = fs.GetStageCreateInfo();
7501
7502 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7503 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7504 vi_ci.pNext = nullptr;
7505 vi_ci.vertexBindingDescriptionCount = 0;
7506 vi_ci.pVertexBindingDescriptions = nullptr;
7507 vi_ci.vertexAttributeDescriptionCount = 0;
7508 vi_ci.pVertexAttributeDescriptions = nullptr;
7509
7510 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7511 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7512 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7513
7514 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7515 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7516 rs_ci.pNext = nullptr;
7517
Mark Youngc89c6312016-03-31 16:03:20 -06007518 VkPipelineColorBlendAttachmentState att = {};
7519 att.blendEnable = VK_FALSE;
7520 att.colorWriteMask = 0xf;
7521
Karl Schultz6addd812016-02-02 17:17:23 -07007522 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7523 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7524 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007525 cb_ci.attachmentCount = 1;
7526 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007527
7528 VkGraphicsPipelineCreateInfo gp_ci = {};
7529 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7530 gp_ci.stageCount = 2;
7531 gp_ci.pStages = shaderStages;
7532 gp_ci.pVertexInputState = &vi_ci;
7533 gp_ci.pInputAssemblyState = &ia_ci;
7534 gp_ci.pViewportState = &vp_state_ci;
7535 gp_ci.pRasterizationState = &rs_ci;
7536 gp_ci.pColorBlendState = &cb_ci;
7537 gp_ci.pDynamicState = &dyn_state_ci;
7538 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7539 gp_ci.layout = pipeline_layout;
7540 gp_ci.renderPass = renderPass();
7541
7542 VkPipelineCacheCreateInfo pc_ci = {};
7543 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7544
7545 VkPipeline pipeline;
7546 VkPipelineCache pipelineCache;
7547
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007548 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007549 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007550 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007551
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007552 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007553
7554 // Now hit second fail case where we set scissor w/ different count than PSO
7555 // First need to successfully create the PSO from above by setting
7556 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007557 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 -06007558
Tobin Ehlisd332f282015-10-02 11:00:56 -06007559 VkRect2D sc = {}; // Just need dummy vp to point to
7560 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007561 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007562 ASSERT_VK_SUCCESS(err);
7563 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007564 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007565 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007566 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007567 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007568 Draw(1, 0, 0, 0);
7569
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007570 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007571
Chia-I Wuf7458c52015-10-26 21:10:41 +08007572 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7573 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7574 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7575 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007576 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007577}
7578
Mark Young7394fdd2016-03-31 14:56:43 -06007579TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7580 VkResult err;
7581
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007583
7584 ASSERT_NO_FATAL_FAILURE(InitState());
7585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7586
7587 VkDescriptorPoolSize ds_type_count = {};
7588 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7589 ds_type_count.descriptorCount = 1;
7590
7591 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7592 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7593 ds_pool_ci.maxSets = 1;
7594 ds_pool_ci.poolSizeCount = 1;
7595 ds_pool_ci.pPoolSizes = &ds_type_count;
7596
7597 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007598 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007599 ASSERT_VK_SUCCESS(err);
7600
7601 VkDescriptorSetLayoutBinding dsl_binding = {};
7602 dsl_binding.binding = 0;
7603 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7604 dsl_binding.descriptorCount = 1;
7605 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7606
7607 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7608 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7609 ds_layout_ci.bindingCount = 1;
7610 ds_layout_ci.pBindings = &dsl_binding;
7611
7612 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007613 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007614 ASSERT_VK_SUCCESS(err);
7615
7616 VkDescriptorSet descriptorSet;
7617 VkDescriptorSetAllocateInfo alloc_info = {};
7618 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7619 alloc_info.descriptorSetCount = 1;
7620 alloc_info.descriptorPool = ds_pool;
7621 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007622 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007623 ASSERT_VK_SUCCESS(err);
7624
7625 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7626 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7627 pipeline_layout_ci.setLayoutCount = 1;
7628 pipeline_layout_ci.pSetLayouts = &ds_layout;
7629
7630 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007631 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007632 ASSERT_VK_SUCCESS(err);
7633
7634 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7635 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7636 vp_state_ci.scissorCount = 1;
7637 vp_state_ci.pScissors = NULL;
7638 vp_state_ci.viewportCount = 1;
7639 vp_state_ci.pViewports = NULL;
7640
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007641 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007642 // Set scissor as dynamic to avoid that error
7643 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7644 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7645 dyn_state_ci.dynamicStateCount = 2;
7646 dyn_state_ci.pDynamicStates = dynamic_states;
7647
7648 VkPipelineShaderStageCreateInfo shaderStages[2];
7649 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7650
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007651 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7652 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007653 this); // TODO - We shouldn't need a fragment shader
7654 // but add it to be able to run on more devices
7655 shaderStages[0] = vs.GetStageCreateInfo();
7656 shaderStages[1] = fs.GetStageCreateInfo();
7657
7658 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7659 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7660 vi_ci.pNext = nullptr;
7661 vi_ci.vertexBindingDescriptionCount = 0;
7662 vi_ci.pVertexBindingDescriptions = nullptr;
7663 vi_ci.vertexAttributeDescriptionCount = 0;
7664 vi_ci.pVertexAttributeDescriptions = nullptr;
7665
7666 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7667 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7668 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7669
7670 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7671 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7672 rs_ci.pNext = nullptr;
7673
Mark Young47107952016-05-02 15:59:55 -06007674 // Check too low (line width of -1.0f).
7675 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007676
7677 VkPipelineColorBlendAttachmentState att = {};
7678 att.blendEnable = VK_FALSE;
7679 att.colorWriteMask = 0xf;
7680
7681 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7682 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7683 cb_ci.pNext = nullptr;
7684 cb_ci.attachmentCount = 1;
7685 cb_ci.pAttachments = &att;
7686
7687 VkGraphicsPipelineCreateInfo gp_ci = {};
7688 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7689 gp_ci.stageCount = 2;
7690 gp_ci.pStages = shaderStages;
7691 gp_ci.pVertexInputState = &vi_ci;
7692 gp_ci.pInputAssemblyState = &ia_ci;
7693 gp_ci.pViewportState = &vp_state_ci;
7694 gp_ci.pRasterizationState = &rs_ci;
7695 gp_ci.pColorBlendState = &cb_ci;
7696 gp_ci.pDynamicState = &dyn_state_ci;
7697 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7698 gp_ci.layout = pipeline_layout;
7699 gp_ci.renderPass = renderPass();
7700
7701 VkPipelineCacheCreateInfo pc_ci = {};
7702 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7703
7704 VkPipeline pipeline;
7705 VkPipelineCache pipelineCache;
7706
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007707 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007708 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007709 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007710
7711 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007712 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007715
7716 // Check too high (line width of 65536.0f).
7717 rs_ci.lineWidth = 65536.0f;
7718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007719 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007720 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007721 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007722
7723 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007724 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007725
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007727
7728 dyn_state_ci.dynamicStateCount = 3;
7729
7730 rs_ci.lineWidth = 1.0f;
7731
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007732 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007733 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007734 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007735 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007737
7738 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007739 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007740 m_errorMonitor->VerifyFound();
7741
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007743
7744 // Check too high with dynamic setting.
7745 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7746 m_errorMonitor->VerifyFound();
7747 EndCommandBuffer();
7748
7749 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7750 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7751 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7752 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007753 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007754}
7755
Karl Schultz6addd812016-02-02 17:17:23 -07007756TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007757 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7759 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007760
7761 ASSERT_NO_FATAL_FAILURE(InitState());
7762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007763
Tony Barbourfe3351b2015-07-28 10:17:20 -06007764 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007765 // Don't care about RenderPass handle b/c error should be flagged before
7766 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007767 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007768
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007769 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007770}
7771
Karl Schultz6addd812016-02-02 17:17:23 -07007772TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007773 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7775 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007776
7777 ASSERT_NO_FATAL_FAILURE(InitState());
7778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007779
Tony Barbourfe3351b2015-07-28 10:17:20 -06007780 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007781 // Just create a dummy Renderpass that's non-NULL so we can get to the
7782 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007783 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007784
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007785 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007786}
7787
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007788TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7789 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7790 "the number of renderPass attachments that use loadOp"
7791 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7792
7793 ASSERT_NO_FATAL_FAILURE(InitState());
7794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7795
7796 // Create a renderPass with a single attachment that uses loadOp CLEAR
7797 VkAttachmentReference attach = {};
7798 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7799 VkSubpassDescription subpass = {};
7800 subpass.inputAttachmentCount = 1;
7801 subpass.pInputAttachments = &attach;
7802 VkRenderPassCreateInfo rpci = {};
7803 rpci.subpassCount = 1;
7804 rpci.pSubpasses = &subpass;
7805 rpci.attachmentCount = 1;
7806 VkAttachmentDescription attach_desc = {};
7807 attach_desc.format = VK_FORMAT_UNDEFINED;
7808 // Set loadOp to CLEAR
7809 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7810 rpci.pAttachments = &attach_desc;
7811 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7812 VkRenderPass rp;
7813 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7814
7815 VkCommandBufferInheritanceInfo hinfo = {};
7816 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7817 hinfo.renderPass = VK_NULL_HANDLE;
7818 hinfo.subpass = 0;
7819 hinfo.framebuffer = VK_NULL_HANDLE;
7820 hinfo.occlusionQueryEnable = VK_FALSE;
7821 hinfo.queryFlags = 0;
7822 hinfo.pipelineStatistics = 0;
7823 VkCommandBufferBeginInfo info = {};
7824 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7825 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7826 info.pInheritanceInfo = &hinfo;
7827
7828 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7829 VkRenderPassBeginInfo rp_begin = {};
7830 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7831 rp_begin.pNext = NULL;
7832 rp_begin.renderPass = renderPass();
7833 rp_begin.framebuffer = framebuffer();
7834 rp_begin.clearValueCount = 0; // Should be 1
7835
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7837 "there must be at least 1 entries in "
7838 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007839
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007840 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007841
7842 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007843
7844 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007845}
7846
Cody Northrop3bb4d962016-05-09 16:15:57 -06007847TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7848
7849 TEST_DESCRIPTION("End a command buffer with an active render pass");
7850
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7852 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007853
7854 ASSERT_NO_FATAL_FAILURE(InitState());
7855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7856
7857 // The framework's BeginCommandBuffer calls CreateRenderPass
7858 BeginCommandBuffer();
7859
7860 // Call directly into vkEndCommandBuffer instead of the
7861 // the framework's EndCommandBuffer, which inserts a
7862 // vkEndRenderPass
7863 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7864
7865 m_errorMonitor->VerifyFound();
7866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007867 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7868 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007869}
7870
Karl Schultz6addd812016-02-02 17:17:23 -07007871TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007872 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7874 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007875
7876 ASSERT_NO_FATAL_FAILURE(InitState());
7877 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007878
7879 // Renderpass is started here
7880 BeginCommandBuffer();
7881
7882 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007883 vk_testing::Buffer dstBuffer;
7884 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007885
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007886 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007887
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007888 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007889}
7890
Karl Schultz6addd812016-02-02 17:17:23 -07007891TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007892 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7894 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007895
7896 ASSERT_NO_FATAL_FAILURE(InitState());
7897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007898
7899 // Renderpass is started here
7900 BeginCommandBuffer();
7901
7902 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007903 vk_testing::Buffer dstBuffer;
7904 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007905
Karl Schultz6addd812016-02-02 17:17:23 -07007906 VkDeviceSize dstOffset = 0;
7907 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007908 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007909
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007910 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007911
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007912 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007913}
7914
Karl Schultz6addd812016-02-02 17:17:23 -07007915TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007916 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7918 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007919
7920 ASSERT_NO_FATAL_FAILURE(InitState());
7921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007922
7923 // Renderpass is started here
7924 BeginCommandBuffer();
7925
Michael Lentine0a369f62016-02-03 16:51:46 -06007926 VkClearColorValue clear_color;
7927 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007928 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7929 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7930 const int32_t tex_width = 32;
7931 const int32_t tex_height = 32;
7932 VkImageCreateInfo image_create_info = {};
7933 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7934 image_create_info.pNext = NULL;
7935 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7936 image_create_info.format = tex_format;
7937 image_create_info.extent.width = tex_width;
7938 image_create_info.extent.height = tex_height;
7939 image_create_info.extent.depth = 1;
7940 image_create_info.mipLevels = 1;
7941 image_create_info.arrayLayers = 1;
7942 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7943 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7944 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007945
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007946 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007947 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007948
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007949 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007950
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007951 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007952
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007953 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007954}
7955
Karl Schultz6addd812016-02-02 17:17:23 -07007956TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007957 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7959 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007960
7961 ASSERT_NO_FATAL_FAILURE(InitState());
7962 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007963
7964 // Renderpass is started here
7965 BeginCommandBuffer();
7966
7967 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007968 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007969 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7970 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7971 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7972 image_create_info.extent.width = 64;
7973 image_create_info.extent.height = 64;
7974 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7975 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007976
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007977 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007978 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007980 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007982 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7983 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007984
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007985 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007986}
7987
Karl Schultz6addd812016-02-02 17:17:23 -07007988TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007989 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007990 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007991
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7993 "must be issued inside an active "
7994 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007995
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007996 ASSERT_NO_FATAL_FAILURE(InitState());
7997 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007998
7999 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008000 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008001 ASSERT_VK_SUCCESS(err);
8002
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008003 VkClearAttachment color_attachment;
8004 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8005 color_attachment.clearValue.color.float32[0] = 0;
8006 color_attachment.clearValue.color.float32[1] = 0;
8007 color_attachment.clearValue.color.float32[2] = 0;
8008 color_attachment.clearValue.color.float32[3] = 0;
8009 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008010 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008011 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008012
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008013 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008014}
8015
Chris Forbes3b97e932016-09-07 11:29:24 +12008016TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8017 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8018 "called too many times in a renderpass instance");
8019
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8021 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008022
8023 ASSERT_NO_FATAL_FAILURE(InitState());
8024 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8025
8026 BeginCommandBuffer();
8027
8028 // error here.
8029 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8030 m_errorMonitor->VerifyFound();
8031
8032 EndCommandBuffer();
8033}
8034
Chris Forbes6d624702016-09-07 13:57:05 +12008035TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8036 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8037 "called before the final subpass has been reached");
8038
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8040 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008041
8042 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008043 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8044 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008045
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008046 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008047
8048 VkRenderPass rp;
8049 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8050 ASSERT_VK_SUCCESS(err);
8051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008052 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008053
8054 VkFramebuffer fb;
8055 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8056 ASSERT_VK_SUCCESS(err);
8057
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008058 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008060 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 +12008061
8062 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8063
8064 // Error here.
8065 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8066 m_errorMonitor->VerifyFound();
8067
8068 // Clean up.
8069 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8070 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8071}
8072
Karl Schultz9e66a292016-04-21 15:57:51 -06008073TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8074 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8076 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008077
8078 ASSERT_NO_FATAL_FAILURE(InitState());
8079 BeginCommandBuffer();
8080
8081 VkBufferMemoryBarrier buf_barrier = {};
8082 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8083 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8084 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8085 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8086 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8087 buf_barrier.buffer = VK_NULL_HANDLE;
8088 buf_barrier.offset = 0;
8089 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008090 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8091 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008092
8093 m_errorMonitor->VerifyFound();
8094}
8095
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008096TEST_F(VkLayerTest, InvalidBarriers) {
8097 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8098
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008100
8101 ASSERT_NO_FATAL_FAILURE(InitState());
8102 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8103
8104 VkMemoryBarrier mem_barrier = {};
8105 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8106 mem_barrier.pNext = NULL;
8107 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8108 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8109 BeginCommandBuffer();
8110 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008111 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008112 &mem_barrier, 0, nullptr, 0, nullptr);
8113 m_errorMonitor->VerifyFound();
8114
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008116 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008117 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 -06008118 ASSERT_TRUE(image.initialized());
8119 VkImageMemoryBarrier img_barrier = {};
8120 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8121 img_barrier.pNext = NULL;
8122 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8123 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8124 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8125 // New layout can't be UNDEFINED
8126 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8127 img_barrier.image = image.handle();
8128 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8129 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8130 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8131 img_barrier.subresourceRange.baseArrayLayer = 0;
8132 img_barrier.subresourceRange.baseMipLevel = 0;
8133 img_barrier.subresourceRange.layerCount = 1;
8134 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008135 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8136 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008137 m_errorMonitor->VerifyFound();
8138 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8139
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8141 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008142 // baseArrayLayer + layerCount must be <= image's arrayLayers
8143 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008144 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8145 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008146 m_errorMonitor->VerifyFound();
8147 img_barrier.subresourceRange.baseArrayLayer = 0;
8148
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008150 // baseMipLevel + levelCount must be <= image's mipLevels
8151 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008152 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8153 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008154 m_errorMonitor->VerifyFound();
8155 img_barrier.subresourceRange.baseMipLevel = 0;
8156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008157 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 -06008158 vk_testing::Buffer buffer;
8159 buffer.init(*m_device, 256);
8160 VkBufferMemoryBarrier buf_barrier = {};
8161 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8162 buf_barrier.pNext = NULL;
8163 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8164 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8165 buf_barrier.buffer = buffer.handle();
8166 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8167 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8168 buf_barrier.offset = 0;
8169 buf_barrier.size = VK_WHOLE_SIZE;
8170 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008171 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8172 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008173 m_errorMonitor->VerifyFound();
8174 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008177 buf_barrier.offset = 257;
8178 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008179 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8180 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008181 m_errorMonitor->VerifyFound();
8182 buf_barrier.offset = 0;
8183
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008185 buf_barrier.size = 257;
8186 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008187 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8188 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008189 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008190
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008191 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008192 m_errorMonitor->SetDesiredFailureMsg(
8193 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8194 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8195 m_errorMonitor->SetDesiredFailureMsg(
8196 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8197 "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 -06008198 VkDepthStencilObj ds_image(m_device);
8199 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8200 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008201 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8202 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008203 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008204 // Use of COLOR aspect on DS image is error
8205 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008206 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8207 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008208 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008209 // Now test depth-only
8210 VkFormatProperties format_props;
8211
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008212 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8213 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8215 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8217 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008218 VkDepthStencilObj d_image(m_device);
8219 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8220 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008221 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008222 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008223 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008224 // Use of COLOR aspect on depth image is error
8225 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008226 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8227 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008228 m_errorMonitor->VerifyFound();
8229 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008230 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8231 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008232 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8234 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008235 VkDepthStencilObj s_image(m_device);
8236 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8237 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008238 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008239 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008240 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008241 // Use of COLOR aspect on depth image is error
8242 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008243 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8244 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008245 m_errorMonitor->VerifyFound();
8246 }
8247 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8249 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8251 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008252 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008253 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 -06008254 ASSERT_TRUE(c_image.initialized());
8255 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8256 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8257 img_barrier.image = c_image.handle();
8258 // Set aspect to depth (non-color)
8259 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008260 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8261 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008262 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008263}
8264
Tony Barbour18ba25c2016-09-29 13:42:40 -06008265TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8266 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8267
8268 m_errorMonitor->SetDesiredFailureMsg(
8269 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8270 "must have required access bit");
8271 ASSERT_NO_FATAL_FAILURE(InitState());
8272 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008273 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 -06008274 ASSERT_TRUE(image.initialized());
8275
8276 VkImageMemoryBarrier barrier = {};
8277 VkImageSubresourceRange range;
8278 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8279 barrier.srcAccessMask = 0;
8280 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8281 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8282 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8283 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8284 barrier.image = image.handle();
8285 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8286 range.baseMipLevel = 0;
8287 range.levelCount = 1;
8288 range.baseArrayLayer = 0;
8289 range.layerCount = 1;
8290 barrier.subresourceRange = range;
8291 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8292 cmdbuf.BeginCommandBuffer();
8293 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8294 &barrier);
8295 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8296 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8297 barrier.srcAccessMask = 0;
8298 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8299 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8300 &barrier);
8301
8302 m_errorMonitor->VerifyFound();
8303}
8304
Karl Schultz6addd812016-02-02 17:17:23 -07008305TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008306 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008307 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008308
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008310
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008311 ASSERT_NO_FATAL_FAILURE(InitState());
8312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008313 uint32_t qfi = 0;
8314 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008315 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8316 buffCI.size = 1024;
8317 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8318 buffCI.queueFamilyIndexCount = 1;
8319 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008320
8321 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008322 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008323 ASSERT_VK_SUCCESS(err);
8324
8325 BeginCommandBuffer();
8326 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008327 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8328 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008329 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008330 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008331
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008332 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008333
Chia-I Wuf7458c52015-10-26 21:10:41 +08008334 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008335}
8336
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008337TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8338 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8340 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8341 "of the indices specified when the device was created, via the "
8342 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008343
8344 ASSERT_NO_FATAL_FAILURE(InitState());
8345 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8346 VkBufferCreateInfo buffCI = {};
8347 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8348 buffCI.size = 1024;
8349 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8350 buffCI.queueFamilyIndexCount = 1;
8351 // Introduce failure by specifying invalid queue_family_index
8352 uint32_t qfi = 777;
8353 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008354 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008355
8356 VkBuffer ib;
8357 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8358
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008359 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008360 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008361}
8362
Karl Schultz6addd812016-02-02 17:17:23 -07008363TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008364TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008365 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008366
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008367 ASSERT_NO_FATAL_FAILURE(InitState());
8368 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008369
Chris Forbesf29a84f2016-10-06 18:39:28 +13008370 // An empty primary command buffer
8371 VkCommandBufferObj cb(m_device, m_commandPool);
8372 cb.BeginCommandBuffer();
8373 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008374
Chris Forbesf29a84f2016-10-06 18:39:28 +13008375 m_commandBuffer->BeginCommandBuffer();
8376 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8377 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008378
Chris Forbesf29a84f2016-10-06 18:39:28 +13008379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8380 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008381 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008382}
8383
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008384TEST_F(VkLayerTest, DSUsageBitsErrors) {
8385 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8386 "that do not have correct usage bits sets.");
8387 VkResult err;
8388
8389 ASSERT_NO_FATAL_FAILURE(InitState());
8390 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8391 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8392 ds_type_count[i].type = VkDescriptorType(i);
8393 ds_type_count[i].descriptorCount = 1;
8394 }
8395 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8396 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8397 ds_pool_ci.pNext = NULL;
8398 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8399 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8400 ds_pool_ci.pPoolSizes = ds_type_count;
8401
8402 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008403 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008404 ASSERT_VK_SUCCESS(err);
8405
8406 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008407 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008408 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8409 dsl_binding[i].binding = 0;
8410 dsl_binding[i].descriptorType = VkDescriptorType(i);
8411 dsl_binding[i].descriptorCount = 1;
8412 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8413 dsl_binding[i].pImmutableSamplers = NULL;
8414 }
8415
8416 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8417 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8418 ds_layout_ci.pNext = NULL;
8419 ds_layout_ci.bindingCount = 1;
8420 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8421 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8422 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008423 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008424 ASSERT_VK_SUCCESS(err);
8425 }
8426 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8427 VkDescriptorSetAllocateInfo alloc_info = {};
8428 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8429 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8430 alloc_info.descriptorPool = ds_pool;
8431 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008432 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008433 ASSERT_VK_SUCCESS(err);
8434
8435 // Create a buffer & bufferView to be used for invalid updates
8436 VkBufferCreateInfo buff_ci = {};
8437 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8438 // This usage is not valid for any descriptor type
8439 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8440 buff_ci.size = 256;
8441 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8442 VkBuffer buffer;
8443 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8444 ASSERT_VK_SUCCESS(err);
8445
8446 VkBufferViewCreateInfo buff_view_ci = {};
8447 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8448 buff_view_ci.buffer = buffer;
8449 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8450 buff_view_ci.range = VK_WHOLE_SIZE;
8451 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008452 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008453 ASSERT_VK_SUCCESS(err);
8454
8455 // Create an image to be used for invalid updates
8456 VkImageCreateInfo image_ci = {};
8457 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8458 image_ci.imageType = VK_IMAGE_TYPE_2D;
8459 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8460 image_ci.extent.width = 64;
8461 image_ci.extent.height = 64;
8462 image_ci.extent.depth = 1;
8463 image_ci.mipLevels = 1;
8464 image_ci.arrayLayers = 1;
8465 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8466 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8467 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8468 // This usage is not valid for any descriptor type
8469 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8470 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8471 VkImage image;
8472 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8473 ASSERT_VK_SUCCESS(err);
8474 // Bind memory to image
8475 VkMemoryRequirements mem_reqs;
8476 VkDeviceMemory image_mem;
8477 bool pass;
8478 VkMemoryAllocateInfo mem_alloc = {};
8479 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8480 mem_alloc.pNext = NULL;
8481 mem_alloc.allocationSize = 0;
8482 mem_alloc.memoryTypeIndex = 0;
8483 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8484 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008485 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008486 ASSERT_TRUE(pass);
8487 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8488 ASSERT_VK_SUCCESS(err);
8489 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8490 ASSERT_VK_SUCCESS(err);
8491 // Now create view for image
8492 VkImageViewCreateInfo image_view_ci = {};
8493 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8494 image_view_ci.image = image;
8495 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8496 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8497 image_view_ci.subresourceRange.layerCount = 1;
8498 image_view_ci.subresourceRange.baseArrayLayer = 0;
8499 image_view_ci.subresourceRange.levelCount = 1;
8500 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8501 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008502 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008503 ASSERT_VK_SUCCESS(err);
8504
8505 VkDescriptorBufferInfo buff_info = {};
8506 buff_info.buffer = buffer;
8507 VkDescriptorImageInfo img_info = {};
8508 img_info.imageView = image_view;
8509 VkWriteDescriptorSet descriptor_write = {};
8510 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8511 descriptor_write.dstBinding = 0;
8512 descriptor_write.descriptorCount = 1;
8513 descriptor_write.pTexelBufferView = &buff_view;
8514 descriptor_write.pBufferInfo = &buff_info;
8515 descriptor_write.pImageInfo = &img_info;
8516
8517 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008518 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8519 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8520 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8521 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8522 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8523 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8524 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8525 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8526 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8527 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8528 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008529 // Start loop at 1 as SAMPLER desc type has no usage bit error
8530 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8531 descriptor_write.descriptorType = VkDescriptorType(i);
8532 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008534
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008535 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008536
8537 m_errorMonitor->VerifyFound();
8538 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8539 }
8540 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8541 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008542 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008543 vkDestroyImageView(m_device->device(), image_view, NULL);
8544 vkDestroyBuffer(m_device->device(), buffer, NULL);
8545 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008546 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008547 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8548}
8549
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008550TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008551 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8552 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8553 "1. offset value greater than buffer size\n"
8554 "2. range value of 0\n"
8555 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008556 VkResult err;
8557
8558 ASSERT_NO_FATAL_FAILURE(InitState());
8559 VkDescriptorPoolSize ds_type_count = {};
8560 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8561 ds_type_count.descriptorCount = 1;
8562
8563 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8564 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8565 ds_pool_ci.pNext = NULL;
8566 ds_pool_ci.maxSets = 1;
8567 ds_pool_ci.poolSizeCount = 1;
8568 ds_pool_ci.pPoolSizes = &ds_type_count;
8569
8570 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008571 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008572 ASSERT_VK_SUCCESS(err);
8573
8574 // Create layout with single uniform buffer descriptor
8575 VkDescriptorSetLayoutBinding dsl_binding = {};
8576 dsl_binding.binding = 0;
8577 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8578 dsl_binding.descriptorCount = 1;
8579 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8580 dsl_binding.pImmutableSamplers = NULL;
8581
8582 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8583 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8584 ds_layout_ci.pNext = NULL;
8585 ds_layout_ci.bindingCount = 1;
8586 ds_layout_ci.pBindings = &dsl_binding;
8587 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008588 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008589 ASSERT_VK_SUCCESS(err);
8590
8591 VkDescriptorSet descriptor_set = {};
8592 VkDescriptorSetAllocateInfo alloc_info = {};
8593 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8594 alloc_info.descriptorSetCount = 1;
8595 alloc_info.descriptorPool = ds_pool;
8596 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008597 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008598 ASSERT_VK_SUCCESS(err);
8599
8600 // Create a buffer to be used for invalid updates
8601 VkBufferCreateInfo buff_ci = {};
8602 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8603 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8604 buff_ci.size = 256;
8605 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8606 VkBuffer buffer;
8607 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8608 ASSERT_VK_SUCCESS(err);
8609 // Have to bind memory to buffer before descriptor update
8610 VkMemoryAllocateInfo mem_alloc = {};
8611 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8612 mem_alloc.pNext = NULL;
8613 mem_alloc.allocationSize = 256;
8614 mem_alloc.memoryTypeIndex = 0;
8615
8616 VkMemoryRequirements mem_reqs;
8617 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008618 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008619 if (!pass) {
8620 vkDestroyBuffer(m_device->device(), buffer, NULL);
8621 return;
8622 }
8623
8624 VkDeviceMemory mem;
8625 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8626 ASSERT_VK_SUCCESS(err);
8627 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8628 ASSERT_VK_SUCCESS(err);
8629
8630 VkDescriptorBufferInfo buff_info = {};
8631 buff_info.buffer = buffer;
8632 // First make offset 1 larger than buffer size
8633 buff_info.offset = 257;
8634 buff_info.range = VK_WHOLE_SIZE;
8635 VkWriteDescriptorSet descriptor_write = {};
8636 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8637 descriptor_write.dstBinding = 0;
8638 descriptor_write.descriptorCount = 1;
8639 descriptor_write.pTexelBufferView = nullptr;
8640 descriptor_write.pBufferInfo = &buff_info;
8641 descriptor_write.pImageInfo = nullptr;
8642
8643 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8644 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008646
8647 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8648
8649 m_errorMonitor->VerifyFound();
8650 // Now cause error due to range of 0
8651 buff_info.offset = 0;
8652 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8654 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008655
8656 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8657
8658 m_errorMonitor->VerifyFound();
8659 // Now cause error due to range exceeding buffer size - offset
8660 buff_info.offset = 128;
8661 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008662 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 -06008663
8664 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8665
8666 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008667 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008668 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8669 vkDestroyBuffer(m_device->device(), buffer, NULL);
8670 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8671 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8672}
8673
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008674TEST_F(VkLayerTest, DSAspectBitsErrors) {
8675 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8676 // are set, but could expand this test to hit more cases.
8677 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8678 "that do not have correct aspect bits sets.");
8679 VkResult err;
8680
8681 ASSERT_NO_FATAL_FAILURE(InitState());
8682 VkDescriptorPoolSize ds_type_count = {};
8683 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8684 ds_type_count.descriptorCount = 1;
8685
8686 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8687 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8688 ds_pool_ci.pNext = NULL;
8689 ds_pool_ci.maxSets = 5;
8690 ds_pool_ci.poolSizeCount = 1;
8691 ds_pool_ci.pPoolSizes = &ds_type_count;
8692
8693 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008694 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008695 ASSERT_VK_SUCCESS(err);
8696
8697 VkDescriptorSetLayoutBinding dsl_binding = {};
8698 dsl_binding.binding = 0;
8699 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8700 dsl_binding.descriptorCount = 1;
8701 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8702 dsl_binding.pImmutableSamplers = NULL;
8703
8704 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8705 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8706 ds_layout_ci.pNext = NULL;
8707 ds_layout_ci.bindingCount = 1;
8708 ds_layout_ci.pBindings = &dsl_binding;
8709 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008710 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008711 ASSERT_VK_SUCCESS(err);
8712
8713 VkDescriptorSet descriptor_set = {};
8714 VkDescriptorSetAllocateInfo alloc_info = {};
8715 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8716 alloc_info.descriptorSetCount = 1;
8717 alloc_info.descriptorPool = ds_pool;
8718 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008719 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008720 ASSERT_VK_SUCCESS(err);
8721
8722 // Create an image to be used for invalid updates
8723 VkImageCreateInfo image_ci = {};
8724 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8725 image_ci.imageType = VK_IMAGE_TYPE_2D;
8726 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8727 image_ci.extent.width = 64;
8728 image_ci.extent.height = 64;
8729 image_ci.extent.depth = 1;
8730 image_ci.mipLevels = 1;
8731 image_ci.arrayLayers = 1;
8732 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8733 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8734 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8735 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8736 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8737 VkImage image;
8738 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8739 ASSERT_VK_SUCCESS(err);
8740 // Bind memory to image
8741 VkMemoryRequirements mem_reqs;
8742 VkDeviceMemory image_mem;
8743 bool pass;
8744 VkMemoryAllocateInfo mem_alloc = {};
8745 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8746 mem_alloc.pNext = NULL;
8747 mem_alloc.allocationSize = 0;
8748 mem_alloc.memoryTypeIndex = 0;
8749 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8750 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008751 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008752 ASSERT_TRUE(pass);
8753 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8754 ASSERT_VK_SUCCESS(err);
8755 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8756 ASSERT_VK_SUCCESS(err);
8757 // Now create view for image
8758 VkImageViewCreateInfo image_view_ci = {};
8759 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8760 image_view_ci.image = image;
8761 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8762 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8763 image_view_ci.subresourceRange.layerCount = 1;
8764 image_view_ci.subresourceRange.baseArrayLayer = 0;
8765 image_view_ci.subresourceRange.levelCount = 1;
8766 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008767 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008768
8769 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008770 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008771 ASSERT_VK_SUCCESS(err);
8772
8773 VkDescriptorImageInfo img_info = {};
8774 img_info.imageView = image_view;
8775 VkWriteDescriptorSet descriptor_write = {};
8776 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8777 descriptor_write.dstBinding = 0;
8778 descriptor_write.descriptorCount = 1;
8779 descriptor_write.pTexelBufferView = NULL;
8780 descriptor_write.pBufferInfo = NULL;
8781 descriptor_write.pImageInfo = &img_info;
8782 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8783 descriptor_write.dstSet = descriptor_set;
8784 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8785 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008787
8788 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8789
8790 m_errorMonitor->VerifyFound();
8791 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8792 vkDestroyImage(m_device->device(), image, NULL);
8793 vkFreeMemory(m_device->device(), image_mem, NULL);
8794 vkDestroyImageView(m_device->device(), image_view, NULL);
8795 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8796 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8797}
8798
Karl Schultz6addd812016-02-02 17:17:23 -07008799TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008800 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008801 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008802
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8804 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8805 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008806
Tobin Ehlis3b780662015-05-28 12:11:26 -06008807 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008808 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008809 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008810 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8811 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008812
8813 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008814 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8815 ds_pool_ci.pNext = NULL;
8816 ds_pool_ci.maxSets = 1;
8817 ds_pool_ci.poolSizeCount = 1;
8818 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008819
Tobin Ehlis3b780662015-05-28 12:11:26 -06008820 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008821 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008822 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008823 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008824 dsl_binding.binding = 0;
8825 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8826 dsl_binding.descriptorCount = 1;
8827 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8828 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008829
Tony Barboureb254902015-07-15 12:50:33 -06008830 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008831 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8832 ds_layout_ci.pNext = NULL;
8833 ds_layout_ci.bindingCount = 1;
8834 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008835
Tobin Ehlis3b780662015-05-28 12:11:26 -06008836 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008837 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008838 ASSERT_VK_SUCCESS(err);
8839
8840 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008841 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008842 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008843 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008844 alloc_info.descriptorPool = ds_pool;
8845 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008846 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008847 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008848
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008849 VkSamplerCreateInfo sampler_ci = {};
8850 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8851 sampler_ci.pNext = NULL;
8852 sampler_ci.magFilter = VK_FILTER_NEAREST;
8853 sampler_ci.minFilter = VK_FILTER_NEAREST;
8854 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8855 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8856 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8857 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8858 sampler_ci.mipLodBias = 1.0;
8859 sampler_ci.anisotropyEnable = VK_FALSE;
8860 sampler_ci.maxAnisotropy = 1;
8861 sampler_ci.compareEnable = VK_FALSE;
8862 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8863 sampler_ci.minLod = 1.0;
8864 sampler_ci.maxLod = 1.0;
8865 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8866 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8867 VkSampler sampler;
8868 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8869 ASSERT_VK_SUCCESS(err);
8870
8871 VkDescriptorImageInfo info = {};
8872 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008873
8874 VkWriteDescriptorSet descriptor_write;
8875 memset(&descriptor_write, 0, sizeof(descriptor_write));
8876 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008877 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008878 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008879 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008880 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008881 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008882
8883 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8884
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008885 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008886
Chia-I Wuf7458c52015-10-26 21:10:41 +08008887 vkDestroySampler(m_device->device(), sampler, NULL);
8888 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8889 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008890}
8891
Karl Schultz6addd812016-02-02 17:17:23 -07008892TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008893 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008894 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8897 " binding #0 with 1 total descriptors but update of 1 descriptors "
8898 "starting at binding offset of 0 combined with update array element "
8899 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008900
Tobin Ehlis3b780662015-05-28 12:11:26 -06008901 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008902 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008903 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008904 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8905 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008906
8907 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008908 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8909 ds_pool_ci.pNext = NULL;
8910 ds_pool_ci.maxSets = 1;
8911 ds_pool_ci.poolSizeCount = 1;
8912 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008913
Tobin Ehlis3b780662015-05-28 12:11:26 -06008914 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008915 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008916 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008917
Tony Barboureb254902015-07-15 12:50:33 -06008918 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008919 dsl_binding.binding = 0;
8920 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8921 dsl_binding.descriptorCount = 1;
8922 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8923 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008924
8925 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008926 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8927 ds_layout_ci.pNext = NULL;
8928 ds_layout_ci.bindingCount = 1;
8929 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008930
Tobin Ehlis3b780662015-05-28 12:11:26 -06008931 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008932 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008933 ASSERT_VK_SUCCESS(err);
8934
8935 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008936 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008937 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008938 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008939 alloc_info.descriptorPool = ds_pool;
8940 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008941 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008942 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008943
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008944 // Correctly update descriptor to avoid "NOT_UPDATED" error
8945 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008946 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008947 buff_info.offset = 0;
8948 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008949
8950 VkWriteDescriptorSet descriptor_write;
8951 memset(&descriptor_write, 0, sizeof(descriptor_write));
8952 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008953 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008954 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008955 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008956 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8957 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008958
8959 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8960
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008961 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008962
Chia-I Wuf7458c52015-10-26 21:10:41 +08008963 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8964 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008965}
8966
Karl Schultz6addd812016-02-02 17:17:23 -07008967TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8968 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8969 // index 2
8970 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008971
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008973
Tobin Ehlis3b780662015-05-28 12:11:26 -06008974 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008975 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008976 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008977 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8978 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008979
8980 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008981 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8982 ds_pool_ci.pNext = NULL;
8983 ds_pool_ci.maxSets = 1;
8984 ds_pool_ci.poolSizeCount = 1;
8985 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008986
Tobin Ehlis3b780662015-05-28 12:11:26 -06008987 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008988 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008989 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008990
Tony Barboureb254902015-07-15 12:50:33 -06008991 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008992 dsl_binding.binding = 0;
8993 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8994 dsl_binding.descriptorCount = 1;
8995 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8996 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008997
8998 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008999 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9000 ds_layout_ci.pNext = NULL;
9001 ds_layout_ci.bindingCount = 1;
9002 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009003 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009004 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009005 ASSERT_VK_SUCCESS(err);
9006
9007 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009008 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009009 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009010 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009011 alloc_info.descriptorPool = ds_pool;
9012 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009013 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009014 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009015
Tony Barboureb254902015-07-15 12:50:33 -06009016 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009017 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9018 sampler_ci.pNext = NULL;
9019 sampler_ci.magFilter = VK_FILTER_NEAREST;
9020 sampler_ci.minFilter = VK_FILTER_NEAREST;
9021 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9022 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9023 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9024 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9025 sampler_ci.mipLodBias = 1.0;
9026 sampler_ci.anisotropyEnable = VK_FALSE;
9027 sampler_ci.maxAnisotropy = 1;
9028 sampler_ci.compareEnable = VK_FALSE;
9029 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9030 sampler_ci.minLod = 1.0;
9031 sampler_ci.maxLod = 1.0;
9032 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9033 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009034
Tobin Ehlis3b780662015-05-28 12:11:26 -06009035 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009036 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009037 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009038
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009039 VkDescriptorImageInfo info = {};
9040 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009041
9042 VkWriteDescriptorSet descriptor_write;
9043 memset(&descriptor_write, 0, sizeof(descriptor_write));
9044 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009045 descriptor_write.dstSet = descriptorSet;
9046 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009047 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009048 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009049 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009050 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009051
9052 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9053
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009054 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009055
Chia-I Wuf7458c52015-10-26 21:10:41 +08009056 vkDestroySampler(m_device->device(), sampler, NULL);
9057 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9058 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009059}
9060
Karl Schultz6addd812016-02-02 17:17:23 -07009061TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9062 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9063 // types
9064 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009065
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009066 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 -06009067
Tobin Ehlis3b780662015-05-28 12:11:26 -06009068 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009069
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009070 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009071 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9072 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009073
9074 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009075 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9076 ds_pool_ci.pNext = NULL;
9077 ds_pool_ci.maxSets = 1;
9078 ds_pool_ci.poolSizeCount = 1;
9079 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009080
Tobin Ehlis3b780662015-05-28 12:11:26 -06009081 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009082 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009083 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009084 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009085 dsl_binding.binding = 0;
9086 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9087 dsl_binding.descriptorCount = 1;
9088 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9089 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009090
Tony Barboureb254902015-07-15 12:50:33 -06009091 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009092 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9093 ds_layout_ci.pNext = NULL;
9094 ds_layout_ci.bindingCount = 1;
9095 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009096
Tobin Ehlis3b780662015-05-28 12:11:26 -06009097 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009098 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009099 ASSERT_VK_SUCCESS(err);
9100
9101 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009102 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009103 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009104 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009105 alloc_info.descriptorPool = ds_pool;
9106 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009107 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009108 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009109
Tony Barboureb254902015-07-15 12:50:33 -06009110 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009111 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9112 sampler_ci.pNext = NULL;
9113 sampler_ci.magFilter = VK_FILTER_NEAREST;
9114 sampler_ci.minFilter = VK_FILTER_NEAREST;
9115 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9116 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9117 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9118 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9119 sampler_ci.mipLodBias = 1.0;
9120 sampler_ci.anisotropyEnable = VK_FALSE;
9121 sampler_ci.maxAnisotropy = 1;
9122 sampler_ci.compareEnable = VK_FALSE;
9123 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9124 sampler_ci.minLod = 1.0;
9125 sampler_ci.maxLod = 1.0;
9126 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9127 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009128 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009129 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009130 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009131
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009132 VkDescriptorImageInfo info = {};
9133 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009134
9135 VkWriteDescriptorSet descriptor_write;
9136 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009137 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009138 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009139 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009140 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009141 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009142 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009143
9144 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9145
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009146 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009147
Chia-I Wuf7458c52015-10-26 21:10:41 +08009148 vkDestroySampler(m_device->device(), sampler, NULL);
9149 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9150 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009151}
9152
Karl Schultz6addd812016-02-02 17:17:23 -07009153TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009154 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009155 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9158 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009159
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009160 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009161 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9162 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009163 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009164 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9165 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009166
9167 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009168 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9169 ds_pool_ci.pNext = NULL;
9170 ds_pool_ci.maxSets = 1;
9171 ds_pool_ci.poolSizeCount = 1;
9172 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009173
9174 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009175 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009176 ASSERT_VK_SUCCESS(err);
9177
9178 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009179 dsl_binding.binding = 0;
9180 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9181 dsl_binding.descriptorCount = 1;
9182 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9183 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009184
9185 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009186 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9187 ds_layout_ci.pNext = NULL;
9188 ds_layout_ci.bindingCount = 1;
9189 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009190 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009191 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009192 ASSERT_VK_SUCCESS(err);
9193
9194 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009195 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009196 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009197 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009198 alloc_info.descriptorPool = ds_pool;
9199 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009200 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009201 ASSERT_VK_SUCCESS(err);
9202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009203 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009204
9205 VkDescriptorImageInfo descriptor_info;
9206 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9207 descriptor_info.sampler = sampler;
9208
9209 VkWriteDescriptorSet descriptor_write;
9210 memset(&descriptor_write, 0, sizeof(descriptor_write));
9211 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009212 descriptor_write.dstSet = descriptorSet;
9213 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009214 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009215 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9216 descriptor_write.pImageInfo = &descriptor_info;
9217
9218 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9219
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009220 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009221
Chia-I Wuf7458c52015-10-26 21:10:41 +08009222 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9223 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009224}
9225
Karl Schultz6addd812016-02-02 17:17:23 -07009226TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9227 // Create a single combined Image/Sampler descriptor and send it an invalid
9228 // imageView
9229 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9232 "image sampler descriptor failed due "
9233 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009234
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009235 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009236 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009237 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9238 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009239
9240 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009241 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9242 ds_pool_ci.pNext = NULL;
9243 ds_pool_ci.maxSets = 1;
9244 ds_pool_ci.poolSizeCount = 1;
9245 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009246
9247 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009248 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009249 ASSERT_VK_SUCCESS(err);
9250
9251 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009252 dsl_binding.binding = 0;
9253 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9254 dsl_binding.descriptorCount = 1;
9255 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9256 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009257
9258 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009259 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9260 ds_layout_ci.pNext = NULL;
9261 ds_layout_ci.bindingCount = 1;
9262 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009263 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009264 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009265 ASSERT_VK_SUCCESS(err);
9266
9267 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009268 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009269 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009270 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009271 alloc_info.descriptorPool = ds_pool;
9272 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009273 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009274 ASSERT_VK_SUCCESS(err);
9275
9276 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009277 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9278 sampler_ci.pNext = NULL;
9279 sampler_ci.magFilter = VK_FILTER_NEAREST;
9280 sampler_ci.minFilter = VK_FILTER_NEAREST;
9281 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9282 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9283 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9284 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9285 sampler_ci.mipLodBias = 1.0;
9286 sampler_ci.anisotropyEnable = VK_FALSE;
9287 sampler_ci.maxAnisotropy = 1;
9288 sampler_ci.compareEnable = VK_FALSE;
9289 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9290 sampler_ci.minLod = 1.0;
9291 sampler_ci.maxLod = 1.0;
9292 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9293 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009294
9295 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009296 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009297 ASSERT_VK_SUCCESS(err);
9298
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009299 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009300
9301 VkDescriptorImageInfo descriptor_info;
9302 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9303 descriptor_info.sampler = sampler;
9304 descriptor_info.imageView = view;
9305
9306 VkWriteDescriptorSet descriptor_write;
9307 memset(&descriptor_write, 0, sizeof(descriptor_write));
9308 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009309 descriptor_write.dstSet = descriptorSet;
9310 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009311 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009312 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9313 descriptor_write.pImageInfo = &descriptor_info;
9314
9315 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9316
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009317 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009318
Chia-I Wuf7458c52015-10-26 21:10:41 +08009319 vkDestroySampler(m_device->device(), sampler, NULL);
9320 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9321 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009322}
9323
Karl Schultz6addd812016-02-02 17:17:23 -07009324TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9325 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9326 // into the other
9327 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009328
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9330 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9331 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009332
Tobin Ehlis04356f92015-10-27 16:35:27 -06009333 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009334 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009335 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009336 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9337 ds_type_count[0].descriptorCount = 1;
9338 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9339 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009340
9341 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009342 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9343 ds_pool_ci.pNext = NULL;
9344 ds_pool_ci.maxSets = 1;
9345 ds_pool_ci.poolSizeCount = 2;
9346 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009347
9348 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009349 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009350 ASSERT_VK_SUCCESS(err);
9351 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009352 dsl_binding[0].binding = 0;
9353 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9354 dsl_binding[0].descriptorCount = 1;
9355 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9356 dsl_binding[0].pImmutableSamplers = NULL;
9357 dsl_binding[1].binding = 1;
9358 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9359 dsl_binding[1].descriptorCount = 1;
9360 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9361 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009362
9363 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009364 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9365 ds_layout_ci.pNext = NULL;
9366 ds_layout_ci.bindingCount = 2;
9367 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009368
9369 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009370 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009371 ASSERT_VK_SUCCESS(err);
9372
9373 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009374 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009375 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009376 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009377 alloc_info.descriptorPool = ds_pool;
9378 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009379 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009380 ASSERT_VK_SUCCESS(err);
9381
9382 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009383 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9384 sampler_ci.pNext = NULL;
9385 sampler_ci.magFilter = VK_FILTER_NEAREST;
9386 sampler_ci.minFilter = VK_FILTER_NEAREST;
9387 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9388 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9389 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9390 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9391 sampler_ci.mipLodBias = 1.0;
9392 sampler_ci.anisotropyEnable = VK_FALSE;
9393 sampler_ci.maxAnisotropy = 1;
9394 sampler_ci.compareEnable = VK_FALSE;
9395 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9396 sampler_ci.minLod = 1.0;
9397 sampler_ci.maxLod = 1.0;
9398 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9399 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009400
9401 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009402 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009403 ASSERT_VK_SUCCESS(err);
9404
9405 VkDescriptorImageInfo info = {};
9406 info.sampler = sampler;
9407
9408 VkWriteDescriptorSet descriptor_write;
9409 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9410 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009411 descriptor_write.dstSet = descriptorSet;
9412 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009413 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009414 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9415 descriptor_write.pImageInfo = &info;
9416 // This write update should succeed
9417 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9418 // Now perform a copy update that fails due to type mismatch
9419 VkCopyDescriptorSet copy_ds_update;
9420 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9421 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9422 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009423 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009424 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009425 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009426 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009427 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9428
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009429 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009430 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009431 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 -06009432 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9433 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9434 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009435 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009436 copy_ds_update.dstSet = descriptorSet;
9437 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009438 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009439 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9440
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009441 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009442
Tobin Ehlis04356f92015-10-27 16:35:27 -06009443 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9445 "update array offset of 0 and update of "
9446 "5 descriptors oversteps total number "
9447 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009448
Tobin Ehlis04356f92015-10-27 16:35:27 -06009449 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9450 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9451 copy_ds_update.srcSet = descriptorSet;
9452 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009453 copy_ds_update.dstSet = descriptorSet;
9454 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009455 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009456 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9457
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009458 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009459
Chia-I Wuf7458c52015-10-26 21:10:41 +08009460 vkDestroySampler(m_device->device(), sampler, NULL);
9461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009463}
9464
Karl Schultz6addd812016-02-02 17:17:23 -07009465TEST_F(VkLayerTest, NumSamplesMismatch) {
9466 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9467 // sampleCount
9468 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009469
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009471
Tobin Ehlis3b780662015-05-28 12:11:26 -06009472 ASSERT_NO_FATAL_FAILURE(InitState());
9473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009474 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009475 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009476 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009477
9478 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009479 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9480 ds_pool_ci.pNext = NULL;
9481 ds_pool_ci.maxSets = 1;
9482 ds_pool_ci.poolSizeCount = 1;
9483 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009484
Tobin Ehlis3b780662015-05-28 12:11:26 -06009485 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009486 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009487 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009488
Tony Barboureb254902015-07-15 12:50:33 -06009489 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009490 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009491 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009492 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009493 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9494 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009495
Tony Barboureb254902015-07-15 12:50:33 -06009496 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9497 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9498 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009499 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009500 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009501
Tobin Ehlis3b780662015-05-28 12:11:26 -06009502 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009503 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009504 ASSERT_VK_SUCCESS(err);
9505
9506 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009507 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009508 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009509 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009510 alloc_info.descriptorPool = ds_pool;
9511 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009512 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009513 ASSERT_VK_SUCCESS(err);
9514
Tony Barboureb254902015-07-15 12:50:33 -06009515 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009516 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009517 pipe_ms_state_ci.pNext = NULL;
9518 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9519 pipe_ms_state_ci.sampleShadingEnable = 0;
9520 pipe_ms_state_ci.minSampleShading = 1.0;
9521 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009522
Tony Barboureb254902015-07-15 12:50:33 -06009523 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009524 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9525 pipeline_layout_ci.pNext = NULL;
9526 pipeline_layout_ci.setLayoutCount = 1;
9527 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009528
9529 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009530 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009531 ASSERT_VK_SUCCESS(err);
9532
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009533 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9534 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9535 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009536 VkPipelineObj pipe(m_device);
9537 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009538 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009539 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009540 pipe.SetMSAA(&pipe_ms_state_ci);
9541 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009542
Tony Barbourfe3351b2015-07-28 10:17:20 -06009543 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009544 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009545
Mark Young29927482016-05-04 14:38:51 -06009546 // Render triangle (the error should trigger on the attempt to draw).
9547 Draw(3, 1, 0, 0);
9548
9549 // Finalize recording of the command buffer
9550 EndCommandBuffer();
9551
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009552 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009553
Chia-I Wuf7458c52015-10-26 21:10:41 +08009554 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9555 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9556 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009557}
Mark Young29927482016-05-04 14:38:51 -06009558
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009559TEST_F(VkLayerTest, RenderPassIncompatible) {
9560 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9561 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009562 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009563 VkResult err;
9564
9565 ASSERT_NO_FATAL_FAILURE(InitState());
9566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9567
9568 VkDescriptorSetLayoutBinding dsl_binding = {};
9569 dsl_binding.binding = 0;
9570 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9571 dsl_binding.descriptorCount = 1;
9572 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9573 dsl_binding.pImmutableSamplers = NULL;
9574
9575 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9576 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9577 ds_layout_ci.pNext = NULL;
9578 ds_layout_ci.bindingCount = 1;
9579 ds_layout_ci.pBindings = &dsl_binding;
9580
9581 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009582 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009583 ASSERT_VK_SUCCESS(err);
9584
9585 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9586 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9587 pipeline_layout_ci.pNext = NULL;
9588 pipeline_layout_ci.setLayoutCount = 1;
9589 pipeline_layout_ci.pSetLayouts = &ds_layout;
9590
9591 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009592 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009593 ASSERT_VK_SUCCESS(err);
9594
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009595 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9596 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9597 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009598 // Create a renderpass that will be incompatible with default renderpass
9599 VkAttachmentReference attach = {};
9600 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9601 VkAttachmentReference color_att = {};
9602 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9603 VkSubpassDescription subpass = {};
9604 subpass.inputAttachmentCount = 1;
9605 subpass.pInputAttachments = &attach;
9606 subpass.colorAttachmentCount = 1;
9607 subpass.pColorAttachments = &color_att;
9608 VkRenderPassCreateInfo rpci = {};
9609 rpci.subpassCount = 1;
9610 rpci.pSubpasses = &subpass;
9611 rpci.attachmentCount = 1;
9612 VkAttachmentDescription attach_desc = {};
9613 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009614 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9615 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009616 rpci.pAttachments = &attach_desc;
9617 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9618 VkRenderPass rp;
9619 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9620 VkPipelineObj pipe(m_device);
9621 pipe.AddShader(&vs);
9622 pipe.AddShader(&fs);
9623 pipe.AddColorAttachment();
9624 VkViewport view_port = {};
9625 m_viewports.push_back(view_port);
9626 pipe.SetViewport(m_viewports);
9627 VkRect2D rect = {};
9628 m_scissors.push_back(rect);
9629 pipe.SetScissor(m_scissors);
9630 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9631
9632 VkCommandBufferInheritanceInfo cbii = {};
9633 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9634 cbii.renderPass = rp;
9635 cbii.subpass = 0;
9636 VkCommandBufferBeginInfo cbbi = {};
9637 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9638 cbbi.pInheritanceInfo = &cbii;
9639 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9640 VkRenderPassBeginInfo rpbi = {};
9641 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9642 rpbi.framebuffer = m_framebuffer;
9643 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009644 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9645 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009646
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009648 // Render triangle (the error should trigger on the attempt to draw).
9649 Draw(3, 1, 0, 0);
9650
9651 // Finalize recording of the command buffer
9652 EndCommandBuffer();
9653
9654 m_errorMonitor->VerifyFound();
9655
9656 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9657 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9658 vkDestroyRenderPass(m_device->device(), rp, NULL);
9659}
9660
Mark Youngc89c6312016-03-31 16:03:20 -06009661TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9662 // Create Pipeline where the number of blend attachments doesn't match the
9663 // number of color attachments. In this case, we don't add any color
9664 // blend attachments even though we have a color attachment.
9665 VkResult err;
9666
9667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009668 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009669
9670 ASSERT_NO_FATAL_FAILURE(InitState());
9671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9672 VkDescriptorPoolSize ds_type_count = {};
9673 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9674 ds_type_count.descriptorCount = 1;
9675
9676 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9677 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9678 ds_pool_ci.pNext = NULL;
9679 ds_pool_ci.maxSets = 1;
9680 ds_pool_ci.poolSizeCount = 1;
9681 ds_pool_ci.pPoolSizes = &ds_type_count;
9682
9683 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009684 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009685 ASSERT_VK_SUCCESS(err);
9686
9687 VkDescriptorSetLayoutBinding dsl_binding = {};
9688 dsl_binding.binding = 0;
9689 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9690 dsl_binding.descriptorCount = 1;
9691 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9692 dsl_binding.pImmutableSamplers = NULL;
9693
9694 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9695 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9696 ds_layout_ci.pNext = NULL;
9697 ds_layout_ci.bindingCount = 1;
9698 ds_layout_ci.pBindings = &dsl_binding;
9699
9700 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009701 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009702 ASSERT_VK_SUCCESS(err);
9703
9704 VkDescriptorSet descriptorSet;
9705 VkDescriptorSetAllocateInfo alloc_info = {};
9706 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9707 alloc_info.descriptorSetCount = 1;
9708 alloc_info.descriptorPool = ds_pool;
9709 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009710 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009711 ASSERT_VK_SUCCESS(err);
9712
9713 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009714 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009715 pipe_ms_state_ci.pNext = NULL;
9716 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9717 pipe_ms_state_ci.sampleShadingEnable = 0;
9718 pipe_ms_state_ci.minSampleShading = 1.0;
9719 pipe_ms_state_ci.pSampleMask = NULL;
9720
9721 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9722 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9723 pipeline_layout_ci.pNext = NULL;
9724 pipeline_layout_ci.setLayoutCount = 1;
9725 pipeline_layout_ci.pSetLayouts = &ds_layout;
9726
9727 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009728 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009729 ASSERT_VK_SUCCESS(err);
9730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009731 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9732 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9733 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009734 VkPipelineObj pipe(m_device);
9735 pipe.AddShader(&vs);
9736 pipe.AddShader(&fs);
9737 pipe.SetMSAA(&pipe_ms_state_ci);
9738 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9739
9740 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009741 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009742
Mark Young29927482016-05-04 14:38:51 -06009743 // Render triangle (the error should trigger on the attempt to draw).
9744 Draw(3, 1, 0, 0);
9745
9746 // Finalize recording of the command buffer
9747 EndCommandBuffer();
9748
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009749 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009750
9751 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9752 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9753 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9754}
Mark Young29927482016-05-04 14:38:51 -06009755
Mark Muellerd4914412016-06-13 17:52:06 -06009756TEST_F(VkLayerTest, MissingClearAttachment) {
9757 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9758 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009759 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009761 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009762
9763 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9764 m_errorMonitor->VerifyFound();
9765}
9766
Karl Schultz6addd812016-02-02 17:17:23 -07009767TEST_F(VkLayerTest, ClearCmdNoDraw) {
9768 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9769 // to issuing a Draw
9770 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009771
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009773 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009774
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009775 ASSERT_NO_FATAL_FAILURE(InitState());
9776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009777
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009778 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009779 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9780 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009781
9782 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009783 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9784 ds_pool_ci.pNext = NULL;
9785 ds_pool_ci.maxSets = 1;
9786 ds_pool_ci.poolSizeCount = 1;
9787 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009788
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009789 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009790 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009791 ASSERT_VK_SUCCESS(err);
9792
Tony Barboureb254902015-07-15 12:50:33 -06009793 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009794 dsl_binding.binding = 0;
9795 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9796 dsl_binding.descriptorCount = 1;
9797 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9798 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009799
Tony Barboureb254902015-07-15 12:50:33 -06009800 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009801 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9802 ds_layout_ci.pNext = NULL;
9803 ds_layout_ci.bindingCount = 1;
9804 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009805
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009806 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009807 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009808 ASSERT_VK_SUCCESS(err);
9809
9810 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009811 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009812 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009813 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009814 alloc_info.descriptorPool = ds_pool;
9815 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009816 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009817 ASSERT_VK_SUCCESS(err);
9818
Tony Barboureb254902015-07-15 12:50:33 -06009819 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009820 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009821 pipe_ms_state_ci.pNext = NULL;
9822 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9823 pipe_ms_state_ci.sampleShadingEnable = 0;
9824 pipe_ms_state_ci.minSampleShading = 1.0;
9825 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009826
Tony Barboureb254902015-07-15 12:50:33 -06009827 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009828 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9829 pipeline_layout_ci.pNext = NULL;
9830 pipeline_layout_ci.setLayoutCount = 1;
9831 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009832
9833 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009834 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009835 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009836
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009837 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009838 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009839 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009840 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009841
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009842 VkPipelineObj pipe(m_device);
9843 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009844 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009845 pipe.SetMSAA(&pipe_ms_state_ci);
9846 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009847
9848 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009849
Karl Schultz6addd812016-02-02 17:17:23 -07009850 // Main thing we care about for this test is that the VkImage obj we're
9851 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009852 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009853 VkClearAttachment color_attachment;
9854 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9855 color_attachment.clearValue.color.float32[0] = 1.0;
9856 color_attachment.clearValue.color.float32[1] = 1.0;
9857 color_attachment.clearValue.color.float32[2] = 1.0;
9858 color_attachment.clearValue.color.float32[3] = 1.0;
9859 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009860 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009862 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009863
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009864 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009865
Chia-I Wuf7458c52015-10-26 21:10:41 +08009866 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9867 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9868 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009869}
9870
Karl Schultz6addd812016-02-02 17:17:23 -07009871TEST_F(VkLayerTest, VtxBufferBadIndex) {
9872 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009873
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9875 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009876
Tobin Ehlis502480b2015-06-24 15:53:07 -06009877 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009878 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009880
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009881 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009882 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9883 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009884
9885 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009886 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9887 ds_pool_ci.pNext = NULL;
9888 ds_pool_ci.maxSets = 1;
9889 ds_pool_ci.poolSizeCount = 1;
9890 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009891
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009892 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009893 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009894 ASSERT_VK_SUCCESS(err);
9895
Tony Barboureb254902015-07-15 12:50:33 -06009896 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009897 dsl_binding.binding = 0;
9898 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9899 dsl_binding.descriptorCount = 1;
9900 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9901 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009902
Tony Barboureb254902015-07-15 12:50:33 -06009903 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009904 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9905 ds_layout_ci.pNext = NULL;
9906 ds_layout_ci.bindingCount = 1;
9907 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009908
Tobin Ehlis502480b2015-06-24 15:53:07 -06009909 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009910 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009911 ASSERT_VK_SUCCESS(err);
9912
9913 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009914 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009915 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009916 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009917 alloc_info.descriptorPool = ds_pool;
9918 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009919 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009920 ASSERT_VK_SUCCESS(err);
9921
Tony Barboureb254902015-07-15 12:50:33 -06009922 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009923 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009924 pipe_ms_state_ci.pNext = NULL;
9925 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9926 pipe_ms_state_ci.sampleShadingEnable = 0;
9927 pipe_ms_state_ci.minSampleShading = 1.0;
9928 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009929
Tony Barboureb254902015-07-15 12:50:33 -06009930 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009931 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9932 pipeline_layout_ci.pNext = NULL;
9933 pipeline_layout_ci.setLayoutCount = 1;
9934 pipeline_layout_ci.pSetLayouts = &ds_layout;
9935 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009936
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009937 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009938 ASSERT_VK_SUCCESS(err);
9939
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009940 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9941 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9942 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009943 VkPipelineObj pipe(m_device);
9944 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009945 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009946 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009947 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009948 pipe.SetViewport(m_viewports);
9949 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009950 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009951
9952 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009953 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009954 // Don't care about actual data, just need to get to draw to flag error
9955 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009956 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009957 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009958 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009959
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009960 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009961
Chia-I Wuf7458c52015-10-26 21:10:41 +08009962 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9963 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9964 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009965}
Mark Muellerdfe37552016-07-07 14:47:42 -06009966
Mark Mueller2ee294f2016-08-04 12:59:48 -06009967TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9968 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9969 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009970 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009971
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009972 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9973 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009974
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009975 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9976 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009977
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009978 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009981 // The following test fails with recent NVidia drivers.
9982 // By the time core_validation is reached, the NVidia
9983 // driver has sanitized the invalid condition and core_validation
9984 // is not introduced to the failure condition. This is not the case
9985 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009986 // uint32_t count = static_cast<uint32_t>(~0);
9987 // VkPhysicalDevice physical_device;
9988 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9989 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009990
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009992 float queue_priority = 0.0;
9993
9994 VkDeviceQueueCreateInfo queue_create_info = {};
9995 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9996 queue_create_info.queueCount = 1;
9997 queue_create_info.pQueuePriorities = &queue_priority;
9998 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
9999
10000 VkPhysicalDeviceFeatures features = m_device->phy().features();
10001 VkDevice testDevice;
10002 VkDeviceCreateInfo device_create_info = {};
10003 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10004 device_create_info.queueCreateInfoCount = 1;
10005 device_create_info.pQueueCreateInfos = &queue_create_info;
10006 device_create_info.pEnabledFeatures = &features;
10007 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10008 m_errorMonitor->VerifyFound();
10009
10010 queue_create_info.queueFamilyIndex = 1;
10011
10012 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10013 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10014 for (unsigned i = 0; i < feature_count; i++) {
10015 if (VK_FALSE == feature_array[i]) {
10016 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010018 device_create_info.pEnabledFeatures = &features;
10019 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10020 m_errorMonitor->VerifyFound();
10021 break;
10022 }
10023 }
10024}
10025
10026TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10027 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10028 "End a command buffer with a query still in progress.");
10029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010030 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10031 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10032 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010034 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010037
10038 ASSERT_NO_FATAL_FAILURE(InitState());
10039
10040 VkEvent event;
10041 VkEventCreateInfo event_create_info{};
10042 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10043 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10044
Mark Mueller2ee294f2016-08-04 12:59:48 -060010045 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010046 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010047
10048 BeginCommandBuffer();
10049
10050 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010051 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 -060010052 ASSERT_TRUE(image.initialized());
10053 VkImageMemoryBarrier img_barrier = {};
10054 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10055 img_barrier.pNext = NULL;
10056 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10057 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10058 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10059 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10060 img_barrier.image = image.handle();
10061 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010062
10063 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10064 // that layer validation catches the case when it is not.
10065 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010066 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10067 img_barrier.subresourceRange.baseArrayLayer = 0;
10068 img_barrier.subresourceRange.baseMipLevel = 0;
10069 img_barrier.subresourceRange.layerCount = 1;
10070 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010071 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10072 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010073 m_errorMonitor->VerifyFound();
10074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010076
10077 VkQueryPool query_pool;
10078 VkQueryPoolCreateInfo query_pool_create_info = {};
10079 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10080 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10081 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010082 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010083
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010084 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010085 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10086
10087 vkEndCommandBuffer(m_commandBuffer->handle());
10088 m_errorMonitor->VerifyFound();
10089
10090 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10091 vkDestroyEvent(m_device->device(), event, nullptr);
10092}
10093
Mark Muellerdfe37552016-07-07 14:47:42 -060010094TEST_F(VkLayerTest, VertexBufferInvalid) {
10095 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10096 "delete a buffer twice, use an invalid offset for each "
10097 "buffer type, and attempt to bind a null buffer");
10098
10099 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10100 "using deleted buffer ";
10101 const char *double_destroy_message = "Cannot free buffer 0x";
10102 const char *invalid_offset_message = "vkBindBufferMemory(): "
10103 "memoryOffset is 0x";
10104 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10105 "storage memoryOffset "
10106 "is 0x";
10107 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10108 "texel memoryOffset "
10109 "is 0x";
10110 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10111 "uniform memoryOffset "
10112 "is 0x";
10113 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
10114 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -060010115 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010116
10117 ASSERT_NO_FATAL_FAILURE(InitState());
10118 ASSERT_NO_FATAL_FAILURE(InitViewport());
10119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10120
10121 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010122 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010123 pipe_ms_state_ci.pNext = NULL;
10124 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10125 pipe_ms_state_ci.sampleShadingEnable = 0;
10126 pipe_ms_state_ci.minSampleShading = 1.0;
10127 pipe_ms_state_ci.pSampleMask = nullptr;
10128
10129 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10130 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10131 VkPipelineLayout pipeline_layout;
10132
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010133 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010134 ASSERT_VK_SUCCESS(err);
10135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010136 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10137 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010138 VkPipelineObj pipe(m_device);
10139 pipe.AddShader(&vs);
10140 pipe.AddShader(&fs);
10141 pipe.AddColorAttachment();
10142 pipe.SetMSAA(&pipe_ms_state_ci);
10143 pipe.SetViewport(m_viewports);
10144 pipe.SetScissor(m_scissors);
10145 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10146
10147 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010148 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010149
10150 {
10151 // Create and bind a vertex buffer in a reduced scope, which will cause
10152 // it to be deleted upon leaving this scope
10153 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010154 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010155 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10156 draw_verticies.AddVertexInputToPipe(pipe);
10157 }
10158
10159 Draw(1, 0, 0, 0);
10160
10161 EndCommandBuffer();
10162
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010164 QueueCommandBuffer(false);
10165 m_errorMonitor->VerifyFound();
10166
10167 {
10168 // Create and bind a vertex buffer in a reduced scope, and delete it
10169 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010170 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010172 buffer_test.TestDoubleDestroy();
10173 }
10174 m_errorMonitor->VerifyFound();
10175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010176 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010177 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10179 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10180 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010181 m_errorMonitor->VerifyFound();
10182 }
10183
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010184 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10185 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010186 // Create and bind a memory buffer with an invalid offset again,
10187 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10189 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10190 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010191 m_errorMonitor->VerifyFound();
10192 }
10193
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010194 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010195 // Create and bind a memory buffer with an invalid offset again, but
10196 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10198 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10199 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010200 m_errorMonitor->VerifyFound();
10201 }
10202
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010203 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010204 // Create and bind a memory buffer with an invalid offset again, but
10205 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10207 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10208 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010209 m_errorMonitor->VerifyFound();
10210 }
10211
10212 {
10213 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10215 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10216 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010217 m_errorMonitor->VerifyFound();
10218 }
10219
10220 {
10221 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10223 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10224 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010225 }
10226 m_errorMonitor->VerifyFound();
10227
10228 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10229}
10230
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010231// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10232TEST_F(VkLayerTest, InvalidImageLayout) {
10233 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010234 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10235 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010236 // 3 in ValidateCmdBufImageLayouts
10237 // * -1 Attempt to submit cmd buf w/ deleted image
10238 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10239 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10241 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010242
10243 ASSERT_NO_FATAL_FAILURE(InitState());
10244 // Create src & dst images to use for copy operations
10245 VkImage src_image;
10246 VkImage dst_image;
10247
10248 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10249 const int32_t tex_width = 32;
10250 const int32_t tex_height = 32;
10251
10252 VkImageCreateInfo image_create_info = {};
10253 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10254 image_create_info.pNext = NULL;
10255 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10256 image_create_info.format = tex_format;
10257 image_create_info.extent.width = tex_width;
10258 image_create_info.extent.height = tex_height;
10259 image_create_info.extent.depth = 1;
10260 image_create_info.mipLevels = 1;
10261 image_create_info.arrayLayers = 4;
10262 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10263 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10264 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10265 image_create_info.flags = 0;
10266
10267 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10268 ASSERT_VK_SUCCESS(err);
10269 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10270 ASSERT_VK_SUCCESS(err);
10271
10272 BeginCommandBuffer();
10273 VkImageCopy copyRegion;
10274 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10275 copyRegion.srcSubresource.mipLevel = 0;
10276 copyRegion.srcSubresource.baseArrayLayer = 0;
10277 copyRegion.srcSubresource.layerCount = 1;
10278 copyRegion.srcOffset.x = 0;
10279 copyRegion.srcOffset.y = 0;
10280 copyRegion.srcOffset.z = 0;
10281 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10282 copyRegion.dstSubresource.mipLevel = 0;
10283 copyRegion.dstSubresource.baseArrayLayer = 0;
10284 copyRegion.dstSubresource.layerCount = 1;
10285 copyRegion.dstOffset.x = 0;
10286 copyRegion.dstOffset.y = 0;
10287 copyRegion.dstOffset.z = 0;
10288 copyRegion.extent.width = 1;
10289 copyRegion.extent.height = 1;
10290 copyRegion.extent.depth = 1;
10291 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10292 m_errorMonitor->VerifyFound();
10293 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10295 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10296 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010297 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10298 m_errorMonitor->VerifyFound();
10299 // Final src error is due to bad layout type
10300 m_errorMonitor->SetDesiredFailureMsg(
10301 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10302 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10303 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10304 m_errorMonitor->VerifyFound();
10305 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10307 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010308 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10309 m_errorMonitor->VerifyFound();
10310 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10312 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10313 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010314 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10315 m_errorMonitor->VerifyFound();
10316 m_errorMonitor->SetDesiredFailureMsg(
10317 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10318 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10319 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10320 m_errorMonitor->VerifyFound();
10321 // Now cause error due to bad image layout transition in PipelineBarrier
10322 VkImageMemoryBarrier image_barrier[1] = {};
10323 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10324 image_barrier[0].image = src_image;
10325 image_barrier[0].subresourceRange.layerCount = 2;
10326 image_barrier[0].subresourceRange.levelCount = 2;
10327 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10329 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10330 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10331 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10332 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010333 m_errorMonitor->VerifyFound();
10334
10335 // Finally some layout errors at RenderPass create time
10336 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10337 VkAttachmentReference attach = {};
10338 // perf warning for GENERAL layout w/ non-DS input attachment
10339 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10340 VkSubpassDescription subpass = {};
10341 subpass.inputAttachmentCount = 1;
10342 subpass.pInputAttachments = &attach;
10343 VkRenderPassCreateInfo rpci = {};
10344 rpci.subpassCount = 1;
10345 rpci.pSubpasses = &subpass;
10346 rpci.attachmentCount = 1;
10347 VkAttachmentDescription attach_desc = {};
10348 attach_desc.format = VK_FORMAT_UNDEFINED;
10349 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010350 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010351 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10353 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010354 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10355 m_errorMonitor->VerifyFound();
10356 // error w/ non-general layout
10357 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10358
10359 m_errorMonitor->SetDesiredFailureMsg(
10360 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10361 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10362 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10363 m_errorMonitor->VerifyFound();
10364 subpass.inputAttachmentCount = 0;
10365 subpass.colorAttachmentCount = 1;
10366 subpass.pColorAttachments = &attach;
10367 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10368 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10370 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010371 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10372 m_errorMonitor->VerifyFound();
10373 // error w/ non-color opt or GENERAL layout for color attachment
10374 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10375 m_errorMonitor->SetDesiredFailureMsg(
10376 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10377 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10378 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10379 m_errorMonitor->VerifyFound();
10380 subpass.colorAttachmentCount = 0;
10381 subpass.pDepthStencilAttachment = &attach;
10382 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10383 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10385 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010386 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10387 m_errorMonitor->VerifyFound();
10388 // error w/ non-ds opt or GENERAL layout for color attachment
10389 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10391 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10392 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010393 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10394 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010395 // For this error we need a valid renderpass so create default one
10396 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10397 attach.attachment = 0;
10398 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10399 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10400 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10401 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10402 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10403 // Can't do a CLEAR load on READ_ONLY initialLayout
10404 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10405 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10406 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10408 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10409 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010410 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10411 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010412
10413 vkDestroyImage(m_device->device(), src_image, NULL);
10414 vkDestroyImage(m_device->device(), dst_image, NULL);
10415}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010416
Tobin Ehlise0936662016-10-11 08:10:51 -060010417TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10418 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10419 VkResult err;
10420
10421 ASSERT_NO_FATAL_FAILURE(InitState());
10422
10423 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10424 VkImageTiling tiling;
10425 VkFormatProperties format_properties;
10426 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10427 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10428 tiling = VK_IMAGE_TILING_LINEAR;
10429 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10430 tiling = VK_IMAGE_TILING_OPTIMAL;
10431 } else {
10432 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10433 "skipped.\n");
10434 return;
10435 }
10436
10437 VkDescriptorPoolSize ds_type = {};
10438 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10439 ds_type.descriptorCount = 1;
10440
10441 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10442 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10443 ds_pool_ci.maxSets = 1;
10444 ds_pool_ci.poolSizeCount = 1;
10445 ds_pool_ci.pPoolSizes = &ds_type;
10446 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10447
10448 VkDescriptorPool ds_pool;
10449 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10450 ASSERT_VK_SUCCESS(err);
10451
10452 VkDescriptorSetLayoutBinding dsl_binding = {};
10453 dsl_binding.binding = 0;
10454 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10455 dsl_binding.descriptorCount = 1;
10456 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10457 dsl_binding.pImmutableSamplers = NULL;
10458
10459 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10460 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10461 ds_layout_ci.pNext = NULL;
10462 ds_layout_ci.bindingCount = 1;
10463 ds_layout_ci.pBindings = &dsl_binding;
10464
10465 VkDescriptorSetLayout ds_layout;
10466 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10467 ASSERT_VK_SUCCESS(err);
10468
10469 VkDescriptorSetAllocateInfo alloc_info = {};
10470 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10471 alloc_info.descriptorSetCount = 1;
10472 alloc_info.descriptorPool = ds_pool;
10473 alloc_info.pSetLayouts = &ds_layout;
10474 VkDescriptorSet descriptor_set;
10475 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10476 ASSERT_VK_SUCCESS(err);
10477
10478 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10479 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10480 pipeline_layout_ci.pNext = NULL;
10481 pipeline_layout_ci.setLayoutCount = 1;
10482 pipeline_layout_ci.pSetLayouts = &ds_layout;
10483 VkPipelineLayout pipeline_layout;
10484 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10485 ASSERT_VK_SUCCESS(err);
10486
10487 VkImageObj image(m_device);
10488 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10489 ASSERT_TRUE(image.initialized());
10490 VkImageView view = image.targetView(tex_format);
10491
10492 VkDescriptorImageInfo image_info = {};
10493 image_info.imageView = view;
10494 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10495
10496 VkWriteDescriptorSet descriptor_write = {};
10497 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10498 descriptor_write.dstSet = descriptor_set;
10499 descriptor_write.dstBinding = 0;
10500 descriptor_write.descriptorCount = 1;
10501 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10502 descriptor_write.pImageInfo = &image_info;
10503
10504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10505 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10506 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10507 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10508 m_errorMonitor->VerifyFound();
10509
10510 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10511 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10512 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10513 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10514}
10515
Mark Mueller93b938f2016-08-18 10:27:40 -060010516TEST_F(VkLayerTest, SimultaneousUse) {
10517 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10518 "in primary and secondary command buffers.");
10519
10520 ASSERT_NO_FATAL_FAILURE(InitState());
10521 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10522
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010523 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010524 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10525 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010526
10527 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010528 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010529 command_buffer_allocate_info.commandPool = m_commandPool;
10530 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10531 command_buffer_allocate_info.commandBufferCount = 1;
10532
10533 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010535 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10536 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010537 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010538 command_buffer_inheritance_info.renderPass = m_renderPass;
10539 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10540 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010541 command_buffer_begin_info.flags =
10542 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010543 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10544
10545 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010546 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10547 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010548 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010549 vkEndCommandBuffer(secondary_command_buffer);
10550
Mark Mueller93b938f2016-08-18 10:27:40 -060010551 VkSubmitInfo submit_info = {};
10552 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10553 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010554 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010555 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010556
Mark Mueller4042b652016-09-05 22:52:21 -060010557 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010558 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10560 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010561 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010562 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10563 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010564
10565 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010566 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10567
Mark Mueller4042b652016-09-05 22:52:21 -060010568 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010569 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010570 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010571
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10573 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010574 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010575 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10576 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010577}
10578
Mark Mueller917f6bc2016-08-30 10:57:19 -060010579TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10580 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10581 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010582 "Delete objects that are inuse. Call VkQueueSubmit "
10583 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010584
10585 ASSERT_NO_FATAL_FAILURE(InitState());
10586 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010588 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10589 const char *cannot_delete_event_message = "Cannot delete event 0x";
10590 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10591 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010592
10593 BeginCommandBuffer();
10594
10595 VkEvent event;
10596 VkEventCreateInfo event_create_info = {};
10597 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10598 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010599 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010600
Mark Muellerc8d441e2016-08-23 17:36:00 -060010601 EndCommandBuffer();
10602 vkDestroyEvent(m_device->device(), event, nullptr);
10603
10604 VkSubmitInfo submit_info = {};
10605 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10606 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010607 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010609 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10610 m_errorMonitor->VerifyFound();
10611
10612 m_errorMonitor->SetDesiredFailureMsg(0, "");
10613 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10614
10615 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10616
Mark Mueller917f6bc2016-08-30 10:57:19 -060010617 VkSemaphoreCreateInfo semaphore_create_info = {};
10618 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10619 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010620 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010621 VkFenceCreateInfo fence_create_info = {};
10622 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10623 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010624 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010625
10626 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010627 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010628 descriptor_pool_type_count.descriptorCount = 1;
10629
10630 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10631 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10632 descriptor_pool_create_info.maxSets = 1;
10633 descriptor_pool_create_info.poolSizeCount = 1;
10634 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010635 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010636
10637 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010638 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010639
10640 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010641 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010642 descriptorset_layout_binding.descriptorCount = 1;
10643 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10644
10645 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010646 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010647 descriptorset_layout_create_info.bindingCount = 1;
10648 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10649
10650 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010651 ASSERT_VK_SUCCESS(
10652 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010653
10654 VkDescriptorSet descriptorset;
10655 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010656 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010657 descriptorset_allocate_info.descriptorSetCount = 1;
10658 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10659 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010660 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010661
Mark Mueller4042b652016-09-05 22:52:21 -060010662 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10663
10664 VkDescriptorBufferInfo buffer_info = {};
10665 buffer_info.buffer = buffer_test.GetBuffer();
10666 buffer_info.offset = 0;
10667 buffer_info.range = 1024;
10668
10669 VkWriteDescriptorSet write_descriptor_set = {};
10670 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10671 write_descriptor_set.dstSet = descriptorset;
10672 write_descriptor_set.descriptorCount = 1;
10673 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10674 write_descriptor_set.pBufferInfo = &buffer_info;
10675
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010676 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010677
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010678 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10679 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010680
10681 VkPipelineObj pipe(m_device);
10682 pipe.AddColorAttachment();
10683 pipe.AddShader(&vs);
10684 pipe.AddShader(&fs);
10685
10686 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010687 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010688 pipeline_layout_create_info.setLayoutCount = 1;
10689 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10690
10691 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010692 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010693
10694 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10695
Mark Muellerc8d441e2016-08-23 17:36:00 -060010696 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010697 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010698
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010699 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10700 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10701 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010702
Mark Muellerc8d441e2016-08-23 17:36:00 -060010703 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010704
Mark Mueller917f6bc2016-08-30 10:57:19 -060010705 submit_info.signalSemaphoreCount = 1;
10706 submit_info.pSignalSemaphores = &semaphore;
10707 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010710 vkDestroyEvent(m_device->device(), event, nullptr);
10711 m_errorMonitor->VerifyFound();
10712
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010714 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10715 m_errorMonitor->VerifyFound();
10716
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010718 vkDestroyFence(m_device->device(), fence, nullptr);
10719 m_errorMonitor->VerifyFound();
10720
Tobin Ehlis122207b2016-09-01 08:50:06 -070010721 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010722 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10723 vkDestroyFence(m_device->device(), fence, nullptr);
10724 vkDestroyEvent(m_device->device(), event, nullptr);
10725 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010726 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010727 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10728}
10729
Tobin Ehlis2adda372016-09-01 08:51:06 -070010730TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10731 TEST_DESCRIPTION("Delete in-use query pool.");
10732
10733 ASSERT_NO_FATAL_FAILURE(InitState());
10734 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10735
10736 VkQueryPool query_pool;
10737 VkQueryPoolCreateInfo query_pool_ci{};
10738 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10739 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10740 query_pool_ci.queryCount = 1;
10741 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10742 BeginCommandBuffer();
10743 // Reset query pool to create binding with cmd buffer
10744 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10745
10746 EndCommandBuffer();
10747
10748 VkSubmitInfo submit_info = {};
10749 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10750 submit_info.commandBufferCount = 1;
10751 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10752 // Submit cmd buffer and then destroy query pool while in-flight
10753 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10754
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010756 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10757 m_errorMonitor->VerifyFound();
10758
10759 vkQueueWaitIdle(m_device->m_queue);
10760 // Now that cmd buffer done we can safely destroy query_pool
10761 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10762}
10763
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010764TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10765 TEST_DESCRIPTION("Delete in-use pipeline.");
10766
10767 ASSERT_NO_FATAL_FAILURE(InitState());
10768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10769
10770 // Empty pipeline layout used for binding PSO
10771 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10772 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10773 pipeline_layout_ci.setLayoutCount = 0;
10774 pipeline_layout_ci.pSetLayouts = NULL;
10775
10776 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010777 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010778 ASSERT_VK_SUCCESS(err);
10779
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010781 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010782 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10783 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010784 // Store pipeline handle so we can actually delete it before test finishes
10785 VkPipeline delete_this_pipeline;
10786 { // Scope pipeline so it will be auto-deleted
10787 VkPipelineObj pipe(m_device);
10788 pipe.AddShader(&vs);
10789 pipe.AddShader(&fs);
10790 pipe.AddColorAttachment();
10791 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10792 delete_this_pipeline = pipe.handle();
10793
10794 BeginCommandBuffer();
10795 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010796 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010797
10798 EndCommandBuffer();
10799
10800 VkSubmitInfo submit_info = {};
10801 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10802 submit_info.commandBufferCount = 1;
10803 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10804 // Submit cmd buffer and then pipeline destroyed while in-flight
10805 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10806 } // Pipeline deletion triggered here
10807 m_errorMonitor->VerifyFound();
10808 // Make sure queue finished and then actually delete pipeline
10809 vkQueueWaitIdle(m_device->m_queue);
10810 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10811 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10812}
10813
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010814TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10815 TEST_DESCRIPTION("Delete in-use imageView.");
10816
10817 ASSERT_NO_FATAL_FAILURE(InitState());
10818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10819
10820 VkDescriptorPoolSize ds_type_count;
10821 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10822 ds_type_count.descriptorCount = 1;
10823
10824 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10825 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10826 ds_pool_ci.maxSets = 1;
10827 ds_pool_ci.poolSizeCount = 1;
10828 ds_pool_ci.pPoolSizes = &ds_type_count;
10829
10830 VkDescriptorPool ds_pool;
10831 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10832 ASSERT_VK_SUCCESS(err);
10833
10834 VkSamplerCreateInfo sampler_ci = {};
10835 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10836 sampler_ci.pNext = NULL;
10837 sampler_ci.magFilter = VK_FILTER_NEAREST;
10838 sampler_ci.minFilter = VK_FILTER_NEAREST;
10839 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10840 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10841 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10842 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10843 sampler_ci.mipLodBias = 1.0;
10844 sampler_ci.anisotropyEnable = VK_FALSE;
10845 sampler_ci.maxAnisotropy = 1;
10846 sampler_ci.compareEnable = VK_FALSE;
10847 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10848 sampler_ci.minLod = 1.0;
10849 sampler_ci.maxLod = 1.0;
10850 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10851 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10852 VkSampler sampler;
10853
10854 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10855 ASSERT_VK_SUCCESS(err);
10856
10857 VkDescriptorSetLayoutBinding layout_binding;
10858 layout_binding.binding = 0;
10859 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10860 layout_binding.descriptorCount = 1;
10861 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10862 layout_binding.pImmutableSamplers = NULL;
10863
10864 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10865 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10866 ds_layout_ci.bindingCount = 1;
10867 ds_layout_ci.pBindings = &layout_binding;
10868 VkDescriptorSetLayout ds_layout;
10869 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10870 ASSERT_VK_SUCCESS(err);
10871
10872 VkDescriptorSetAllocateInfo alloc_info = {};
10873 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10874 alloc_info.descriptorSetCount = 1;
10875 alloc_info.descriptorPool = ds_pool;
10876 alloc_info.pSetLayouts = &ds_layout;
10877 VkDescriptorSet descriptor_set;
10878 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10879 ASSERT_VK_SUCCESS(err);
10880
10881 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10882 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10883 pipeline_layout_ci.pNext = NULL;
10884 pipeline_layout_ci.setLayoutCount = 1;
10885 pipeline_layout_ci.pSetLayouts = &ds_layout;
10886
10887 VkPipelineLayout pipeline_layout;
10888 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10889 ASSERT_VK_SUCCESS(err);
10890
10891 VkImageObj image(m_device);
10892 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10893 ASSERT_TRUE(image.initialized());
10894
10895 VkImageView view;
10896 VkImageViewCreateInfo ivci = {};
10897 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10898 ivci.image = image.handle();
10899 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10900 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10901 ivci.subresourceRange.layerCount = 1;
10902 ivci.subresourceRange.baseMipLevel = 0;
10903 ivci.subresourceRange.levelCount = 1;
10904 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10905
10906 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10907 ASSERT_VK_SUCCESS(err);
10908
10909 VkDescriptorImageInfo image_info{};
10910 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10911 image_info.imageView = view;
10912 image_info.sampler = sampler;
10913
10914 VkWriteDescriptorSet descriptor_write = {};
10915 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10916 descriptor_write.dstSet = descriptor_set;
10917 descriptor_write.dstBinding = 0;
10918 descriptor_write.descriptorCount = 1;
10919 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10920 descriptor_write.pImageInfo = &image_info;
10921
10922 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10923
10924 // Create PSO to use the sampler
10925 char const *vsSource = "#version 450\n"
10926 "\n"
10927 "out gl_PerVertex { \n"
10928 " vec4 gl_Position;\n"
10929 "};\n"
10930 "void main(){\n"
10931 " gl_Position = vec4(1);\n"
10932 "}\n";
10933 char const *fsSource = "#version 450\n"
10934 "\n"
10935 "layout(set=0, binding=0) uniform sampler2D s;\n"
10936 "layout(location=0) out vec4 x;\n"
10937 "void main(){\n"
10938 " x = texture(s, vec2(1));\n"
10939 "}\n";
10940 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10941 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10942 VkPipelineObj pipe(m_device);
10943 pipe.AddShader(&vs);
10944 pipe.AddShader(&fs);
10945 pipe.AddColorAttachment();
10946 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10947
10948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10949
10950 BeginCommandBuffer();
10951 // Bind pipeline to cmd buffer
10952 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10953 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10954 &descriptor_set, 0, nullptr);
10955 Draw(1, 0, 0, 0);
10956 EndCommandBuffer();
10957 // Submit cmd buffer then destroy sampler
10958 VkSubmitInfo submit_info = {};
10959 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10960 submit_info.commandBufferCount = 1;
10961 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10962 // Submit cmd buffer and then destroy imageView while in-flight
10963 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10964
10965 vkDestroyImageView(m_device->device(), view, nullptr);
10966 m_errorMonitor->VerifyFound();
10967 vkQueueWaitIdle(m_device->m_queue);
10968 // Now we can actually destroy imageView
10969 vkDestroyImageView(m_device->device(), view, NULL);
10970 vkDestroySampler(m_device->device(), sampler, nullptr);
10971 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10972 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10973 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10974}
10975
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010976TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10977 TEST_DESCRIPTION("Delete in-use bufferView.");
10978
10979 ASSERT_NO_FATAL_FAILURE(InitState());
10980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10981
10982 VkDescriptorPoolSize ds_type_count;
10983 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10984 ds_type_count.descriptorCount = 1;
10985
10986 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10987 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10988 ds_pool_ci.maxSets = 1;
10989 ds_pool_ci.poolSizeCount = 1;
10990 ds_pool_ci.pPoolSizes = &ds_type_count;
10991
10992 VkDescriptorPool ds_pool;
10993 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10994 ASSERT_VK_SUCCESS(err);
10995
10996 VkDescriptorSetLayoutBinding layout_binding;
10997 layout_binding.binding = 0;
10998 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10999 layout_binding.descriptorCount = 1;
11000 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11001 layout_binding.pImmutableSamplers = NULL;
11002
11003 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11004 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11005 ds_layout_ci.bindingCount = 1;
11006 ds_layout_ci.pBindings = &layout_binding;
11007 VkDescriptorSetLayout ds_layout;
11008 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11009 ASSERT_VK_SUCCESS(err);
11010
11011 VkDescriptorSetAllocateInfo alloc_info = {};
11012 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11013 alloc_info.descriptorSetCount = 1;
11014 alloc_info.descriptorPool = ds_pool;
11015 alloc_info.pSetLayouts = &ds_layout;
11016 VkDescriptorSet descriptor_set;
11017 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11018 ASSERT_VK_SUCCESS(err);
11019
11020 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11021 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11022 pipeline_layout_ci.pNext = NULL;
11023 pipeline_layout_ci.setLayoutCount = 1;
11024 pipeline_layout_ci.pSetLayouts = &ds_layout;
11025
11026 VkPipelineLayout pipeline_layout;
11027 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11028 ASSERT_VK_SUCCESS(err);
11029
11030 VkBuffer buffer;
11031 uint32_t queue_family_index = 0;
11032 VkBufferCreateInfo buffer_create_info = {};
11033 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11034 buffer_create_info.size = 1024;
11035 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11036 buffer_create_info.queueFamilyIndexCount = 1;
11037 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11038
11039 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11040 ASSERT_VK_SUCCESS(err);
11041
11042 VkMemoryRequirements memory_reqs;
11043 VkDeviceMemory buffer_memory;
11044
11045 VkMemoryAllocateInfo memory_info = {};
11046 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11047 memory_info.allocationSize = 0;
11048 memory_info.memoryTypeIndex = 0;
11049
11050 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11051 memory_info.allocationSize = memory_reqs.size;
11052 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11053 ASSERT_TRUE(pass);
11054
11055 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11056 ASSERT_VK_SUCCESS(err);
11057 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11058 ASSERT_VK_SUCCESS(err);
11059
11060 VkBufferView view;
11061 VkBufferViewCreateInfo bvci = {};
11062 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11063 bvci.buffer = buffer;
11064 bvci.format = VK_FORMAT_R8_UNORM;
11065 bvci.range = VK_WHOLE_SIZE;
11066
11067 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11068 ASSERT_VK_SUCCESS(err);
11069
11070 VkWriteDescriptorSet descriptor_write = {};
11071 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11072 descriptor_write.dstSet = descriptor_set;
11073 descriptor_write.dstBinding = 0;
11074 descriptor_write.descriptorCount = 1;
11075 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11076 descriptor_write.pTexelBufferView = &view;
11077
11078 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11079
11080 char const *vsSource = "#version 450\n"
11081 "\n"
11082 "out gl_PerVertex { \n"
11083 " vec4 gl_Position;\n"
11084 "};\n"
11085 "void main(){\n"
11086 " gl_Position = vec4(1);\n"
11087 "}\n";
11088 char const *fsSource = "#version 450\n"
11089 "\n"
11090 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11091 "layout(location=0) out vec4 x;\n"
11092 "void main(){\n"
11093 " x = imageLoad(s, 0);\n"
11094 "}\n";
11095 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11096 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11097 VkPipelineObj pipe(m_device);
11098 pipe.AddShader(&vs);
11099 pipe.AddShader(&fs);
11100 pipe.AddColorAttachment();
11101 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11102
11103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11104
11105 BeginCommandBuffer();
11106 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11107 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11108 VkRect2D scissor = {{0, 0}, {16, 16}};
11109 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11110 // Bind pipeline to cmd buffer
11111 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11112 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11113 &descriptor_set, 0, nullptr);
11114 Draw(1, 0, 0, 0);
11115 EndCommandBuffer();
11116
11117 VkSubmitInfo submit_info = {};
11118 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11119 submit_info.commandBufferCount = 1;
11120 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11121 // Submit cmd buffer and then destroy bufferView while in-flight
11122 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11123
11124 vkDestroyBufferView(m_device->device(), view, nullptr);
11125 m_errorMonitor->VerifyFound();
11126 vkQueueWaitIdle(m_device->m_queue);
11127 // Now we can actually destroy bufferView
11128 vkDestroyBufferView(m_device->device(), view, NULL);
11129 vkDestroyBuffer(m_device->device(), buffer, NULL);
11130 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11131 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11132 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11133 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11134}
11135
Tobin Ehlis209532e2016-09-07 13:52:18 -060011136TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11137 TEST_DESCRIPTION("Delete in-use sampler.");
11138
11139 ASSERT_NO_FATAL_FAILURE(InitState());
11140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11141
11142 VkDescriptorPoolSize ds_type_count;
11143 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11144 ds_type_count.descriptorCount = 1;
11145
11146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11148 ds_pool_ci.maxSets = 1;
11149 ds_pool_ci.poolSizeCount = 1;
11150 ds_pool_ci.pPoolSizes = &ds_type_count;
11151
11152 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011153 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011154 ASSERT_VK_SUCCESS(err);
11155
11156 VkSamplerCreateInfo sampler_ci = {};
11157 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11158 sampler_ci.pNext = NULL;
11159 sampler_ci.magFilter = VK_FILTER_NEAREST;
11160 sampler_ci.minFilter = VK_FILTER_NEAREST;
11161 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11162 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11163 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11164 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11165 sampler_ci.mipLodBias = 1.0;
11166 sampler_ci.anisotropyEnable = VK_FALSE;
11167 sampler_ci.maxAnisotropy = 1;
11168 sampler_ci.compareEnable = VK_FALSE;
11169 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11170 sampler_ci.minLod = 1.0;
11171 sampler_ci.maxLod = 1.0;
11172 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11173 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11174 VkSampler sampler;
11175
11176 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11177 ASSERT_VK_SUCCESS(err);
11178
11179 VkDescriptorSetLayoutBinding layout_binding;
11180 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011181 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011182 layout_binding.descriptorCount = 1;
11183 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11184 layout_binding.pImmutableSamplers = NULL;
11185
11186 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11187 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11188 ds_layout_ci.bindingCount = 1;
11189 ds_layout_ci.pBindings = &layout_binding;
11190 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011191 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011192 ASSERT_VK_SUCCESS(err);
11193
11194 VkDescriptorSetAllocateInfo alloc_info = {};
11195 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11196 alloc_info.descriptorSetCount = 1;
11197 alloc_info.descriptorPool = ds_pool;
11198 alloc_info.pSetLayouts = &ds_layout;
11199 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011200 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011201 ASSERT_VK_SUCCESS(err);
11202
11203 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11204 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11205 pipeline_layout_ci.pNext = NULL;
11206 pipeline_layout_ci.setLayoutCount = 1;
11207 pipeline_layout_ci.pSetLayouts = &ds_layout;
11208
11209 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011210 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011211 ASSERT_VK_SUCCESS(err);
11212
11213 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011214 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 -060011215 ASSERT_TRUE(image.initialized());
11216
11217 VkImageView view;
11218 VkImageViewCreateInfo ivci = {};
11219 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11220 ivci.image = image.handle();
11221 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11222 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11223 ivci.subresourceRange.layerCount = 1;
11224 ivci.subresourceRange.baseMipLevel = 0;
11225 ivci.subresourceRange.levelCount = 1;
11226 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11227
11228 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11229 ASSERT_VK_SUCCESS(err);
11230
11231 VkDescriptorImageInfo image_info{};
11232 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11233 image_info.imageView = view;
11234 image_info.sampler = sampler;
11235
11236 VkWriteDescriptorSet descriptor_write = {};
11237 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11238 descriptor_write.dstSet = descriptor_set;
11239 descriptor_write.dstBinding = 0;
11240 descriptor_write.descriptorCount = 1;
11241 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11242 descriptor_write.pImageInfo = &image_info;
11243
11244 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11245
11246 // Create PSO to use the sampler
11247 char const *vsSource = "#version 450\n"
11248 "\n"
11249 "out gl_PerVertex { \n"
11250 " vec4 gl_Position;\n"
11251 "};\n"
11252 "void main(){\n"
11253 " gl_Position = vec4(1);\n"
11254 "}\n";
11255 char const *fsSource = "#version 450\n"
11256 "\n"
11257 "layout(set=0, binding=0) uniform sampler2D s;\n"
11258 "layout(location=0) out vec4 x;\n"
11259 "void main(){\n"
11260 " x = texture(s, vec2(1));\n"
11261 "}\n";
11262 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11263 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11264 VkPipelineObj pipe(m_device);
11265 pipe.AddShader(&vs);
11266 pipe.AddShader(&fs);
11267 pipe.AddColorAttachment();
11268 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011271
11272 BeginCommandBuffer();
11273 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011274 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11275 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11276 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011277 Draw(1, 0, 0, 0);
11278 EndCommandBuffer();
11279 // Submit cmd buffer then destroy sampler
11280 VkSubmitInfo submit_info = {};
11281 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11282 submit_info.commandBufferCount = 1;
11283 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11284 // Submit cmd buffer and then destroy sampler while in-flight
11285 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11286
11287 vkDestroySampler(m_device->device(), sampler, nullptr);
11288 m_errorMonitor->VerifyFound();
11289 vkQueueWaitIdle(m_device->m_queue);
11290 // Now we can actually destroy sampler
11291 vkDestroySampler(m_device->device(), sampler, nullptr);
11292 vkDestroyImageView(m_device->device(), view, NULL);
11293 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11294 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11295 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11296}
11297
Mark Mueller1cd9f412016-08-25 13:23:52 -060011298TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011299 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011300 "signaled but not waited on by the queue. Wait on a "
11301 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011302
11303 ASSERT_NO_FATAL_FAILURE(InitState());
11304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011306 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11307 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11308 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011309
11310 BeginCommandBuffer();
11311 EndCommandBuffer();
11312
11313 VkSemaphoreCreateInfo semaphore_create_info = {};
11314 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11315 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011316 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011317 VkSubmitInfo submit_info = {};
11318 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11319 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011320 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011321 submit_info.signalSemaphoreCount = 1;
11322 submit_info.pSignalSemaphores = &semaphore;
11323 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11324 m_errorMonitor->SetDesiredFailureMsg(0, "");
11325 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11326 BeginCommandBuffer();
11327 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011329 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11330 m_errorMonitor->VerifyFound();
11331
Mark Mueller1cd9f412016-08-25 13:23:52 -060011332 VkFenceCreateInfo fence_create_info = {};
11333 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11334 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011335 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011338 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11339 m_errorMonitor->VerifyFound();
11340
Mark Mueller4042b652016-09-05 22:52:21 -060011341 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011342 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011343 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11344}
11345
Tobin Ehlis4af23302016-07-19 10:50:30 -060011346TEST_F(VkLayerTest, FramebufferIncompatible) {
11347 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11348 "that does not match the framebuffer for the active "
11349 "renderpass.");
11350 ASSERT_NO_FATAL_FAILURE(InitState());
11351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11352
11353 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011354 VkAttachmentDescription attachment = {0,
11355 VK_FORMAT_B8G8R8A8_UNORM,
11356 VK_SAMPLE_COUNT_1_BIT,
11357 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11358 VK_ATTACHMENT_STORE_OP_STORE,
11359 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11360 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11361 VK_IMAGE_LAYOUT_UNDEFINED,
11362 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011364 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011366 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011368 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011369
11370 VkRenderPass rp;
11371 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11372 ASSERT_VK_SUCCESS(err);
11373
11374 // A compatible framebuffer.
11375 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011376 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 -060011377 ASSERT_TRUE(image.initialized());
11378
11379 VkImageViewCreateInfo ivci = {
11380 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11381 nullptr,
11382 0,
11383 image.handle(),
11384 VK_IMAGE_VIEW_TYPE_2D,
11385 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011386 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11387 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011388 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11389 };
11390 VkImageView view;
11391 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11392 ASSERT_VK_SUCCESS(err);
11393
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011394 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011395 VkFramebuffer fb;
11396 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11397 ASSERT_VK_SUCCESS(err);
11398
11399 VkCommandBufferAllocateInfo cbai = {};
11400 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11401 cbai.commandPool = m_commandPool;
11402 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11403 cbai.commandBufferCount = 1;
11404
11405 VkCommandBuffer sec_cb;
11406 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11407 ASSERT_VK_SUCCESS(err);
11408 VkCommandBufferBeginInfo cbbi = {};
11409 VkCommandBufferInheritanceInfo cbii = {};
11410 cbii.renderPass = renderPass();
11411 cbii.framebuffer = fb;
11412 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11413 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011414 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 -060011415 cbbi.pInheritanceInfo = &cbii;
11416 vkBeginCommandBuffer(sec_cb, &cbbi);
11417 vkEndCommandBuffer(sec_cb);
11418
Chris Forbes3400bc52016-09-13 18:10:34 +120011419 VkCommandBufferBeginInfo cbbi2 = {
11420 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11421 0, nullptr
11422 };
11423 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11424 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011427 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011428 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11429 m_errorMonitor->VerifyFound();
11430 // Cleanup
11431 vkDestroyImageView(m_device->device(), view, NULL);
11432 vkDestroyRenderPass(m_device->device(), rp, NULL);
11433 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11434}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011435
11436TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11437 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11438 "invalid value. If logicOp is not available, attempt to "
11439 "use it and verify that we see the correct error.");
11440 ASSERT_NO_FATAL_FAILURE(InitState());
11441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11442
11443 auto features = m_device->phy().features();
11444 // Set the expected error depending on whether or not logicOp available
11445 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11447 "enabled, logicOpEnable must be "
11448 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011449 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011451 }
11452 // Create a pipeline using logicOp
11453 VkResult err;
11454
11455 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11456 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11457
11458 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011459 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011460 ASSERT_VK_SUCCESS(err);
11461
11462 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11463 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11464 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011465 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011466 vp_state_ci.pViewports = &vp;
11467 vp_state_ci.scissorCount = 1;
11468 VkRect2D scissors = {}; // Dummy scissors to point to
11469 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011470
11471 VkPipelineShaderStageCreateInfo shaderStages[2];
11472 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011474 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11475 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011476 shaderStages[0] = vs.GetStageCreateInfo();
11477 shaderStages[1] = fs.GetStageCreateInfo();
11478
11479 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11480 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11481
11482 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11483 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11484 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11485
11486 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11487 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011488 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011489
11490 VkPipelineColorBlendAttachmentState att = {};
11491 att.blendEnable = VK_FALSE;
11492 att.colorWriteMask = 0xf;
11493
11494 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11495 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11496 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11497 cb_ci.logicOpEnable = VK_TRUE;
11498 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11499 cb_ci.attachmentCount = 1;
11500 cb_ci.pAttachments = &att;
11501
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011502 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11503 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11504 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11505
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011506 VkGraphicsPipelineCreateInfo gp_ci = {};
11507 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11508 gp_ci.stageCount = 2;
11509 gp_ci.pStages = shaderStages;
11510 gp_ci.pVertexInputState = &vi_ci;
11511 gp_ci.pInputAssemblyState = &ia_ci;
11512 gp_ci.pViewportState = &vp_state_ci;
11513 gp_ci.pRasterizationState = &rs_ci;
11514 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011515 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011516 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11517 gp_ci.layout = pipeline_layout;
11518 gp_ci.renderPass = renderPass();
11519
11520 VkPipelineCacheCreateInfo pc_ci = {};
11521 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11522
11523 VkPipeline pipeline;
11524 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011525 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011526 ASSERT_VK_SUCCESS(err);
11527
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011528 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011529 m_errorMonitor->VerifyFound();
11530 if (VK_SUCCESS == err) {
11531 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11532 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011533 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11534 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11535}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011536#endif // DRAW_STATE_TESTS
11537
Tobin Ehlis0788f522015-05-26 16:11:58 -060011538#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011539#if GTEST_IS_THREADSAFE
11540struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011541 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011542 VkEvent event;
11543 bool bailout;
11544};
11545
Karl Schultz6addd812016-02-02 17:17:23 -070011546extern "C" void *AddToCommandBuffer(void *arg) {
11547 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011548
Mike Stroyana6d14942016-07-13 15:10:05 -060011549 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011550 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011551 if (data->bailout) {
11552 break;
11553 }
11554 }
11555 return NULL;
11556}
11557
Karl Schultz6addd812016-02-02 17:17:23 -070011558TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011559 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011560
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011562
Mike Stroyanaccf7692015-05-12 16:00:45 -060011563 ASSERT_NO_FATAL_FAILURE(InitState());
11564 ASSERT_NO_FATAL_FAILURE(InitViewport());
11565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11566
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011567 // Calls AllocateCommandBuffers
11568 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011569
11570 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011571 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011572
11573 VkEventCreateInfo event_info;
11574 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011575 VkResult err;
11576
11577 memset(&event_info, 0, sizeof(event_info));
11578 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11579
Chia-I Wuf7458c52015-10-26 21:10:41 +080011580 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011581 ASSERT_VK_SUCCESS(err);
11582
Mike Stroyanaccf7692015-05-12 16:00:45 -060011583 err = vkResetEvent(device(), event);
11584 ASSERT_VK_SUCCESS(err);
11585
11586 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011587 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011588 data.event = event;
11589 data.bailout = false;
11590 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011591
11592 // First do some correct operations using multiple threads.
11593 // Add many entries to command buffer from another thread.
11594 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11595 // Make non-conflicting calls from this thread at the same time.
11596 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011597 uint32_t count;
11598 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011599 }
11600 test_platform_thread_join(thread, NULL);
11601
11602 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011603 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011604 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011605 // Add many entries to command buffer from this thread at the same time.
11606 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011607
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011608 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011609 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011610
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011611 m_errorMonitor->SetBailout(NULL);
11612
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011613 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011614
Chia-I Wuf7458c52015-10-26 21:10:41 +080011615 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011616}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011617#endif // GTEST_IS_THREADSAFE
11618#endif // THREADING_TESTS
11619
Chris Forbes9f7ff632015-05-25 11:13:08 +120011620#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011621TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011622 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11623 "with an impossible code size");
11624
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011626
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011627 ASSERT_NO_FATAL_FAILURE(InitState());
11628 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11629
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011630 VkShaderModule module;
11631 VkShaderModuleCreateInfo moduleCreateInfo;
11632 struct icd_spv_header spv;
11633
11634 spv.magic = ICD_SPV_MAGIC;
11635 spv.version = ICD_SPV_VERSION;
11636 spv.gen_magic = 0;
11637
11638 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11639 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011640 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011641 moduleCreateInfo.codeSize = 4;
11642 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011643 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011644
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011645 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011646}
11647
Karl Schultz6addd812016-02-02 17:17:23 -070011648TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011649 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11650 "with a bad magic number");
11651
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011653
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011654 ASSERT_NO_FATAL_FAILURE(InitState());
11655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11656
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011657 VkShaderModule module;
11658 VkShaderModuleCreateInfo moduleCreateInfo;
11659 struct icd_spv_header spv;
11660
11661 spv.magic = ~ICD_SPV_MAGIC;
11662 spv.version = ICD_SPV_VERSION;
11663 spv.gen_magic = 0;
11664
11665 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11666 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011667 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011668 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11669 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011670 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011671
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011672 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011673}
11674
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011675#if 0
11676// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011677TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011679 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011680
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011681 ASSERT_NO_FATAL_FAILURE(InitState());
11682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11683
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011684 VkShaderModule module;
11685 VkShaderModuleCreateInfo moduleCreateInfo;
11686 struct icd_spv_header spv;
11687
11688 spv.magic = ICD_SPV_MAGIC;
11689 spv.version = ~ICD_SPV_VERSION;
11690 spv.gen_magic = 0;
11691
11692 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11693 moduleCreateInfo.pNext = NULL;
11694
Karl Schultz6addd812016-02-02 17:17:23 -070011695 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011696 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11697 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011698 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011699
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011700 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011701}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011702#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011703
Karl Schultz6addd812016-02-02 17:17:23 -070011704TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011705 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11706 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011708
Chris Forbes9f7ff632015-05-25 11:13:08 +120011709 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011711
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011712 char const *vsSource = "#version 450\n"
11713 "\n"
11714 "layout(location=0) out float x;\n"
11715 "out gl_PerVertex {\n"
11716 " vec4 gl_Position;\n"
11717 "};\n"
11718 "void main(){\n"
11719 " gl_Position = vec4(1);\n"
11720 " x = 0;\n"
11721 "}\n";
11722 char const *fsSource = "#version 450\n"
11723 "\n"
11724 "layout(location=0) out vec4 color;\n"
11725 "void main(){\n"
11726 " color = vec4(1);\n"
11727 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011728
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011729 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11730 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011731
11732 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011733 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011734 pipe.AddShader(&vs);
11735 pipe.AddShader(&fs);
11736
Chris Forbes9f7ff632015-05-25 11:13:08 +120011737 VkDescriptorSetObj descriptorSet(m_device);
11738 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011739 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011740
Tony Barbour5781e8f2015-08-04 16:23:11 -060011741 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011742
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011743 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011744}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011745
Mark Mueller098c9cb2016-09-08 09:01:57 -060011746TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11747 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11748
11749 ASSERT_NO_FATAL_FAILURE(InitState());
11750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11751
11752 const char *bad_specialization_message =
11753 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11754
11755 char const *vsSource =
11756 "#version 450\n"
11757 "\n"
11758 "out gl_PerVertex {\n"
11759 " vec4 gl_Position;\n"
11760 "};\n"
11761 "void main(){\n"
11762 " gl_Position = vec4(1);\n"
11763 "}\n";
11764
11765 char const *fsSource =
11766 "#version 450\n"
11767 "\n"
11768 "layout (constant_id = 0) const float r = 0.0f;\n"
11769 "layout(location = 0) out vec4 uFragColor;\n"
11770 "void main(){\n"
11771 " uFragColor = vec4(r,1,0,1);\n"
11772 "}\n";
11773
11774 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11775 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11776
11777 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11778 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11779
11780 VkPipelineLayout pipeline_layout;
11781 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11782
11783 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11784 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11785 vp_state_create_info.viewportCount = 1;
11786 VkViewport viewport = {};
11787 vp_state_create_info.pViewports = &viewport;
11788 vp_state_create_info.scissorCount = 1;
11789 VkRect2D scissors = {};
11790 vp_state_create_info.pScissors = &scissors;
11791
11792 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11793
11794 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11795 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11796 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11797 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11798
11799 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11800 vs.GetStageCreateInfo(),
11801 fs.GetStageCreateInfo()
11802 };
11803
11804 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11805 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11806
11807 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11808 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11809 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11810
11811 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11812 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11813 rasterization_state_create_info.pNext = nullptr;
11814 rasterization_state_create_info.lineWidth = 1.0f;
11815 rasterization_state_create_info.rasterizerDiscardEnable = true;
11816
11817 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11818 color_blend_attachment_state.blendEnable = VK_FALSE;
11819 color_blend_attachment_state.colorWriteMask = 0xf;
11820
11821 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11822 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11823 color_blend_state_create_info.attachmentCount = 1;
11824 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11825
11826 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11827 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11828 graphicspipe_create_info.stageCount = 2;
11829 graphicspipe_create_info.pStages = shader_stage_create_info;
11830 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11831 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11832 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11833 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11834 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11835 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11836 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11837 graphicspipe_create_info.layout = pipeline_layout;
11838 graphicspipe_create_info.renderPass = renderPass();
11839
11840 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11841 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11842
11843 VkPipelineCache pipelineCache;
11844 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11845
11846 // This structure maps constant ids to data locations.
11847 const VkSpecializationMapEntry entry =
11848 // id, offset, size
11849 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11850
11851 uint32_t data = 1;
11852
11853 // Set up the info describing spec map and data
11854 const VkSpecializationInfo specialization_info = {
11855 1,
11856 &entry,
11857 1 * sizeof(float),
11858 &data,
11859 };
11860 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11861
11862 VkPipeline pipeline;
11863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11864 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11865 m_errorMonitor->VerifyFound();
11866
11867 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11868 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11869}
11870
11871TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11872 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11873
11874 ASSERT_NO_FATAL_FAILURE(InitState());
11875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11876
11877 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11878
11879 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11880 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11881 descriptor_pool_type_count[0].descriptorCount = 1;
11882 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11883 descriptor_pool_type_count[1].descriptorCount = 1;
11884
11885 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11886 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11887 descriptor_pool_create_info.maxSets = 1;
11888 descriptor_pool_create_info.poolSizeCount = 2;
11889 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11890 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11891
11892 VkDescriptorPool descriptorset_pool;
11893 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11894
11895 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11896 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11897 descriptorset_layout_binding.descriptorCount = 1;
11898 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11899
11900 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11901 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11902 descriptorset_layout_create_info.bindingCount = 1;
11903 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11904
11905 VkDescriptorSetLayout descriptorset_layout;
11906 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11907
11908 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11909 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11910 descriptorset_allocate_info.descriptorSetCount = 1;
11911 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11912 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11913 VkDescriptorSet descriptorset;
11914 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11915
11916 // Challenge core_validation with a non uniform buffer type.
11917 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11918
Mark Mueller098c9cb2016-09-08 09:01:57 -060011919 char const *vsSource =
11920 "#version 450\n"
11921 "\n"
11922 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11923 " mat4 mvp;\n"
11924 "} ubuf;\n"
11925 "out gl_PerVertex {\n"
11926 " vec4 gl_Position;\n"
11927 "};\n"
11928 "void main(){\n"
11929 " gl_Position = ubuf.mvp * vec4(1);\n"
11930 "}\n";
11931
11932 char const *fsSource =
11933 "#version 450\n"
11934 "\n"
11935 "layout(location = 0) out vec4 uFragColor;\n"
11936 "void main(){\n"
11937 " uFragColor = vec4(0,1,0,1);\n"
11938 "}\n";
11939
11940 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11941 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11942
11943 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11944 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11945 pipeline_layout_create_info.setLayoutCount = 1;
11946 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11947
11948 VkPipelineLayout pipeline_layout;
11949 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11950
11951 VkPipelineObj pipe(m_device);
11952 pipe.AddColorAttachment();
11953 pipe.AddShader(&vs);
11954 pipe.AddShader(&fs);
11955
11956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11957 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11958 m_errorMonitor->VerifyFound();
11959
11960 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11961 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11962 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11963}
11964
11965TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11966 TEST_DESCRIPTION(
11967 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11968
11969 ASSERT_NO_FATAL_FAILURE(InitState());
11970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11971
11972 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11973
11974 VkDescriptorPoolSize descriptor_pool_type_count = {};
11975 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11976 descriptor_pool_type_count.descriptorCount = 1;
11977
11978 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11979 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11980 descriptor_pool_create_info.maxSets = 1;
11981 descriptor_pool_create_info.poolSizeCount = 1;
11982 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11983 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11984
11985 VkDescriptorPool descriptorset_pool;
11986 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11987
11988 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11989 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11990 descriptorset_layout_binding.descriptorCount = 1;
11991 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11992 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11993
11994 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11995 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11996 descriptorset_layout_create_info.bindingCount = 1;
11997 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11998
11999 VkDescriptorSetLayout descriptorset_layout;
12000 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12001 nullptr, &descriptorset_layout));
12002
12003 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12004 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12005 descriptorset_allocate_info.descriptorSetCount = 1;
12006 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12007 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12008 VkDescriptorSet descriptorset;
12009 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12010
12011 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12012
Mark Mueller098c9cb2016-09-08 09:01:57 -060012013 char const *vsSource =
12014 "#version 450\n"
12015 "\n"
12016 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12017 " mat4 mvp;\n"
12018 "} ubuf;\n"
12019 "out gl_PerVertex {\n"
12020 " vec4 gl_Position;\n"
12021 "};\n"
12022 "void main(){\n"
12023 " gl_Position = ubuf.mvp * vec4(1);\n"
12024 "}\n";
12025
12026 char const *fsSource =
12027 "#version 450\n"
12028 "\n"
12029 "layout(location = 0) out vec4 uFragColor;\n"
12030 "void main(){\n"
12031 " uFragColor = vec4(0,1,0,1);\n"
12032 "}\n";
12033
12034 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12035 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12036
12037 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12038 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12039 pipeline_layout_create_info.setLayoutCount = 1;
12040 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12041
12042 VkPipelineLayout pipeline_layout;
12043 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12044
12045 VkPipelineObj pipe(m_device);
12046 pipe.AddColorAttachment();
12047 pipe.AddShader(&vs);
12048 pipe.AddShader(&fs);
12049
12050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12051 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12052 m_errorMonitor->VerifyFound();
12053
12054 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12055 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12056 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12057}
12058
12059TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12060 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12061 "accessible from the current shader stage.");
12062
12063 ASSERT_NO_FATAL_FAILURE(InitState());
12064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12065
12066 const char *push_constant_not_accessible_message =
12067 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12068
12069 char const *vsSource =
12070 "#version 450\n"
12071 "\n"
12072 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12073 "out gl_PerVertex {\n"
12074 " vec4 gl_Position;\n"
12075 "};\n"
12076 "void main(){\n"
12077 " gl_Position = vec4(consts.x);\n"
12078 "}\n";
12079
12080 char const *fsSource =
12081 "#version 450\n"
12082 "\n"
12083 "layout(location = 0) out vec4 uFragColor;\n"
12084 "void main(){\n"
12085 " uFragColor = vec4(0,1,0,1);\n"
12086 "}\n";
12087
12088 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12089 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12090
12091 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12092 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12093
12094 // Set up a push constant range
12095 VkPushConstantRange push_constant_ranges = {};
12096 // Set to the wrong stage to challenge core_validation
12097 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12098 push_constant_ranges.size = 4;
12099
12100 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12101 pipeline_layout_create_info.pushConstantRangeCount = 1;
12102
12103 VkPipelineLayout pipeline_layout;
12104 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12105
12106 VkPipelineObj pipe(m_device);
12107 pipe.AddColorAttachment();
12108 pipe.AddShader(&vs);
12109 pipe.AddShader(&fs);
12110
12111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12112 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12113 m_errorMonitor->VerifyFound();
12114
12115 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12116}
12117
12118TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12119 TEST_DESCRIPTION(
12120 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12121
12122 ASSERT_NO_FATAL_FAILURE(InitState());
12123 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12124
12125 const char *feature_not_enabled_message =
12126 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12127
12128 // Some awkward steps are required to test with custom device features.
12129 std::vector<const char *> device_extension_names;
12130 auto features = m_device->phy().features();
12131 // Disable support for 64 bit floats
12132 features.shaderFloat64 = false;
12133 // The sacrificial device object
12134 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12135
12136 char const *vsSource = "#version 450\n"
12137 "\n"
12138 "out gl_PerVertex {\n"
12139 " vec4 gl_Position;\n"
12140 "};\n"
12141 "void main(){\n"
12142 " gl_Position = vec4(1);\n"
12143 "}\n";
12144 char const *fsSource = "#version 450\n"
12145 "\n"
12146 "layout(location=0) out vec4 color;\n"
12147 "void main(){\n"
12148 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12149 " color = vec4(green);\n"
12150 "}\n";
12151
12152 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12153 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12154
12155 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012156
12157 VkPipelineObj pipe(&test_device);
12158 pipe.AddColorAttachment();
12159 pipe.AddShader(&vs);
12160 pipe.AddShader(&fs);
12161
12162 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12163 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12164 VkPipelineLayout pipeline_layout;
12165 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12166
12167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12168 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12169 m_errorMonitor->VerifyFound();
12170
12171 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12172}
12173
12174TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12175 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12176
12177 ASSERT_NO_FATAL_FAILURE(InitState());
12178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12179
12180 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12181
12182 char const *vsSource = "#version 450\n"
12183 "\n"
12184 "out gl_PerVertex {\n"
12185 " vec4 gl_Position;\n"
12186 "};\n"
12187 "layout(xfb_buffer = 1) out;"
12188 "void main(){\n"
12189 " gl_Position = vec4(1);\n"
12190 "}\n";
12191 char const *fsSource = "#version 450\n"
12192 "\n"
12193 "layout(location=0) out vec4 color;\n"
12194 "void main(){\n"
12195 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12196 " color = vec4(green);\n"
12197 "}\n";
12198
12199 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12200 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12201
12202 VkPipelineObj pipe(m_device);
12203 pipe.AddColorAttachment();
12204 pipe.AddShader(&vs);
12205 pipe.AddShader(&fs);
12206
12207 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12208 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12209 VkPipelineLayout pipeline_layout;
12210 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12211
12212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12213 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12214 m_errorMonitor->VerifyFound();
12215
12216 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12217}
12218
Karl Schultz6addd812016-02-02 17:17:23 -070012219TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012220 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12221 "which is not present in the outputs of the previous stage");
12222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012224
Chris Forbes59cb88d2015-05-25 11:13:13 +120012225 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012227
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012228 char const *vsSource = "#version 450\n"
12229 "\n"
12230 "out gl_PerVertex {\n"
12231 " vec4 gl_Position;\n"
12232 "};\n"
12233 "void main(){\n"
12234 " gl_Position = vec4(1);\n"
12235 "}\n";
12236 char const *fsSource = "#version 450\n"
12237 "\n"
12238 "layout(location=0) in float x;\n"
12239 "layout(location=0) out vec4 color;\n"
12240 "void main(){\n"
12241 " color = vec4(x);\n"
12242 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012243
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012244 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12245 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012246
12247 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012248 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012249 pipe.AddShader(&vs);
12250 pipe.AddShader(&fs);
12251
Chris Forbes59cb88d2015-05-25 11:13:13 +120012252 VkDescriptorSetObj descriptorSet(m_device);
12253 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012254 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012255
Tony Barbour5781e8f2015-08-04 16:23:11 -060012256 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012257
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012258 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012259}
12260
Karl Schultz6addd812016-02-02 17:17:23 -070012261TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012262 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12263 "within an interace block, which is not present in the outputs "
12264 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012266
12267 ASSERT_NO_FATAL_FAILURE(InitState());
12268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012270 char const *vsSource = "#version 450\n"
12271 "\n"
12272 "out gl_PerVertex {\n"
12273 " vec4 gl_Position;\n"
12274 "};\n"
12275 "void main(){\n"
12276 " gl_Position = vec4(1);\n"
12277 "}\n";
12278 char const *fsSource = "#version 450\n"
12279 "\n"
12280 "in block { layout(location=0) float x; } ins;\n"
12281 "layout(location=0) out vec4 color;\n"
12282 "void main(){\n"
12283 " color = vec4(ins.x);\n"
12284 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012285
12286 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12287 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12288
12289 VkPipelineObj pipe(m_device);
12290 pipe.AddColorAttachment();
12291 pipe.AddShader(&vs);
12292 pipe.AddShader(&fs);
12293
12294 VkDescriptorSetObj descriptorSet(m_device);
12295 descriptorSet.AppendDummy();
12296 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12297
12298 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12299
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012300 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012301}
12302
Karl Schultz6addd812016-02-02 17:17:23 -070012303TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012304 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012305 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12307 "output arr[2] of float32' vs 'ptr to "
12308 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012309
12310 ASSERT_NO_FATAL_FAILURE(InitState());
12311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012313 char const *vsSource = "#version 450\n"
12314 "\n"
12315 "layout(location=0) out float x[2];\n"
12316 "out gl_PerVertex {\n"
12317 " vec4 gl_Position;\n"
12318 "};\n"
12319 "void main(){\n"
12320 " x[0] = 0; x[1] = 0;\n"
12321 " gl_Position = vec4(1);\n"
12322 "}\n";
12323 char const *fsSource = "#version 450\n"
12324 "\n"
12325 "layout(location=0) in float x[3];\n"
12326 "layout(location=0) out vec4 color;\n"
12327 "void main(){\n"
12328 " color = vec4(x[0] + x[1] + x[2]);\n"
12329 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012330
12331 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12332 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12333
12334 VkPipelineObj pipe(m_device);
12335 pipe.AddColorAttachment();
12336 pipe.AddShader(&vs);
12337 pipe.AddShader(&fs);
12338
12339 VkDescriptorSetObj descriptorSet(m_device);
12340 descriptorSet.AppendDummy();
12341 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12342
12343 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12344
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012345 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012346}
12347
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012348
Karl Schultz6addd812016-02-02 17:17:23 -070012349TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012350 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012351 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012353
Chris Forbesb56af562015-05-25 11:13:17 +120012354 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012357 char const *vsSource = "#version 450\n"
12358 "\n"
12359 "layout(location=0) out int x;\n"
12360 "out gl_PerVertex {\n"
12361 " vec4 gl_Position;\n"
12362 "};\n"
12363 "void main(){\n"
12364 " x = 0;\n"
12365 " gl_Position = vec4(1);\n"
12366 "}\n";
12367 char const *fsSource = "#version 450\n"
12368 "\n"
12369 "layout(location=0) in float x;\n" /* VS writes int */
12370 "layout(location=0) out vec4 color;\n"
12371 "void main(){\n"
12372 " color = vec4(x);\n"
12373 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012374
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012375 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12376 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012377
12378 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012379 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012380 pipe.AddShader(&vs);
12381 pipe.AddShader(&fs);
12382
Chris Forbesb56af562015-05-25 11:13:17 +120012383 VkDescriptorSetObj descriptorSet(m_device);
12384 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012385 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012386
Tony Barbour5781e8f2015-08-04 16:23:11 -060012387 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012388
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012389 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012390}
12391
Karl Schultz6addd812016-02-02 17:17:23 -070012392TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012393 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012394 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012395 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012397
12398 ASSERT_NO_FATAL_FAILURE(InitState());
12399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12400
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012401 char const *vsSource = "#version 450\n"
12402 "\n"
12403 "out block { layout(location=0) int x; } outs;\n"
12404 "out gl_PerVertex {\n"
12405 " vec4 gl_Position;\n"
12406 "};\n"
12407 "void main(){\n"
12408 " outs.x = 0;\n"
12409 " gl_Position = vec4(1);\n"
12410 "}\n";
12411 char const *fsSource = "#version 450\n"
12412 "\n"
12413 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12414 "layout(location=0) out vec4 color;\n"
12415 "void main(){\n"
12416 " color = vec4(ins.x);\n"
12417 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012418
12419 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12420 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12421
12422 VkPipelineObj pipe(m_device);
12423 pipe.AddColorAttachment();
12424 pipe.AddShader(&vs);
12425 pipe.AddShader(&fs);
12426
12427 VkDescriptorSetObj descriptorSet(m_device);
12428 descriptorSet.AppendDummy();
12429 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12430
12431 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12432
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012433 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012434}
12435
12436TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012437 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012438 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012439 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012440 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 +130012441
12442 ASSERT_NO_FATAL_FAILURE(InitState());
12443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012445 char const *vsSource = "#version 450\n"
12446 "\n"
12447 "out block { layout(location=1) float x; } outs;\n"
12448 "out gl_PerVertex {\n"
12449 " vec4 gl_Position;\n"
12450 "};\n"
12451 "void main(){\n"
12452 " outs.x = 0;\n"
12453 " gl_Position = vec4(1);\n"
12454 "}\n";
12455 char const *fsSource = "#version 450\n"
12456 "\n"
12457 "in block { layout(location=0) float x; } ins;\n"
12458 "layout(location=0) out vec4 color;\n"
12459 "void main(){\n"
12460 " color = vec4(ins.x);\n"
12461 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012462
12463 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12464 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12465
12466 VkPipelineObj pipe(m_device);
12467 pipe.AddColorAttachment();
12468 pipe.AddShader(&vs);
12469 pipe.AddShader(&fs);
12470
12471 VkDescriptorSetObj descriptorSet(m_device);
12472 descriptorSet.AppendDummy();
12473 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12474
12475 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12476
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012477 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012478}
12479
12480TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012481 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012482 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012483 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012484 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 +130012485
12486 ASSERT_NO_FATAL_FAILURE(InitState());
12487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012489 char const *vsSource = "#version 450\n"
12490 "\n"
12491 "out block { layout(location=0, component=0) float x; } outs;\n"
12492 "out gl_PerVertex {\n"
12493 " vec4 gl_Position;\n"
12494 "};\n"
12495 "void main(){\n"
12496 " outs.x = 0;\n"
12497 " gl_Position = vec4(1);\n"
12498 "}\n";
12499 char const *fsSource = "#version 450\n"
12500 "\n"
12501 "in block { layout(location=0, component=1) float x; } ins;\n"
12502 "layout(location=0) out vec4 color;\n"
12503 "void main(){\n"
12504 " color = vec4(ins.x);\n"
12505 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012506
12507 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12508 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12509
12510 VkPipelineObj pipe(m_device);
12511 pipe.AddColorAttachment();
12512 pipe.AddShader(&vs);
12513 pipe.AddShader(&fs);
12514
12515 VkDescriptorSetObj descriptorSet(m_device);
12516 descriptorSet.AppendDummy();
12517 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12518
12519 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12520
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012521 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012522}
12523
Karl Schultz6addd812016-02-02 17:17:23 -070012524TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012525 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12526 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012528
Chris Forbesde136e02015-05-25 11:13:28 +120012529 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012531
12532 VkVertexInputBindingDescription input_binding;
12533 memset(&input_binding, 0, sizeof(input_binding));
12534
12535 VkVertexInputAttributeDescription input_attrib;
12536 memset(&input_attrib, 0, sizeof(input_attrib));
12537 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12538
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012539 char const *vsSource = "#version 450\n"
12540 "\n"
12541 "out gl_PerVertex {\n"
12542 " vec4 gl_Position;\n"
12543 "};\n"
12544 "void main(){\n"
12545 " gl_Position = vec4(1);\n"
12546 "}\n";
12547 char const *fsSource = "#version 450\n"
12548 "\n"
12549 "layout(location=0) out vec4 color;\n"
12550 "void main(){\n"
12551 " color = vec4(1);\n"
12552 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012553
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012554 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12555 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012556
12557 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012558 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012559 pipe.AddShader(&vs);
12560 pipe.AddShader(&fs);
12561
12562 pipe.AddVertexInputBindings(&input_binding, 1);
12563 pipe.AddVertexInputAttribs(&input_attrib, 1);
12564
Chris Forbesde136e02015-05-25 11:13:28 +120012565 VkDescriptorSetObj descriptorSet(m_device);
12566 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012567 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012568
Tony Barbour5781e8f2015-08-04 16:23:11 -060012569 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012570
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012571 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012572}
12573
Karl Schultz6addd812016-02-02 17:17:23 -070012574TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012575 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12576 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012578
12579 ASSERT_NO_FATAL_FAILURE(InitState());
12580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12581
12582 VkVertexInputBindingDescription input_binding;
12583 memset(&input_binding, 0, sizeof(input_binding));
12584
12585 VkVertexInputAttributeDescription input_attrib;
12586 memset(&input_attrib, 0, sizeof(input_attrib));
12587 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012589 char const *vsSource = "#version 450\n"
12590 "\n"
12591 "layout(location=1) in float x;\n"
12592 "out gl_PerVertex {\n"
12593 " vec4 gl_Position;\n"
12594 "};\n"
12595 "void main(){\n"
12596 " gl_Position = vec4(x);\n"
12597 "}\n";
12598 char const *fsSource = "#version 450\n"
12599 "\n"
12600 "layout(location=0) out vec4 color;\n"
12601 "void main(){\n"
12602 " color = vec4(1);\n"
12603 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012604
12605 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12606 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12607
12608 VkPipelineObj pipe(m_device);
12609 pipe.AddColorAttachment();
12610 pipe.AddShader(&vs);
12611 pipe.AddShader(&fs);
12612
12613 pipe.AddVertexInputBindings(&input_binding, 1);
12614 pipe.AddVertexInputAttribs(&input_attrib, 1);
12615
12616 VkDescriptorSetObj descriptorSet(m_device);
12617 descriptorSet.AppendDummy();
12618 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12619
12620 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12621
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012622 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012623}
12624
Karl Schultz6addd812016-02-02 17:17:23 -070012625TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012626 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012627 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012628 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 -060012629
Chris Forbes62e8e502015-05-25 11:13:29 +120012630 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012631 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012632
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012633 char const *vsSource = "#version 450\n"
12634 "\n"
12635 "layout(location=0) in vec4 x;\n" /* not provided */
12636 "out gl_PerVertex {\n"
12637 " vec4 gl_Position;\n"
12638 "};\n"
12639 "void main(){\n"
12640 " gl_Position = x;\n"
12641 "}\n";
12642 char const *fsSource = "#version 450\n"
12643 "\n"
12644 "layout(location=0) out vec4 color;\n"
12645 "void main(){\n"
12646 " color = vec4(1);\n"
12647 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012648
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012649 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12650 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012651
12652 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012653 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012654 pipe.AddShader(&vs);
12655 pipe.AddShader(&fs);
12656
Chris Forbes62e8e502015-05-25 11:13:29 +120012657 VkDescriptorSetObj descriptorSet(m_device);
12658 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012659 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012660
Tony Barbour5781e8f2015-08-04 16:23:11 -060012661 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012662
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012663 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012664}
12665
Karl Schultz6addd812016-02-02 17:17:23 -070012666TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012667 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12668 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012669 "vertex shader input that consumes it");
12670 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 -060012671
Chris Forbesc97d98e2015-05-25 11:13:31 +120012672 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012674
12675 VkVertexInputBindingDescription input_binding;
12676 memset(&input_binding, 0, sizeof(input_binding));
12677
12678 VkVertexInputAttributeDescription input_attrib;
12679 memset(&input_attrib, 0, sizeof(input_attrib));
12680 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12681
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012682 char const *vsSource = "#version 450\n"
12683 "\n"
12684 "layout(location=0) in int x;\n" /* attrib provided float */
12685 "out gl_PerVertex {\n"
12686 " vec4 gl_Position;\n"
12687 "};\n"
12688 "void main(){\n"
12689 " gl_Position = vec4(x);\n"
12690 "}\n";
12691 char const *fsSource = "#version 450\n"
12692 "\n"
12693 "layout(location=0) out vec4 color;\n"
12694 "void main(){\n"
12695 " color = vec4(1);\n"
12696 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012697
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012698 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12699 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012700
12701 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012702 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012703 pipe.AddShader(&vs);
12704 pipe.AddShader(&fs);
12705
12706 pipe.AddVertexInputBindings(&input_binding, 1);
12707 pipe.AddVertexInputAttribs(&input_attrib, 1);
12708
Chris Forbesc97d98e2015-05-25 11:13:31 +120012709 VkDescriptorSetObj descriptorSet(m_device);
12710 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012711 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012712
Tony Barbour5781e8f2015-08-04 16:23:11 -060012713 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012714
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012715 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012716}
12717
Chris Forbesc68b43c2016-04-06 11:18:47 +120012718TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012719 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12720 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12722 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012723
12724 ASSERT_NO_FATAL_FAILURE(InitState());
12725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12726
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012727 char const *vsSource = "#version 450\n"
12728 "\n"
12729 "out gl_PerVertex {\n"
12730 " vec4 gl_Position;\n"
12731 "};\n"
12732 "void main(){\n"
12733 " gl_Position = vec4(1);\n"
12734 "}\n";
12735 char const *fsSource = "#version 450\n"
12736 "\n"
12737 "layout(location=0) out vec4 color;\n"
12738 "void main(){\n"
12739 " color = vec4(1);\n"
12740 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012741
12742 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12743 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12744
12745 VkPipelineObj pipe(m_device);
12746 pipe.AddColorAttachment();
12747 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012748 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012749 pipe.AddShader(&fs);
12750
12751 VkDescriptorSetObj descriptorSet(m_device);
12752 descriptorSet.AppendDummy();
12753 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12754
12755 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12756
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012757 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012758}
12759
Chris Forbes82ff92a2016-09-09 10:50:24 +120012760TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12762 "No entrypoint found named `foo`");
12763
12764 ASSERT_NO_FATAL_FAILURE(InitState());
12765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12766
12767 char const *vsSource = "#version 450\n"
12768 "out gl_PerVertex {\n"
12769 " vec4 gl_Position;\n"
12770 "};\n"
12771 "void main(){\n"
12772 " gl_Position = vec4(0);\n"
12773 "}\n";
12774 char const *fsSource = "#version 450\n"
12775 "\n"
12776 "layout(location=0) out vec4 color;\n"
12777 "void main(){\n"
12778 " color = vec4(1);\n"
12779 "}\n";
12780
12781 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12782 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12783
12784 VkPipelineObj pipe(m_device);
12785 pipe.AddColorAttachment();
12786 pipe.AddShader(&vs);
12787 pipe.AddShader(&fs);
12788
12789 VkDescriptorSetObj descriptorSet(m_device);
12790 descriptorSet.AppendDummy();
12791 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12792
12793 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12794
12795 m_errorMonitor->VerifyFound();
12796}
12797
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012798TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12799 m_errorMonitor->SetDesiredFailureMsg(
12800 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12801 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12802 "uses a depth/stencil attachment");
12803
12804 ASSERT_NO_FATAL_FAILURE(InitState());
12805 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12806
12807 char const *vsSource = "#version 450\n"
12808 "void main(){ gl_Position = vec4(0); }\n";
12809 char const *fsSource = "#version 450\n"
12810 "\n"
12811 "layout(location=0) out vec4 color;\n"
12812 "void main(){\n"
12813 " color = vec4(1);\n"
12814 "}\n";
12815
12816 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12817 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12818
12819 VkPipelineObj pipe(m_device);
12820 pipe.AddColorAttachment();
12821 pipe.AddShader(&vs);
12822 pipe.AddShader(&fs);
12823
12824 VkDescriptorSetObj descriptorSet(m_device);
12825 descriptorSet.AppendDummy();
12826 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12827
12828 VkAttachmentDescription attachments[] = {
12829 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12830 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12831 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12832 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12833 },
12834 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12835 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12836 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12837 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12838 },
12839 };
12840 VkAttachmentReference refs[] = {
12841 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12842 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12843 };
12844 VkSubpassDescription subpass = {
12845 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12846 1, &refs[0], nullptr, &refs[1],
12847 0, nullptr
12848 };
12849 VkRenderPassCreateInfo rpci = {
12850 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12851 0, 2, attachments, 1, &subpass, 0, nullptr
12852 };
12853 VkRenderPass rp;
12854 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12855 ASSERT_VK_SUCCESS(err);
12856
12857 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12858
12859 m_errorMonitor->VerifyFound();
12860
12861 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12862}
12863
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012864TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012865 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12866 "the TCS without the patch decoration, but consumed in the TES "
12867 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12869 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012870
12871 ASSERT_NO_FATAL_FAILURE(InitState());
12872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12873
Chris Forbesc1e852d2016-04-04 19:26:42 +120012874 if (!m_device->phy().features().tessellationShader) {
12875 printf("Device does not support tessellation shaders; skipped.\n");
12876 return;
12877 }
12878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012879 char const *vsSource = "#version 450\n"
12880 "void main(){}\n";
12881 char const *tcsSource = "#version 450\n"
12882 "layout(location=0) out int x[];\n"
12883 "layout(vertices=3) out;\n"
12884 "void main(){\n"
12885 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12886 " gl_TessLevelInner[0] = 1;\n"
12887 " x[gl_InvocationID] = gl_InvocationID;\n"
12888 "}\n";
12889 char const *tesSource = "#version 450\n"
12890 "layout(triangles, equal_spacing, cw) in;\n"
12891 "layout(location=0) patch in int x;\n"
12892 "out gl_PerVertex { vec4 gl_Position; };\n"
12893 "void main(){\n"
12894 " gl_Position.xyz = gl_TessCoord;\n"
12895 " gl_Position.w = x;\n"
12896 "}\n";
12897 char const *fsSource = "#version 450\n"
12898 "layout(location=0) out vec4 color;\n"
12899 "void main(){\n"
12900 " color = vec4(1);\n"
12901 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012902
12903 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12904 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12905 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12906 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012908 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12909 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012910
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012911 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012912
12913 VkPipelineObj pipe(m_device);
12914 pipe.SetInputAssembly(&iasci);
12915 pipe.SetTessellation(&tsci);
12916 pipe.AddColorAttachment();
12917 pipe.AddShader(&vs);
12918 pipe.AddShader(&tcs);
12919 pipe.AddShader(&tes);
12920 pipe.AddShader(&fs);
12921
12922 VkDescriptorSetObj descriptorSet(m_device);
12923 descriptorSet.AppendDummy();
12924 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12925
12926 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12927
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012928 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012929}
12930
Karl Schultz6addd812016-02-02 17:17:23 -070012931TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012932 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12933 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12935 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012936
Chris Forbes280ba2c2015-06-12 11:16:41 +120012937 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012939
12940 /* Two binding descriptions for binding 0 */
12941 VkVertexInputBindingDescription input_bindings[2];
12942 memset(input_bindings, 0, sizeof(input_bindings));
12943
12944 VkVertexInputAttributeDescription input_attrib;
12945 memset(&input_attrib, 0, sizeof(input_attrib));
12946 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12947
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012948 char const *vsSource = "#version 450\n"
12949 "\n"
12950 "layout(location=0) in float x;\n" /* attrib provided float */
12951 "out gl_PerVertex {\n"
12952 " vec4 gl_Position;\n"
12953 "};\n"
12954 "void main(){\n"
12955 " gl_Position = vec4(x);\n"
12956 "}\n";
12957 char const *fsSource = "#version 450\n"
12958 "\n"
12959 "layout(location=0) out vec4 color;\n"
12960 "void main(){\n"
12961 " color = vec4(1);\n"
12962 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012963
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012964 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12965 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012966
12967 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012968 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012969 pipe.AddShader(&vs);
12970 pipe.AddShader(&fs);
12971
12972 pipe.AddVertexInputBindings(input_bindings, 2);
12973 pipe.AddVertexInputAttribs(&input_attrib, 1);
12974
Chris Forbes280ba2c2015-06-12 11:16:41 +120012975 VkDescriptorSetObj descriptorSet(m_device);
12976 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012977 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012978
Tony Barbour5781e8f2015-08-04 16:23:11 -060012979 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012980
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012981 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012982}
Chris Forbes8f68b562015-05-25 11:13:32 +120012983
Karl Schultz6addd812016-02-02 17:17:23 -070012984TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012985 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012986 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012988
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012989 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012991 char const *vsSource = "#version 450\n"
12992 "\n"
12993 "out gl_PerVertex {\n"
12994 " vec4 gl_Position;\n"
12995 "};\n"
12996 "void main(){\n"
12997 " gl_Position = vec4(1);\n"
12998 "}\n";
12999 char const *fsSource = "#version 450\n"
13000 "\n"
13001 "void main(){\n"
13002 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013003
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013004 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13005 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013006
13007 VkPipelineObj pipe(m_device);
13008 pipe.AddShader(&vs);
13009 pipe.AddShader(&fs);
13010
Chia-I Wu08accc62015-07-07 11:50:03 +080013011 /* set up CB 0, not written */
13012 pipe.AddColorAttachment();
13013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013014
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013015 VkDescriptorSetObj descriptorSet(m_device);
13016 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013017 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013018
Tony Barbour5781e8f2015-08-04 16:23:11 -060013019 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013020
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013021 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013022}
13023
Karl Schultz6addd812016-02-02 17:17:23 -070013024TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013025 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013026 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013028 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013029
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013030 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013032 char const *vsSource = "#version 450\n"
13033 "\n"
13034 "out gl_PerVertex {\n"
13035 " vec4 gl_Position;\n"
13036 "};\n"
13037 "void main(){\n"
13038 " gl_Position = vec4(1);\n"
13039 "}\n";
13040 char const *fsSource = "#version 450\n"
13041 "\n"
13042 "layout(location=0) out vec4 x;\n"
13043 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13044 "void main(){\n"
13045 " x = vec4(1);\n"
13046 " y = vec4(1);\n"
13047 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013048
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013049 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13050 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013051
13052 VkPipelineObj pipe(m_device);
13053 pipe.AddShader(&vs);
13054 pipe.AddShader(&fs);
13055
Chia-I Wu08accc62015-07-07 11:50:03 +080013056 /* set up CB 0, not written */
13057 pipe.AddColorAttachment();
13058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013059 /* FS writes CB 1, but we don't configure it */
13060
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013061 VkDescriptorSetObj descriptorSet(m_device);
13062 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013063 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013064
Tony Barbour5781e8f2015-08-04 16:23:11 -060013065 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013066
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013067 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013068}
13069
Karl Schultz6addd812016-02-02 17:17:23 -070013070TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013071 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013072 "type of an fragment shader output variable, and the format of the corresponding attachment");
13073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013074
Chris Forbesa36d69e2015-05-25 11:13:44 +120013075 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013077 char const *vsSource = "#version 450\n"
13078 "\n"
13079 "out gl_PerVertex {\n"
13080 " vec4 gl_Position;\n"
13081 "};\n"
13082 "void main(){\n"
13083 " gl_Position = vec4(1);\n"
13084 "}\n";
13085 char const *fsSource = "#version 450\n"
13086 "\n"
13087 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13088 "void main(){\n"
13089 " x = ivec4(1);\n"
13090 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013091
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013092 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13093 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013094
13095 VkPipelineObj pipe(m_device);
13096 pipe.AddShader(&vs);
13097 pipe.AddShader(&fs);
13098
Chia-I Wu08accc62015-07-07 11:50:03 +080013099 /* set up CB 0; type is UNORM by default */
13100 pipe.AddColorAttachment();
13101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013102
Chris Forbesa36d69e2015-05-25 11:13:44 +120013103 VkDescriptorSetObj descriptorSet(m_device);
13104 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013105 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013106
Tony Barbour5781e8f2015-08-04 16:23:11 -060013107 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013108
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013109 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013110}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013111
Karl Schultz6addd812016-02-02 17:17:23 -070013112TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013113 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13114 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013116
Chris Forbes556c76c2015-08-14 12:04:59 +120013117 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013119 char const *vsSource = "#version 450\n"
13120 "\n"
13121 "out gl_PerVertex {\n"
13122 " vec4 gl_Position;\n"
13123 "};\n"
13124 "void main(){\n"
13125 " gl_Position = vec4(1);\n"
13126 "}\n";
13127 char const *fsSource = "#version 450\n"
13128 "\n"
13129 "layout(location=0) out vec4 x;\n"
13130 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13131 "void main(){\n"
13132 " x = vec4(bar.y);\n"
13133 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013134
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013135 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13136 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013137
Chris Forbes556c76c2015-08-14 12:04:59 +120013138 VkPipelineObj pipe(m_device);
13139 pipe.AddShader(&vs);
13140 pipe.AddShader(&fs);
13141
13142 /* set up CB 0; type is UNORM by default */
13143 pipe.AddColorAttachment();
13144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13145
13146 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013147 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013148
13149 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13150
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013151 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013152}
13153
Chris Forbes5c59e902016-02-26 16:56:09 +130013154TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013155 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13156 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013158
13159 ASSERT_NO_FATAL_FAILURE(InitState());
13160
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013161 char const *vsSource = "#version 450\n"
13162 "\n"
13163 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13164 "out gl_PerVertex {\n"
13165 " vec4 gl_Position;\n"
13166 "};\n"
13167 "void main(){\n"
13168 " gl_Position = vec4(consts.x);\n"
13169 "}\n";
13170 char const *fsSource = "#version 450\n"
13171 "\n"
13172 "layout(location=0) out vec4 x;\n"
13173 "void main(){\n"
13174 " x = vec4(1);\n"
13175 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013176
13177 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13178 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13179
13180 VkPipelineObj pipe(m_device);
13181 pipe.AddShader(&vs);
13182 pipe.AddShader(&fs);
13183
13184 /* set up CB 0; type is UNORM by default */
13185 pipe.AddColorAttachment();
13186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13187
13188 VkDescriptorSetObj descriptorSet(m_device);
13189 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13190
13191 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13192
13193 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013194 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013195}
13196
Chris Forbes3fb17902016-08-22 14:57:55 +120013197TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13198 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13199 "which is not included in the subpass description");
13200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13201 "consumes input attachment index 0 but not provided in subpass");
13202
13203 ASSERT_NO_FATAL_FAILURE(InitState());
13204
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013205 char const *vsSource = "#version 450\n"
13206 "\n"
13207 "out gl_PerVertex {\n"
13208 " vec4 gl_Position;\n"
13209 "};\n"
13210 "void main(){\n"
13211 " gl_Position = vec4(1);\n"
13212 "}\n";
13213 char const *fsSource = "#version 450\n"
13214 "\n"
13215 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13216 "layout(location=0) out vec4 color;\n"
13217 "void main() {\n"
13218 " color = subpassLoad(x);\n"
13219 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013220
13221 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13222 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13223
13224 VkPipelineObj pipe(m_device);
13225 pipe.AddShader(&vs);
13226 pipe.AddShader(&fs);
13227 pipe.AddColorAttachment();
13228 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13229
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013230 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13231 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013232 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013233 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013234 ASSERT_VK_SUCCESS(err);
13235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013236 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013237 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013238 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013239 ASSERT_VK_SUCCESS(err);
13240
13241 // error here.
13242 pipe.CreateVKPipeline(pl, renderPass());
13243
13244 m_errorMonitor->VerifyFound();
13245
13246 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13247 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13248}
13249
Chris Forbes5a9a0472016-08-22 16:02:09 +120013250TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13251 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13252 "with a format having a different fundamental type");
13253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13254 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13255
13256 ASSERT_NO_FATAL_FAILURE(InitState());
13257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013258 char const *vsSource = "#version 450\n"
13259 "\n"
13260 "out gl_PerVertex {\n"
13261 " vec4 gl_Position;\n"
13262 "};\n"
13263 "void main(){\n"
13264 " gl_Position = vec4(1);\n"
13265 "}\n";
13266 char const *fsSource = "#version 450\n"
13267 "\n"
13268 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13269 "layout(location=0) out vec4 color;\n"
13270 "void main() {\n"
13271 " color = subpassLoad(x);\n"
13272 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013273
13274 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13275 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13276
13277 VkPipelineObj pipe(m_device);
13278 pipe.AddShader(&vs);
13279 pipe.AddShader(&fs);
13280 pipe.AddColorAttachment();
13281 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13282
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013283 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13284 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013285 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013286 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013287 ASSERT_VK_SUCCESS(err);
13288
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013289 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013290 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013291 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013292 ASSERT_VK_SUCCESS(err);
13293
13294 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013295 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13296 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13297 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13298 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13299 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 +120013300 };
13301 VkAttachmentReference color = {
13302 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13303 };
13304 VkAttachmentReference input = {
13305 1, VK_IMAGE_LAYOUT_GENERAL,
13306 };
13307
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013308 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013309
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013310 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013311 VkRenderPass rp;
13312 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13313 ASSERT_VK_SUCCESS(err);
13314
13315 // error here.
13316 pipe.CreateVKPipeline(pl, rp);
13317
13318 m_errorMonitor->VerifyFound();
13319
13320 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13321 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13322 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13323}
13324
Chris Forbes541f7b02016-08-22 15:30:27 +120013325TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13326 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13327 "which is not included in the subpass description -- array case");
13328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13329 "consumes input attachment index 1 but not provided in subpass");
13330
13331 ASSERT_NO_FATAL_FAILURE(InitState());
13332
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013333 char const *vsSource = "#version 450\n"
13334 "\n"
13335 "out gl_PerVertex {\n"
13336 " vec4 gl_Position;\n"
13337 "};\n"
13338 "void main(){\n"
13339 " gl_Position = vec4(1);\n"
13340 "}\n";
13341 char const *fsSource = "#version 450\n"
13342 "\n"
13343 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13344 "layout(location=0) out vec4 color;\n"
13345 "void main() {\n"
13346 " color = subpassLoad(xs[1]);\n"
13347 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013348
13349 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13350 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13351
13352 VkPipelineObj pipe(m_device);
13353 pipe.AddShader(&vs);
13354 pipe.AddShader(&fs);
13355 pipe.AddColorAttachment();
13356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013358 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13359 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013360 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013361 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013362 ASSERT_VK_SUCCESS(err);
13363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013364 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013365 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013366 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013367 ASSERT_VK_SUCCESS(err);
13368
13369 // error here.
13370 pipe.CreateVKPipeline(pl, renderPass());
13371
13372 m_errorMonitor->VerifyFound();
13373
13374 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13375 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13376}
13377
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013378TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013379 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13380 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013382
13383 ASSERT_NO_FATAL_FAILURE(InitState());
13384
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013385 char const *csSource = "#version 450\n"
13386 "\n"
13387 "layout(local_size_x=1) in;\n"
13388 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13389 "void main(){\n"
13390 " x = vec4(1);\n"
13391 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013392
13393 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13394
13395 VkDescriptorSetObj descriptorSet(m_device);
13396 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13397
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013398 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13399 nullptr,
13400 0,
13401 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13402 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13403 descriptorSet.GetPipelineLayout(),
13404 VK_NULL_HANDLE,
13405 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013406
13407 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013408 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013409
13410 m_errorMonitor->VerifyFound();
13411
13412 if (err == VK_SUCCESS) {
13413 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13414 }
13415}
13416
Chris Forbes22a9b092016-07-19 14:34:05 +120013417TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013418 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13419 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13421 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013422
13423 ASSERT_NO_FATAL_FAILURE(InitState());
13424
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013425 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13426 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013427 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013428 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013429 ASSERT_VK_SUCCESS(err);
13430
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013431 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013432 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013433 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013434 ASSERT_VK_SUCCESS(err);
13435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013436 char const *csSource = "#version 450\n"
13437 "\n"
13438 "layout(local_size_x=1) in;\n"
13439 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13440 "void main() {\n"
13441 " x.x = 1.0f;\n"
13442 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013443 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013445 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13446 nullptr,
13447 0,
13448 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13449 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13450 pl,
13451 VK_NULL_HANDLE,
13452 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013453
13454 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013455 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013456
13457 m_errorMonitor->VerifyFound();
13458
13459 if (err == VK_SUCCESS) {
13460 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13461 }
13462
13463 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13464 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13465}
13466
Chris Forbes50020592016-07-27 13:52:41 +120013467TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13468 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13469 "does not match the dimensionality declared in the shader");
13470
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013471 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 +120013472
13473 ASSERT_NO_FATAL_FAILURE(InitState());
13474 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13475
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013476 char const *vsSource = "#version 450\n"
13477 "\n"
13478 "out gl_PerVertex { vec4 gl_Position; };\n"
13479 "void main() { gl_Position = vec4(0); }\n";
13480 char const *fsSource = "#version 450\n"
13481 "\n"
13482 "layout(set=0, binding=0) uniform sampler3D s;\n"
13483 "layout(location=0) out vec4 color;\n"
13484 "void main() {\n"
13485 " color = texture(s, vec3(0));\n"
13486 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013487 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13488 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13489
13490 VkPipelineObj pipe(m_device);
13491 pipe.AddShader(&vs);
13492 pipe.AddShader(&fs);
13493 pipe.AddColorAttachment();
13494
13495 VkTextureObj texture(m_device, nullptr);
13496 VkSamplerObj sampler(m_device);
13497
13498 VkDescriptorSetObj descriptorSet(m_device);
13499 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13500 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13501
13502 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13503 ASSERT_VK_SUCCESS(err);
13504
13505 BeginCommandBuffer();
13506
13507 m_commandBuffer->BindPipeline(pipe);
13508 m_commandBuffer->BindDescriptorSet(descriptorSet);
13509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013510 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013511 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013512 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013513 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13514
13515 // error produced here.
13516 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13517
13518 m_errorMonitor->VerifyFound();
13519
13520 EndCommandBuffer();
13521}
13522
Chris Forbes5533bfc2016-07-27 14:12:34 +120013523TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13524 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13525 "are consumed via singlesample images types in the shader, or vice versa.");
13526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013528
13529 ASSERT_NO_FATAL_FAILURE(InitState());
13530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13531
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013532 char const *vsSource = "#version 450\n"
13533 "\n"
13534 "out gl_PerVertex { vec4 gl_Position; };\n"
13535 "void main() { gl_Position = vec4(0); }\n";
13536 char const *fsSource = "#version 450\n"
13537 "\n"
13538 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13539 "layout(location=0) out vec4 color;\n"
13540 "void main() {\n"
13541 " color = texelFetch(s, ivec2(0), 0);\n"
13542 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013543 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13544 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13545
13546 VkPipelineObj pipe(m_device);
13547 pipe.AddShader(&vs);
13548 pipe.AddShader(&fs);
13549 pipe.AddColorAttachment();
13550
13551 VkTextureObj texture(m_device, nullptr);
13552 VkSamplerObj sampler(m_device);
13553
13554 VkDescriptorSetObj descriptorSet(m_device);
13555 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13556 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13557
13558 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13559 ASSERT_VK_SUCCESS(err);
13560
13561 BeginCommandBuffer();
13562
13563 m_commandBuffer->BindPipeline(pipe);
13564 m_commandBuffer->BindDescriptorSet(descriptorSet);
13565
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013566 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013567 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013568 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013569 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13570
13571 // error produced here.
13572 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13573
13574 m_errorMonitor->VerifyFound();
13575
13576 EndCommandBuffer();
13577}
13578
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013579#endif // SHADER_CHECKER_TESTS
13580
13581#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013582TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013584
13585 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013586
13587 // Create an image
13588 VkImage image;
13589
Karl Schultz6addd812016-02-02 17:17:23 -070013590 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13591 const int32_t tex_width = 32;
13592 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013593
13594 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013595 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13596 image_create_info.pNext = NULL;
13597 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13598 image_create_info.format = tex_format;
13599 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013600 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013601 image_create_info.extent.depth = 1;
13602 image_create_info.mipLevels = 1;
13603 image_create_info.arrayLayers = 1;
13604 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13605 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13606 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13607 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013608
13609 // Introduce error by sending down a bogus width extent
13610 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013611 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013612
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013613 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013614}
13615
Mark Youngc48c4c12016-04-11 14:26:49 -060013616TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13618 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013619
13620 ASSERT_NO_FATAL_FAILURE(InitState());
13621
13622 // Create an image
13623 VkImage image;
13624
13625 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13626 const int32_t tex_width = 32;
13627 const int32_t tex_height = 32;
13628
13629 VkImageCreateInfo image_create_info = {};
13630 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13631 image_create_info.pNext = NULL;
13632 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13633 image_create_info.format = tex_format;
13634 image_create_info.extent.width = tex_width;
13635 image_create_info.extent.height = tex_height;
13636 image_create_info.extent.depth = 1;
13637 image_create_info.mipLevels = 1;
13638 image_create_info.arrayLayers = 1;
13639 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13640 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13641 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13642 image_create_info.flags = 0;
13643
13644 // Introduce error by sending down a bogus width extent
13645 image_create_info.extent.width = 0;
13646 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13647
13648 m_errorMonitor->VerifyFound();
13649}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013650#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013651
Tobin Ehliscde08892015-09-22 10:11:37 -060013652#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013653
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013654TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13655 TEST_DESCRIPTION("Create a render pass with an attachment description "
13656 "format set to VK_FORMAT_UNDEFINED");
13657
13658 ASSERT_NO_FATAL_FAILURE(InitState());
13659 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13660
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013662
13663 VkAttachmentReference color_attach = {};
13664 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13665 color_attach.attachment = 0;
13666 VkSubpassDescription subpass = {};
13667 subpass.colorAttachmentCount = 1;
13668 subpass.pColorAttachments = &color_attach;
13669
13670 VkRenderPassCreateInfo rpci = {};
13671 rpci.subpassCount = 1;
13672 rpci.pSubpasses = &subpass;
13673 rpci.attachmentCount = 1;
13674 VkAttachmentDescription attach_desc = {};
13675 attach_desc.format = VK_FORMAT_UNDEFINED;
13676 rpci.pAttachments = &attach_desc;
13677 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13678 VkRenderPass rp;
13679 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13680
13681 m_errorMonitor->VerifyFound();
13682
13683 if (result == VK_SUCCESS) {
13684 vkDestroyRenderPass(m_device->device(), rp, NULL);
13685 }
13686}
13687
Karl Schultz6addd812016-02-02 17:17:23 -070013688TEST_F(VkLayerTest, InvalidImageView) {
13689 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013690
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013692
Tobin Ehliscde08892015-09-22 10:11:37 -060013693 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013694
Mike Stroyana3082432015-09-25 13:39:21 -060013695 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013696 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013697
Karl Schultz6addd812016-02-02 17:17:23 -070013698 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13699 const int32_t tex_width = 32;
13700 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013701
13702 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013703 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13704 image_create_info.pNext = NULL;
13705 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13706 image_create_info.format = tex_format;
13707 image_create_info.extent.width = tex_width;
13708 image_create_info.extent.height = tex_height;
13709 image_create_info.extent.depth = 1;
13710 image_create_info.mipLevels = 1;
13711 image_create_info.arrayLayers = 1;
13712 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13713 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13714 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13715 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013716
Chia-I Wuf7458c52015-10-26 21:10:41 +080013717 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013718 ASSERT_VK_SUCCESS(err);
13719
13720 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013721 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13722 image_view_create_info.image = image;
13723 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13724 image_view_create_info.format = tex_format;
13725 image_view_create_info.subresourceRange.layerCount = 1;
13726 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13727 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013728 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013729
13730 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013731 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013732
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013733 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013734 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013735}
Mike Stroyana3082432015-09-25 13:39:21 -060013736
Mark Youngd339ba32016-05-30 13:28:35 -060013737TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13738 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013740 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013741
13742 ASSERT_NO_FATAL_FAILURE(InitState());
13743
13744 // Create an image and try to create a view with no memory backing the image
13745 VkImage image;
13746
13747 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13748 const int32_t tex_width = 32;
13749 const int32_t tex_height = 32;
13750
13751 VkImageCreateInfo image_create_info = {};
13752 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13753 image_create_info.pNext = NULL;
13754 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13755 image_create_info.format = tex_format;
13756 image_create_info.extent.width = tex_width;
13757 image_create_info.extent.height = tex_height;
13758 image_create_info.extent.depth = 1;
13759 image_create_info.mipLevels = 1;
13760 image_create_info.arrayLayers = 1;
13761 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13762 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13763 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13764 image_create_info.flags = 0;
13765
13766 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13767 ASSERT_VK_SUCCESS(err);
13768
13769 VkImageViewCreateInfo image_view_create_info = {};
13770 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13771 image_view_create_info.image = image;
13772 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13773 image_view_create_info.format = tex_format;
13774 image_view_create_info.subresourceRange.layerCount = 1;
13775 image_view_create_info.subresourceRange.baseMipLevel = 0;
13776 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013777 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013778
13779 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013780 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013781
13782 m_errorMonitor->VerifyFound();
13783 vkDestroyImage(m_device->device(), image, NULL);
13784 // If last error is success, it still created the view, so delete it.
13785 if (err == VK_SUCCESS) {
13786 vkDestroyImageView(m_device->device(), view, NULL);
13787 }
Mark Youngd339ba32016-05-30 13:28:35 -060013788}
13789
Karl Schultz6addd812016-02-02 17:17:23 -070013790TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013791 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013793 "formats must have ONLY the "
13794 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13796 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013797
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013798 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013799
Karl Schultz6addd812016-02-02 17:17:23 -070013800 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013801 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013802 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013803 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013804
13805 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013806 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013807 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013808 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13809 image_view_create_info.format = tex_format;
13810 image_view_create_info.subresourceRange.baseMipLevel = 0;
13811 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013812 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013813 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013814 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013815
13816 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013817 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013818
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013819 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013820}
13821
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013822TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013823 VkResult err;
13824 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013825
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13827 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013828
Mike Stroyana3082432015-09-25 13:39:21 -060013829 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013830
13831 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013832 VkImage srcImage;
13833 VkImage dstImage;
13834 VkDeviceMemory srcMem;
13835 VkDeviceMemory destMem;
13836 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013837
13838 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013839 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13840 image_create_info.pNext = NULL;
13841 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13842 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13843 image_create_info.extent.width = 32;
13844 image_create_info.extent.height = 32;
13845 image_create_info.extent.depth = 1;
13846 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013847 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013848 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13849 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13850 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13851 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013853 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013854 ASSERT_VK_SUCCESS(err);
13855
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013856 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013857 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013858 ASSERT_VK_SUCCESS(err);
13859
13860 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013861 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013862 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13863 memAlloc.pNext = NULL;
13864 memAlloc.allocationSize = 0;
13865 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013866
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013867 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013868 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013869 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013870 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013871 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013872 ASSERT_VK_SUCCESS(err);
13873
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013874 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013875 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013876 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013877 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013878 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013879 ASSERT_VK_SUCCESS(err);
13880
13881 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13882 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013883 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013884 ASSERT_VK_SUCCESS(err);
13885
13886 BeginCommandBuffer();
13887 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013888 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013889 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013890 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013891 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013892 copyRegion.srcOffset.x = 0;
13893 copyRegion.srcOffset.y = 0;
13894 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013895 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013896 copyRegion.dstSubresource.mipLevel = 0;
13897 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013898 // Introduce failure by forcing the dst layerCount to differ from src
13899 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013900 copyRegion.dstOffset.x = 0;
13901 copyRegion.dstOffset.y = 0;
13902 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013903 copyRegion.extent.width = 1;
13904 copyRegion.extent.height = 1;
13905 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013906 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013907 EndCommandBuffer();
13908
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013909 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013910
Chia-I Wuf7458c52015-10-26 21:10:41 +080013911 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013912 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013913 vkFreeMemory(m_device->device(), srcMem, NULL);
13914 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013915}
13916
Tony Barbourd6673642016-05-05 14:46:39 -060013917TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13918
13919 TEST_DESCRIPTION("Creating images with unsuported formats ");
13920
13921 ASSERT_NO_FATAL_FAILURE(InitState());
13922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13923 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013924 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 -060013925 VK_IMAGE_TILING_OPTIMAL, 0);
13926 ASSERT_TRUE(image.initialized());
13927
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013928 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13929 VkImageCreateInfo image_create_info;
13930 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13931 image_create_info.pNext = NULL;
13932 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13933 image_create_info.format = VK_FORMAT_UNDEFINED;
13934 image_create_info.extent.width = 32;
13935 image_create_info.extent.height = 32;
13936 image_create_info.extent.depth = 1;
13937 image_create_info.mipLevels = 1;
13938 image_create_info.arrayLayers = 1;
13939 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13940 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13941 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13942 image_create_info.flags = 0;
13943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13945 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013946
13947 VkImage localImage;
13948 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13949 m_errorMonitor->VerifyFound();
13950
Tony Barbourd6673642016-05-05 14:46:39 -060013951 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013952 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013953 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13954 VkFormat format = static_cast<VkFormat>(f);
13955 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013956 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013957 unsupported = format;
13958 break;
13959 }
13960 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013961
Tony Barbourd6673642016-05-05 14:46:39 -060013962 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013963 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013965
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013966 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013967 m_errorMonitor->VerifyFound();
13968 }
13969}
13970
13971TEST_F(VkLayerTest, ImageLayerViewTests) {
13972 VkResult ret;
13973 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13974
13975 ASSERT_NO_FATAL_FAILURE(InitState());
13976
13977 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013978 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 -060013979 VK_IMAGE_TILING_OPTIMAL, 0);
13980 ASSERT_TRUE(image.initialized());
13981
13982 VkImageView imgView;
13983 VkImageViewCreateInfo imgViewInfo = {};
13984 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13985 imgViewInfo.image = image.handle();
13986 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13987 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13988 imgViewInfo.subresourceRange.layerCount = 1;
13989 imgViewInfo.subresourceRange.baseMipLevel = 0;
13990 imgViewInfo.subresourceRange.levelCount = 1;
13991 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13992
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013994 // View can't have baseMipLevel >= image's mipLevels - Expect
13995 // VIEW_CREATE_ERROR
13996 imgViewInfo.subresourceRange.baseMipLevel = 1;
13997 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13998 m_errorMonitor->VerifyFound();
13999 imgViewInfo.subresourceRange.baseMipLevel = 0;
14000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014002 // View can't have baseArrayLayer >= image's arraySize - Expect
14003 // VIEW_CREATE_ERROR
14004 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14005 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14006 m_errorMonitor->VerifyFound();
14007 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14008
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14010 "pCreateInfo->subresourceRange."
14011 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014012 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14013 imgViewInfo.subresourceRange.levelCount = 0;
14014 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14015 m_errorMonitor->VerifyFound();
14016 imgViewInfo.subresourceRange.levelCount = 1;
14017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14019 "pCreateInfo->subresourceRange."
14020 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014021 m_errorMonitor->SetDesiredFailureMsg(
14022 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14023 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014024 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14025 imgViewInfo.subresourceRange.layerCount = 0;
14026 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14027 m_errorMonitor->VerifyFound();
14028 imgViewInfo.subresourceRange.layerCount = 1;
14029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14032 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14033 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014034 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14035 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14036 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14037 m_errorMonitor->VerifyFound();
14038 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14041 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14042 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014043 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14044 // VIEW_CREATE_ERROR
14045 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14046 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14047 m_errorMonitor->VerifyFound();
14048 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14049
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14051 "differing formats but they must be "
14052 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014053 // TODO: Update framework to easily passing mutable flag into ImageObj init
14054 // For now just allowing image for this one test to not have memory bound
14055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14056 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014057 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14058 // VIEW_CREATE_ERROR
14059 VkImageCreateInfo mutImgInfo = image.create_info();
14060 VkImage mutImage;
14061 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014062 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014063 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14064 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14065 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14066 ASSERT_VK_SUCCESS(ret);
14067 imgViewInfo.image = mutImage;
14068 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14069 m_errorMonitor->VerifyFound();
14070 imgViewInfo.image = image.handle();
14071 vkDestroyImage(m_device->handle(), mutImage, NULL);
14072}
14073
14074TEST_F(VkLayerTest, MiscImageLayerTests) {
14075
14076 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14077
14078 ASSERT_NO_FATAL_FAILURE(InitState());
14079
14080 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014081 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 -060014082 VK_IMAGE_TILING_OPTIMAL, 0);
14083 ASSERT_TRUE(image.initialized());
14084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060014086 vk_testing::Buffer buffer;
14087 VkMemoryPropertyFlags reqs = 0;
14088 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14089 VkBufferImageCopy region = {};
14090 region.bufferRowLength = 128;
14091 region.bufferImageHeight = 128;
14092 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14093 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14094 region.imageSubresource.layerCount = 0;
14095 region.imageExtent.height = 4;
14096 region.imageExtent.width = 4;
14097 region.imageExtent.depth = 1;
14098 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014099 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14100 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014101 m_errorMonitor->VerifyFound();
14102 region.imageSubresource.layerCount = 1;
14103
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014104 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14105 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14106 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
14108 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14109 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014110 m_errorMonitor->VerifyFound();
14111
14112 // BufferOffset must be a multiple of 4
14113 // Introduce failure by setting bufferOffset to a value not divisible by 4
14114 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
14116 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14117 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014118 m_errorMonitor->VerifyFound();
14119
14120 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14121 region.bufferOffset = 0;
14122 region.imageExtent.height = 128;
14123 region.imageExtent.width = 128;
14124 // Introduce failure by setting bufferRowLength > 0 but less than width
14125 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14127 "must be zero or greater-than-or-equal-to imageExtent.width");
14128 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14129 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014130 m_errorMonitor->VerifyFound();
14131
14132 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14133 region.bufferRowLength = 128;
14134 // Introduce failure by setting bufferRowHeight > 0 but less than height
14135 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14137 "must be zero or greater-than-or-equal-to imageExtent.height");
14138 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14139 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014140 m_errorMonitor->VerifyFound();
14141
14142 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
14144 "specify only COLOR or DEPTH or "
14145 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060014146 // Expect MISMATCHED_IMAGE_ASPECT
14147 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014148 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14149 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014150 m_errorMonitor->VerifyFound();
14151 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14154 "If the format of srcImage is a depth, stencil, depth stencil or "
14155 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014156 // Expect INVALID_FILTER
14157 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014158 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 -060014159 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014160 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 -060014161 VkImageBlit blitRegion = {};
14162 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14163 blitRegion.srcSubresource.baseArrayLayer = 0;
14164 blitRegion.srcSubresource.layerCount = 1;
14165 blitRegion.srcSubresource.mipLevel = 0;
14166 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14167 blitRegion.dstSubresource.baseArrayLayer = 0;
14168 blitRegion.dstSubresource.layerCount = 1;
14169 blitRegion.dstSubresource.mipLevel = 0;
14170
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014171 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14172 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014173 m_errorMonitor->VerifyFound();
14174
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014175 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14177 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14178 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014179 m_errorMonitor->VerifyFound();
14180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014182 VkImageMemoryBarrier img_barrier;
14183 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14184 img_barrier.pNext = NULL;
14185 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14186 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14187 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14188 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14189 img_barrier.image = image.handle();
14190 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14191 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14192 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14193 img_barrier.subresourceRange.baseArrayLayer = 0;
14194 img_barrier.subresourceRange.baseMipLevel = 0;
14195 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14196 img_barrier.subresourceRange.layerCount = 0;
14197 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014198 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14199 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014200 m_errorMonitor->VerifyFound();
14201 img_barrier.subresourceRange.layerCount = 1;
14202}
14203
14204TEST_F(VkLayerTest, ImageFormatLimits) {
14205
14206 TEST_DESCRIPTION("Exceed the limits of image format ");
14207
Cody Northropc31a84f2016-08-22 10:41:47 -060014208 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014210 VkImageCreateInfo image_create_info = {};
14211 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14212 image_create_info.pNext = NULL;
14213 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14214 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14215 image_create_info.extent.width = 32;
14216 image_create_info.extent.height = 32;
14217 image_create_info.extent.depth = 1;
14218 image_create_info.mipLevels = 1;
14219 image_create_info.arrayLayers = 1;
14220 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14221 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14222 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14223 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14224 image_create_info.flags = 0;
14225
14226 VkImage nullImg;
14227 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014228 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14229 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014230 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14231 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14232 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14233 m_errorMonitor->VerifyFound();
14234 image_create_info.extent.depth = 1;
14235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014237 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14238 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14239 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14240 m_errorMonitor->VerifyFound();
14241 image_create_info.mipLevels = 1;
14242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014244 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14245 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14246 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14247 m_errorMonitor->VerifyFound();
14248 image_create_info.arrayLayers = 1;
14249
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014251 int samples = imgFmtProps.sampleCounts >> 1;
14252 image_create_info.samples = (VkSampleCountFlagBits)samples;
14253 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14254 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14255 m_errorMonitor->VerifyFound();
14256 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14259 "VK_IMAGE_LAYOUT_UNDEFINED or "
14260 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014261 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14262 // Expect INVALID_LAYOUT
14263 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14264 m_errorMonitor->VerifyFound();
14265 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14266}
14267
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014268TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14269
14270 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014272
14273 ASSERT_NO_FATAL_FAILURE(InitState());
14274
14275 VkImageObj src_image(m_device);
14276 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14277 VkImageObj dst_image(m_device);
14278 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14279
14280 BeginCommandBuffer();
14281 VkImageCopy copy_region;
14282 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14283 copy_region.srcSubresource.mipLevel = 0;
14284 copy_region.srcSubresource.baseArrayLayer = 0;
14285 copy_region.srcSubresource.layerCount = 0;
14286 copy_region.srcOffset.x = 0;
14287 copy_region.srcOffset.y = 0;
14288 copy_region.srcOffset.z = 0;
14289 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14290 copy_region.dstSubresource.mipLevel = 0;
14291 copy_region.dstSubresource.baseArrayLayer = 0;
14292 copy_region.dstSubresource.layerCount = 0;
14293 copy_region.dstOffset.x = 0;
14294 copy_region.dstOffset.y = 0;
14295 copy_region.dstOffset.z = 0;
14296 copy_region.extent.width = 64;
14297 copy_region.extent.height = 64;
14298 copy_region.extent.depth = 1;
14299 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14300 &copy_region);
14301 EndCommandBuffer();
14302
14303 m_errorMonitor->VerifyFound();
14304}
14305
14306TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14307
14308 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014310
14311 ASSERT_NO_FATAL_FAILURE(InitState());
14312
14313 VkImageObj src_image(m_device);
14314 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14315 VkImageObj dst_image(m_device);
14316 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14317
14318 BeginCommandBuffer();
14319 VkImageCopy copy_region;
14320 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14321 copy_region.srcSubresource.mipLevel = 0;
14322 copy_region.srcSubresource.baseArrayLayer = 0;
14323 copy_region.srcSubresource.layerCount = 0;
14324 copy_region.srcOffset.x = 0;
14325 copy_region.srcOffset.y = 0;
14326 copy_region.srcOffset.z = 0;
14327 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14328 copy_region.dstSubresource.mipLevel = 0;
14329 copy_region.dstSubresource.baseArrayLayer = 0;
14330 copy_region.dstSubresource.layerCount = 0;
14331 copy_region.dstOffset.x = 0;
14332 copy_region.dstOffset.y = 0;
14333 copy_region.dstOffset.z = 0;
14334 copy_region.extent.width = 64;
14335 copy_region.extent.height = 64;
14336 copy_region.extent.depth = 1;
14337 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14338 &copy_region);
14339 EndCommandBuffer();
14340
14341 m_errorMonitor->VerifyFound();
14342}
14343
Karl Schultz6addd812016-02-02 17:17:23 -070014344TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014345 VkResult err;
14346 bool pass;
14347
14348 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14350 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014351
14352 ASSERT_NO_FATAL_FAILURE(InitState());
14353
14354 // Create two images of different types and try to copy between them
14355 VkImage srcImage;
14356 VkImage dstImage;
14357 VkDeviceMemory srcMem;
14358 VkDeviceMemory destMem;
14359 VkMemoryRequirements memReqs;
14360
14361 VkImageCreateInfo image_create_info = {};
14362 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14363 image_create_info.pNext = NULL;
14364 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14365 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14366 image_create_info.extent.width = 32;
14367 image_create_info.extent.height = 32;
14368 image_create_info.extent.depth = 1;
14369 image_create_info.mipLevels = 1;
14370 image_create_info.arrayLayers = 1;
14371 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14372 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14373 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14374 image_create_info.flags = 0;
14375
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014376 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014377 ASSERT_VK_SUCCESS(err);
14378
14379 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14380 // Introduce failure by creating second image with a different-sized format.
14381 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014383 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014384 ASSERT_VK_SUCCESS(err);
14385
14386 // Allocate memory
14387 VkMemoryAllocateInfo memAlloc = {};
14388 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14389 memAlloc.pNext = NULL;
14390 memAlloc.allocationSize = 0;
14391 memAlloc.memoryTypeIndex = 0;
14392
14393 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14394 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014395 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014396 ASSERT_TRUE(pass);
14397 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14398 ASSERT_VK_SUCCESS(err);
14399
14400 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14401 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014402 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014403 ASSERT_TRUE(pass);
14404 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14405 ASSERT_VK_SUCCESS(err);
14406
14407 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14408 ASSERT_VK_SUCCESS(err);
14409 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14410 ASSERT_VK_SUCCESS(err);
14411
14412 BeginCommandBuffer();
14413 VkImageCopy copyRegion;
14414 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14415 copyRegion.srcSubresource.mipLevel = 0;
14416 copyRegion.srcSubresource.baseArrayLayer = 0;
14417 copyRegion.srcSubresource.layerCount = 0;
14418 copyRegion.srcOffset.x = 0;
14419 copyRegion.srcOffset.y = 0;
14420 copyRegion.srcOffset.z = 0;
14421 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14422 copyRegion.dstSubresource.mipLevel = 0;
14423 copyRegion.dstSubresource.baseArrayLayer = 0;
14424 copyRegion.dstSubresource.layerCount = 0;
14425 copyRegion.dstOffset.x = 0;
14426 copyRegion.dstOffset.y = 0;
14427 copyRegion.dstOffset.z = 0;
14428 copyRegion.extent.width = 1;
14429 copyRegion.extent.height = 1;
14430 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014431 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014432 EndCommandBuffer();
14433
14434 m_errorMonitor->VerifyFound();
14435
14436 vkDestroyImage(m_device->device(), srcImage, NULL);
14437 vkDestroyImage(m_device->device(), dstImage, NULL);
14438 vkFreeMemory(m_device->device(), srcMem, NULL);
14439 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014440}
14441
Karl Schultz6addd812016-02-02 17:17:23 -070014442TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14443 VkResult err;
14444 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014445
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014446 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14448 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014449
Mike Stroyana3082432015-09-25 13:39:21 -060014450 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014451
14452 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014453 VkImage srcImage;
14454 VkImage dstImage;
14455 VkDeviceMemory srcMem;
14456 VkDeviceMemory destMem;
14457 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014458
14459 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014460 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14461 image_create_info.pNext = NULL;
14462 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14463 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14464 image_create_info.extent.width = 32;
14465 image_create_info.extent.height = 32;
14466 image_create_info.extent.depth = 1;
14467 image_create_info.mipLevels = 1;
14468 image_create_info.arrayLayers = 1;
14469 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14470 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14471 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14472 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014474 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014475 ASSERT_VK_SUCCESS(err);
14476
Karl Schultzbdb75952016-04-19 11:36:49 -060014477 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14478
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014479 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014480 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014481 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014482 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014483
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014484 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014485 ASSERT_VK_SUCCESS(err);
14486
14487 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014488 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014489 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14490 memAlloc.pNext = NULL;
14491 memAlloc.allocationSize = 0;
14492 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014493
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014494 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014495 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014496 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014497 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014498 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014499 ASSERT_VK_SUCCESS(err);
14500
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014501 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014502 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014503 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014504 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014505 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014506 ASSERT_VK_SUCCESS(err);
14507
14508 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14509 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014510 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014511 ASSERT_VK_SUCCESS(err);
14512
14513 BeginCommandBuffer();
14514 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014515 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014516 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014517 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014518 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014519 copyRegion.srcOffset.x = 0;
14520 copyRegion.srcOffset.y = 0;
14521 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014522 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014523 copyRegion.dstSubresource.mipLevel = 0;
14524 copyRegion.dstSubresource.baseArrayLayer = 0;
14525 copyRegion.dstSubresource.layerCount = 0;
14526 copyRegion.dstOffset.x = 0;
14527 copyRegion.dstOffset.y = 0;
14528 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014529 copyRegion.extent.width = 1;
14530 copyRegion.extent.height = 1;
14531 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014532 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014533 EndCommandBuffer();
14534
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014535 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014536
Chia-I Wuf7458c52015-10-26 21:10:41 +080014537 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014538 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014539 vkFreeMemory(m_device->device(), srcMem, NULL);
14540 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014541}
14542
Karl Schultz6addd812016-02-02 17:17:23 -070014543TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14544 VkResult err;
14545 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14548 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014549
Mike Stroyana3082432015-09-25 13:39:21 -060014550 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014551
14552 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014553 VkImage srcImage;
14554 VkImage dstImage;
14555 VkDeviceMemory srcMem;
14556 VkDeviceMemory destMem;
14557 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014558
14559 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014560 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14561 image_create_info.pNext = NULL;
14562 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14563 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14564 image_create_info.extent.width = 32;
14565 image_create_info.extent.height = 1;
14566 image_create_info.extent.depth = 1;
14567 image_create_info.mipLevels = 1;
14568 image_create_info.arrayLayers = 1;
14569 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14570 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14571 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14572 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014574 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014575 ASSERT_VK_SUCCESS(err);
14576
Karl Schultz6addd812016-02-02 17:17:23 -070014577 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014579 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014580 ASSERT_VK_SUCCESS(err);
14581
14582 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014583 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014584 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14585 memAlloc.pNext = NULL;
14586 memAlloc.allocationSize = 0;
14587 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014588
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014589 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014590 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014591 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014592 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014593 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014594 ASSERT_VK_SUCCESS(err);
14595
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014596 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014597 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014598 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014599 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014600 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014601 ASSERT_VK_SUCCESS(err);
14602
14603 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14604 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014605 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014606 ASSERT_VK_SUCCESS(err);
14607
14608 BeginCommandBuffer();
14609 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014610 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14611 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014612 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014613 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014614 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014615 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014616 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014617 resolveRegion.srcOffset.x = 0;
14618 resolveRegion.srcOffset.y = 0;
14619 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014620 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014621 resolveRegion.dstSubresource.mipLevel = 0;
14622 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014623 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014624 resolveRegion.dstOffset.x = 0;
14625 resolveRegion.dstOffset.y = 0;
14626 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014627 resolveRegion.extent.width = 1;
14628 resolveRegion.extent.height = 1;
14629 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014630 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014631 EndCommandBuffer();
14632
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014633 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014634
Chia-I Wuf7458c52015-10-26 21:10:41 +080014635 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014636 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014637 vkFreeMemory(m_device->device(), srcMem, NULL);
14638 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014639}
14640
Karl Schultz6addd812016-02-02 17:17:23 -070014641TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14642 VkResult err;
14643 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014644
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14646 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014647
Mike Stroyana3082432015-09-25 13:39:21 -060014648 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014649
Chris Forbesa7530692016-05-08 12:35:39 +120014650 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014651 VkImage srcImage;
14652 VkImage dstImage;
14653 VkDeviceMemory srcMem;
14654 VkDeviceMemory destMem;
14655 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014656
14657 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014658 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14659 image_create_info.pNext = NULL;
14660 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14661 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14662 image_create_info.extent.width = 32;
14663 image_create_info.extent.height = 1;
14664 image_create_info.extent.depth = 1;
14665 image_create_info.mipLevels = 1;
14666 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014667 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014668 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14669 // Note: Some implementations expect color attachment usage for any
14670 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014671 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014672 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014673
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014674 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014675 ASSERT_VK_SUCCESS(err);
14676
Karl Schultz6addd812016-02-02 17:17:23 -070014677 // Note: Some implementations expect color attachment usage for any
14678 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014679 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014680
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014681 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014682 ASSERT_VK_SUCCESS(err);
14683
14684 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014685 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014686 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14687 memAlloc.pNext = NULL;
14688 memAlloc.allocationSize = 0;
14689 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014690
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014691 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014692 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014693 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014694 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014695 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014696 ASSERT_VK_SUCCESS(err);
14697
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014698 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014699 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014700 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014701 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014702 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014703 ASSERT_VK_SUCCESS(err);
14704
14705 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14706 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014707 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014708 ASSERT_VK_SUCCESS(err);
14709
14710 BeginCommandBuffer();
14711 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014712 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14713 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014714 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014715 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014716 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014717 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014718 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014719 resolveRegion.srcOffset.x = 0;
14720 resolveRegion.srcOffset.y = 0;
14721 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014722 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014723 resolveRegion.dstSubresource.mipLevel = 0;
14724 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014725 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014726 resolveRegion.dstOffset.x = 0;
14727 resolveRegion.dstOffset.y = 0;
14728 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014729 resolveRegion.extent.width = 1;
14730 resolveRegion.extent.height = 1;
14731 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014732 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014733 EndCommandBuffer();
14734
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014735 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014736
Chia-I Wuf7458c52015-10-26 21:10:41 +080014737 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014738 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014739 vkFreeMemory(m_device->device(), srcMem, NULL);
14740 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014741}
14742
Karl Schultz6addd812016-02-02 17:17:23 -070014743TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14744 VkResult err;
14745 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014746
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14748 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014749
Mike Stroyana3082432015-09-25 13:39:21 -060014750 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014751
14752 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014753 VkImage srcImage;
14754 VkImage dstImage;
14755 VkDeviceMemory srcMem;
14756 VkDeviceMemory destMem;
14757 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014758
14759 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014760 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14761 image_create_info.pNext = NULL;
14762 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14763 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14764 image_create_info.extent.width = 32;
14765 image_create_info.extent.height = 1;
14766 image_create_info.extent.depth = 1;
14767 image_create_info.mipLevels = 1;
14768 image_create_info.arrayLayers = 1;
14769 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14770 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14771 // Note: Some implementations expect color attachment usage for any
14772 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014773 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014774 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014775
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014776 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014777 ASSERT_VK_SUCCESS(err);
14778
Karl Schultz6addd812016-02-02 17:17:23 -070014779 // Set format to something other than source image
14780 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14781 // Note: Some implementations expect color attachment usage for any
14782 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014783 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014784 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014785
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014786 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014787 ASSERT_VK_SUCCESS(err);
14788
14789 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014790 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014791 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14792 memAlloc.pNext = NULL;
14793 memAlloc.allocationSize = 0;
14794 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014795
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014796 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014797 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014798 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014799 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014800 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014801 ASSERT_VK_SUCCESS(err);
14802
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014803 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014804 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014805 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014806 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014807 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014808 ASSERT_VK_SUCCESS(err);
14809
14810 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14811 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014812 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014813 ASSERT_VK_SUCCESS(err);
14814
14815 BeginCommandBuffer();
14816 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014817 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14818 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014819 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014820 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014821 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014822 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014823 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014824 resolveRegion.srcOffset.x = 0;
14825 resolveRegion.srcOffset.y = 0;
14826 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014827 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014828 resolveRegion.dstSubresource.mipLevel = 0;
14829 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014830 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014831 resolveRegion.dstOffset.x = 0;
14832 resolveRegion.dstOffset.y = 0;
14833 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014834 resolveRegion.extent.width = 1;
14835 resolveRegion.extent.height = 1;
14836 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014837 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014838 EndCommandBuffer();
14839
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014840 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014841
Chia-I Wuf7458c52015-10-26 21:10:41 +080014842 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014843 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014844 vkFreeMemory(m_device->device(), srcMem, NULL);
14845 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014846}
14847
Karl Schultz6addd812016-02-02 17:17:23 -070014848TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14849 VkResult err;
14850 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014851
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14853 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014854
Mike Stroyana3082432015-09-25 13:39:21 -060014855 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014856
14857 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014858 VkImage srcImage;
14859 VkImage dstImage;
14860 VkDeviceMemory srcMem;
14861 VkDeviceMemory destMem;
14862 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014863
14864 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014865 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14866 image_create_info.pNext = NULL;
14867 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14868 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14869 image_create_info.extent.width = 32;
14870 image_create_info.extent.height = 1;
14871 image_create_info.extent.depth = 1;
14872 image_create_info.mipLevels = 1;
14873 image_create_info.arrayLayers = 1;
14874 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14875 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14876 // Note: Some implementations expect color attachment usage for any
14877 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014878 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014879 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014880
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014881 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014882 ASSERT_VK_SUCCESS(err);
14883
Karl Schultz6addd812016-02-02 17:17:23 -070014884 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14885 // Note: Some implementations expect color attachment usage for any
14886 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014887 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014888 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014890 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014891 ASSERT_VK_SUCCESS(err);
14892
14893 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014894 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014895 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14896 memAlloc.pNext = NULL;
14897 memAlloc.allocationSize = 0;
14898 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014899
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014900 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014901 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014902 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014903 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014904 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014905 ASSERT_VK_SUCCESS(err);
14906
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014907 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014908 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014909 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014910 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014911 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014912 ASSERT_VK_SUCCESS(err);
14913
14914 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14915 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014916 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014917 ASSERT_VK_SUCCESS(err);
14918
14919 BeginCommandBuffer();
14920 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014921 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14922 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014923 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014924 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014925 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014926 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014927 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014928 resolveRegion.srcOffset.x = 0;
14929 resolveRegion.srcOffset.y = 0;
14930 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014931 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014932 resolveRegion.dstSubresource.mipLevel = 0;
14933 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014934 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014935 resolveRegion.dstOffset.x = 0;
14936 resolveRegion.dstOffset.y = 0;
14937 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014938 resolveRegion.extent.width = 1;
14939 resolveRegion.extent.height = 1;
14940 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014941 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014942 EndCommandBuffer();
14943
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014944 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014945
Chia-I Wuf7458c52015-10-26 21:10:41 +080014946 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014947 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014948 vkFreeMemory(m_device->device(), srcMem, NULL);
14949 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014950}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014951
Karl Schultz6addd812016-02-02 17:17:23 -070014952TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014953 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014954 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14955 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014956 // The image format check comes 2nd in validation so we trigger it first,
14957 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014958 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14961 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014962
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014963 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014964
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014965 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014966 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14967 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014968
14969 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014970 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14971 ds_pool_ci.pNext = NULL;
14972 ds_pool_ci.maxSets = 1;
14973 ds_pool_ci.poolSizeCount = 1;
14974 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014975
14976 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014977 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014978 ASSERT_VK_SUCCESS(err);
14979
14980 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014981 dsl_binding.binding = 0;
14982 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14983 dsl_binding.descriptorCount = 1;
14984 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14985 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014986
14987 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014988 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14989 ds_layout_ci.pNext = NULL;
14990 ds_layout_ci.bindingCount = 1;
14991 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014992 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014993 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014994 ASSERT_VK_SUCCESS(err);
14995
14996 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014997 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080014998 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070014999 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015000 alloc_info.descriptorPool = ds_pool;
15001 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015002 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015003 ASSERT_VK_SUCCESS(err);
15004
Karl Schultz6addd812016-02-02 17:17:23 -070015005 VkImage image_bad;
15006 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015007 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015008 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015009 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015010 const int32_t tex_width = 32;
15011 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015012
15013 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015014 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15015 image_create_info.pNext = NULL;
15016 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15017 image_create_info.format = tex_format_bad;
15018 image_create_info.extent.width = tex_width;
15019 image_create_info.extent.height = tex_height;
15020 image_create_info.extent.depth = 1;
15021 image_create_info.mipLevels = 1;
15022 image_create_info.arrayLayers = 1;
15023 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15024 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015025 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015026 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015028 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015029 ASSERT_VK_SUCCESS(err);
15030 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015031 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15032 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015033 ASSERT_VK_SUCCESS(err);
15034
15035 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015036 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15037 image_view_create_info.image = image_bad;
15038 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15039 image_view_create_info.format = tex_format_bad;
15040 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15041 image_view_create_info.subresourceRange.baseMipLevel = 0;
15042 image_view_create_info.subresourceRange.layerCount = 1;
15043 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015044 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015045
15046 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015047 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015048
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015049 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015050
Chia-I Wuf7458c52015-10-26 21:10:41 +080015051 vkDestroyImage(m_device->device(), image_bad, NULL);
15052 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015053 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15054 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015055}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015056
15057TEST_F(VkLayerTest, ClearImageErrors) {
15058 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15059 "ClearDepthStencilImage with a color image.");
15060
15061 ASSERT_NO_FATAL_FAILURE(InitState());
15062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15063
15064 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15065 BeginCommandBuffer();
15066 m_commandBuffer->EndRenderPass();
15067
15068 // Color image
15069 VkClearColorValue clear_color;
15070 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15071 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15072 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15073 const int32_t img_width = 32;
15074 const int32_t img_height = 32;
15075 VkImageCreateInfo image_create_info = {};
15076 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15077 image_create_info.pNext = NULL;
15078 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15079 image_create_info.format = color_format;
15080 image_create_info.extent.width = img_width;
15081 image_create_info.extent.height = img_height;
15082 image_create_info.extent.depth = 1;
15083 image_create_info.mipLevels = 1;
15084 image_create_info.arrayLayers = 1;
15085 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15086 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15087 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15088
15089 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015090 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015092 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015093
15094 // Depth/Stencil image
15095 VkClearDepthStencilValue clear_value = {0};
15096 reqs = 0; // don't need HOST_VISIBLE DS image
15097 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15098 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15099 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15100 ds_image_create_info.extent.width = 64;
15101 ds_image_create_info.extent.height = 64;
15102 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15103 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15104
15105 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015106 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015108 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 -060015109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015112 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015113 &color_range);
15114
15115 m_errorMonitor->VerifyFound();
15116
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15118 "image created without "
15119 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015121 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015122 &color_range);
15123
15124 m_errorMonitor->VerifyFound();
15125
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015126 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15128 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015130 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15131 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015132
15133 m_errorMonitor->VerifyFound();
15134}
Tobin Ehliscde08892015-09-22 10:11:37 -060015135#endif // IMAGE_TESTS
15136
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015137
15138// WSI Enabled Tests
15139//
15140TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15141
15142#if defined(VK_USE_PLATFORM_XCB_KHR)
15143 VkSurfaceKHR surface = VK_NULL_HANDLE;
15144
15145 VkResult err;
15146 bool pass;
15147 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15148 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15149 // uint32_t swapchain_image_count = 0;
15150 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15151 // uint32_t image_index = 0;
15152 // VkPresentInfoKHR present_info = {};
15153
15154 ASSERT_NO_FATAL_FAILURE(InitState());
15155
15156 // Use the create function from one of the VK_KHR_*_surface extension in
15157 // order to create a surface, testing all known errors in the process,
15158 // before successfully creating a surface:
15159 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15161 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15162 pass = (err != VK_SUCCESS);
15163 ASSERT_TRUE(pass);
15164 m_errorMonitor->VerifyFound();
15165
15166 // Next, try to create a surface with the wrong
15167 // VkXcbSurfaceCreateInfoKHR::sType:
15168 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15169 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15171 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15172 pass = (err != VK_SUCCESS);
15173 ASSERT_TRUE(pass);
15174 m_errorMonitor->VerifyFound();
15175
15176 // Create a native window, and then correctly create a surface:
15177 xcb_connection_t *connection;
15178 xcb_screen_t *screen;
15179 xcb_window_t xcb_window;
15180 xcb_intern_atom_reply_t *atom_wm_delete_window;
15181
15182 const xcb_setup_t *setup;
15183 xcb_screen_iterator_t iter;
15184 int scr;
15185 uint32_t value_mask, value_list[32];
15186 int width = 1;
15187 int height = 1;
15188
15189 connection = xcb_connect(NULL, &scr);
15190 ASSERT_TRUE(connection != NULL);
15191 setup = xcb_get_setup(connection);
15192 iter = xcb_setup_roots_iterator(setup);
15193 while (scr-- > 0)
15194 xcb_screen_next(&iter);
15195 screen = iter.data;
15196
15197 xcb_window = xcb_generate_id(connection);
15198
15199 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15200 value_list[0] = screen->black_pixel;
15201 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15202
15203 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15204 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15205
15206 /* Magic code that will send notification when window is destroyed */
15207 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15208 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15209
15210 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15211 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15212 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15213 free(reply);
15214
15215 xcb_map_window(connection, xcb_window);
15216
15217 // Force the x/y coordinates to 100,100 results are identical in consecutive
15218 // runs
15219 const uint32_t coords[] = { 100, 100 };
15220 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15221
15222 // Finally, try to correctly create a surface:
15223 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15224 xcb_create_info.pNext = NULL;
15225 xcb_create_info.flags = 0;
15226 xcb_create_info.connection = connection;
15227 xcb_create_info.window = xcb_window;
15228 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15229 pass = (err == VK_SUCCESS);
15230 ASSERT_TRUE(pass);
15231
15232 // Check if surface supports presentation:
15233
15234 // 1st, do so without having queried the queue families:
15235 VkBool32 supported = false;
15236 // TODO: Get the following error to come out:
15237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15238 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15239 "function");
15240 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15241 pass = (err != VK_SUCCESS);
15242 // ASSERT_TRUE(pass);
15243 // m_errorMonitor->VerifyFound();
15244
15245 // Next, query a queue family index that's too large:
15246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15247 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15248 pass = (err != VK_SUCCESS);
15249 ASSERT_TRUE(pass);
15250 m_errorMonitor->VerifyFound();
15251
15252 // Finally, do so correctly:
15253 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15254 // SUPPORTED
15255 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15256 pass = (err == VK_SUCCESS);
15257 ASSERT_TRUE(pass);
15258
15259 // Before proceeding, try to create a swapchain without having called
15260 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15261 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15262 swapchain_create_info.pNext = NULL;
15263 swapchain_create_info.flags = 0;
15264 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15265 swapchain_create_info.surface = surface;
15266 swapchain_create_info.imageArrayLayers = 1;
15267 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15268 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15270 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15271 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15272 pass = (err != VK_SUCCESS);
15273 ASSERT_TRUE(pass);
15274 m_errorMonitor->VerifyFound();
15275
15276 // Get the surface capabilities:
15277 VkSurfaceCapabilitiesKHR surface_capabilities;
15278
15279 // Do so correctly (only error logged by this entrypoint is if the
15280 // extension isn't enabled):
15281 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15282 pass = (err == VK_SUCCESS);
15283 ASSERT_TRUE(pass);
15284
15285 // Get the surface formats:
15286 uint32_t surface_format_count;
15287
15288 // First, try without a pointer to surface_format_count:
15289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15290 "specified as NULL");
15291 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15292 pass = (err == VK_SUCCESS);
15293 ASSERT_TRUE(pass);
15294 m_errorMonitor->VerifyFound();
15295
15296 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15297 // correctly done a 1st try (to get the count):
15298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15299 surface_format_count = 0;
15300 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15301 pass = (err == VK_SUCCESS);
15302 ASSERT_TRUE(pass);
15303 m_errorMonitor->VerifyFound();
15304
15305 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15306 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15307 pass = (err == VK_SUCCESS);
15308 ASSERT_TRUE(pass);
15309
15310 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15311 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15312
15313 // Next, do a 2nd try with surface_format_count being set too high:
15314 surface_format_count += 5;
15315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15316 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15317 pass = (err == VK_SUCCESS);
15318 ASSERT_TRUE(pass);
15319 m_errorMonitor->VerifyFound();
15320
15321 // Finally, do a correct 1st and 2nd try:
15322 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15323 pass = (err == VK_SUCCESS);
15324 ASSERT_TRUE(pass);
15325 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15326 pass = (err == VK_SUCCESS);
15327 ASSERT_TRUE(pass);
15328
15329 // Get the surface present modes:
15330 uint32_t surface_present_mode_count;
15331
15332 // First, try without a pointer to surface_format_count:
15333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15334 "specified as NULL");
15335
15336 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15337 pass = (err == VK_SUCCESS);
15338 ASSERT_TRUE(pass);
15339 m_errorMonitor->VerifyFound();
15340
15341 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15342 // correctly done a 1st try (to get the count):
15343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15344 surface_present_mode_count = 0;
15345 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15346 (VkPresentModeKHR *)&surface_present_mode_count);
15347 pass = (err == VK_SUCCESS);
15348 ASSERT_TRUE(pass);
15349 m_errorMonitor->VerifyFound();
15350
15351 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15352 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15353 pass = (err == VK_SUCCESS);
15354 ASSERT_TRUE(pass);
15355
15356 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15357 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15358
15359 // Next, do a 2nd try with surface_format_count being set too high:
15360 surface_present_mode_count += 5;
15361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15362 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15363 pass = (err == VK_SUCCESS);
15364 ASSERT_TRUE(pass);
15365 m_errorMonitor->VerifyFound();
15366
15367 // Finally, do a correct 1st and 2nd try:
15368 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15369 pass = (err == VK_SUCCESS);
15370 ASSERT_TRUE(pass);
15371 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15372 pass = (err == VK_SUCCESS);
15373 ASSERT_TRUE(pass);
15374
15375 // Create a swapchain:
15376
15377 // First, try without a pointer to swapchain_create_info:
15378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15379 "specified as NULL");
15380
15381 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15382 pass = (err != VK_SUCCESS);
15383 ASSERT_TRUE(pass);
15384 m_errorMonitor->VerifyFound();
15385
15386 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15387 // sType:
15388 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15390
15391 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15392 pass = (err != VK_SUCCESS);
15393 ASSERT_TRUE(pass);
15394 m_errorMonitor->VerifyFound();
15395
15396 // Next, call with a NULL swapchain pointer:
15397 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15398 swapchain_create_info.pNext = NULL;
15399 swapchain_create_info.flags = 0;
15400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15401 "specified as NULL");
15402
15403 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15404 pass = (err != VK_SUCCESS);
15405 ASSERT_TRUE(pass);
15406 m_errorMonitor->VerifyFound();
15407
15408 // TODO: Enhance swapchain layer so that
15409 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15410
15411 // Next, call with a queue family index that's too large:
15412 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15413 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15414 swapchain_create_info.queueFamilyIndexCount = 2;
15415 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15417 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15418 pass = (err != VK_SUCCESS);
15419 ASSERT_TRUE(pass);
15420 m_errorMonitor->VerifyFound();
15421
15422 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15423 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15424 swapchain_create_info.queueFamilyIndexCount = 1;
15425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15426 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15427 "pCreateInfo->pQueueFamilyIndices).");
15428 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15429 pass = (err != VK_SUCCESS);
15430 ASSERT_TRUE(pass);
15431 m_errorMonitor->VerifyFound();
15432
15433 // Next, call with an invalid imageSharingMode:
15434 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15435 swapchain_create_info.queueFamilyIndexCount = 1;
15436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15437 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15438 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15439 pass = (err != VK_SUCCESS);
15440 ASSERT_TRUE(pass);
15441 m_errorMonitor->VerifyFound();
15442 // Fix for the future:
15443 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15444 // SUPPORTED
15445 swapchain_create_info.queueFamilyIndexCount = 0;
15446 queueFamilyIndex[0] = 0;
15447 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15448
15449 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15450 // Get the images from a swapchain:
15451 // Acquire an image from a swapchain:
15452 // Present an image to a swapchain:
15453 // Destroy the swapchain:
15454
15455 // TODOs:
15456 //
15457 // - Try destroying the device without first destroying the swapchain
15458 //
15459 // - Try destroying the device without first destroying the surface
15460 //
15461 // - Try destroying the surface without first destroying the swapchain
15462
15463 // Destroy the surface:
15464 vkDestroySurfaceKHR(instance(), surface, NULL);
15465
15466 // Tear down the window:
15467 xcb_destroy_window(connection, xcb_window);
15468 xcb_disconnect(connection);
15469
15470#else // VK_USE_PLATFORM_XCB_KHR
15471 return;
15472#endif // VK_USE_PLATFORM_XCB_KHR
15473}
15474
15475//
15476// POSITIVE VALIDATION TESTS
15477//
15478// These tests do not expect to encounter ANY validation errors pass only if this is true
15479
Tobin Ehlise0006882016-11-03 10:14:28 -060015480TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15481 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15482 "by a transition in the primary.");
15483 VkResult err;
15484 m_errorMonitor->ExpectSuccess();
15485 ASSERT_NO_FATAL_FAILURE(InitState());
15486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15487 // Allocate a secondary and primary cmd buffer
15488 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15489 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15490 command_buffer_allocate_info.commandPool = m_commandPool;
15491 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15492 command_buffer_allocate_info.commandBufferCount = 1;
15493
15494 VkCommandBuffer secondary_command_buffer;
15495 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15496 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15497 VkCommandBuffer primary_command_buffer;
15498 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15499 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15500 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15501 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15502 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15503 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15504 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15505
15506 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15507 ASSERT_VK_SUCCESS(err);
15508 VkImageObj image(m_device);
15509 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15510 ASSERT_TRUE(image.initialized());
15511 VkImageMemoryBarrier img_barrier = {};
15512 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15513 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15514 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15515 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15516 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15517 img_barrier.image = image.handle();
15518 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15519 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15520 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15521 img_barrier.subresourceRange.baseArrayLayer = 0;
15522 img_barrier.subresourceRange.baseMipLevel = 0;
15523 img_barrier.subresourceRange.layerCount = 1;
15524 img_barrier.subresourceRange.levelCount = 1;
15525 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15526 0, nullptr, 1, &img_barrier);
15527 err = vkEndCommandBuffer(secondary_command_buffer);
15528 ASSERT_VK_SUCCESS(err);
15529
15530 // Now update primary cmd buffer to execute secondary and transitions image
15531 command_buffer_begin_info.pInheritanceInfo = nullptr;
15532 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15533 ASSERT_VK_SUCCESS(err);
15534 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15535 VkImageMemoryBarrier img_barrier2 = {};
15536 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15537 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15538 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15539 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15540 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15541 img_barrier2.image = image.handle();
15542 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15543 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15544 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15545 img_barrier2.subresourceRange.baseArrayLayer = 0;
15546 img_barrier2.subresourceRange.baseMipLevel = 0;
15547 img_barrier2.subresourceRange.layerCount = 1;
15548 img_barrier2.subresourceRange.levelCount = 1;
15549 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15550 nullptr, 1, &img_barrier2);
15551 err = vkEndCommandBuffer(primary_command_buffer);
15552 ASSERT_VK_SUCCESS(err);
15553 VkSubmitInfo submit_info = {};
15554 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15555 submit_info.commandBufferCount = 1;
15556 submit_info.pCommandBuffers = &primary_command_buffer;
15557 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15558 ASSERT_VK_SUCCESS(err);
15559 m_errorMonitor->VerifyNotFound();
15560 err = vkDeviceWaitIdle(m_device->device());
15561 ASSERT_VK_SUCCESS(err);
15562 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15563 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15564}
15565
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015566// This is a positive test. No failures are expected.
15567TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15568 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15569 "is ignoring VkWriteDescriptorSet members that are not "
15570 "related to the descriptor type specified by "
15571 "VkWriteDescriptorSet::descriptorType. Correct "
15572 "validation behavior will result in the test running to "
15573 "completion without validation errors.");
15574
15575 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15576
15577 ASSERT_NO_FATAL_FAILURE(InitState());
15578
15579 // Image Case
15580 {
15581 m_errorMonitor->ExpectSuccess();
15582
15583 VkImage image;
15584 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15585 const int32_t tex_width = 32;
15586 const int32_t tex_height = 32;
15587 VkImageCreateInfo image_create_info = {};
15588 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15589 image_create_info.pNext = NULL;
15590 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15591 image_create_info.format = tex_format;
15592 image_create_info.extent.width = tex_width;
15593 image_create_info.extent.height = tex_height;
15594 image_create_info.extent.depth = 1;
15595 image_create_info.mipLevels = 1;
15596 image_create_info.arrayLayers = 1;
15597 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15598 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15599 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15600 image_create_info.flags = 0;
15601 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15602 ASSERT_VK_SUCCESS(err);
15603
15604 VkMemoryRequirements memory_reqs;
15605 VkDeviceMemory image_memory;
15606 bool pass;
15607 VkMemoryAllocateInfo memory_info = {};
15608 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15609 memory_info.pNext = NULL;
15610 memory_info.allocationSize = 0;
15611 memory_info.memoryTypeIndex = 0;
15612 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15613 memory_info.allocationSize = memory_reqs.size;
15614 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15615 ASSERT_TRUE(pass);
15616 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15617 ASSERT_VK_SUCCESS(err);
15618 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15619 ASSERT_VK_SUCCESS(err);
15620
15621 VkImageViewCreateInfo image_view_create_info = {};
15622 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15623 image_view_create_info.image = image;
15624 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15625 image_view_create_info.format = tex_format;
15626 image_view_create_info.subresourceRange.layerCount = 1;
15627 image_view_create_info.subresourceRange.baseMipLevel = 0;
15628 image_view_create_info.subresourceRange.levelCount = 1;
15629 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15630
15631 VkImageView view;
15632 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15633 ASSERT_VK_SUCCESS(err);
15634
15635 VkDescriptorPoolSize ds_type_count = {};
15636 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15637 ds_type_count.descriptorCount = 1;
15638
15639 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15640 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15641 ds_pool_ci.pNext = NULL;
15642 ds_pool_ci.maxSets = 1;
15643 ds_pool_ci.poolSizeCount = 1;
15644 ds_pool_ci.pPoolSizes = &ds_type_count;
15645
15646 VkDescriptorPool ds_pool;
15647 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15648 ASSERT_VK_SUCCESS(err);
15649
15650 VkDescriptorSetLayoutBinding dsl_binding = {};
15651 dsl_binding.binding = 0;
15652 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15653 dsl_binding.descriptorCount = 1;
15654 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15655 dsl_binding.pImmutableSamplers = NULL;
15656
15657 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15658 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15659 ds_layout_ci.pNext = NULL;
15660 ds_layout_ci.bindingCount = 1;
15661 ds_layout_ci.pBindings = &dsl_binding;
15662 VkDescriptorSetLayout ds_layout;
15663 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15664 ASSERT_VK_SUCCESS(err);
15665
15666 VkDescriptorSet descriptor_set;
15667 VkDescriptorSetAllocateInfo alloc_info = {};
15668 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15669 alloc_info.descriptorSetCount = 1;
15670 alloc_info.descriptorPool = ds_pool;
15671 alloc_info.pSetLayouts = &ds_layout;
15672 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15673 ASSERT_VK_SUCCESS(err);
15674
15675 VkDescriptorImageInfo image_info = {};
15676 image_info.imageView = view;
15677 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15678
15679 VkWriteDescriptorSet descriptor_write;
15680 memset(&descriptor_write, 0, sizeof(descriptor_write));
15681 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15682 descriptor_write.dstSet = descriptor_set;
15683 descriptor_write.dstBinding = 0;
15684 descriptor_write.descriptorCount = 1;
15685 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15686 descriptor_write.pImageInfo = &image_info;
15687
15688 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15689 // be
15690 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15691 // This will most likely produce a crash if the parameter_validation
15692 // layer
15693 // does not correctly ignore pBufferInfo.
15694 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15695 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15696
15697 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15698
15699 m_errorMonitor->VerifyNotFound();
15700
15701 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15702 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15703 vkDestroyImageView(m_device->device(), view, NULL);
15704 vkDestroyImage(m_device->device(), image, NULL);
15705 vkFreeMemory(m_device->device(), image_memory, NULL);
15706 }
15707
15708 // Buffer Case
15709 {
15710 m_errorMonitor->ExpectSuccess();
15711
15712 VkBuffer buffer;
15713 uint32_t queue_family_index = 0;
15714 VkBufferCreateInfo buffer_create_info = {};
15715 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15716 buffer_create_info.size = 1024;
15717 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15718 buffer_create_info.queueFamilyIndexCount = 1;
15719 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15720
15721 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15722 ASSERT_VK_SUCCESS(err);
15723
15724 VkMemoryRequirements memory_reqs;
15725 VkDeviceMemory buffer_memory;
15726 bool pass;
15727 VkMemoryAllocateInfo memory_info = {};
15728 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15729 memory_info.pNext = NULL;
15730 memory_info.allocationSize = 0;
15731 memory_info.memoryTypeIndex = 0;
15732
15733 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15734 memory_info.allocationSize = memory_reqs.size;
15735 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15736 ASSERT_TRUE(pass);
15737
15738 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15739 ASSERT_VK_SUCCESS(err);
15740 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15741 ASSERT_VK_SUCCESS(err);
15742
15743 VkDescriptorPoolSize ds_type_count = {};
15744 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15745 ds_type_count.descriptorCount = 1;
15746
15747 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15748 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15749 ds_pool_ci.pNext = NULL;
15750 ds_pool_ci.maxSets = 1;
15751 ds_pool_ci.poolSizeCount = 1;
15752 ds_pool_ci.pPoolSizes = &ds_type_count;
15753
15754 VkDescriptorPool ds_pool;
15755 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15756 ASSERT_VK_SUCCESS(err);
15757
15758 VkDescriptorSetLayoutBinding dsl_binding = {};
15759 dsl_binding.binding = 0;
15760 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15761 dsl_binding.descriptorCount = 1;
15762 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15763 dsl_binding.pImmutableSamplers = NULL;
15764
15765 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15766 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15767 ds_layout_ci.pNext = NULL;
15768 ds_layout_ci.bindingCount = 1;
15769 ds_layout_ci.pBindings = &dsl_binding;
15770 VkDescriptorSetLayout ds_layout;
15771 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15772 ASSERT_VK_SUCCESS(err);
15773
15774 VkDescriptorSet descriptor_set;
15775 VkDescriptorSetAllocateInfo alloc_info = {};
15776 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15777 alloc_info.descriptorSetCount = 1;
15778 alloc_info.descriptorPool = ds_pool;
15779 alloc_info.pSetLayouts = &ds_layout;
15780 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15781 ASSERT_VK_SUCCESS(err);
15782
15783 VkDescriptorBufferInfo buffer_info = {};
15784 buffer_info.buffer = buffer;
15785 buffer_info.offset = 0;
15786 buffer_info.range = 1024;
15787
15788 VkWriteDescriptorSet descriptor_write;
15789 memset(&descriptor_write, 0, sizeof(descriptor_write));
15790 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15791 descriptor_write.dstSet = descriptor_set;
15792 descriptor_write.dstBinding = 0;
15793 descriptor_write.descriptorCount = 1;
15794 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15795 descriptor_write.pBufferInfo = &buffer_info;
15796
15797 // Set pImageInfo and pTexelBufferView to invalid values, which should
15798 // be
15799 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15800 // This will most likely produce a crash if the parameter_validation
15801 // layer
15802 // does not correctly ignore pImageInfo.
15803 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15804 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15805
15806 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15807
15808 m_errorMonitor->VerifyNotFound();
15809
15810 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15811 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15812 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15813 vkDestroyBuffer(m_device->device(), buffer, NULL);
15814 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15815 }
15816
15817 // Texel Buffer Case
15818 {
15819 m_errorMonitor->ExpectSuccess();
15820
15821 VkBuffer buffer;
15822 uint32_t queue_family_index = 0;
15823 VkBufferCreateInfo buffer_create_info = {};
15824 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15825 buffer_create_info.size = 1024;
15826 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15827 buffer_create_info.queueFamilyIndexCount = 1;
15828 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15829
15830 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15831 ASSERT_VK_SUCCESS(err);
15832
15833 VkMemoryRequirements memory_reqs;
15834 VkDeviceMemory buffer_memory;
15835 bool pass;
15836 VkMemoryAllocateInfo memory_info = {};
15837 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15838 memory_info.pNext = NULL;
15839 memory_info.allocationSize = 0;
15840 memory_info.memoryTypeIndex = 0;
15841
15842 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15843 memory_info.allocationSize = memory_reqs.size;
15844 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15845 ASSERT_TRUE(pass);
15846
15847 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15848 ASSERT_VK_SUCCESS(err);
15849 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15850 ASSERT_VK_SUCCESS(err);
15851
15852 VkBufferViewCreateInfo buff_view_ci = {};
15853 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15854 buff_view_ci.buffer = buffer;
15855 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15856 buff_view_ci.range = VK_WHOLE_SIZE;
15857 VkBufferView buffer_view;
15858 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15859
15860 VkDescriptorPoolSize ds_type_count = {};
15861 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15862 ds_type_count.descriptorCount = 1;
15863
15864 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15865 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15866 ds_pool_ci.pNext = NULL;
15867 ds_pool_ci.maxSets = 1;
15868 ds_pool_ci.poolSizeCount = 1;
15869 ds_pool_ci.pPoolSizes = &ds_type_count;
15870
15871 VkDescriptorPool ds_pool;
15872 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15873 ASSERT_VK_SUCCESS(err);
15874
15875 VkDescriptorSetLayoutBinding dsl_binding = {};
15876 dsl_binding.binding = 0;
15877 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15878 dsl_binding.descriptorCount = 1;
15879 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15880 dsl_binding.pImmutableSamplers = NULL;
15881
15882 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15883 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15884 ds_layout_ci.pNext = NULL;
15885 ds_layout_ci.bindingCount = 1;
15886 ds_layout_ci.pBindings = &dsl_binding;
15887 VkDescriptorSetLayout ds_layout;
15888 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15889 ASSERT_VK_SUCCESS(err);
15890
15891 VkDescriptorSet descriptor_set;
15892 VkDescriptorSetAllocateInfo alloc_info = {};
15893 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15894 alloc_info.descriptorSetCount = 1;
15895 alloc_info.descriptorPool = ds_pool;
15896 alloc_info.pSetLayouts = &ds_layout;
15897 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15898 ASSERT_VK_SUCCESS(err);
15899
15900 VkWriteDescriptorSet descriptor_write;
15901 memset(&descriptor_write, 0, sizeof(descriptor_write));
15902 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15903 descriptor_write.dstSet = descriptor_set;
15904 descriptor_write.dstBinding = 0;
15905 descriptor_write.descriptorCount = 1;
15906 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15907 descriptor_write.pTexelBufferView = &buffer_view;
15908
15909 // Set pImageInfo and pBufferInfo to invalid values, which should be
15910 // ignored for descriptorType ==
15911 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15912 // This will most likely produce a crash if the parameter_validation
15913 // layer
15914 // does not correctly ignore pImageInfo and pBufferInfo.
15915 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15916 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15917
15918 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15919
15920 m_errorMonitor->VerifyNotFound();
15921
15922 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15923 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15924 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15925 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15926 vkDestroyBuffer(m_device->device(), buffer, NULL);
15927 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15928 }
15929}
15930
Tobin Ehlisf7428442016-10-25 07:58:24 -060015931TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
15932 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
15933
15934 ASSERT_NO_FATAL_FAILURE(InitState());
15935 // Create layout where two binding #s are "1"
15936 static const uint32_t NUM_BINDINGS = 3;
15937 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15938 dsl_binding[0].binding = 1;
15939 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15940 dsl_binding[0].descriptorCount = 1;
15941 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15942 dsl_binding[0].pImmutableSamplers = NULL;
15943 dsl_binding[1].binding = 0;
15944 dsl_binding[1].descriptorCount = 1;
15945 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15946 dsl_binding[1].descriptorCount = 1;
15947 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15948 dsl_binding[1].pImmutableSamplers = NULL;
15949 dsl_binding[2].binding = 1; // Duplicate binding should cause error
15950 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15951 dsl_binding[2].descriptorCount = 1;
15952 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15953 dsl_binding[2].pImmutableSamplers = NULL;
15954
15955 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15956 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15957 ds_layout_ci.pNext = NULL;
15958 ds_layout_ci.bindingCount = NUM_BINDINGS;
15959 ds_layout_ci.pBindings = dsl_binding;
15960 VkDescriptorSetLayout ds_layout;
15961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
15962 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15963 m_errorMonitor->VerifyFound();
15964}
15965
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015966TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015967 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
15968
15969 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015970
15971 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015972
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015973 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
15974
15975 {
15976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
15977 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
15978 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15979 m_errorMonitor->VerifyFound();
15980 }
15981
15982 {
15983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
15984 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
15985 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15986 m_errorMonitor->VerifyFound();
15987 }
15988
15989 {
15990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15991 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
15992 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15993 m_errorMonitor->VerifyFound();
15994 }
15995
15996 {
15997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15998 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
15999 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16000 m_errorMonitor->VerifyFound();
16001 }
16002
16003 {
16004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16005 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16006 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16007 m_errorMonitor->VerifyFound();
16008 }
16009
16010 {
16011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16012 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16013 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16014 m_errorMonitor->VerifyFound();
16015 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016016
16017 {
16018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16019 VkRect2D scissor = {{-1, 0}, {16, 16}};
16020 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16021 m_errorMonitor->VerifyFound();
16022 }
16023
16024 {
16025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16026 VkRect2D scissor = {{0, -2}, {16, 16}};
16027 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16028 m_errorMonitor->VerifyFound();
16029 }
16030
16031 {
16032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16033 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16034 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16035 m_errorMonitor->VerifyFound();
16036 }
16037
16038 {
16039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16040 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16041 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16042 m_errorMonitor->VerifyFound();
16043 }
16044
16045 EndCommandBuffer();
16046}
16047
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016048// This is a positive test. No failures are expected.
16049TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16050 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16051 VkResult err;
16052
16053 ASSERT_NO_FATAL_FAILURE(InitState());
16054 m_errorMonitor->ExpectSuccess();
16055 VkDescriptorPoolSize ds_type_count = {};
16056 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16057 ds_type_count.descriptorCount = 2;
16058
16059 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16060 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16061 ds_pool_ci.pNext = NULL;
16062 ds_pool_ci.maxSets = 1;
16063 ds_pool_ci.poolSizeCount = 1;
16064 ds_pool_ci.pPoolSizes = &ds_type_count;
16065
16066 VkDescriptorPool ds_pool;
16067 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16068 ASSERT_VK_SUCCESS(err);
16069
16070 // Create layout with two uniform buffer descriptors w/ empty binding between them
16071 static const uint32_t NUM_BINDINGS = 3;
16072 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16073 dsl_binding[0].binding = 0;
16074 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16075 dsl_binding[0].descriptorCount = 1;
16076 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16077 dsl_binding[0].pImmutableSamplers = NULL;
16078 dsl_binding[1].binding = 1;
16079 dsl_binding[1].descriptorCount = 0; // empty binding
16080 dsl_binding[2].binding = 2;
16081 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16082 dsl_binding[2].descriptorCount = 1;
16083 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16084 dsl_binding[2].pImmutableSamplers = NULL;
16085
16086 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16087 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16088 ds_layout_ci.pNext = NULL;
16089 ds_layout_ci.bindingCount = NUM_BINDINGS;
16090 ds_layout_ci.pBindings = dsl_binding;
16091 VkDescriptorSetLayout ds_layout;
16092 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16093 ASSERT_VK_SUCCESS(err);
16094
16095 VkDescriptorSet descriptor_set = {};
16096 VkDescriptorSetAllocateInfo alloc_info = {};
16097 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16098 alloc_info.descriptorSetCount = 1;
16099 alloc_info.descriptorPool = ds_pool;
16100 alloc_info.pSetLayouts = &ds_layout;
16101 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16102 ASSERT_VK_SUCCESS(err);
16103
16104 // Create a buffer to be used for update
16105 VkBufferCreateInfo buff_ci = {};
16106 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16107 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16108 buff_ci.size = 256;
16109 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16110 VkBuffer buffer;
16111 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16112 ASSERT_VK_SUCCESS(err);
16113 // Have to bind memory to buffer before descriptor update
16114 VkMemoryAllocateInfo mem_alloc = {};
16115 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16116 mem_alloc.pNext = NULL;
16117 mem_alloc.allocationSize = 512; // one allocation for both buffers
16118 mem_alloc.memoryTypeIndex = 0;
16119
16120 VkMemoryRequirements mem_reqs;
16121 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16122 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16123 if (!pass) {
16124 vkDestroyBuffer(m_device->device(), buffer, NULL);
16125 return;
16126 }
16127
16128 VkDeviceMemory mem;
16129 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16130 ASSERT_VK_SUCCESS(err);
16131 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16132 ASSERT_VK_SUCCESS(err);
16133
16134 // Only update the descriptor at binding 2
16135 VkDescriptorBufferInfo buff_info = {};
16136 buff_info.buffer = buffer;
16137 buff_info.offset = 0;
16138 buff_info.range = VK_WHOLE_SIZE;
16139 VkWriteDescriptorSet descriptor_write = {};
16140 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16141 descriptor_write.dstBinding = 2;
16142 descriptor_write.descriptorCount = 1;
16143 descriptor_write.pTexelBufferView = nullptr;
16144 descriptor_write.pBufferInfo = &buff_info;
16145 descriptor_write.pImageInfo = nullptr;
16146 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16147 descriptor_write.dstSet = descriptor_set;
16148
16149 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16150
16151 m_errorMonitor->VerifyNotFound();
16152 // Cleanup
16153 vkFreeMemory(m_device->device(), mem, NULL);
16154 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16155 vkDestroyBuffer(m_device->device(), buffer, NULL);
16156 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16157}
16158
16159// This is a positive test. No failures are expected.
16160TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16161 VkResult err;
16162 bool pass;
16163
16164 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16165 "the buffer, create an image, and bind the same memory to "
16166 "it");
16167
16168 m_errorMonitor->ExpectSuccess();
16169
16170 ASSERT_NO_FATAL_FAILURE(InitState());
16171
16172 VkBuffer buffer;
16173 VkImage image;
16174 VkDeviceMemory mem;
16175 VkMemoryRequirements mem_reqs;
16176
16177 VkBufferCreateInfo buf_info = {};
16178 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16179 buf_info.pNext = NULL;
16180 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16181 buf_info.size = 256;
16182 buf_info.queueFamilyIndexCount = 0;
16183 buf_info.pQueueFamilyIndices = NULL;
16184 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16185 buf_info.flags = 0;
16186 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16187 ASSERT_VK_SUCCESS(err);
16188
16189 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16190
16191 VkMemoryAllocateInfo alloc_info = {};
16192 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16193 alloc_info.pNext = NULL;
16194 alloc_info.memoryTypeIndex = 0;
16195
16196 // Ensure memory is big enough for both bindings
16197 alloc_info.allocationSize = 0x10000;
16198
16199 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16200 if (!pass) {
16201 vkDestroyBuffer(m_device->device(), buffer, NULL);
16202 return;
16203 }
16204
16205 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16206 ASSERT_VK_SUCCESS(err);
16207
16208 uint8_t *pData;
16209 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16210 ASSERT_VK_SUCCESS(err);
16211
16212 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16213
16214 vkUnmapMemory(m_device->device(), mem);
16215
16216 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16217 ASSERT_VK_SUCCESS(err);
16218
16219 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16220 // memory. In fact, it was never used by the GPU.
16221 // Just be be sure, wait for idle.
16222 vkDestroyBuffer(m_device->device(), buffer, NULL);
16223 vkDeviceWaitIdle(m_device->device());
16224
16225 VkImageCreateInfo image_create_info = {};
16226 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16227 image_create_info.pNext = NULL;
16228 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16229 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16230 image_create_info.extent.width = 64;
16231 image_create_info.extent.height = 64;
16232 image_create_info.extent.depth = 1;
16233 image_create_info.mipLevels = 1;
16234 image_create_info.arrayLayers = 1;
16235 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16236 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16237 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16238 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16239 image_create_info.queueFamilyIndexCount = 0;
16240 image_create_info.pQueueFamilyIndices = NULL;
16241 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16242 image_create_info.flags = 0;
16243
16244 VkMemoryAllocateInfo mem_alloc = {};
16245 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16246 mem_alloc.pNext = NULL;
16247 mem_alloc.allocationSize = 0;
16248 mem_alloc.memoryTypeIndex = 0;
16249
16250 /* Create a mappable image. It will be the texture if linear images are ok
16251 * to be textures or it will be the staging image if they are not.
16252 */
16253 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16254 ASSERT_VK_SUCCESS(err);
16255
16256 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16257
16258 mem_alloc.allocationSize = mem_reqs.size;
16259
16260 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16261 if (!pass) {
16262 vkDestroyImage(m_device->device(), image, NULL);
16263 return;
16264 }
16265
16266 // VALIDATION FAILURE:
16267 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16268 ASSERT_VK_SUCCESS(err);
16269
16270 m_errorMonitor->VerifyNotFound();
16271
16272 vkFreeMemory(m_device->device(), mem, NULL);
16273 vkDestroyBuffer(m_device->device(), buffer, NULL);
16274 vkDestroyImage(m_device->device(), image, NULL);
16275}
16276
Tobin Ehlis953e8392016-11-17 10:54:13 -070016277TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16278 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16279 // We previously had a bug where dynamic offset of inactive bindings was still being used
16280 VkResult err;
16281 m_errorMonitor->ExpectSuccess();
16282
16283 ASSERT_NO_FATAL_FAILURE(InitState());
16284 ASSERT_NO_FATAL_FAILURE(InitViewport());
16285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16286
16287 VkDescriptorPoolSize ds_type_count = {};
16288 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16289 ds_type_count.descriptorCount = 3;
16290
16291 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16292 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16293 ds_pool_ci.pNext = NULL;
16294 ds_pool_ci.maxSets = 1;
16295 ds_pool_ci.poolSizeCount = 1;
16296 ds_pool_ci.pPoolSizes = &ds_type_count;
16297
16298 VkDescriptorPool ds_pool;
16299 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16300 ASSERT_VK_SUCCESS(err);
16301
16302 const uint32_t BINDING_COUNT = 3;
16303 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
16304 dsl_binding[0].binding = 0;
16305 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16306 dsl_binding[0].descriptorCount = 1;
16307 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16308 dsl_binding[0].pImmutableSamplers = NULL;
16309 dsl_binding[1].binding = 1;
16310 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16311 dsl_binding[1].descriptorCount = 1;
16312 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16313 dsl_binding[1].pImmutableSamplers = NULL;
16314 dsl_binding[2].binding = 2;
16315 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16316 dsl_binding[2].descriptorCount = 1;
16317 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16318 dsl_binding[2].pImmutableSamplers = NULL;
16319
16320 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16321 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16322 ds_layout_ci.pNext = NULL;
16323 ds_layout_ci.bindingCount = BINDING_COUNT;
16324 ds_layout_ci.pBindings = dsl_binding;
16325 VkDescriptorSetLayout ds_layout;
16326 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16327 ASSERT_VK_SUCCESS(err);
16328
16329 VkDescriptorSet descriptor_set;
16330 VkDescriptorSetAllocateInfo alloc_info = {};
16331 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16332 alloc_info.descriptorSetCount = 1;
16333 alloc_info.descriptorPool = ds_pool;
16334 alloc_info.pSetLayouts = &ds_layout;
16335 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16336 ASSERT_VK_SUCCESS(err);
16337
16338 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16339 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16340 pipeline_layout_ci.pNext = NULL;
16341 pipeline_layout_ci.setLayoutCount = 1;
16342 pipeline_layout_ci.pSetLayouts = &ds_layout;
16343
16344 VkPipelineLayout pipeline_layout;
16345 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16346 ASSERT_VK_SUCCESS(err);
16347
16348 // Create two buffers to update the descriptors with
16349 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16350 uint32_t qfi = 0;
16351 VkBufferCreateInfo buffCI = {};
16352 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16353 buffCI.size = 2048;
16354 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16355 buffCI.queueFamilyIndexCount = 1;
16356 buffCI.pQueueFamilyIndices = &qfi;
16357
16358 VkBuffer dyub1;
16359 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16360 ASSERT_VK_SUCCESS(err);
16361 // buffer2
16362 buffCI.size = 1024;
16363 VkBuffer dyub2;
16364 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16365 ASSERT_VK_SUCCESS(err);
16366 // Allocate memory and bind to buffers
16367 VkMemoryAllocateInfo mem_alloc[2] = {};
16368 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16369 mem_alloc[0].pNext = NULL;
16370 mem_alloc[0].memoryTypeIndex = 0;
16371 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16372 mem_alloc[1].pNext = NULL;
16373 mem_alloc[1].memoryTypeIndex = 0;
16374
16375 VkMemoryRequirements mem_reqs1;
16376 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16377 VkMemoryRequirements mem_reqs2;
16378 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16379 mem_alloc[0].allocationSize = mem_reqs1.size;
16380 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16381 mem_alloc[1].allocationSize = mem_reqs2.size;
16382 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16383 if (!pass) {
16384 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16385 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16386 return;
16387 }
16388
16389 VkDeviceMemory mem1;
16390 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16391 ASSERT_VK_SUCCESS(err);
16392 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16393 ASSERT_VK_SUCCESS(err);
16394 VkDeviceMemory mem2;
16395 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16396 ASSERT_VK_SUCCESS(err);
16397 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16398 ASSERT_VK_SUCCESS(err);
16399 // Update descriptors
16400 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16401 buff_info[0].buffer = dyub1;
16402 buff_info[0].offset = 0;
16403 buff_info[0].range = 256;
16404 buff_info[1].buffer = dyub1;
16405 buff_info[1].offset = 256;
16406 buff_info[1].range = 512;
16407 buff_info[2].buffer = dyub2;
16408 buff_info[2].offset = 0;
16409 buff_info[2].range = 512;
16410
16411 VkWriteDescriptorSet descriptor_write;
16412 memset(&descriptor_write, 0, sizeof(descriptor_write));
16413 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16414 descriptor_write.dstSet = descriptor_set;
16415 descriptor_write.dstBinding = 0;
16416 descriptor_write.descriptorCount = BINDING_COUNT;
16417 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16418 descriptor_write.pBufferInfo = buff_info;
16419
16420 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16421
16422 BeginCommandBuffer();
16423
16424 // Create PSO to be used for draw-time errors below
16425 char const *vsSource = "#version 450\n"
16426 "\n"
16427 "out gl_PerVertex { \n"
16428 " vec4 gl_Position;\n"
16429 "};\n"
16430 "void main(){\n"
16431 " gl_Position = vec4(1);\n"
16432 "}\n";
16433 char const *fsSource = "#version 450\n"
16434 "\n"
16435 "layout(location=0) out vec4 x;\n"
16436 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16437 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16438 "void main(){\n"
16439 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16440 "}\n";
16441 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16442 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16443 VkPipelineObj pipe(m_device);
16444 pipe.SetViewport(m_viewports);
16445 pipe.SetScissor(m_scissors);
16446 pipe.AddShader(&vs);
16447 pipe.AddShader(&fs);
16448 pipe.AddColorAttachment();
16449 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16450
16451 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16452 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16453 // we used to have a bug in this case.
16454 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16455 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16456 &descriptor_set, BINDING_COUNT, dyn_off);
16457 Draw(1, 0, 0, 0);
16458 m_errorMonitor->VerifyNotFound();
16459
16460 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16461 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16462 vkFreeMemory(m_device->device(), mem1, NULL);
16463 vkFreeMemory(m_device->device(), mem2, NULL);
16464
16465 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16466 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16467 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16468}
16469
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016470TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16471
16472 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16473 "mapping while using VK_WHOLE_SIZE does not cause access "
16474 "violations");
16475 VkResult err;
16476 uint8_t *pData;
16477 ASSERT_NO_FATAL_FAILURE(InitState());
16478
16479 VkDeviceMemory mem;
16480 VkMemoryRequirements mem_reqs;
16481 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16482 VkMemoryAllocateInfo alloc_info = {};
16483 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16484 alloc_info.pNext = NULL;
16485 alloc_info.memoryTypeIndex = 0;
16486
16487 static const VkDeviceSize allocation_size = 0x1000;
16488 alloc_info.allocationSize = allocation_size;
16489
16490 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16491 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16492 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16493 if (!pass) {
16494 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16495 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16496 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16497 if (!pass) {
16498 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16499 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16500 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16501 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16502 if (!pass) {
16503 return;
16504 }
16505 }
16506 }
16507
16508 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16509 ASSERT_VK_SUCCESS(err);
16510
16511 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16512 // mapped range
16513 m_errorMonitor->ExpectSuccess();
16514 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16515 ASSERT_VK_SUCCESS(err);
16516 VkMappedMemoryRange mmr = {};
16517 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16518 mmr.memory = mem;
16519 mmr.offset = 0;
16520 mmr.size = VK_WHOLE_SIZE;
16521 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16522 ASSERT_VK_SUCCESS(err);
16523 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16524 ASSERT_VK_SUCCESS(err);
16525 m_errorMonitor->VerifyNotFound();
16526 vkUnmapMemory(m_device->device(), mem);
16527
16528 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16529 // mapped range
16530 m_errorMonitor->ExpectSuccess();
16531 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16532 ASSERT_VK_SUCCESS(err);
16533 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16534 mmr.memory = mem;
16535 mmr.offset = 13;
16536 mmr.size = VK_WHOLE_SIZE;
16537 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16538 ASSERT_VK_SUCCESS(err);
16539 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16540 ASSERT_VK_SUCCESS(err);
16541 m_errorMonitor->VerifyNotFound();
16542 vkUnmapMemory(m_device->device(), mem);
16543
16544 // Map with prime offset and size
16545 // Flush/Invalidate subrange of mapped area with prime offset and size
16546 m_errorMonitor->ExpectSuccess();
16547 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16548 ASSERT_VK_SUCCESS(err);
16549 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16550 mmr.memory = mem;
16551 mmr.offset = allocation_size - 107;
16552 mmr.size = 61;
16553 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16554 ASSERT_VK_SUCCESS(err);
16555 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16556 ASSERT_VK_SUCCESS(err);
16557 m_errorMonitor->VerifyNotFound();
16558 vkUnmapMemory(m_device->device(), mem);
16559
16560 // Map without offset and flush WHOLE_SIZE with two separate offsets
16561 m_errorMonitor->ExpectSuccess();
16562 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16563 ASSERT_VK_SUCCESS(err);
16564 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16565 mmr.memory = mem;
16566 mmr.offset = allocation_size - 100;
16567 mmr.size = VK_WHOLE_SIZE;
16568 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16569 ASSERT_VK_SUCCESS(err);
16570 mmr.offset = allocation_size - 200;
16571 mmr.size = VK_WHOLE_SIZE;
16572 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16573 ASSERT_VK_SUCCESS(err);
16574 m_errorMonitor->VerifyNotFound();
16575 vkUnmapMemory(m_device->device(), mem);
16576
16577 vkFreeMemory(m_device->device(), mem, NULL);
16578}
16579
16580// This is a positive test. We used to expect error in this case but spec now allows it
16581TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16582 m_errorMonitor->ExpectSuccess();
16583 vk_testing::Fence testFence;
16584 VkFenceCreateInfo fenceInfo = {};
16585 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16586 fenceInfo.pNext = NULL;
16587
16588 ASSERT_NO_FATAL_FAILURE(InitState());
16589 testFence.init(*m_device, fenceInfo);
16590 VkFence fences[1] = { testFence.handle() };
16591 VkResult result = vkResetFences(m_device->device(), 1, fences);
16592 ASSERT_VK_SUCCESS(result);
16593
16594 m_errorMonitor->VerifyNotFound();
16595}
16596
16597TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16598 m_errorMonitor->ExpectSuccess();
16599
16600 ASSERT_NO_FATAL_FAILURE(InitState());
16601 VkResult err;
16602
16603 // Record (empty!) command buffer that can be submitted multiple times
16604 // simultaneously.
16605 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16606 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16607 m_commandBuffer->BeginCommandBuffer(&cbbi);
16608 m_commandBuffer->EndCommandBuffer();
16609
16610 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16611 VkFence fence;
16612 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16613 ASSERT_VK_SUCCESS(err);
16614
16615 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16616 VkSemaphore s1, s2;
16617 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16618 ASSERT_VK_SUCCESS(err);
16619 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16620 ASSERT_VK_SUCCESS(err);
16621
16622 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16623 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16624 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16625 ASSERT_VK_SUCCESS(err);
16626
16627 // Submit CB again, signaling s2.
16628 si.pSignalSemaphores = &s2;
16629 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16630 ASSERT_VK_SUCCESS(err);
16631
16632 // Wait for fence.
16633 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16634 ASSERT_VK_SUCCESS(err);
16635
16636 // CB is still in flight from second submission, but semaphore s1 is no
16637 // longer in flight. delete it.
16638 vkDestroySemaphore(m_device->device(), s1, nullptr);
16639
16640 m_errorMonitor->VerifyNotFound();
16641
16642 // Force device idle and clean up remaining objects
16643 vkDeviceWaitIdle(m_device->device());
16644 vkDestroySemaphore(m_device->device(), s2, nullptr);
16645 vkDestroyFence(m_device->device(), fence, nullptr);
16646}
16647
16648TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16649 m_errorMonitor->ExpectSuccess();
16650
16651 ASSERT_NO_FATAL_FAILURE(InitState());
16652 VkResult err;
16653
16654 // A fence created signaled
16655 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16656 VkFence f1;
16657 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16658 ASSERT_VK_SUCCESS(err);
16659
16660 // A fence created not
16661 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16662 VkFence f2;
16663 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16664 ASSERT_VK_SUCCESS(err);
16665
16666 // Submit the unsignaled fence
16667 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16668 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16669
16670 // Wait on both fences, with signaled first.
16671 VkFence fences[] = { f1, f2 };
16672 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16673
16674 // Should have both retired!
16675 vkDestroyFence(m_device->device(), f1, nullptr);
16676 vkDestroyFence(m_device->device(), f2, nullptr);
16677
16678 m_errorMonitor->VerifyNotFound();
16679}
16680
16681TEST_F(VkPositiveLayerTest, ValidUsage) {
16682 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16683 "doesn't generate validation errors");
16684
16685 ASSERT_NO_FATAL_FAILURE(InitState());
16686
16687 m_errorMonitor->ExpectSuccess();
16688 // Verify that we can create a view with usage INPUT_ATTACHMENT
16689 VkImageObj image(m_device);
16690 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16691 ASSERT_TRUE(image.initialized());
16692 VkImageView imageView;
16693 VkImageViewCreateInfo ivci = {};
16694 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16695 ivci.image = image.handle();
16696 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16697 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16698 ivci.subresourceRange.layerCount = 1;
16699 ivci.subresourceRange.baseMipLevel = 0;
16700 ivci.subresourceRange.levelCount = 1;
16701 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16702
16703 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16704 m_errorMonitor->VerifyNotFound();
16705 vkDestroyImageView(m_device->device(), imageView, NULL);
16706}
16707
16708// This is a positive test. No failures are expected.
16709TEST_F(VkPositiveLayerTest, BindSparse) {
16710 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16711 "and then free the memory");
16712
16713 ASSERT_NO_FATAL_FAILURE(InitState());
16714
16715 auto index = m_device->graphics_queue_node_index_;
16716 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16717 return;
16718
16719 m_errorMonitor->ExpectSuccess();
16720
16721 VkImage image;
16722 VkImageCreateInfo image_create_info = {};
16723 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16724 image_create_info.pNext = NULL;
16725 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16726 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16727 image_create_info.extent.width = 64;
16728 image_create_info.extent.height = 64;
16729 image_create_info.extent.depth = 1;
16730 image_create_info.mipLevels = 1;
16731 image_create_info.arrayLayers = 1;
16732 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16733 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16734 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16735 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16736 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16737 ASSERT_VK_SUCCESS(err);
16738
16739 VkMemoryRequirements memory_reqs;
16740 VkDeviceMemory memory_one, memory_two;
16741 bool pass;
16742 VkMemoryAllocateInfo memory_info = {};
16743 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16744 memory_info.pNext = NULL;
16745 memory_info.allocationSize = 0;
16746 memory_info.memoryTypeIndex = 0;
16747 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16748 // Find an image big enough to allow sparse mapping of 2 memory regions
16749 // Increase the image size until it is at least twice the
16750 // size of the required alignment, to ensure we can bind both
16751 // allocated memory blocks to the image on aligned offsets.
16752 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16753 vkDestroyImage(m_device->device(), image, nullptr);
16754 image_create_info.extent.width *= 2;
16755 image_create_info.extent.height *= 2;
16756 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16757 ASSERT_VK_SUCCESS(err);
16758 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16759 }
16760 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16761 // at the end of the first
16762 memory_info.allocationSize = memory_reqs.alignment;
16763 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16764 ASSERT_TRUE(pass);
16765 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16766 ASSERT_VK_SUCCESS(err);
16767 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16768 ASSERT_VK_SUCCESS(err);
16769 VkSparseMemoryBind binds[2];
16770 binds[0].flags = 0;
16771 binds[0].memory = memory_one;
16772 binds[0].memoryOffset = 0;
16773 binds[0].resourceOffset = 0;
16774 binds[0].size = memory_info.allocationSize;
16775 binds[1].flags = 0;
16776 binds[1].memory = memory_two;
16777 binds[1].memoryOffset = 0;
16778 binds[1].resourceOffset = memory_info.allocationSize;
16779 binds[1].size = memory_info.allocationSize;
16780
16781 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16782 opaqueBindInfo.image = image;
16783 opaqueBindInfo.bindCount = 2;
16784 opaqueBindInfo.pBinds = binds;
16785
16786 VkFence fence = VK_NULL_HANDLE;
16787 VkBindSparseInfo bindSparseInfo = {};
16788 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16789 bindSparseInfo.imageOpaqueBindCount = 1;
16790 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16791
16792 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16793 vkQueueWaitIdle(m_device->m_queue);
16794 vkDestroyImage(m_device->device(), image, NULL);
16795 vkFreeMemory(m_device->device(), memory_one, NULL);
16796 vkFreeMemory(m_device->device(), memory_two, NULL);
16797 m_errorMonitor->VerifyNotFound();
16798}
16799
16800TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16801 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16802 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16803 "the command buffer has prior knowledge of that "
16804 "attachment's layout.");
16805
16806 m_errorMonitor->ExpectSuccess();
16807
16808 ASSERT_NO_FATAL_FAILURE(InitState());
16809
16810 // A renderpass with one color attachment.
16811 VkAttachmentDescription attachment = { 0,
16812 VK_FORMAT_R8G8B8A8_UNORM,
16813 VK_SAMPLE_COUNT_1_BIT,
16814 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16815 VK_ATTACHMENT_STORE_OP_STORE,
16816 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16817 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16818 VK_IMAGE_LAYOUT_UNDEFINED,
16819 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16820
16821 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16822
16823 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16824
16825 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16826
16827 VkRenderPass rp;
16828 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16829 ASSERT_VK_SUCCESS(err);
16830
16831 // A compatible framebuffer.
16832 VkImageObj image(m_device);
16833 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16834 ASSERT_TRUE(image.initialized());
16835
16836 VkImageViewCreateInfo ivci = {
16837 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16838 nullptr,
16839 0,
16840 image.handle(),
16841 VK_IMAGE_VIEW_TYPE_2D,
16842 VK_FORMAT_R8G8B8A8_UNORM,
16843 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16844 VK_COMPONENT_SWIZZLE_IDENTITY },
16845 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16846 };
16847 VkImageView view;
16848 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16849 ASSERT_VK_SUCCESS(err);
16850
16851 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16852 VkFramebuffer fb;
16853 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16854 ASSERT_VK_SUCCESS(err);
16855
16856 // Record a single command buffer which uses this renderpass twice. The
16857 // bug is triggered at the beginning of the second renderpass, when the
16858 // command buffer already has a layout recorded for the attachment.
16859 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16860 BeginCommandBuffer();
16861 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16862 vkCmdEndRenderPass(m_commandBuffer->handle());
16863 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16864
16865 m_errorMonitor->VerifyNotFound();
16866
16867 vkCmdEndRenderPass(m_commandBuffer->handle());
16868 EndCommandBuffer();
16869
16870 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16871 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16872 vkDestroyImageView(m_device->device(), view, nullptr);
16873}
16874
16875TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16876 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16877 "command buffer, bind them together, then destroy "
16878 "command pool and framebuffer and verify there are no "
16879 "errors.");
16880
16881 m_errorMonitor->ExpectSuccess();
16882
16883 ASSERT_NO_FATAL_FAILURE(InitState());
16884
16885 // A renderpass with one color attachment.
16886 VkAttachmentDescription attachment = { 0,
16887 VK_FORMAT_R8G8B8A8_UNORM,
16888 VK_SAMPLE_COUNT_1_BIT,
16889 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16890 VK_ATTACHMENT_STORE_OP_STORE,
16891 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16892 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16893 VK_IMAGE_LAYOUT_UNDEFINED,
16894 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16895
16896 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16897
16898 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16899
16900 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16901
16902 VkRenderPass rp;
16903 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16904 ASSERT_VK_SUCCESS(err);
16905
16906 // A compatible framebuffer.
16907 VkImageObj image(m_device);
16908 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16909 ASSERT_TRUE(image.initialized());
16910
16911 VkImageViewCreateInfo ivci = {
16912 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16913 nullptr,
16914 0,
16915 image.handle(),
16916 VK_IMAGE_VIEW_TYPE_2D,
16917 VK_FORMAT_R8G8B8A8_UNORM,
16918 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16919 VK_COMPONENT_SWIZZLE_IDENTITY },
16920 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16921 };
16922 VkImageView view;
16923 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16924 ASSERT_VK_SUCCESS(err);
16925
16926 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16927 VkFramebuffer fb;
16928 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16929 ASSERT_VK_SUCCESS(err);
16930
16931 // Explicitly create a command buffer to bind the FB to so that we can then
16932 // destroy the command pool in order to implicitly free command buffer
16933 VkCommandPool command_pool;
16934 VkCommandPoolCreateInfo pool_create_info{};
16935 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16936 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16937 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16938 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16939
16940 VkCommandBuffer command_buffer;
16941 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16942 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16943 command_buffer_allocate_info.commandPool = command_pool;
16944 command_buffer_allocate_info.commandBufferCount = 1;
16945 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16946 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16947
16948 // Begin our cmd buffer with renderpass using our framebuffer
16949 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16950 VkCommandBufferBeginInfo begin_info{};
16951 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16952 vkBeginCommandBuffer(command_buffer, &begin_info);
16953
16954 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16955 vkCmdEndRenderPass(command_buffer);
16956 vkEndCommandBuffer(command_buffer);
16957 vkDestroyImageView(m_device->device(), view, nullptr);
16958 // Destroy command pool to implicitly free command buffer
16959 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16960 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16961 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16962 m_errorMonitor->VerifyNotFound();
16963}
16964
16965TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16966 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16967 "transitions for the first subpass");
16968
16969 m_errorMonitor->ExpectSuccess();
16970
16971 ASSERT_NO_FATAL_FAILURE(InitState());
16972
16973 // A renderpass with one color attachment.
16974 VkAttachmentDescription attachment = { 0,
16975 VK_FORMAT_R8G8B8A8_UNORM,
16976 VK_SAMPLE_COUNT_1_BIT,
16977 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16978 VK_ATTACHMENT_STORE_OP_STORE,
16979 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16980 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16981 VK_IMAGE_LAYOUT_UNDEFINED,
16982 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16983
16984 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16985
16986 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16987
16988 VkSubpassDependency dep = { 0,
16989 0,
16990 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16991 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16992 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16993 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16994 VK_DEPENDENCY_BY_REGION_BIT };
16995
16996 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16997
16998 VkResult err;
16999 VkRenderPass rp;
17000 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17001 ASSERT_VK_SUCCESS(err);
17002
17003 // A compatible framebuffer.
17004 VkImageObj image(m_device);
17005 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17006 ASSERT_TRUE(image.initialized());
17007
17008 VkImageViewCreateInfo ivci = {
17009 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17010 nullptr,
17011 0,
17012 image.handle(),
17013 VK_IMAGE_VIEW_TYPE_2D,
17014 VK_FORMAT_R8G8B8A8_UNORM,
17015 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17016 VK_COMPONENT_SWIZZLE_IDENTITY },
17017 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17018 };
17019 VkImageView view;
17020 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17021 ASSERT_VK_SUCCESS(err);
17022
17023 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17024 VkFramebuffer fb;
17025 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17026 ASSERT_VK_SUCCESS(err);
17027
17028 // Record a single command buffer which issues a pipeline barrier w/
17029 // image memory barrier for the attachment. This detects the previously
17030 // missing tracking of the subpass layout by throwing a validation error
17031 // if it doesn't occur.
17032 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17033 BeginCommandBuffer();
17034 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17035
17036 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17037 nullptr,
17038 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17039 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17040 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17041 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17042 VK_QUEUE_FAMILY_IGNORED,
17043 VK_QUEUE_FAMILY_IGNORED,
17044 image.handle(),
17045 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17046 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17047 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17048 &imb);
17049
17050 vkCmdEndRenderPass(m_commandBuffer->handle());
17051 m_errorMonitor->VerifyNotFound();
17052 EndCommandBuffer();
17053
17054 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17055 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17056 vkDestroyImageView(m_device->device(), view, nullptr);
17057}
17058
17059TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17060 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17061 "is used as a depth/stencil framebuffer attachment, the "
17062 "aspectMask is ignored and both depth and stencil image "
17063 "subresources are used.");
17064
17065 VkFormatProperties format_properties;
17066 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17067 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17068 return;
17069 }
17070
17071 m_errorMonitor->ExpectSuccess();
17072
17073 ASSERT_NO_FATAL_FAILURE(InitState());
17074
17075 VkAttachmentDescription attachment = { 0,
17076 VK_FORMAT_D32_SFLOAT_S8_UINT,
17077 VK_SAMPLE_COUNT_1_BIT,
17078 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17079 VK_ATTACHMENT_STORE_OP_STORE,
17080 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17081 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17082 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17083 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17084
17085 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17086
17087 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17088
17089 VkSubpassDependency dep = { 0,
17090 0,
17091 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17092 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17093 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17094 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17095 VK_DEPENDENCY_BY_REGION_BIT};
17096
17097 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17098
17099 VkResult err;
17100 VkRenderPass rp;
17101 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17102 ASSERT_VK_SUCCESS(err);
17103
17104 VkImageObj image(m_device);
17105 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17106 0x26, // usage
17107 VK_IMAGE_TILING_OPTIMAL, 0);
17108 ASSERT_TRUE(image.initialized());
17109 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17110
17111 VkImageViewCreateInfo ivci = {
17112 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17113 nullptr,
17114 0,
17115 image.handle(),
17116 VK_IMAGE_VIEW_TYPE_2D,
17117 VK_FORMAT_D32_SFLOAT_S8_UINT,
17118 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17119 { 0x2, 0, 1, 0, 1 },
17120 };
17121 VkImageView view;
17122 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17123 ASSERT_VK_SUCCESS(err);
17124
17125 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17126 VkFramebuffer fb;
17127 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17128 ASSERT_VK_SUCCESS(err);
17129
17130 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17131 BeginCommandBuffer();
17132 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17133
17134 VkImageMemoryBarrier imb = {};
17135 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17136 imb.pNext = nullptr;
17137 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17138 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17139 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17140 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17141 imb.srcQueueFamilyIndex = 0;
17142 imb.dstQueueFamilyIndex = 0;
17143 imb.image = image.handle();
17144 imb.subresourceRange.aspectMask = 0x6;
17145 imb.subresourceRange.baseMipLevel = 0;
17146 imb.subresourceRange.levelCount = 0x1;
17147 imb.subresourceRange.baseArrayLayer = 0;
17148 imb.subresourceRange.layerCount = 0x1;
17149
17150 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17151 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17152 &imb);
17153
17154 vkCmdEndRenderPass(m_commandBuffer->handle());
17155 EndCommandBuffer();
17156 QueueCommandBuffer(false);
17157 m_errorMonitor->VerifyNotFound();
17158
17159 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17160 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17161 vkDestroyImageView(m_device->device(), view, nullptr);
17162}
17163
17164TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17165 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17166 "errors, when an attachment reference is "
17167 "VK_ATTACHMENT_UNUSED");
17168
17169 m_errorMonitor->ExpectSuccess();
17170
17171 ASSERT_NO_FATAL_FAILURE(InitState());
17172
17173 // A renderpass with no attachments
17174 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17175
17176 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17177
17178 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17179
17180 VkRenderPass rp;
17181 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17182 ASSERT_VK_SUCCESS(err);
17183
17184 // A compatible framebuffer.
17185 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17186 VkFramebuffer fb;
17187 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17188 ASSERT_VK_SUCCESS(err);
17189
17190 // Record a command buffer which just begins and ends the renderpass. The
17191 // bug manifests in BeginRenderPass.
17192 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17193 BeginCommandBuffer();
17194 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17195 vkCmdEndRenderPass(m_commandBuffer->handle());
17196 m_errorMonitor->VerifyNotFound();
17197 EndCommandBuffer();
17198
17199 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17200 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17201}
17202
17203// This is a positive test. No errors are expected.
17204TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17205 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17206 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17207 VkResult result = VK_SUCCESS;
17208 VkImageFormatProperties formatProps;
17209 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17210 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17211 &formatProps);
17212 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17213 return;
17214 }
17215
17216 ASSERT_NO_FATAL_FAILURE(InitState());
17217 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17218 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17219 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17220 VkAttachmentDescription att = {};
17221 VkAttachmentReference ref = {};
17222 att.format = depth_stencil_fmt;
17223 att.samples = VK_SAMPLE_COUNT_1_BIT;
17224 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17225 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17226 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17227 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17228 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17229 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17230
17231 VkClearValue clear;
17232 clear.depthStencil.depth = 1.0;
17233 clear.depthStencil.stencil = 0;
17234 ref.attachment = 0;
17235 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17236
17237 VkSubpassDescription subpass = {};
17238 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17239 subpass.flags = 0;
17240 subpass.inputAttachmentCount = 0;
17241 subpass.pInputAttachments = NULL;
17242 subpass.colorAttachmentCount = 0;
17243 subpass.pColorAttachments = NULL;
17244 subpass.pResolveAttachments = NULL;
17245 subpass.pDepthStencilAttachment = &ref;
17246 subpass.preserveAttachmentCount = 0;
17247 subpass.pPreserveAttachments = NULL;
17248
17249 VkRenderPass rp;
17250 VkRenderPassCreateInfo rp_info = {};
17251 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17252 rp_info.attachmentCount = 1;
17253 rp_info.pAttachments = &att;
17254 rp_info.subpassCount = 1;
17255 rp_info.pSubpasses = &subpass;
17256 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17257 ASSERT_VK_SUCCESS(result);
17258
17259 VkImageView *depthView = m_depthStencil->BindInfo();
17260 VkFramebufferCreateInfo fb_info = {};
17261 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17262 fb_info.pNext = NULL;
17263 fb_info.renderPass = rp;
17264 fb_info.attachmentCount = 1;
17265 fb_info.pAttachments = depthView;
17266 fb_info.width = 100;
17267 fb_info.height = 100;
17268 fb_info.layers = 1;
17269 VkFramebuffer fb;
17270 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17271 ASSERT_VK_SUCCESS(result);
17272
17273 VkRenderPassBeginInfo rpbinfo = {};
17274 rpbinfo.clearValueCount = 1;
17275 rpbinfo.pClearValues = &clear;
17276 rpbinfo.pNext = NULL;
17277 rpbinfo.renderPass = rp;
17278 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17279 rpbinfo.renderArea.extent.width = 100;
17280 rpbinfo.renderArea.extent.height = 100;
17281 rpbinfo.renderArea.offset.x = 0;
17282 rpbinfo.renderArea.offset.y = 0;
17283 rpbinfo.framebuffer = fb;
17284
17285 VkFence fence = {};
17286 VkFenceCreateInfo fence_ci = {};
17287 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17288 fence_ci.pNext = nullptr;
17289 fence_ci.flags = 0;
17290 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17291 ASSERT_VK_SUCCESS(result);
17292
17293 m_commandBuffer->BeginCommandBuffer();
17294 m_commandBuffer->BeginRenderPass(rpbinfo);
17295 m_commandBuffer->EndRenderPass();
17296 m_commandBuffer->EndCommandBuffer();
17297 m_commandBuffer->QueueCommandBuffer(fence);
17298
17299 VkImageObj destImage(m_device);
17300 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17301 VK_IMAGE_TILING_OPTIMAL, 0);
17302 VkImageMemoryBarrier barrier = {};
17303 VkImageSubresourceRange range;
17304 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17305 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17306 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17307 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17308 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17309 barrier.image = m_depthStencil->handle();
17310 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17311 range.baseMipLevel = 0;
17312 range.levelCount = 1;
17313 range.baseArrayLayer = 0;
17314 range.layerCount = 1;
17315 barrier.subresourceRange = range;
17316 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17317 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17318 cmdbuf.BeginCommandBuffer();
17319 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17320 &barrier);
17321 barrier.srcAccessMask = 0;
17322 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17323 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17324 barrier.image = destImage.handle();
17325 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17326 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17327 &barrier);
17328 VkImageCopy cregion;
17329 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17330 cregion.srcSubresource.mipLevel = 0;
17331 cregion.srcSubresource.baseArrayLayer = 0;
17332 cregion.srcSubresource.layerCount = 1;
17333 cregion.srcOffset.x = 0;
17334 cregion.srcOffset.y = 0;
17335 cregion.srcOffset.z = 0;
17336 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17337 cregion.dstSubresource.mipLevel = 0;
17338 cregion.dstSubresource.baseArrayLayer = 0;
17339 cregion.dstSubresource.layerCount = 1;
17340 cregion.dstOffset.x = 0;
17341 cregion.dstOffset.y = 0;
17342 cregion.dstOffset.z = 0;
17343 cregion.extent.width = 100;
17344 cregion.extent.height = 100;
17345 cregion.extent.depth = 1;
17346 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17347 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17348 cmdbuf.EndCommandBuffer();
17349
17350 VkSubmitInfo submit_info;
17351 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17352 submit_info.pNext = NULL;
17353 submit_info.waitSemaphoreCount = 0;
17354 submit_info.pWaitSemaphores = NULL;
17355 submit_info.pWaitDstStageMask = NULL;
17356 submit_info.commandBufferCount = 1;
17357 submit_info.pCommandBuffers = &cmdbuf.handle();
17358 submit_info.signalSemaphoreCount = 0;
17359 submit_info.pSignalSemaphores = NULL;
17360
17361 m_errorMonitor->ExpectSuccess();
17362 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17363 m_errorMonitor->VerifyNotFound();
17364
17365 vkQueueWaitIdle(m_device->m_queue);
17366 vkDestroyFence(m_device->device(), fence, nullptr);
17367 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17368 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17369}
17370
17371// This is a positive test. No errors should be generated.
17372TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17373 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17374
17375 m_errorMonitor->ExpectSuccess();
17376 ASSERT_NO_FATAL_FAILURE(InitState());
17377
17378 VkEvent event;
17379 VkEventCreateInfo event_create_info{};
17380 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17381 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17382
17383 VkCommandPool command_pool;
17384 VkCommandPoolCreateInfo pool_create_info{};
17385 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17386 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17387 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17388 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17389
17390 VkCommandBuffer command_buffer;
17391 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17392 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17393 command_buffer_allocate_info.commandPool = command_pool;
17394 command_buffer_allocate_info.commandBufferCount = 1;
17395 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17396 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17397
17398 VkQueue queue = VK_NULL_HANDLE;
17399 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17400
17401 {
17402 VkCommandBufferBeginInfo begin_info{};
17403 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17404 vkBeginCommandBuffer(command_buffer, &begin_info);
17405
17406 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17407 nullptr, 0, nullptr);
17408 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17409 vkEndCommandBuffer(command_buffer);
17410 }
17411 {
17412 VkSubmitInfo submit_info{};
17413 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17414 submit_info.commandBufferCount = 1;
17415 submit_info.pCommandBuffers = &command_buffer;
17416 submit_info.signalSemaphoreCount = 0;
17417 submit_info.pSignalSemaphores = nullptr;
17418 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17419 }
17420 { vkSetEvent(m_device->device(), event); }
17421
17422 vkQueueWaitIdle(queue);
17423
17424 vkDestroyEvent(m_device->device(), event, nullptr);
17425 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17426 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17427
17428 m_errorMonitor->VerifyNotFound();
17429}
17430// This is a positive test. No errors should be generated.
17431TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17432 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17433
17434 ASSERT_NO_FATAL_FAILURE(InitState());
17435 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17436 return;
17437
17438 m_errorMonitor->ExpectSuccess();
17439
17440 VkQueryPool query_pool;
17441 VkQueryPoolCreateInfo query_pool_create_info{};
17442 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17443 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17444 query_pool_create_info.queryCount = 1;
17445 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17446
17447 VkCommandPool command_pool;
17448 VkCommandPoolCreateInfo pool_create_info{};
17449 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17450 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17451 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17452 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17453
17454 VkCommandBuffer command_buffer;
17455 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17456 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17457 command_buffer_allocate_info.commandPool = command_pool;
17458 command_buffer_allocate_info.commandBufferCount = 1;
17459 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17460 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17461
17462 VkCommandBuffer secondary_command_buffer;
17463 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17464 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17465
17466 VkQueue queue = VK_NULL_HANDLE;
17467 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17468
17469 uint32_t qfi = 0;
17470 VkBufferCreateInfo buff_create_info = {};
17471 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17472 buff_create_info.size = 1024;
17473 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17474 buff_create_info.queueFamilyIndexCount = 1;
17475 buff_create_info.pQueueFamilyIndices = &qfi;
17476
17477 VkResult err;
17478 VkBuffer buffer;
17479 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17480 ASSERT_VK_SUCCESS(err);
17481 VkMemoryAllocateInfo mem_alloc = {};
17482 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17483 mem_alloc.pNext = NULL;
17484 mem_alloc.allocationSize = 1024;
17485 mem_alloc.memoryTypeIndex = 0;
17486
17487 VkMemoryRequirements memReqs;
17488 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17489 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17490 if (!pass) {
17491 vkDestroyBuffer(m_device->device(), buffer, NULL);
17492 return;
17493 }
17494
17495 VkDeviceMemory mem;
17496 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17497 ASSERT_VK_SUCCESS(err);
17498 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17499 ASSERT_VK_SUCCESS(err);
17500
17501 VkCommandBufferInheritanceInfo hinfo = {};
17502 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17503 hinfo.renderPass = VK_NULL_HANDLE;
17504 hinfo.subpass = 0;
17505 hinfo.framebuffer = VK_NULL_HANDLE;
17506 hinfo.occlusionQueryEnable = VK_FALSE;
17507 hinfo.queryFlags = 0;
17508 hinfo.pipelineStatistics = 0;
17509
17510 {
17511 VkCommandBufferBeginInfo begin_info{};
17512 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17513 begin_info.pInheritanceInfo = &hinfo;
17514 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17515
17516 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17517 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17518
17519 vkEndCommandBuffer(secondary_command_buffer);
17520
17521 begin_info.pInheritanceInfo = nullptr;
17522 vkBeginCommandBuffer(command_buffer, &begin_info);
17523
17524 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17525 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17526
17527 vkEndCommandBuffer(command_buffer);
17528 }
17529 {
17530 VkSubmitInfo submit_info{};
17531 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17532 submit_info.commandBufferCount = 1;
17533 submit_info.pCommandBuffers = &command_buffer;
17534 submit_info.signalSemaphoreCount = 0;
17535 submit_info.pSignalSemaphores = nullptr;
17536 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17537 }
17538
17539 vkQueueWaitIdle(queue);
17540
17541 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17542 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17543 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17544 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17545 vkDestroyBuffer(m_device->device(), buffer, NULL);
17546 vkFreeMemory(m_device->device(), mem, NULL);
17547
17548 m_errorMonitor->VerifyNotFound();
17549}
17550
17551// This is a positive test. No errors should be generated.
17552TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17553 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17554
17555 ASSERT_NO_FATAL_FAILURE(InitState());
17556 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17557 return;
17558
17559 m_errorMonitor->ExpectSuccess();
17560
17561 VkQueryPool query_pool;
17562 VkQueryPoolCreateInfo query_pool_create_info{};
17563 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17564 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17565 query_pool_create_info.queryCount = 1;
17566 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17567
17568 VkCommandPool command_pool;
17569 VkCommandPoolCreateInfo pool_create_info{};
17570 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17571 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17572 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17573 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17574
17575 VkCommandBuffer command_buffer[2];
17576 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17577 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17578 command_buffer_allocate_info.commandPool = command_pool;
17579 command_buffer_allocate_info.commandBufferCount = 2;
17580 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17581 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17582
17583 VkQueue queue = VK_NULL_HANDLE;
17584 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17585
17586 uint32_t qfi = 0;
17587 VkBufferCreateInfo buff_create_info = {};
17588 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17589 buff_create_info.size = 1024;
17590 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17591 buff_create_info.queueFamilyIndexCount = 1;
17592 buff_create_info.pQueueFamilyIndices = &qfi;
17593
17594 VkResult err;
17595 VkBuffer buffer;
17596 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17597 ASSERT_VK_SUCCESS(err);
17598 VkMemoryAllocateInfo mem_alloc = {};
17599 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17600 mem_alloc.pNext = NULL;
17601 mem_alloc.allocationSize = 1024;
17602 mem_alloc.memoryTypeIndex = 0;
17603
17604 VkMemoryRequirements memReqs;
17605 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17606 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17607 if (!pass) {
17608 vkDestroyBuffer(m_device->device(), buffer, NULL);
17609 return;
17610 }
17611
17612 VkDeviceMemory mem;
17613 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17614 ASSERT_VK_SUCCESS(err);
17615 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17616 ASSERT_VK_SUCCESS(err);
17617
17618 {
17619 VkCommandBufferBeginInfo begin_info{};
17620 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17621 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17622
17623 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17624 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17625
17626 vkEndCommandBuffer(command_buffer[0]);
17627
17628 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17629
17630 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17631
17632 vkEndCommandBuffer(command_buffer[1]);
17633 }
17634 {
17635 VkSubmitInfo submit_info{};
17636 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17637 submit_info.commandBufferCount = 2;
17638 submit_info.pCommandBuffers = command_buffer;
17639 submit_info.signalSemaphoreCount = 0;
17640 submit_info.pSignalSemaphores = nullptr;
17641 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17642 }
17643
17644 vkQueueWaitIdle(queue);
17645
17646 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17647 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17648 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17649 vkDestroyBuffer(m_device->device(), buffer, NULL);
17650 vkFreeMemory(m_device->device(), mem, NULL);
17651
17652 m_errorMonitor->VerifyNotFound();
17653}
17654
Tony Barbourc46924f2016-11-04 11:49:52 -060017655TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017656 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17657
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017658 ASSERT_NO_FATAL_FAILURE(InitState());
17659 VkEvent event;
17660 VkEventCreateInfo event_create_info{};
17661 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17662 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17663
17664 VkCommandPool command_pool;
17665 VkCommandPoolCreateInfo pool_create_info{};
17666 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17667 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17668 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17669 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17670
17671 VkCommandBuffer command_buffer;
17672 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17673 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17674 command_buffer_allocate_info.commandPool = command_pool;
17675 command_buffer_allocate_info.commandBufferCount = 1;
17676 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17677 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17678
17679 VkQueue queue = VK_NULL_HANDLE;
17680 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17681
17682 {
17683 VkCommandBufferBeginInfo begin_info{};
17684 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17685 vkBeginCommandBuffer(command_buffer, &begin_info);
17686
17687 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017688 vkEndCommandBuffer(command_buffer);
17689 }
17690 {
17691 VkSubmitInfo submit_info{};
17692 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17693 submit_info.commandBufferCount = 1;
17694 submit_info.pCommandBuffers = &command_buffer;
17695 submit_info.signalSemaphoreCount = 0;
17696 submit_info.pSignalSemaphores = nullptr;
17697 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17698 }
17699 {
17700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17701 "command buffer.");
17702 vkSetEvent(m_device->device(), event);
17703 m_errorMonitor->VerifyFound();
17704 }
17705
17706 vkQueueWaitIdle(queue);
17707
17708 vkDestroyEvent(m_device->device(), event, nullptr);
17709 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17710 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17711}
17712
17713// This is a positive test. No errors should be generated.
17714TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17715 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17716 "run through a Submit & WaitForFences cycle 3 times. This "
17717 "previously revealed a bug so running this positive test "
17718 "to prevent a regression.");
17719 m_errorMonitor->ExpectSuccess();
17720
17721 ASSERT_NO_FATAL_FAILURE(InitState());
17722 VkQueue queue = VK_NULL_HANDLE;
17723 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17724
17725 static const uint32_t NUM_OBJECTS = 2;
17726 static const uint32_t NUM_FRAMES = 3;
17727 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17728 VkFence fences[NUM_OBJECTS] = {};
17729
17730 VkCommandPool cmd_pool;
17731 VkCommandPoolCreateInfo cmd_pool_ci = {};
17732 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17733 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17734 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17735 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17736 ASSERT_VK_SUCCESS(err);
17737
17738 VkCommandBufferAllocateInfo cmd_buf_info = {};
17739 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17740 cmd_buf_info.commandPool = cmd_pool;
17741 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17742 cmd_buf_info.commandBufferCount = 1;
17743
17744 VkFenceCreateInfo fence_ci = {};
17745 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17746 fence_ci.pNext = nullptr;
17747 fence_ci.flags = 0;
17748
17749 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17750 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17751 ASSERT_VK_SUCCESS(err);
17752 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17753 ASSERT_VK_SUCCESS(err);
17754 }
17755
17756 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17757 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17758 // Create empty cmd buffer
17759 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17760 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17761
17762 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17763 ASSERT_VK_SUCCESS(err);
17764 err = vkEndCommandBuffer(cmd_buffers[obj]);
17765 ASSERT_VK_SUCCESS(err);
17766
17767 VkSubmitInfo submit_info = {};
17768 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17769 submit_info.commandBufferCount = 1;
17770 submit_info.pCommandBuffers = &cmd_buffers[obj];
17771 // Submit cmd buffer and wait for fence
17772 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17773 ASSERT_VK_SUCCESS(err);
17774 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17775 ASSERT_VK_SUCCESS(err);
17776 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17777 ASSERT_VK_SUCCESS(err);
17778 }
17779 }
17780 m_errorMonitor->VerifyNotFound();
17781 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17782 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17783 vkDestroyFence(m_device->device(), fences[i], nullptr);
17784 }
17785}
17786// This is a positive test. No errors should be generated.
17787TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17788
17789 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17790 "submitted on separate queues followed by a QueueWaitIdle.");
17791
17792 ASSERT_NO_FATAL_FAILURE(InitState());
17793 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17794 return;
17795
17796 m_errorMonitor->ExpectSuccess();
17797
17798 VkSemaphore semaphore;
17799 VkSemaphoreCreateInfo semaphore_create_info{};
17800 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17801 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17802
17803 VkCommandPool command_pool;
17804 VkCommandPoolCreateInfo pool_create_info{};
17805 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17806 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17807 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17808 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17809
17810 VkCommandBuffer command_buffer[2];
17811 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17812 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17813 command_buffer_allocate_info.commandPool = command_pool;
17814 command_buffer_allocate_info.commandBufferCount = 2;
17815 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17816 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17817
17818 VkQueue queue = VK_NULL_HANDLE;
17819 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17820
17821 {
17822 VkCommandBufferBeginInfo begin_info{};
17823 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17824 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17825
17826 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17827 nullptr, 0, nullptr, 0, nullptr);
17828
17829 VkViewport viewport{};
17830 viewport.maxDepth = 1.0f;
17831 viewport.minDepth = 0.0f;
17832 viewport.width = 512;
17833 viewport.height = 512;
17834 viewport.x = 0;
17835 viewport.y = 0;
17836 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17837 vkEndCommandBuffer(command_buffer[0]);
17838 }
17839 {
17840 VkCommandBufferBeginInfo begin_info{};
17841 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17842 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17843
17844 VkViewport viewport{};
17845 viewport.maxDepth = 1.0f;
17846 viewport.minDepth = 0.0f;
17847 viewport.width = 512;
17848 viewport.height = 512;
17849 viewport.x = 0;
17850 viewport.y = 0;
17851 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17852 vkEndCommandBuffer(command_buffer[1]);
17853 }
17854 {
17855 VkSubmitInfo submit_info{};
17856 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17857 submit_info.commandBufferCount = 1;
17858 submit_info.pCommandBuffers = &command_buffer[0];
17859 submit_info.signalSemaphoreCount = 1;
17860 submit_info.pSignalSemaphores = &semaphore;
17861 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17862 }
17863 {
17864 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17865 VkSubmitInfo submit_info{};
17866 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17867 submit_info.commandBufferCount = 1;
17868 submit_info.pCommandBuffers = &command_buffer[1];
17869 submit_info.waitSemaphoreCount = 1;
17870 submit_info.pWaitSemaphores = &semaphore;
17871 submit_info.pWaitDstStageMask = flags;
17872 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17873 }
17874
17875 vkQueueWaitIdle(m_device->m_queue);
17876
17877 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17878 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17879 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17880
17881 m_errorMonitor->VerifyNotFound();
17882}
17883
17884// This is a positive test. No errors should be generated.
17885TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17886
17887 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17888 "submitted on separate queues, the second having a fence"
17889 "followed by a QueueWaitIdle.");
17890
17891 ASSERT_NO_FATAL_FAILURE(InitState());
17892 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17893 return;
17894
17895 m_errorMonitor->ExpectSuccess();
17896
17897 VkFence fence;
17898 VkFenceCreateInfo fence_create_info{};
17899 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17900 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17901
17902 VkSemaphore semaphore;
17903 VkSemaphoreCreateInfo semaphore_create_info{};
17904 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17905 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17906
17907 VkCommandPool command_pool;
17908 VkCommandPoolCreateInfo pool_create_info{};
17909 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17910 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17911 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17912 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17913
17914 VkCommandBuffer command_buffer[2];
17915 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17916 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17917 command_buffer_allocate_info.commandPool = command_pool;
17918 command_buffer_allocate_info.commandBufferCount = 2;
17919 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17920 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17921
17922 VkQueue queue = VK_NULL_HANDLE;
17923 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17924
17925 {
17926 VkCommandBufferBeginInfo begin_info{};
17927 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17928 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17929
17930 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17931 nullptr, 0, nullptr, 0, nullptr);
17932
17933 VkViewport viewport{};
17934 viewport.maxDepth = 1.0f;
17935 viewport.minDepth = 0.0f;
17936 viewport.width = 512;
17937 viewport.height = 512;
17938 viewport.x = 0;
17939 viewport.y = 0;
17940 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17941 vkEndCommandBuffer(command_buffer[0]);
17942 }
17943 {
17944 VkCommandBufferBeginInfo begin_info{};
17945 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17946 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17947
17948 VkViewport viewport{};
17949 viewport.maxDepth = 1.0f;
17950 viewport.minDepth = 0.0f;
17951 viewport.width = 512;
17952 viewport.height = 512;
17953 viewport.x = 0;
17954 viewport.y = 0;
17955 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17956 vkEndCommandBuffer(command_buffer[1]);
17957 }
17958 {
17959 VkSubmitInfo submit_info{};
17960 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17961 submit_info.commandBufferCount = 1;
17962 submit_info.pCommandBuffers = &command_buffer[0];
17963 submit_info.signalSemaphoreCount = 1;
17964 submit_info.pSignalSemaphores = &semaphore;
17965 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17966 }
17967 {
17968 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17969 VkSubmitInfo submit_info{};
17970 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17971 submit_info.commandBufferCount = 1;
17972 submit_info.pCommandBuffers = &command_buffer[1];
17973 submit_info.waitSemaphoreCount = 1;
17974 submit_info.pWaitSemaphores = &semaphore;
17975 submit_info.pWaitDstStageMask = flags;
17976 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17977 }
17978
17979 vkQueueWaitIdle(m_device->m_queue);
17980
17981 vkDestroyFence(m_device->device(), fence, nullptr);
17982 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17983 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17984 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17985
17986 m_errorMonitor->VerifyNotFound();
17987}
17988
17989// This is a positive test. No errors should be generated.
17990TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17991
17992 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17993 "submitted on separate queues, the second having a fence"
17994 "followed by two consecutive WaitForFences calls on the same fence.");
17995
17996 ASSERT_NO_FATAL_FAILURE(InitState());
17997 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17998 return;
17999
18000 m_errorMonitor->ExpectSuccess();
18001
18002 VkFence fence;
18003 VkFenceCreateInfo fence_create_info{};
18004 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18005 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18006
18007 VkSemaphore semaphore;
18008 VkSemaphoreCreateInfo semaphore_create_info{};
18009 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18010 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18011
18012 VkCommandPool command_pool;
18013 VkCommandPoolCreateInfo pool_create_info{};
18014 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18015 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18016 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18017 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18018
18019 VkCommandBuffer command_buffer[2];
18020 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18021 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18022 command_buffer_allocate_info.commandPool = command_pool;
18023 command_buffer_allocate_info.commandBufferCount = 2;
18024 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18025 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18026
18027 VkQueue queue = VK_NULL_HANDLE;
18028 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18029
18030 {
18031 VkCommandBufferBeginInfo begin_info{};
18032 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18033 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18034
18035 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18036 nullptr, 0, nullptr, 0, nullptr);
18037
18038 VkViewport viewport{};
18039 viewport.maxDepth = 1.0f;
18040 viewport.minDepth = 0.0f;
18041 viewport.width = 512;
18042 viewport.height = 512;
18043 viewport.x = 0;
18044 viewport.y = 0;
18045 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18046 vkEndCommandBuffer(command_buffer[0]);
18047 }
18048 {
18049 VkCommandBufferBeginInfo begin_info{};
18050 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18051 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18052
18053 VkViewport viewport{};
18054 viewport.maxDepth = 1.0f;
18055 viewport.minDepth = 0.0f;
18056 viewport.width = 512;
18057 viewport.height = 512;
18058 viewport.x = 0;
18059 viewport.y = 0;
18060 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18061 vkEndCommandBuffer(command_buffer[1]);
18062 }
18063 {
18064 VkSubmitInfo submit_info{};
18065 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18066 submit_info.commandBufferCount = 1;
18067 submit_info.pCommandBuffers = &command_buffer[0];
18068 submit_info.signalSemaphoreCount = 1;
18069 submit_info.pSignalSemaphores = &semaphore;
18070 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18071 }
18072 {
18073 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18074 VkSubmitInfo submit_info{};
18075 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18076 submit_info.commandBufferCount = 1;
18077 submit_info.pCommandBuffers = &command_buffer[1];
18078 submit_info.waitSemaphoreCount = 1;
18079 submit_info.pWaitSemaphores = &semaphore;
18080 submit_info.pWaitDstStageMask = flags;
18081 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18082 }
18083
18084 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18085 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18086
18087 vkDestroyFence(m_device->device(), fence, nullptr);
18088 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18089 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18090 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18091
18092 m_errorMonitor->VerifyNotFound();
18093}
18094
18095TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18096
18097 ASSERT_NO_FATAL_FAILURE(InitState());
18098 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18099 printf("Test requires two queues, skipping\n");
18100 return;
18101 }
18102
18103 VkResult err;
18104
18105 m_errorMonitor->ExpectSuccess();
18106
18107 VkQueue q0 = m_device->m_queue;
18108 VkQueue q1 = nullptr;
18109 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18110 ASSERT_NE(q1, nullptr);
18111
18112 // An (empty) command buffer. We must have work in the first submission --
18113 // the layer treats unfenced work differently from fenced work.
18114 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18115 VkCommandPool pool;
18116 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18117 ASSERT_VK_SUCCESS(err);
18118 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18119 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18120 VkCommandBuffer cb;
18121 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18122 ASSERT_VK_SUCCESS(err);
18123 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18124 err = vkBeginCommandBuffer(cb, &cbbi);
18125 ASSERT_VK_SUCCESS(err);
18126 err = vkEndCommandBuffer(cb);
18127 ASSERT_VK_SUCCESS(err);
18128
18129 // A semaphore
18130 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18131 VkSemaphore s;
18132 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18133 ASSERT_VK_SUCCESS(err);
18134
18135 // First submission, to q0
18136 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18137
18138 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18139 ASSERT_VK_SUCCESS(err);
18140
18141 // Second submission, to q1, waiting on s
18142 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18143 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18144
18145 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18146 ASSERT_VK_SUCCESS(err);
18147
18148 // Wait for q0 idle
18149 err = vkQueueWaitIdle(q0);
18150 ASSERT_VK_SUCCESS(err);
18151
18152 // Command buffer should have been completed (it was on q0); reset the pool.
18153 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18154
18155 m_errorMonitor->VerifyNotFound();
18156
18157 // Force device completely idle and clean up resources
18158 vkDeviceWaitIdle(m_device->device());
18159 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18160 vkDestroySemaphore(m_device->device(), s, nullptr);
18161}
18162
18163// This is a positive test. No errors should be generated.
18164TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18165
18166 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18167 "submitted on separate queues, the second having a fence, "
18168 "followed by a WaitForFences call.");
18169
18170 ASSERT_NO_FATAL_FAILURE(InitState());
18171 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18172 return;
18173
18174 m_errorMonitor->ExpectSuccess();
18175
18176 ASSERT_NO_FATAL_FAILURE(InitState());
18177 VkFence fence;
18178 VkFenceCreateInfo fence_create_info{};
18179 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18180 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18181
18182 VkSemaphore semaphore;
18183 VkSemaphoreCreateInfo semaphore_create_info{};
18184 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18185 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18186
18187 VkCommandPool command_pool;
18188 VkCommandPoolCreateInfo pool_create_info{};
18189 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18190 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18191 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18192 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18193
18194 VkCommandBuffer command_buffer[2];
18195 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18196 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18197 command_buffer_allocate_info.commandPool = command_pool;
18198 command_buffer_allocate_info.commandBufferCount = 2;
18199 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18200 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18201
18202 VkQueue queue = VK_NULL_HANDLE;
18203 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18204
18205 {
18206 VkCommandBufferBeginInfo begin_info{};
18207 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18208 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18209
18210 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18211 nullptr, 0, nullptr, 0, nullptr);
18212
18213 VkViewport viewport{};
18214 viewport.maxDepth = 1.0f;
18215 viewport.minDepth = 0.0f;
18216 viewport.width = 512;
18217 viewport.height = 512;
18218 viewport.x = 0;
18219 viewport.y = 0;
18220 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18221 vkEndCommandBuffer(command_buffer[0]);
18222 }
18223 {
18224 VkCommandBufferBeginInfo begin_info{};
18225 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18226 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18227
18228 VkViewport viewport{};
18229 viewport.maxDepth = 1.0f;
18230 viewport.minDepth = 0.0f;
18231 viewport.width = 512;
18232 viewport.height = 512;
18233 viewport.x = 0;
18234 viewport.y = 0;
18235 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18236 vkEndCommandBuffer(command_buffer[1]);
18237 }
18238 {
18239 VkSubmitInfo submit_info{};
18240 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18241 submit_info.commandBufferCount = 1;
18242 submit_info.pCommandBuffers = &command_buffer[0];
18243 submit_info.signalSemaphoreCount = 1;
18244 submit_info.pSignalSemaphores = &semaphore;
18245 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18246 }
18247 {
18248 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18249 VkSubmitInfo submit_info{};
18250 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18251 submit_info.commandBufferCount = 1;
18252 submit_info.pCommandBuffers = &command_buffer[1];
18253 submit_info.waitSemaphoreCount = 1;
18254 submit_info.pWaitSemaphores = &semaphore;
18255 submit_info.pWaitDstStageMask = flags;
18256 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18257 }
18258
18259 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18260
18261 vkDestroyFence(m_device->device(), fence, nullptr);
18262 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18263 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18264 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18265
18266 m_errorMonitor->VerifyNotFound();
18267}
18268
18269// This is a positive test. No errors should be generated.
18270TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18271
18272 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18273 "on the same queue, sharing a signal/wait semaphore, the "
18274 "second having a fence, "
18275 "followed by a WaitForFences call.");
18276
18277 m_errorMonitor->ExpectSuccess();
18278
18279 ASSERT_NO_FATAL_FAILURE(InitState());
18280 VkFence fence;
18281 VkFenceCreateInfo fence_create_info{};
18282 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18283 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18284
18285 VkSemaphore semaphore;
18286 VkSemaphoreCreateInfo semaphore_create_info{};
18287 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18288 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18289
18290 VkCommandPool command_pool;
18291 VkCommandPoolCreateInfo pool_create_info{};
18292 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18293 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18294 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18295 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18296
18297 VkCommandBuffer command_buffer[2];
18298 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18299 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18300 command_buffer_allocate_info.commandPool = command_pool;
18301 command_buffer_allocate_info.commandBufferCount = 2;
18302 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18303 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18304
18305 {
18306 VkCommandBufferBeginInfo begin_info{};
18307 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18308 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18309
18310 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18311 nullptr, 0, nullptr, 0, nullptr);
18312
18313 VkViewport viewport{};
18314 viewport.maxDepth = 1.0f;
18315 viewport.minDepth = 0.0f;
18316 viewport.width = 512;
18317 viewport.height = 512;
18318 viewport.x = 0;
18319 viewport.y = 0;
18320 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18321 vkEndCommandBuffer(command_buffer[0]);
18322 }
18323 {
18324 VkCommandBufferBeginInfo begin_info{};
18325 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18326 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18327
18328 VkViewport viewport{};
18329 viewport.maxDepth = 1.0f;
18330 viewport.minDepth = 0.0f;
18331 viewport.width = 512;
18332 viewport.height = 512;
18333 viewport.x = 0;
18334 viewport.y = 0;
18335 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18336 vkEndCommandBuffer(command_buffer[1]);
18337 }
18338 {
18339 VkSubmitInfo submit_info{};
18340 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18341 submit_info.commandBufferCount = 1;
18342 submit_info.pCommandBuffers = &command_buffer[0];
18343 submit_info.signalSemaphoreCount = 1;
18344 submit_info.pSignalSemaphores = &semaphore;
18345 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18346 }
18347 {
18348 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18349 VkSubmitInfo submit_info{};
18350 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18351 submit_info.commandBufferCount = 1;
18352 submit_info.pCommandBuffers = &command_buffer[1];
18353 submit_info.waitSemaphoreCount = 1;
18354 submit_info.pWaitSemaphores = &semaphore;
18355 submit_info.pWaitDstStageMask = flags;
18356 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18357 }
18358
18359 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18360
18361 vkDestroyFence(m_device->device(), fence, nullptr);
18362 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18363 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18364 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18365
18366 m_errorMonitor->VerifyNotFound();
18367}
18368
18369// This is a positive test. No errors should be generated.
18370TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18371
18372 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18373 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18374 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18375
18376 m_errorMonitor->ExpectSuccess();
18377
18378 ASSERT_NO_FATAL_FAILURE(InitState());
18379 VkFence fence;
18380 VkFenceCreateInfo fence_create_info{};
18381 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18382 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18383
18384 VkCommandPool command_pool;
18385 VkCommandPoolCreateInfo pool_create_info{};
18386 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18387 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18388 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18389 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18390
18391 VkCommandBuffer command_buffer[2];
18392 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18393 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18394 command_buffer_allocate_info.commandPool = command_pool;
18395 command_buffer_allocate_info.commandBufferCount = 2;
18396 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18397 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18398
18399 {
18400 VkCommandBufferBeginInfo begin_info{};
18401 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18402 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18403
18404 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18405 nullptr, 0, nullptr, 0, nullptr);
18406
18407 VkViewport viewport{};
18408 viewport.maxDepth = 1.0f;
18409 viewport.minDepth = 0.0f;
18410 viewport.width = 512;
18411 viewport.height = 512;
18412 viewport.x = 0;
18413 viewport.y = 0;
18414 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18415 vkEndCommandBuffer(command_buffer[0]);
18416 }
18417 {
18418 VkCommandBufferBeginInfo begin_info{};
18419 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18420 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18421
18422 VkViewport viewport{};
18423 viewport.maxDepth = 1.0f;
18424 viewport.minDepth = 0.0f;
18425 viewport.width = 512;
18426 viewport.height = 512;
18427 viewport.x = 0;
18428 viewport.y = 0;
18429 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18430 vkEndCommandBuffer(command_buffer[1]);
18431 }
18432 {
18433 VkSubmitInfo submit_info{};
18434 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18435 submit_info.commandBufferCount = 1;
18436 submit_info.pCommandBuffers = &command_buffer[0];
18437 submit_info.signalSemaphoreCount = 0;
18438 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18439 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18440 }
18441 {
18442 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18443 VkSubmitInfo submit_info{};
18444 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18445 submit_info.commandBufferCount = 1;
18446 submit_info.pCommandBuffers = &command_buffer[1];
18447 submit_info.waitSemaphoreCount = 0;
18448 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18449 submit_info.pWaitDstStageMask = flags;
18450 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18451 }
18452
18453 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18454
18455 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18456 ASSERT_VK_SUCCESS(err);
18457
18458 vkDestroyFence(m_device->device(), fence, nullptr);
18459 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18460 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18461
18462 m_errorMonitor->VerifyNotFound();
18463}
18464
18465// This is a positive test. No errors should be generated.
18466TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18467
18468 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18469 "on the same queue, the second having a fence, followed "
18470 "by a WaitForFences call.");
18471
18472 m_errorMonitor->ExpectSuccess();
18473
18474 ASSERT_NO_FATAL_FAILURE(InitState());
18475 VkFence fence;
18476 VkFenceCreateInfo fence_create_info{};
18477 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18478 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18479
18480 VkCommandPool command_pool;
18481 VkCommandPoolCreateInfo pool_create_info{};
18482 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18483 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18484 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18485 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18486
18487 VkCommandBuffer command_buffer[2];
18488 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18489 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18490 command_buffer_allocate_info.commandPool = command_pool;
18491 command_buffer_allocate_info.commandBufferCount = 2;
18492 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18493 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18494
18495 {
18496 VkCommandBufferBeginInfo begin_info{};
18497 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18498 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18499
18500 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18501 nullptr, 0, nullptr, 0, nullptr);
18502
18503 VkViewport viewport{};
18504 viewport.maxDepth = 1.0f;
18505 viewport.minDepth = 0.0f;
18506 viewport.width = 512;
18507 viewport.height = 512;
18508 viewport.x = 0;
18509 viewport.y = 0;
18510 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18511 vkEndCommandBuffer(command_buffer[0]);
18512 }
18513 {
18514 VkCommandBufferBeginInfo begin_info{};
18515 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18516 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18517
18518 VkViewport viewport{};
18519 viewport.maxDepth = 1.0f;
18520 viewport.minDepth = 0.0f;
18521 viewport.width = 512;
18522 viewport.height = 512;
18523 viewport.x = 0;
18524 viewport.y = 0;
18525 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18526 vkEndCommandBuffer(command_buffer[1]);
18527 }
18528 {
18529 VkSubmitInfo submit_info{};
18530 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18531 submit_info.commandBufferCount = 1;
18532 submit_info.pCommandBuffers = &command_buffer[0];
18533 submit_info.signalSemaphoreCount = 0;
18534 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18535 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18536 }
18537 {
18538 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18539 VkSubmitInfo submit_info{};
18540 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18541 submit_info.commandBufferCount = 1;
18542 submit_info.pCommandBuffers = &command_buffer[1];
18543 submit_info.waitSemaphoreCount = 0;
18544 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18545 submit_info.pWaitDstStageMask = flags;
18546 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18547 }
18548
18549 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18550
18551 vkDestroyFence(m_device->device(), fence, nullptr);
18552 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18553 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18554
18555 m_errorMonitor->VerifyNotFound();
18556}
18557
18558// This is a positive test. No errors should be generated.
18559TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18560
18561 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18562 "QueueSubmit call followed by a WaitForFences call.");
18563 ASSERT_NO_FATAL_FAILURE(InitState());
18564
18565 m_errorMonitor->ExpectSuccess();
18566
18567 VkFence fence;
18568 VkFenceCreateInfo fence_create_info{};
18569 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18570 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18571
18572 VkSemaphore semaphore;
18573 VkSemaphoreCreateInfo semaphore_create_info{};
18574 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18575 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18576
18577 VkCommandPool command_pool;
18578 VkCommandPoolCreateInfo pool_create_info{};
18579 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18580 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18581 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18582 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18583
18584 VkCommandBuffer command_buffer[2];
18585 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18586 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18587 command_buffer_allocate_info.commandPool = command_pool;
18588 command_buffer_allocate_info.commandBufferCount = 2;
18589 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18590 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18591
18592 {
18593 VkCommandBufferBeginInfo begin_info{};
18594 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18595 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18596
18597 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18598 nullptr, 0, nullptr, 0, nullptr);
18599
18600 VkViewport viewport{};
18601 viewport.maxDepth = 1.0f;
18602 viewport.minDepth = 0.0f;
18603 viewport.width = 512;
18604 viewport.height = 512;
18605 viewport.x = 0;
18606 viewport.y = 0;
18607 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18608 vkEndCommandBuffer(command_buffer[0]);
18609 }
18610 {
18611 VkCommandBufferBeginInfo begin_info{};
18612 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18613 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18614
18615 VkViewport viewport{};
18616 viewport.maxDepth = 1.0f;
18617 viewport.minDepth = 0.0f;
18618 viewport.width = 512;
18619 viewport.height = 512;
18620 viewport.x = 0;
18621 viewport.y = 0;
18622 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18623 vkEndCommandBuffer(command_buffer[1]);
18624 }
18625 {
18626 VkSubmitInfo submit_info[2];
18627 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18628
18629 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18630 submit_info[0].pNext = NULL;
18631 submit_info[0].commandBufferCount = 1;
18632 submit_info[0].pCommandBuffers = &command_buffer[0];
18633 submit_info[0].signalSemaphoreCount = 1;
18634 submit_info[0].pSignalSemaphores = &semaphore;
18635 submit_info[0].waitSemaphoreCount = 0;
18636 submit_info[0].pWaitSemaphores = NULL;
18637 submit_info[0].pWaitDstStageMask = 0;
18638
18639 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18640 submit_info[1].pNext = NULL;
18641 submit_info[1].commandBufferCount = 1;
18642 submit_info[1].pCommandBuffers = &command_buffer[1];
18643 submit_info[1].waitSemaphoreCount = 1;
18644 submit_info[1].pWaitSemaphores = &semaphore;
18645 submit_info[1].pWaitDstStageMask = flags;
18646 submit_info[1].signalSemaphoreCount = 0;
18647 submit_info[1].pSignalSemaphores = NULL;
18648 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18649 }
18650
18651 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18652
18653 vkDestroyFence(m_device->device(), fence, nullptr);
18654 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18655 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18656 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18657
18658 m_errorMonitor->VerifyNotFound();
18659}
18660
18661TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18662 m_errorMonitor->ExpectSuccess();
18663
18664 ASSERT_NO_FATAL_FAILURE(InitState());
18665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18666
18667 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18668 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18669
18670 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18671 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18672 m_errorMonitor->VerifyNotFound();
18673 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18674 m_errorMonitor->VerifyNotFound();
18675 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18676 m_errorMonitor->VerifyNotFound();
18677
18678 m_commandBuffer->EndCommandBuffer();
18679 m_errorMonitor->VerifyNotFound();
18680}
18681
18682TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18683 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18684 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18685 "has a valid layout, and a second subpass then uses a "
18686 "valid *READ_ONLY* layout.");
18687 m_errorMonitor->ExpectSuccess();
18688 ASSERT_NO_FATAL_FAILURE(InitState());
18689
18690 VkAttachmentReference attach[2] = {};
18691 attach[0].attachment = 0;
18692 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18693 attach[1].attachment = 0;
18694 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18695 VkSubpassDescription subpasses[2] = {};
18696 // First subpass clears DS attach on load
18697 subpasses[0].pDepthStencilAttachment = &attach[0];
18698 // 2nd subpass reads in DS as input attachment
18699 subpasses[1].inputAttachmentCount = 1;
18700 subpasses[1].pInputAttachments = &attach[1];
18701 VkAttachmentDescription attach_desc = {};
18702 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18703 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18704 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18705 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18706 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18707 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18708 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18709 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18710 VkRenderPassCreateInfo rpci = {};
18711 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18712 rpci.attachmentCount = 1;
18713 rpci.pAttachments = &attach_desc;
18714 rpci.subpassCount = 2;
18715 rpci.pSubpasses = subpasses;
18716
18717 // Now create RenderPass and verify no errors
18718 VkRenderPass rp;
18719 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18720 m_errorMonitor->VerifyNotFound();
18721
18722 vkDestroyRenderPass(m_device->device(), rp, NULL);
18723}
18724
18725TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18726 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18727 "as vertex attributes");
18728 m_errorMonitor->ExpectSuccess();
18729
18730 ASSERT_NO_FATAL_FAILURE(InitState());
18731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18732
18733 VkVertexInputBindingDescription input_binding;
18734 memset(&input_binding, 0, sizeof(input_binding));
18735
18736 VkVertexInputAttributeDescription input_attribs[2];
18737 memset(input_attribs, 0, sizeof(input_attribs));
18738
18739 for (int i = 0; i < 2; i++) {
18740 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18741 input_attribs[i].location = i;
18742 }
18743
18744 char const *vsSource = "#version 450\n"
18745 "\n"
18746 "layout(location=0) in mat2x4 x;\n"
18747 "out gl_PerVertex {\n"
18748 " vec4 gl_Position;\n"
18749 "};\n"
18750 "void main(){\n"
18751 " gl_Position = x[0] + x[1];\n"
18752 "}\n";
18753 char const *fsSource = "#version 450\n"
18754 "\n"
18755 "layout(location=0) out vec4 color;\n"
18756 "void main(){\n"
18757 " color = vec4(1);\n"
18758 "}\n";
18759
18760 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18761 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18762
18763 VkPipelineObj pipe(m_device);
18764 pipe.AddColorAttachment();
18765 pipe.AddShader(&vs);
18766 pipe.AddShader(&fs);
18767
18768 pipe.AddVertexInputBindings(&input_binding, 1);
18769 pipe.AddVertexInputAttribs(input_attribs, 2);
18770
18771 VkDescriptorSetObj descriptorSet(m_device);
18772 descriptorSet.AppendDummy();
18773 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18774
18775 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18776
18777 /* expect success */
18778 m_errorMonitor->VerifyNotFound();
18779}
18780
18781TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18782 m_errorMonitor->ExpectSuccess();
18783
18784 ASSERT_NO_FATAL_FAILURE(InitState());
18785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18786
18787 VkVertexInputBindingDescription input_binding;
18788 memset(&input_binding, 0, sizeof(input_binding));
18789
18790 VkVertexInputAttributeDescription input_attribs[2];
18791 memset(input_attribs, 0, sizeof(input_attribs));
18792
18793 for (int i = 0; i < 2; i++) {
18794 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18795 input_attribs[i].location = i;
18796 }
18797
18798 char const *vsSource = "#version 450\n"
18799 "\n"
18800 "layout(location=0) in vec4 x[2];\n"
18801 "out gl_PerVertex {\n"
18802 " vec4 gl_Position;\n"
18803 "};\n"
18804 "void main(){\n"
18805 " gl_Position = x[0] + x[1];\n"
18806 "}\n";
18807 char const *fsSource = "#version 450\n"
18808 "\n"
18809 "layout(location=0) out vec4 color;\n"
18810 "void main(){\n"
18811 " color = vec4(1);\n"
18812 "}\n";
18813
18814 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18815 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18816
18817 VkPipelineObj pipe(m_device);
18818 pipe.AddColorAttachment();
18819 pipe.AddShader(&vs);
18820 pipe.AddShader(&fs);
18821
18822 pipe.AddVertexInputBindings(&input_binding, 1);
18823 pipe.AddVertexInputAttribs(input_attribs, 2);
18824
18825 VkDescriptorSetObj descriptorSet(m_device);
18826 descriptorSet.AppendDummy();
18827 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18828
18829 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18830
18831 m_errorMonitor->VerifyNotFound();
18832}
18833
18834TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18835 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18836 "through multiple vertex shader inputs, each consuming a different "
18837 "subset of the components.");
18838 m_errorMonitor->ExpectSuccess();
18839
18840 ASSERT_NO_FATAL_FAILURE(InitState());
18841 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18842
18843 VkVertexInputBindingDescription input_binding;
18844 memset(&input_binding, 0, sizeof(input_binding));
18845
18846 VkVertexInputAttributeDescription input_attribs[3];
18847 memset(input_attribs, 0, sizeof(input_attribs));
18848
18849 for (int i = 0; i < 3; i++) {
18850 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18851 input_attribs[i].location = i;
18852 }
18853
18854 char const *vsSource = "#version 450\n"
18855 "\n"
18856 "layout(location=0) in vec4 x;\n"
18857 "layout(location=1) in vec3 y1;\n"
18858 "layout(location=1, component=3) in float y2;\n"
18859 "layout(location=2) in vec4 z;\n"
18860 "out gl_PerVertex {\n"
18861 " vec4 gl_Position;\n"
18862 "};\n"
18863 "void main(){\n"
18864 " gl_Position = x + vec4(y1, y2) + z;\n"
18865 "}\n";
18866 char const *fsSource = "#version 450\n"
18867 "\n"
18868 "layout(location=0) out vec4 color;\n"
18869 "void main(){\n"
18870 " color = vec4(1);\n"
18871 "}\n";
18872
18873 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18874 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18875
18876 VkPipelineObj pipe(m_device);
18877 pipe.AddColorAttachment();
18878 pipe.AddShader(&vs);
18879 pipe.AddShader(&fs);
18880
18881 pipe.AddVertexInputBindings(&input_binding, 1);
18882 pipe.AddVertexInputAttribs(input_attribs, 3);
18883
18884 VkDescriptorSetObj descriptorSet(m_device);
18885 descriptorSet.AppendDummy();
18886 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18887
18888 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18889
18890 m_errorMonitor->VerifyNotFound();
18891}
18892
18893TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18894 m_errorMonitor->ExpectSuccess();
18895
18896 ASSERT_NO_FATAL_FAILURE(InitState());
18897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18898
18899 char const *vsSource = "#version 450\n"
18900 "out gl_PerVertex {\n"
18901 " vec4 gl_Position;\n"
18902 "};\n"
18903 "void main(){\n"
18904 " gl_Position = vec4(0);\n"
18905 "}\n";
18906 char const *fsSource = "#version 450\n"
18907 "\n"
18908 "layout(location=0) out vec4 color;\n"
18909 "void main(){\n"
18910 " color = vec4(1);\n"
18911 "}\n";
18912
18913 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18914 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18915
18916 VkPipelineObj pipe(m_device);
18917 pipe.AddColorAttachment();
18918 pipe.AddShader(&vs);
18919 pipe.AddShader(&fs);
18920
18921 VkDescriptorSetObj descriptorSet(m_device);
18922 descriptorSet.AppendDummy();
18923 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18924
18925 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18926
18927 m_errorMonitor->VerifyNotFound();
18928}
18929
18930TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18931 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18932 "set out in 14.1.3: fundamental type must match, and producer side must "
18933 "have at least as many components");
18934 m_errorMonitor->ExpectSuccess();
18935
18936 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18937
18938 ASSERT_NO_FATAL_FAILURE(InitState());
18939 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18940
18941 char const *vsSource = "#version 450\n"
18942 "out gl_PerVertex {\n"
18943 " vec4 gl_Position;\n"
18944 "};\n"
18945 "layout(location=0) out vec3 x;\n"
18946 "layout(location=1) out ivec3 y;\n"
18947 "layout(location=2) out vec3 z;\n"
18948 "void main(){\n"
18949 " gl_Position = vec4(0);\n"
18950 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18951 "}\n";
18952 char const *fsSource = "#version 450\n"
18953 "\n"
18954 "layout(location=0) out vec4 color;\n"
18955 "layout(location=0) in float x;\n"
18956 "layout(location=1) flat in int y;\n"
18957 "layout(location=2) in vec2 z;\n"
18958 "void main(){\n"
18959 " color = vec4(1 + x + y + z.x);\n"
18960 "}\n";
18961
18962 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18963 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18964
18965 VkPipelineObj pipe(m_device);
18966 pipe.AddColorAttachment();
18967 pipe.AddShader(&vs);
18968 pipe.AddShader(&fs);
18969
18970 VkDescriptorSetObj descriptorSet(m_device);
18971 descriptorSet.AppendDummy();
18972 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18973
18974 VkResult err = VK_SUCCESS;
18975 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18976 ASSERT_VK_SUCCESS(err);
18977
18978 m_errorMonitor->VerifyNotFound();
18979}
18980
18981TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18982 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18983 "passed between the TCS and TES stages");
18984 m_errorMonitor->ExpectSuccess();
18985
18986 ASSERT_NO_FATAL_FAILURE(InitState());
18987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18988
18989 if (!m_device->phy().features().tessellationShader) {
18990 printf("Device does not support tessellation shaders; skipped.\n");
18991 return;
18992 }
18993
18994 char const *vsSource = "#version 450\n"
18995 "void main(){}\n";
18996 char const *tcsSource = "#version 450\n"
18997 "layout(location=0) out int x[];\n"
18998 "layout(vertices=3) out;\n"
18999 "void main(){\n"
19000 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19001 " gl_TessLevelInner[0] = 1;\n"
19002 " x[gl_InvocationID] = gl_InvocationID;\n"
19003 "}\n";
19004 char const *tesSource = "#version 450\n"
19005 "layout(triangles, equal_spacing, cw) in;\n"
19006 "layout(location=0) in int x[];\n"
19007 "out gl_PerVertex { vec4 gl_Position; };\n"
19008 "void main(){\n"
19009 " gl_Position.xyz = gl_TessCoord;\n"
19010 " gl_Position.w = x[0] + x[1] + x[2];\n"
19011 "}\n";
19012 char const *fsSource = "#version 450\n"
19013 "layout(location=0) out vec4 color;\n"
19014 "void main(){\n"
19015 " color = vec4(1);\n"
19016 "}\n";
19017
19018 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19019 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19020 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19021 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19022
19023 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19024 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19025
19026 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19027
19028 VkPipelineObj pipe(m_device);
19029 pipe.SetInputAssembly(&iasci);
19030 pipe.SetTessellation(&tsci);
19031 pipe.AddColorAttachment();
19032 pipe.AddShader(&vs);
19033 pipe.AddShader(&tcs);
19034 pipe.AddShader(&tes);
19035 pipe.AddShader(&fs);
19036
19037 VkDescriptorSetObj descriptorSet(m_device);
19038 descriptorSet.AppendDummy();
19039 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19040
19041 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19042
19043 m_errorMonitor->VerifyNotFound();
19044}
19045
19046TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19047 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19048 "interface block passed into the geometry shader. This "
19049 "is interesting because the 'extra' array level is not "
19050 "present on the member type, but on the block instance.");
19051 m_errorMonitor->ExpectSuccess();
19052
19053 ASSERT_NO_FATAL_FAILURE(InitState());
19054 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19055
19056 if (!m_device->phy().features().geometryShader) {
19057 printf("Device does not support geometry shaders; skipped.\n");
19058 return;
19059 }
19060
19061 char const *vsSource = "#version 450\n"
19062 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19063 "void main(){\n"
19064 " vs_out.x = vec4(1);\n"
19065 "}\n";
19066 char const *gsSource = "#version 450\n"
19067 "layout(triangles) in;\n"
19068 "layout(triangle_strip, max_vertices=3) out;\n"
19069 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19070 "out gl_PerVertex { vec4 gl_Position; };\n"
19071 "void main() {\n"
19072 " gl_Position = gs_in[0].x;\n"
19073 " EmitVertex();\n"
19074 "}\n";
19075 char const *fsSource = "#version 450\n"
19076 "layout(location=0) out vec4 color;\n"
19077 "void main(){\n"
19078 " color = vec4(1);\n"
19079 "}\n";
19080
19081 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19082 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19083 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19084
19085 VkPipelineObj pipe(m_device);
19086 pipe.AddColorAttachment();
19087 pipe.AddShader(&vs);
19088 pipe.AddShader(&gs);
19089 pipe.AddShader(&fs);
19090
19091 VkDescriptorSetObj descriptorSet(m_device);
19092 descriptorSet.AppendDummy();
19093 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19094
19095 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19096
19097 m_errorMonitor->VerifyNotFound();
19098}
19099
19100TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19101 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19102 "attributes. This is interesting because they consume multiple "
19103 "locations.");
19104 m_errorMonitor->ExpectSuccess();
19105
19106 ASSERT_NO_FATAL_FAILURE(InitState());
19107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19108
19109 if (!m_device->phy().features().shaderFloat64) {
19110 printf("Device does not support 64bit vertex attributes; skipped.\n");
19111 return;
19112 }
19113
19114 VkVertexInputBindingDescription input_bindings[1];
19115 memset(input_bindings, 0, sizeof(input_bindings));
19116
19117 VkVertexInputAttributeDescription input_attribs[4];
19118 memset(input_attribs, 0, sizeof(input_attribs));
19119 input_attribs[0].location = 0;
19120 input_attribs[0].offset = 0;
19121 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19122 input_attribs[1].location = 2;
19123 input_attribs[1].offset = 32;
19124 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19125 input_attribs[2].location = 4;
19126 input_attribs[2].offset = 64;
19127 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19128 input_attribs[3].location = 6;
19129 input_attribs[3].offset = 96;
19130 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19131
19132 char const *vsSource = "#version 450\n"
19133 "\n"
19134 "layout(location=0) in dmat4 x;\n"
19135 "out gl_PerVertex {\n"
19136 " vec4 gl_Position;\n"
19137 "};\n"
19138 "void main(){\n"
19139 " gl_Position = vec4(x[0][0]);\n"
19140 "}\n";
19141 char const *fsSource = "#version 450\n"
19142 "\n"
19143 "layout(location=0) out vec4 color;\n"
19144 "void main(){\n"
19145 " color = vec4(1);\n"
19146 "}\n";
19147
19148 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19149 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19150
19151 VkPipelineObj pipe(m_device);
19152 pipe.AddColorAttachment();
19153 pipe.AddShader(&vs);
19154 pipe.AddShader(&fs);
19155
19156 pipe.AddVertexInputBindings(input_bindings, 1);
19157 pipe.AddVertexInputAttribs(input_attribs, 4);
19158
19159 VkDescriptorSetObj descriptorSet(m_device);
19160 descriptorSet.AppendDummy();
19161 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19162
19163 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19164
19165 m_errorMonitor->VerifyNotFound();
19166}
19167
19168TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19169 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19170 m_errorMonitor->ExpectSuccess();
19171
19172 ASSERT_NO_FATAL_FAILURE(InitState());
19173
19174 char const *vsSource = "#version 450\n"
19175 "\n"
19176 "out gl_PerVertex {\n"
19177 " vec4 gl_Position;\n"
19178 "};\n"
19179 "void main(){\n"
19180 " gl_Position = vec4(1);\n"
19181 "}\n";
19182 char const *fsSource = "#version 450\n"
19183 "\n"
19184 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19185 "layout(location=0) out vec4 color;\n"
19186 "void main() {\n"
19187 " color = subpassLoad(x);\n"
19188 "}\n";
19189
19190 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19191 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19192
19193 VkPipelineObj pipe(m_device);
19194 pipe.AddShader(&vs);
19195 pipe.AddShader(&fs);
19196 pipe.AddColorAttachment();
19197 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19198
19199 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19200 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19201 VkDescriptorSetLayout dsl;
19202 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19203 ASSERT_VK_SUCCESS(err);
19204
19205 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19206 VkPipelineLayout pl;
19207 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19208 ASSERT_VK_SUCCESS(err);
19209
19210 VkAttachmentDescription descs[2] = {
19211 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19212 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19213 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19214 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19215 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19216 };
19217 VkAttachmentReference color = {
19218 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19219 };
19220 VkAttachmentReference input = {
19221 1, VK_IMAGE_LAYOUT_GENERAL,
19222 };
19223
19224 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19225
19226 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19227 VkRenderPass rp;
19228 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19229 ASSERT_VK_SUCCESS(err);
19230
19231 // should be OK. would go wrong here if it's going to...
19232 pipe.CreateVKPipeline(pl, rp);
19233
19234 m_errorMonitor->VerifyNotFound();
19235
19236 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19237 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19238 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19239}
19240
19241TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19242 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19243 "descriptor-backed resource which is not provided, but the shader does not "
19244 "statically use it. This is interesting because it requires compute pipelines "
19245 "to have a proper descriptor use walk, which they didn't for some time.");
19246 m_errorMonitor->ExpectSuccess();
19247
19248 ASSERT_NO_FATAL_FAILURE(InitState());
19249
19250 char const *csSource = "#version 450\n"
19251 "\n"
19252 "layout(local_size_x=1) in;\n"
19253 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19254 "void main(){\n"
19255 " // x is not used.\n"
19256 "}\n";
19257
19258 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19259
19260 VkDescriptorSetObj descriptorSet(m_device);
19261 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19262
19263 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19264 nullptr,
19265 0,
19266 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19267 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19268 descriptorSet.GetPipelineLayout(),
19269 VK_NULL_HANDLE,
19270 -1 };
19271
19272 VkPipeline pipe;
19273 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19274
19275 m_errorMonitor->VerifyNotFound();
19276
19277 if (err == VK_SUCCESS) {
19278 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19279 }
19280}
19281
19282TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19283 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19284 "sampler portion of a combined image + sampler");
19285 m_errorMonitor->ExpectSuccess();
19286
19287 ASSERT_NO_FATAL_FAILURE(InitState());
19288
19289 VkDescriptorSetLayoutBinding bindings[] = {
19290 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19291 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19292 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19293 };
19294 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19295 VkDescriptorSetLayout dsl;
19296 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19297 ASSERT_VK_SUCCESS(err);
19298
19299 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19300 VkPipelineLayout pl;
19301 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19302 ASSERT_VK_SUCCESS(err);
19303
19304 char const *csSource = "#version 450\n"
19305 "\n"
19306 "layout(local_size_x=1) in;\n"
19307 "layout(set=0, binding=0) uniform sampler s;\n"
19308 "layout(set=0, binding=1) uniform texture2D t;\n"
19309 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19310 "void main() {\n"
19311 " x = texture(sampler2D(t, s), vec2(0));\n"
19312 "}\n";
19313 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19314
19315 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19316 nullptr,
19317 0,
19318 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19319 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19320 pl,
19321 VK_NULL_HANDLE,
19322 -1 };
19323
19324 VkPipeline pipe;
19325 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19326
19327 m_errorMonitor->VerifyNotFound();
19328
19329 if (err == VK_SUCCESS) {
19330 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19331 }
19332
19333 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19334 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19335}
19336
19337TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19338 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19339 "image portion of a combined image + sampler");
19340 m_errorMonitor->ExpectSuccess();
19341
19342 ASSERT_NO_FATAL_FAILURE(InitState());
19343
19344 VkDescriptorSetLayoutBinding bindings[] = {
19345 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19346 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19347 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19348 };
19349 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19350 VkDescriptorSetLayout dsl;
19351 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19352 ASSERT_VK_SUCCESS(err);
19353
19354 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19355 VkPipelineLayout pl;
19356 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19357 ASSERT_VK_SUCCESS(err);
19358
19359 char const *csSource = "#version 450\n"
19360 "\n"
19361 "layout(local_size_x=1) in;\n"
19362 "layout(set=0, binding=0) uniform texture2D t;\n"
19363 "layout(set=0, binding=1) uniform sampler s;\n"
19364 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19365 "void main() {\n"
19366 " x = texture(sampler2D(t, s), vec2(0));\n"
19367 "}\n";
19368 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19369
19370 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19371 nullptr,
19372 0,
19373 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19374 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19375 pl,
19376 VK_NULL_HANDLE,
19377 -1 };
19378
19379 VkPipeline pipe;
19380 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19381
19382 m_errorMonitor->VerifyNotFound();
19383
19384 if (err == VK_SUCCESS) {
19385 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19386 }
19387
19388 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19389 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19390}
19391
19392TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19393 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19394 "both the sampler and the image of a combined image+sampler "
19395 "but via separate variables");
19396 m_errorMonitor->ExpectSuccess();
19397
19398 ASSERT_NO_FATAL_FAILURE(InitState());
19399
19400 VkDescriptorSetLayoutBinding bindings[] = {
19401 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19402 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19403 };
19404 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19405 VkDescriptorSetLayout dsl;
19406 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19407 ASSERT_VK_SUCCESS(err);
19408
19409 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19410 VkPipelineLayout pl;
19411 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19412 ASSERT_VK_SUCCESS(err);
19413
19414 char const *csSource = "#version 450\n"
19415 "\n"
19416 "layout(local_size_x=1) in;\n"
19417 "layout(set=0, binding=0) uniform texture2D t;\n"
19418 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19419 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19420 "void main() {\n"
19421 " x = texture(sampler2D(t, s), vec2(0));\n"
19422 "}\n";
19423 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19424
19425 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19426 nullptr,
19427 0,
19428 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19429 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19430 pl,
19431 VK_NULL_HANDLE,
19432 -1 };
19433
19434 VkPipeline pipe;
19435 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19436
19437 m_errorMonitor->VerifyNotFound();
19438
19439 if (err == VK_SUCCESS) {
19440 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19441 }
19442
19443 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19444 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19445}
19446
19447TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19448 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19449
19450 ASSERT_NO_FATAL_FAILURE(InitState());
19451
19452 // Positive test to check parameter_validation and unique_objects support
19453 // for NV_dedicated_allocation
19454 uint32_t extension_count = 0;
19455 bool supports_nv_dedicated_allocation = false;
19456 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19457 ASSERT_VK_SUCCESS(err);
19458
19459 if (extension_count > 0) {
19460 std::vector<VkExtensionProperties> available_extensions(extension_count);
19461
19462 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19463 ASSERT_VK_SUCCESS(err);
19464
19465 for (const auto &extension_props : available_extensions) {
19466 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19467 supports_nv_dedicated_allocation = true;
19468 }
19469 }
19470 }
19471
19472 if (supports_nv_dedicated_allocation) {
19473 m_errorMonitor->ExpectSuccess();
19474
19475 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19476 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19477 dedicated_buffer_create_info.pNext = nullptr;
19478 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19479
19480 uint32_t queue_family_index = 0;
19481 VkBufferCreateInfo buffer_create_info = {};
19482 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19483 buffer_create_info.pNext = &dedicated_buffer_create_info;
19484 buffer_create_info.size = 1024;
19485 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19486 buffer_create_info.queueFamilyIndexCount = 1;
19487 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19488
19489 VkBuffer buffer;
19490 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19491 ASSERT_VK_SUCCESS(err);
19492
19493 VkMemoryRequirements memory_reqs;
19494 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19495
19496 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19497 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19498 dedicated_memory_info.pNext = nullptr;
19499 dedicated_memory_info.buffer = buffer;
19500 dedicated_memory_info.image = VK_NULL_HANDLE;
19501
19502 VkMemoryAllocateInfo memory_info = {};
19503 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19504 memory_info.pNext = &dedicated_memory_info;
19505 memory_info.allocationSize = memory_reqs.size;
19506
19507 bool pass;
19508 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19509 ASSERT_TRUE(pass);
19510
19511 VkDeviceMemory buffer_memory;
19512 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19513 ASSERT_VK_SUCCESS(err);
19514
19515 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19516 ASSERT_VK_SUCCESS(err);
19517
19518 vkDestroyBuffer(m_device->device(), buffer, NULL);
19519 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19520
19521 m_errorMonitor->VerifyNotFound();
19522 }
19523}
19524
19525TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19526 VkResult err;
19527
19528 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19529
19530 ASSERT_NO_FATAL_FAILURE(InitState());
19531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19532
19533 std::vector<const char *> device_extension_names;
19534 auto features = m_device->phy().features();
19535 // Artificially disable support for non-solid fill modes
19536 features.fillModeNonSolid = false;
19537 // The sacrificial device object
19538 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19539
19540 VkRenderpassObj render_pass(&test_device);
19541
19542 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19543 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19544 pipeline_layout_ci.setLayoutCount = 0;
19545 pipeline_layout_ci.pSetLayouts = NULL;
19546
19547 VkPipelineLayout pipeline_layout;
19548 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19549 ASSERT_VK_SUCCESS(err);
19550
19551 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19552 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19553 rs_ci.pNext = nullptr;
19554 rs_ci.lineWidth = 1.0f;
19555 rs_ci.rasterizerDiscardEnable = true;
19556
19557 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19558 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19559
19560 // Set polygonMode=FILL. No error is expected
19561 m_errorMonitor->ExpectSuccess();
19562 {
19563 VkPipelineObj pipe(&test_device);
19564 pipe.AddShader(&vs);
19565 pipe.AddShader(&fs);
19566 pipe.AddColorAttachment();
19567 // Set polygonMode to a good value
19568 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19569 pipe.SetRasterization(&rs_ci);
19570 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19571 }
19572 m_errorMonitor->VerifyNotFound();
19573
19574 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19575}
19576
19577TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19578 VkResult err;
19579 ASSERT_NO_FATAL_FAILURE(InitState());
19580 ASSERT_NO_FATAL_FAILURE(InitViewport());
19581 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19582
19583 VkPipelineLayout pipeline_layout;
19584 VkPushConstantRange pc_range = {};
19585 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19586 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19587 pipeline_layout_ci.pushConstantRangeCount = 1;
19588 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19589
19590 //
19591 // Check for invalid push constant ranges in pipeline layouts.
19592 //
19593 struct PipelineLayoutTestCase {
19594 VkPushConstantRange const range;
19595 char const *msg;
19596 };
19597
19598 // Check for overlapping ranges
19599 const uint32_t ranges_per_test = 5;
19600 struct OverlappingRangeTestCase {
19601 VkPushConstantRange const ranges[ranges_per_test];
19602 char const *msg;
19603 };
19604
19605 // Run some positive tests to make sure overlap checking in the layer is OK
19606 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19607 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19608 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19609 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19610 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19611 "" },
19612 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19613 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19614 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19615 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19616 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19617 "" } } };
19618 for (const auto &iter : overlapping_range_tests_pos) {
19619 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19620 m_errorMonitor->ExpectSuccess();
19621 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19622 m_errorMonitor->VerifyNotFound();
19623 if (VK_SUCCESS == err) {
19624 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19625 }
19626 }
19627
19628 //
19629 // CmdPushConstants tests
19630 //
19631 const uint8_t dummy_values[100] = {};
19632
19633 BeginCommandBuffer();
19634
19635 // positive overlapping range tests with cmd
19636 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19637 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19638 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19639 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19640 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19641 } };
19642
19643 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19644 const VkPushConstantRange pc_range4[] = {
19645 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19646 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19647 };
19648
19649 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19650 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19651 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19652 ASSERT_VK_SUCCESS(err);
19653 for (const auto &iter : cmd_overlap_tests_pos) {
19654 m_errorMonitor->ExpectSuccess();
19655 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19656 iter.range.size, dummy_values);
19657 m_errorMonitor->VerifyNotFound();
19658 }
19659 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19660
19661 EndCommandBuffer();
19662}
19663
19664
19665
19666
19667
19668
19669
19670#if 0 // A few devices have issues with this test so disabling for now
19671TEST_F(VkPositiveLayerTest, LongFenceChain)
19672{
19673 m_errorMonitor->ExpectSuccess();
19674
19675 ASSERT_NO_FATAL_FAILURE(InitState());
19676 VkResult err;
19677
19678 std::vector<VkFence> fences;
19679
19680 const int chainLength = 32768;
19681
19682 for (int i = 0; i < chainLength; i++) {
19683 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19684 VkFence fence;
19685 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19686 ASSERT_VK_SUCCESS(err);
19687
19688 fences.push_back(fence);
19689
19690 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19691 0, nullptr, 0, nullptr };
19692 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19693 ASSERT_VK_SUCCESS(err);
19694
19695 }
19696
19697 // BOOM, stack overflow.
19698 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19699
19700 for (auto fence : fences)
19701 vkDestroyFence(m_device->device(), fence, nullptr);
19702
19703 m_errorMonitor->VerifyNotFound();
19704}
19705#endif
19706
19707
Cody Northrop1242dfd2016-07-13 17:24:59 -060019708#if defined(ANDROID) && defined(VALIDATION_APK)
19709static bool initialized = false;
19710static bool active = false;
19711
19712// Convert Intents to argv
19713// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019714std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019715 std::vector<std::string> args;
19716 JavaVM &vm = *app.activity->vm;
19717 JNIEnv *p_env;
19718 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19719 return args;
19720
19721 JNIEnv &env = *p_env;
19722 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019723 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019724 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019725 jmethodID get_string_extra_method =
19726 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019727 jvalue get_string_extra_args;
19728 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019729 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019730
19731 std::string args_str;
19732 if (extra_str) {
19733 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19734 args_str = extra_utf;
19735 env.ReleaseStringUTFChars(extra_str, extra_utf);
19736 env.DeleteLocalRef(extra_str);
19737 }
19738
19739 env.DeleteLocalRef(get_string_extra_args.l);
19740 env.DeleteLocalRef(intent);
19741 vm.DetachCurrentThread();
19742
19743 // split args_str
19744 std::stringstream ss(args_str);
19745 std::string arg;
19746 while (std::getline(ss, arg, ' ')) {
19747 if (!arg.empty())
19748 args.push_back(arg);
19749 }
19750
19751 return args;
19752}
19753
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019754static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019755
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019756static void processCommand(struct android_app *app, int32_t cmd) {
19757 switch (cmd) {
19758 case APP_CMD_INIT_WINDOW: {
19759 if (app->window) {
19760 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019761 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019762 break;
19763 }
19764 case APP_CMD_GAINED_FOCUS: {
19765 active = true;
19766 break;
19767 }
19768 case APP_CMD_LOST_FOCUS: {
19769 active = false;
19770 break;
19771 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019772 }
19773}
19774
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019775void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019776 app_dummy();
19777
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019778 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019779
19780 int vulkanSupport = InitVulkan();
19781 if (vulkanSupport == 0) {
19782 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19783 return;
19784 }
19785
19786 app->onAppCmd = processCommand;
19787 app->onInputEvent = processInput;
19788
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019789 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019790 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019791 struct android_poll_source *source;
19792 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019793 if (source) {
19794 source->process(app, source);
19795 }
19796
19797 if (app->destroyRequested != 0) {
19798 VkTestFramework::Finish();
19799 return;
19800 }
19801 }
19802
19803 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019804 // Use the following key to send arguments to gtest, i.e.
19805 // --es args "--gtest_filter=-VkLayerTest.foo"
19806 const char key[] = "args";
19807 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019809 std::string filter = "";
19810 if (args.size() > 0) {
19811 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19812 filter += args[0];
19813 } else {
19814 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19815 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019816
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019817 int argc = 2;
19818 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19819 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019821 // Route output to files until we can override the gtest output
19822 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19823 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019825 ::testing::InitGoogleTest(&argc, argv);
19826 VkTestFramework::InitArgs(&argc, argv);
19827 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019829 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019830
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019831 if (result != 0) {
19832 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19833 } else {
19834 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19835 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019837 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019838
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019839 fclose(stdout);
19840 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019841
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019842 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019844 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019845 }
19846 }
19847}
19848#endif
19849
Tony Barbour300a6082015-04-07 13:44:53 -060019850int main(int argc, char **argv) {
19851 int result;
19852
Cody Northrop8e54a402016-03-08 22:25:52 -070019853#ifdef ANDROID
19854 int vulkanSupport = InitVulkan();
19855 if (vulkanSupport == 0)
19856 return 1;
19857#endif
19858
Tony Barbour300a6082015-04-07 13:44:53 -060019859 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019860 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019861
19862 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19863
19864 result = RUN_ALL_TESTS();
19865
Tony Barbour6918cd52015-04-09 12:58:51 -060019866 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019867 return result;
19868}