blob: 88efefd66bd0b2579fb491afdeb99983bcfca604 [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
Chris Forbes09368e42016-10-13 11:59:22 +13001524#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001525TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1526 VkResult err;
1527 bool pass;
1528
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001529 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1530 // following declaration (which is temporarily being moved below):
1531 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001532 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001533 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001534 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001535 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001536 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001537 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001538
1539 ASSERT_NO_FATAL_FAILURE(InitState());
1540
Ian Elliott3f06ce52016-04-29 14:46:21 -06001541#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1542#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1543 // Use the functions from the VK_KHR_android_surface extension without
1544 // enabling that extension:
1545
1546 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001547 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1549 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001550 pass = (err != VK_SUCCESS);
1551 ASSERT_TRUE(pass);
1552 m_errorMonitor->VerifyFound();
1553#endif // VK_USE_PLATFORM_ANDROID_KHR
1554
Ian Elliott3f06ce52016-04-29 14:46:21 -06001555#if defined(VK_USE_PLATFORM_MIR_KHR)
1556 // Use the functions from the VK_KHR_mir_surface extension without enabling
1557 // that extension:
1558
1559 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001560 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001562 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1563 pass = (err != VK_SUCCESS);
1564 ASSERT_TRUE(pass);
1565 m_errorMonitor->VerifyFound();
1566
1567 // Tell whether an mir_connection supports presentation:
1568 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1570 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001571 m_errorMonitor->VerifyFound();
1572#endif // VK_USE_PLATFORM_MIR_KHR
1573
Ian Elliott3f06ce52016-04-29 14:46:21 -06001574#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1575 // Use the functions from the VK_KHR_wayland_surface extension without
1576 // enabling that extension:
1577
1578 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001579 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1581 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001582 pass = (err != VK_SUCCESS);
1583 ASSERT_TRUE(pass);
1584 m_errorMonitor->VerifyFound();
1585
1586 // Tell whether an wayland_display supports presentation:
1587 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1589 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001590 m_errorMonitor->VerifyFound();
1591#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001592#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593
Ian Elliott3f06ce52016-04-29 14:46:21 -06001594#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001595 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1596 // TO NON-LINUX PLATFORMS:
1597 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001598 // Use the functions from the VK_KHR_win32_surface extension without
1599 // enabling that extension:
1600
1601 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001602 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1604 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001605 pass = (err != VK_SUCCESS);
1606 ASSERT_TRUE(pass);
1607 m_errorMonitor->VerifyFound();
1608
1609 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001611 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001612 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001613// Set this (for now, until all platforms are supported and tested):
1614#define NEED_TO_TEST_THIS_ON_PLATFORM
1615#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001616#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001617 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1618 // TO NON-LINUX PLATFORMS:
1619 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001620#endif
1621#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001622 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1623 // that extension:
1624
1625 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001626 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001628 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1629 pass = (err != VK_SUCCESS);
1630 ASSERT_TRUE(pass);
1631 m_errorMonitor->VerifyFound();
1632
1633 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001634 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001635 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1637 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001638 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001639// Set this (for now, until all platforms are supported and tested):
1640#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001641#endif // VK_USE_PLATFORM_XCB_KHR
1642
Ian Elliott12630812016-04-29 14:35:43 -06001643#if defined(VK_USE_PLATFORM_XLIB_KHR)
1644 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1645 // that extension:
1646
1647 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001648 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001650 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1651 pass = (err != VK_SUCCESS);
1652 ASSERT_TRUE(pass);
1653 m_errorMonitor->VerifyFound();
1654
1655 // Tell whether an Xlib VisualID supports presentation:
1656 Display *dpy = NULL;
1657 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001659 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1660 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001661// Set this (for now, until all platforms are supported and tested):
1662#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001663#endif // VK_USE_PLATFORM_XLIB_KHR
1664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001665// Use the functions from the VK_KHR_surface extension without enabling
1666// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001667
Ian Elliott489eec02016-05-05 14:12:44 -06001668#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001669 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001671 vkDestroySurfaceKHR(instance(), surface, NULL);
1672 m_errorMonitor->VerifyFound();
1673
1674 // Check if surface supports presentation:
1675 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001677 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1678 pass = (err != VK_SUCCESS);
1679 ASSERT_TRUE(pass);
1680 m_errorMonitor->VerifyFound();
1681
1682 // Check surface capabilities:
1683 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1685 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001686 pass = (err != VK_SUCCESS);
1687 ASSERT_TRUE(pass);
1688 m_errorMonitor->VerifyFound();
1689
1690 // Check surface formats:
1691 uint32_t format_count = 0;
1692 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1694 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001695 pass = (err != VK_SUCCESS);
1696 ASSERT_TRUE(pass);
1697 m_errorMonitor->VerifyFound();
1698
1699 // Check surface present modes:
1700 uint32_t present_mode_count = 0;
1701 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1703 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001704 pass = (err != VK_SUCCESS);
1705 ASSERT_TRUE(pass);
1706 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001707#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001708
Ian Elliott1c32c772016-04-28 14:47:13 -06001709 // Use the functions from the VK_KHR_swapchain extension without enabling
1710 // that extension:
1711
1712 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001714 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1715 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001716 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001717 pass = (err != VK_SUCCESS);
1718 ASSERT_TRUE(pass);
1719 m_errorMonitor->VerifyFound();
1720
1721 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1723 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001724 pass = (err != VK_SUCCESS);
1725 ASSERT_TRUE(pass);
1726 m_errorMonitor->VerifyFound();
1727
Chris Forbeseb7d5502016-09-13 18:19:21 +12001728 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1729 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1730 VkFence fence;
1731 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1732
Ian Elliott1c32c772016-04-28 14:47:13 -06001733 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001735 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001736 pass = (err != VK_SUCCESS);
1737 ASSERT_TRUE(pass);
1738 m_errorMonitor->VerifyFound();
1739
Chris Forbeseb7d5502016-09-13 18:19:21 +12001740 vkDestroyFence(m_device->device(), fence, nullptr);
1741
Ian Elliott1c32c772016-04-28 14:47:13 -06001742 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001743 //
1744 // NOTE: Currently can't test this because a real swapchain is needed (as
1745 // opposed to the fake one we created) in order for the layer to lookup the
1746 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001747
1748 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001750 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1751 m_errorMonitor->VerifyFound();
1752}
Chris Forbes09368e42016-10-13 11:59:22 +13001753#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001754
Karl Schultz6addd812016-02-02 17:17:23 -07001755TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1756 VkResult err;
1757 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001761
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001762 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001763
1764 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001765 VkImage image;
1766 VkDeviceMemory mem;
1767 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001768
Karl Schultz6addd812016-02-02 17:17:23 -07001769 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1770 const int32_t tex_width = 32;
1771 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001772
Tony Barboureb254902015-07-15 12:50:33 -06001773 VkImageCreateInfo image_create_info = {};
1774 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001775 image_create_info.pNext = NULL;
1776 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1777 image_create_info.format = tex_format;
1778 image_create_info.extent.width = tex_width;
1779 image_create_info.extent.height = tex_height;
1780 image_create_info.extent.depth = 1;
1781 image_create_info.mipLevels = 1;
1782 image_create_info.arrayLayers = 1;
1783 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1784 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1785 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1786 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001787 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001788
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001789 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001790 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001791 mem_alloc.pNext = NULL;
1792 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001793
Chia-I Wuf7458c52015-10-26 21:10:41 +08001794 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001795 ASSERT_VK_SUCCESS(err);
1796
Karl Schultz6addd812016-02-02 17:17:23 -07001797 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001798
Mark Lobodzinski23065352015-05-29 09:32:35 -05001799 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001800
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001801 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 -07001802 if (!pass) { // If we can't find any unmappable memory this test doesn't
1803 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001804 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001805 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001806 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001807
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001808 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001809 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001810 ASSERT_VK_SUCCESS(err);
1811
1812 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001813 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001814 ASSERT_VK_SUCCESS(err);
1815
1816 // Map memory as if to initialize the image
1817 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001818 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001819
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001820 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001821
Chia-I Wuf7458c52015-10-26 21:10:41 +08001822 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001823 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001824}
1825
Karl Schultz6addd812016-02-02 17:17:23 -07001826TEST_F(VkLayerTest, RebindMemory) {
1827 VkResult err;
1828 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001829
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001831
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001832 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001833
1834 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001835 VkImage image;
1836 VkDeviceMemory mem1;
1837 VkDeviceMemory mem2;
1838 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001839
Karl Schultz6addd812016-02-02 17:17:23 -07001840 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1841 const int32_t tex_width = 32;
1842 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001843
Tony Barboureb254902015-07-15 12:50:33 -06001844 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001845 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1846 image_create_info.pNext = NULL;
1847 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1848 image_create_info.format = tex_format;
1849 image_create_info.extent.width = tex_width;
1850 image_create_info.extent.height = tex_height;
1851 image_create_info.extent.depth = 1;
1852 image_create_info.mipLevels = 1;
1853 image_create_info.arrayLayers = 1;
1854 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1855 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1856 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1857 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001858
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001859 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001860 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1861 mem_alloc.pNext = NULL;
1862 mem_alloc.allocationSize = 0;
1863 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001864
Karl Schultz6addd812016-02-02 17:17:23 -07001865 // Introduce failure, do NOT set memProps to
1866 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001867 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001868 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001869 ASSERT_VK_SUCCESS(err);
1870
Karl Schultz6addd812016-02-02 17:17:23 -07001871 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001872
1873 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001874 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001875 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001876
1877 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001878 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001879 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001880 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001881 ASSERT_VK_SUCCESS(err);
1882
1883 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001884 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001885 ASSERT_VK_SUCCESS(err);
1886
Karl Schultz6addd812016-02-02 17:17:23 -07001887 // Introduce validation failure, try to bind a different memory object to
1888 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001889 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001890
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001891 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001892
Chia-I Wuf7458c52015-10-26 21:10:41 +08001893 vkDestroyImage(m_device->device(), image, NULL);
1894 vkFreeMemory(m_device->device(), mem1, NULL);
1895 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001896}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001897
Karl Schultz6addd812016-02-02 17:17:23 -07001898TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001899 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1902 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001903
1904 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001905 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1906 fenceInfo.pNext = NULL;
1907 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001908
Tony Barbour300a6082015-04-07 13:44:53 -06001909 ASSERT_NO_FATAL_FAILURE(InitState());
1910 ASSERT_NO_FATAL_FAILURE(InitViewport());
1911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1912
Tony Barbourfe3351b2015-07-28 10:17:20 -06001913 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001914 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001915 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001916
1917 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001918
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001919 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001920 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1921 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001922 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001923 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001924 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001925 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001926 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001927 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001928 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001929
1930 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001931 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001932
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001933 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001934}
Chris Forbes4e44c912016-06-16 10:20:00 +12001935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936TEST_F(VkLayerTest, InvalidUsageBits) {
1937 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1938 "Initialize buffer with wrong usage then perform copy expecting errors "
1939 "from both the image and the buffer (2 calls)");
1940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001941
1942 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001943
1944 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1945
Tony Barbourf92621a2016-05-02 14:28:12 -06001946 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001947 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001948 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001949 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001950
Tony Barbourf92621a2016-05-02 14:28:12 -06001951 VkImageView dsv;
1952 VkImageViewCreateInfo dsvci = {};
1953 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1954 dsvci.image = image.handle();
1955 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001956 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06001957 dsvci.subresourceRange.layerCount = 1;
1958 dsvci.subresourceRange.baseMipLevel = 0;
1959 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001960 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001961
Tony Barbourf92621a2016-05-02 14:28:12 -06001962 // Create a view with depth / stencil aspect for image with different usage
1963 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001964
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001965 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001966
1967 // Initialize buffer with TRANSFER_DST usage
1968 vk_testing::Buffer buffer;
1969 VkMemoryPropertyFlags reqs = 0;
1970 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1971 VkBufferImageCopy region = {};
1972 region.bufferRowLength = 128;
1973 region.bufferImageHeight = 128;
1974 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1975 region.imageSubresource.layerCount = 1;
1976 region.imageExtent.height = 16;
1977 region.imageExtent.width = 16;
1978 region.imageExtent.depth = 1;
1979
Tony Barbourf92621a2016-05-02 14:28:12 -06001980 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1981 // TRANSFER_DST
1982 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001983
Chris Forbesda581202016-10-06 18:25:26 +13001984 // two separate errors from this call:
1985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1987
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001988 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1989 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001990 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001991}
Tony Barbour75d79f02016-08-30 09:39:07 -06001992
Tony Barbour75d79f02016-08-30 09:39:07 -06001993
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001994#endif // MEM_TRACKER_TESTS
1995
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001996#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001997
1998TEST_F(VkLayerTest, LeakAnObject) {
1999 VkResult err;
2000
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002001 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002002
2003 // Note that we have to create a new device since destroying the
2004 // framework's device causes Teardown() to fail and just calling Teardown
2005 // will destroy the errorMonitor.
2006
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002008
2009 ASSERT_NO_FATAL_FAILURE(InitState());
2010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002011 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002012 std::vector<VkDeviceQueueCreateInfo> queue_info;
2013 queue_info.reserve(queue_props.size());
2014 std::vector<std::vector<float>> queue_priorities;
2015 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2016 VkDeviceQueueCreateInfo qi = {};
2017 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2018 qi.pNext = NULL;
2019 qi.queueFamilyIndex = i;
2020 qi.queueCount = queue_props[i].queueCount;
2021 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2022 qi.pQueuePriorities = queue_priorities[i].data();
2023 queue_info.push_back(qi);
2024 }
2025
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002026 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002027
2028 // The sacrificial device object
2029 VkDevice testDevice;
2030 VkDeviceCreateInfo device_create_info = {};
2031 auto features = m_device->phy().features();
2032 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2033 device_create_info.pNext = NULL;
2034 device_create_info.queueCreateInfoCount = queue_info.size();
2035 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002036 device_create_info.enabledLayerCount = 0;
2037 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002038 device_create_info.pEnabledFeatures = &features;
2039 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2040 ASSERT_VK_SUCCESS(err);
2041
2042 VkFence fence;
2043 VkFenceCreateInfo fence_create_info = {};
2044 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2045 fence_create_info.pNext = NULL;
2046 fence_create_info.flags = 0;
2047 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2048 ASSERT_VK_SUCCESS(err);
2049
2050 // Induce failure by not calling vkDestroyFence
2051 vkDestroyDevice(testDevice, NULL);
2052 m_errorMonitor->VerifyFound();
2053}
2054
2055TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2056
2057 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2058 "attempt to delete them from another.");
2059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002061
Cody Northropc31a84f2016-08-22 10:41:47 -06002062 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002063 VkCommandPool command_pool_one;
2064 VkCommandPool command_pool_two;
2065
2066 VkCommandPoolCreateInfo pool_create_info{};
2067 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2068 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2069 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2070
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002071 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002072
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002073 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002074
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002075 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002076 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002077 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002078 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002079 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002080 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002081 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002082
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002083 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002084
2085 m_errorMonitor->VerifyFound();
2086
2087 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2088 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2089}
2090
2091TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2092 VkResult err;
2093
2094 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002095 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002096
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002098
2099 ASSERT_NO_FATAL_FAILURE(InitState());
2100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2101
2102 VkDescriptorPoolSize ds_type_count = {};
2103 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2104 ds_type_count.descriptorCount = 1;
2105
2106 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2107 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2108 ds_pool_ci.pNext = NULL;
2109 ds_pool_ci.flags = 0;
2110 ds_pool_ci.maxSets = 1;
2111 ds_pool_ci.poolSizeCount = 1;
2112 ds_pool_ci.pPoolSizes = &ds_type_count;
2113
2114 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002115 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002116 ASSERT_VK_SUCCESS(err);
2117
2118 // Create a second descriptor pool
2119 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002120 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002121 ASSERT_VK_SUCCESS(err);
2122
2123 VkDescriptorSetLayoutBinding dsl_binding = {};
2124 dsl_binding.binding = 0;
2125 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2126 dsl_binding.descriptorCount = 1;
2127 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2128 dsl_binding.pImmutableSamplers = NULL;
2129
2130 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2131 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2132 ds_layout_ci.pNext = NULL;
2133 ds_layout_ci.bindingCount = 1;
2134 ds_layout_ci.pBindings = &dsl_binding;
2135
2136 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002137 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002138 ASSERT_VK_SUCCESS(err);
2139
2140 VkDescriptorSet descriptorSet;
2141 VkDescriptorSetAllocateInfo alloc_info = {};
2142 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2143 alloc_info.descriptorSetCount = 1;
2144 alloc_info.descriptorPool = ds_pool_one;
2145 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002146 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002147 ASSERT_VK_SUCCESS(err);
2148
2149 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2150
2151 m_errorMonitor->VerifyFound();
2152
2153 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2154 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2155 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2156}
2157
2158TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002160
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002161 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002162
2163 ASSERT_NO_FATAL_FAILURE(InitState());
2164
2165 // Pass bogus handle into GetImageMemoryRequirements
2166 VkMemoryRequirements mem_reqs;
2167 uint64_t fakeImageHandle = 0xCADECADE;
2168 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2169
2170 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2171
2172 m_errorMonitor->VerifyFound();
2173}
2174
Karl Schultz6addd812016-02-02 17:17:23 -07002175TEST_F(VkLayerTest, PipelineNotBound) {
2176 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002177
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002178 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002179
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002181
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002182 ASSERT_NO_FATAL_FAILURE(InitState());
2183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002184
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002185 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002186 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2187 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002188
2189 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002190 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2191 ds_pool_ci.pNext = NULL;
2192 ds_pool_ci.maxSets = 1;
2193 ds_pool_ci.poolSizeCount = 1;
2194 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002195
2196 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002198 ASSERT_VK_SUCCESS(err);
2199
2200 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002201 dsl_binding.binding = 0;
2202 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2203 dsl_binding.descriptorCount = 1;
2204 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2205 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002206
2207 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002208 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2209 ds_layout_ci.pNext = NULL;
2210 ds_layout_ci.bindingCount = 1;
2211 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002212
2213 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002214 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002215 ASSERT_VK_SUCCESS(err);
2216
2217 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002218 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002219 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002220 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002221 alloc_info.descriptorPool = ds_pool;
2222 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002224 ASSERT_VK_SUCCESS(err);
2225
2226 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002227 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2228 pipeline_layout_ci.pNext = NULL;
2229 pipeline_layout_ci.setLayoutCount = 1;
2230 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002231
2232 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002233 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234 ASSERT_VK_SUCCESS(err);
2235
Mark Youngad779052016-01-06 14:26:04 -07002236 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002237
2238 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002239 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002240
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002241 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002242
Chia-I Wuf7458c52015-10-26 21:10:41 +08002243 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2244 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2245 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002246}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002247
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002248TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2249 VkResult err;
2250
2251 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2252 "during bind[Buffer|Image]Memory time");
2253
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002254 ASSERT_NO_FATAL_FAILURE(InitState());
2255
2256 // Create an image, allocate memory, set a bad typeIndex and then try to
2257 // bind it
2258 VkImage image;
2259 VkDeviceMemory mem;
2260 VkMemoryRequirements mem_reqs;
2261 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2262 const int32_t tex_width = 32;
2263 const int32_t tex_height = 32;
2264
2265 VkImageCreateInfo image_create_info = {};
2266 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2267 image_create_info.pNext = NULL;
2268 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2269 image_create_info.format = tex_format;
2270 image_create_info.extent.width = tex_width;
2271 image_create_info.extent.height = tex_height;
2272 image_create_info.extent.depth = 1;
2273 image_create_info.mipLevels = 1;
2274 image_create_info.arrayLayers = 1;
2275 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2276 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2277 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2278 image_create_info.flags = 0;
2279
2280 VkMemoryAllocateInfo mem_alloc = {};
2281 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2282 mem_alloc.pNext = NULL;
2283 mem_alloc.allocationSize = 0;
2284 mem_alloc.memoryTypeIndex = 0;
2285
2286 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2287 ASSERT_VK_SUCCESS(err);
2288
2289 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2290 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002291
2292 // Introduce Failure, select invalid TypeIndex
2293 VkPhysicalDeviceMemoryProperties memory_info;
2294
2295 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2296 unsigned int i;
2297 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2298 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2299 mem_alloc.memoryTypeIndex = i;
2300 break;
2301 }
2302 }
2303 if (i >= memory_info.memoryTypeCount) {
2304 printf("No invalid memory type index could be found; skipped.\n");
2305 vkDestroyImage(m_device->device(), image, NULL);
2306 return;
2307 }
2308
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002309 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 -06002310
2311 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2312 ASSERT_VK_SUCCESS(err);
2313
2314 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2315 (void)err;
2316
2317 m_errorMonitor->VerifyFound();
2318
2319 vkDestroyImage(m_device->device(), image, NULL);
2320 vkFreeMemory(m_device->device(), mem, NULL);
2321}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002322
Karl Schultz6addd812016-02-02 17:17:23 -07002323TEST_F(VkLayerTest, BindInvalidMemory) {
2324 VkResult err;
2325 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002326
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002328
Tobin Ehlisec598302015-09-15 15:02:17 -06002329 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002330
2331 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002332 VkImage image;
2333 VkDeviceMemory mem;
2334 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002335
Karl Schultz6addd812016-02-02 17:17:23 -07002336 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2337 const int32_t tex_width = 32;
2338 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002339
2340 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002341 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2342 image_create_info.pNext = NULL;
2343 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2344 image_create_info.format = tex_format;
2345 image_create_info.extent.width = tex_width;
2346 image_create_info.extent.height = tex_height;
2347 image_create_info.extent.depth = 1;
2348 image_create_info.mipLevels = 1;
2349 image_create_info.arrayLayers = 1;
2350 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2351 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2352 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2353 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002354
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002355 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002356 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2357 mem_alloc.pNext = NULL;
2358 mem_alloc.allocationSize = 0;
2359 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002360
Chia-I Wuf7458c52015-10-26 21:10:41 +08002361 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002362 ASSERT_VK_SUCCESS(err);
2363
Karl Schultz6addd812016-02-02 17:17:23 -07002364 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002365
2366 mem_alloc.allocationSize = mem_reqs.size;
2367
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002368 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002369 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002370
2371 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002372 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002373 ASSERT_VK_SUCCESS(err);
2374
2375 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002376 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002377
2378 // Try to bind free memory that has been freed
2379 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2380 // This may very well return an error.
2381 (void)err;
2382
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002383 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002384
Chia-I Wuf7458c52015-10-26 21:10:41 +08002385 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002386}
2387
Karl Schultz6addd812016-02-02 17:17:23 -07002388TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2389 VkResult err;
2390 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002391
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002393
Tobin Ehlisec598302015-09-15 15:02:17 -06002394 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002395
Karl Schultz6addd812016-02-02 17:17:23 -07002396 // Create an image object, allocate memory, destroy the object and then try
2397 // to bind it
2398 VkImage image;
2399 VkDeviceMemory mem;
2400 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002401
Karl Schultz6addd812016-02-02 17:17:23 -07002402 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2403 const int32_t tex_width = 32;
2404 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002405
2406 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002407 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2408 image_create_info.pNext = NULL;
2409 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2410 image_create_info.format = tex_format;
2411 image_create_info.extent.width = tex_width;
2412 image_create_info.extent.height = tex_height;
2413 image_create_info.extent.depth = 1;
2414 image_create_info.mipLevels = 1;
2415 image_create_info.arrayLayers = 1;
2416 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2417 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2418 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2419 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002420
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002421 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002422 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2423 mem_alloc.pNext = NULL;
2424 mem_alloc.allocationSize = 0;
2425 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002426
Chia-I Wuf7458c52015-10-26 21:10:41 +08002427 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002428 ASSERT_VK_SUCCESS(err);
2429
Karl Schultz6addd812016-02-02 17:17:23 -07002430 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002431
2432 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002433 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002434 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002435
2436 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002437 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002438 ASSERT_VK_SUCCESS(err);
2439
2440 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002441 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002442 ASSERT_VK_SUCCESS(err);
2443
2444 // Now Try to bind memory to this destroyed object
2445 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2446 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002447 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002448
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002449 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002450
Chia-I Wuf7458c52015-10-26 21:10:41 +08002451 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002452}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002453
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002454#endif // OBJ_TRACKER_TESTS
2455
Tobin Ehlis0788f522015-05-26 16:11:58 -06002456#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002457
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002458TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2459 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2460
2461 ASSERT_NO_FATAL_FAILURE(InitState());
2462 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2463
2464 VkVertexInputBindingDescription input_binding;
2465 memset(&input_binding, 0, sizeof(input_binding));
2466
2467 VkVertexInputAttributeDescription input_attribs;
2468 memset(&input_attribs, 0, sizeof(input_attribs));
2469
2470 // Pick a really bad format for this purpose and make sure it should fail
2471 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2472 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2473 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2474 printf("Format unsuitable for test; skipped.\n");
2475 return;
2476 }
2477
2478 input_attribs.location = 0;
2479 char const *vsSource = "#version 450\n"
2480 "\n"
2481 "out gl_PerVertex {\n"
2482 " vec4 gl_Position;\n"
2483 "};\n"
2484 "void main(){\n"
2485 " gl_Position = vec4(1);\n"
2486 "}\n";
2487 char const *fsSource = "#version 450\n"
2488 "\n"
2489 "layout(location=0) out vec4 color;\n"
2490 "void main(){\n"
2491 " color = vec4(1);\n"
2492 "}\n";
2493
2494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2495 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2496 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2497
2498 VkPipelineObj pipe(m_device);
2499 pipe.AddColorAttachment();
2500 pipe.AddShader(&vs);
2501 pipe.AddShader(&fs);
2502
2503 pipe.AddVertexInputBindings(&input_binding, 1);
2504 pipe.AddVertexInputAttribs(&input_attribs, 1);
2505
2506 VkDescriptorSetObj descriptorSet(m_device);
2507 descriptorSet.AppendDummy();
2508 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2509
2510 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2511
2512 m_errorMonitor->VerifyFound();
2513}
2514
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002515TEST_F(VkLayerTest, ImageSampleCounts) {
2516
2517 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2518 "validation errors.");
2519 ASSERT_NO_FATAL_FAILURE(InitState());
2520
2521 VkMemoryPropertyFlags reqs = 0;
2522 VkImageCreateInfo image_create_info = {};
2523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2524 image_create_info.pNext = NULL;
2525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2526 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2527 image_create_info.extent.width = 256;
2528 image_create_info.extent.height = 256;
2529 image_create_info.extent.depth = 1;
2530 image_create_info.mipLevels = 1;
2531 image_create_info.arrayLayers = 1;
2532 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2533 image_create_info.flags = 0;
2534
2535 VkImageBlit blit_region = {};
2536 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2537 blit_region.srcSubresource.baseArrayLayer = 0;
2538 blit_region.srcSubresource.layerCount = 1;
2539 blit_region.srcSubresource.mipLevel = 0;
2540 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2541 blit_region.dstSubresource.baseArrayLayer = 0;
2542 blit_region.dstSubresource.layerCount = 1;
2543 blit_region.dstSubresource.mipLevel = 0;
2544
2545 // Create two images, the source with sampleCount = 2, and attempt to blit
2546 // between them
2547 {
2548 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002549 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002550 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002551 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002552 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002553 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002554 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002555 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002556 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2558 "of VK_SAMPLE_COUNT_2_BIT but "
2559 "must be VK_SAMPLE_COUNT_1_BIT");
2560 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2561 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002562 m_errorMonitor->VerifyFound();
2563 m_commandBuffer->EndCommandBuffer();
2564 }
2565
2566 // Create two images, the dest with sampleCount = 4, and attempt to blit
2567 // between them
2568 {
2569 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002570 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002571 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002572 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002573 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002574 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002575 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002576 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002577 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2579 "of VK_SAMPLE_COUNT_4_BIT but "
2580 "must be VK_SAMPLE_COUNT_1_BIT");
2581 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2582 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002583 m_errorMonitor->VerifyFound();
2584 m_commandBuffer->EndCommandBuffer();
2585 }
2586
2587 VkBufferImageCopy copy_region = {};
2588 copy_region.bufferRowLength = 128;
2589 copy_region.bufferImageHeight = 128;
2590 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2591 copy_region.imageSubresource.layerCount = 1;
2592 copy_region.imageExtent.height = 64;
2593 copy_region.imageExtent.width = 64;
2594 copy_region.imageExtent.depth = 1;
2595
2596 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2597 // buffer to image
2598 {
2599 vk_testing::Buffer src_buffer;
2600 VkMemoryPropertyFlags reqs = 0;
2601 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2602 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002603 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002604 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002605 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002606 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2608 "of VK_SAMPLE_COUNT_8_BIT but "
2609 "must be VK_SAMPLE_COUNT_1_BIT");
2610 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2611 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002612 m_errorMonitor->VerifyFound();
2613 m_commandBuffer->EndCommandBuffer();
2614 }
2615
2616 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2617 // image to buffer
2618 {
2619 vk_testing::Buffer dst_buffer;
2620 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2621 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002622 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002623 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002624 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002625 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2627 "of VK_SAMPLE_COUNT_2_BIT but "
2628 "must be VK_SAMPLE_COUNT_1_BIT");
2629 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002630 dst_buffer.handle(), 1, &copy_region);
2631 m_errorMonitor->VerifyFound();
2632 m_commandBuffer->EndCommandBuffer();
2633 }
2634}
2635
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002636TEST_F(VkLayerTest, BlitImageFormats) {
2637
2638 // Image blit with mismatched formats
2639 const char * expected_message =
2640 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2641 " the other one must also have signed/unsigned integer format";
2642
2643 ASSERT_NO_FATAL_FAILURE(InitState());
2644
2645 VkImageObj src_image(m_device);
2646 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2647 VkImageObj dst_image(m_device);
2648 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2649 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002650 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 -06002651
2652 VkImageBlit blitRegion = {};
2653 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2654 blitRegion.srcSubresource.baseArrayLayer = 0;
2655 blitRegion.srcSubresource.layerCount = 1;
2656 blitRegion.srcSubresource.mipLevel = 0;
2657 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2658 blitRegion.dstSubresource.baseArrayLayer = 0;
2659 blitRegion.dstSubresource.layerCount = 1;
2660 blitRegion.dstSubresource.mipLevel = 0;
2661
2662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2663
2664 // Unsigned int vs not an int
2665 BeginCommandBuffer();
2666 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2667 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2668
2669 m_errorMonitor->VerifyFound();
2670
2671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2672
2673 // Unsigned int vs signed int
2674 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2675 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2676
2677 m_errorMonitor->VerifyFound();
2678
2679 EndCommandBuffer();
2680}
2681
2682
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002683TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2684 VkResult err;
2685 bool pass;
2686
2687 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2688 ASSERT_NO_FATAL_FAILURE(InitState());
2689
2690 // If w/d/h granularity is 1, test is not meaningful
2691 // TODO: When virtual device limits are available, create a set of limits for this test that
2692 // will always have a granularity of > 1 for w, h, and d
2693 auto index = m_device->graphics_queue_node_index_;
2694 auto queue_family_properties = m_device->phy().queue_properties();
2695
2696 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2697 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2698 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2699 return;
2700 }
2701
2702 // Create two images of different types and try to copy between them
2703 VkImage srcImage;
2704 VkImage dstImage;
2705 VkDeviceMemory srcMem;
2706 VkDeviceMemory destMem;
2707 VkMemoryRequirements memReqs;
2708
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002709 VkImageCreateInfo image_create_info = {};
2710 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2711 image_create_info.pNext = NULL;
2712 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2713 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2714 image_create_info.extent.width = 32;
2715 image_create_info.extent.height = 32;
2716 image_create_info.extent.depth = 1;
2717 image_create_info.mipLevels = 1;
2718 image_create_info.arrayLayers = 4;
2719 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2720 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2721 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2722 image_create_info.flags = 0;
2723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002724 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002725 ASSERT_VK_SUCCESS(err);
2726
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002727 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002728 ASSERT_VK_SUCCESS(err);
2729
2730 // Allocate memory
2731 VkMemoryAllocateInfo memAlloc = {};
2732 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2733 memAlloc.pNext = NULL;
2734 memAlloc.allocationSize = 0;
2735 memAlloc.memoryTypeIndex = 0;
2736
2737 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2738 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002739 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002740 ASSERT_TRUE(pass);
2741 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2742 ASSERT_VK_SUCCESS(err);
2743
2744 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2745 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002746 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002747 ASSERT_VK_SUCCESS(err);
2748 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2749 ASSERT_VK_SUCCESS(err);
2750
2751 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2752 ASSERT_VK_SUCCESS(err);
2753 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2754 ASSERT_VK_SUCCESS(err);
2755
2756 BeginCommandBuffer();
2757 VkImageCopy copyRegion;
2758 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2759 copyRegion.srcSubresource.mipLevel = 0;
2760 copyRegion.srcSubresource.baseArrayLayer = 0;
2761 copyRegion.srcSubresource.layerCount = 1;
2762 copyRegion.srcOffset.x = 0;
2763 copyRegion.srcOffset.y = 0;
2764 copyRegion.srcOffset.z = 0;
2765 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2766 copyRegion.dstSubresource.mipLevel = 0;
2767 copyRegion.dstSubresource.baseArrayLayer = 0;
2768 copyRegion.dstSubresource.layerCount = 1;
2769 copyRegion.dstOffset.x = 0;
2770 copyRegion.dstOffset.y = 0;
2771 copyRegion.dstOffset.z = 0;
2772 copyRegion.extent.width = 1;
2773 copyRegion.extent.height = 1;
2774 copyRegion.extent.depth = 1;
2775
2776 // Introduce failure by setting srcOffset to a bad granularity value
2777 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2779 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002780 m_errorMonitor->VerifyFound();
2781
2782 // Introduce failure by setting extent to a bad granularity value
2783 copyRegion.srcOffset.y = 0;
2784 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2786 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002787 m_errorMonitor->VerifyFound();
2788
2789 // Now do some buffer/image copies
2790 vk_testing::Buffer buffer;
2791 VkMemoryPropertyFlags reqs = 0;
2792 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2793 VkBufferImageCopy region = {};
2794 region.bufferOffset = 0;
2795 region.bufferRowLength = 3;
2796 region.bufferImageHeight = 128;
2797 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2798 region.imageSubresource.layerCount = 1;
2799 region.imageExtent.height = 16;
2800 region.imageExtent.width = 16;
2801 region.imageExtent.depth = 1;
2802 region.imageOffset.x = 0;
2803 region.imageOffset.y = 0;
2804 region.imageOffset.z = 0;
2805
2806 // Introduce failure by setting bufferRowLength to a bad granularity value
2807 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2809 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2810 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002811 m_errorMonitor->VerifyFound();
2812 region.bufferRowLength = 128;
2813
2814 // Introduce failure by setting bufferOffset to a bad granularity value
2815 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2817 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2818 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002819 m_errorMonitor->VerifyFound();
2820 region.bufferOffset = 0;
2821
2822 // Introduce failure by setting bufferImageHeight to a bad granularity value
2823 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2825 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2826 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002827 m_errorMonitor->VerifyFound();
2828 region.bufferImageHeight = 128;
2829
2830 // Introduce failure by setting imageExtent to a bad granularity value
2831 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2833 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2834 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002835 m_errorMonitor->VerifyFound();
2836 region.imageExtent.width = 16;
2837
2838 // Introduce failure by setting imageOffset to a bad granularity value
2839 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2841 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2842 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002843 m_errorMonitor->VerifyFound();
2844
2845 EndCommandBuffer();
2846
2847 vkDestroyImage(m_device->device(), srcImage, NULL);
2848 vkDestroyImage(m_device->device(), dstImage, NULL);
2849 vkFreeMemory(m_device->device(), srcMem, NULL);
2850 vkFreeMemory(m_device->device(), destMem, NULL);
2851}
2852
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002853TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002854 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2855 "attempt to submit them on a queue created in a different "
2856 "queue family.");
2857
Cody Northropc31a84f2016-08-22 10:41:47 -06002858 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002859 // This test is meaningless unless we have multiple queue families
2860 auto queue_family_properties = m_device->phy().queue_properties();
2861 if (queue_family_properties.size() < 2) {
2862 return;
2863 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002865 // Get safe index of another queue family
2866 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2867 ASSERT_NO_FATAL_FAILURE(InitState());
2868 // Create a second queue using a different queue family
2869 VkQueue other_queue;
2870 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2871
2872 // Record an empty cmd buffer
2873 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2874 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2875 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2876 vkEndCommandBuffer(m_commandBuffer->handle());
2877
2878 // And submit on the wrong queue
2879 VkSubmitInfo submit_info = {};
2880 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2881 submit_info.commandBufferCount = 1;
2882 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002883 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002884
2885 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002886}
2887
Chris Forbes4c24a922016-11-16 08:59:10 +13002888TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2889 ASSERT_NO_FATAL_FAILURE(InitState());
2890
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002891 // There are no attachments, but refer to attachment 0.
2892 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002893 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002894 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2895 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002896 };
2897
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002898 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2899 nullptr,
2900 0,
2901 0,
2902 nullptr,
2903 1,
2904 subpasses,
2905 0,
2906 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002907 VkRenderPass rp;
2908
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002909 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002911 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002912 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2913 m_errorMonitor->VerifyFound();
2914}
2915
Chris Forbesa58c4522016-09-28 15:19:39 +13002916TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2917 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2918 ASSERT_NO_FATAL_FAILURE(InitState());
2919
2920 // A renderpass with two subpasses, both writing the same attachment.
2921 VkAttachmentDescription attach[] = {
2922 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2923 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2924 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2925 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2926 },
2927 };
2928 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2929 VkSubpassDescription subpasses[] = {
2930 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2931 1, &ref, nullptr, nullptr, 0, nullptr },
2932 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2933 1, &ref, nullptr, nullptr, 0, nullptr },
2934 };
2935 VkSubpassDependency dep = {
2936 0, 1,
2937 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2938 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2939 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2940 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2941 VK_DEPENDENCY_BY_REGION_BIT
2942 };
2943 VkRenderPassCreateInfo rpci = {
2944 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2945 0, 1, attach, 2, subpasses, 1, &dep
2946 };
2947 VkRenderPass rp;
2948 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2949 ASSERT_VK_SUCCESS(err);
2950
2951 VkImageObj image(m_device);
2952 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2953 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2954 VK_IMAGE_TILING_OPTIMAL, 0);
2955 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2956
2957 VkFramebufferCreateInfo fbci = {
2958 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2959 0, rp, 1, &imageView, 32, 32, 1
2960 };
2961 VkFramebuffer fb;
2962 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2963 ASSERT_VK_SUCCESS(err);
2964
2965 char const *vsSource =
2966 "#version 450\n"
2967 "void main() { gl_Position = vec4(1); }\n";
2968 char const *fsSource =
2969 "#version 450\n"
2970 "layout(location=0) out vec4 color;\n"
2971 "void main() { color = vec4(1); }\n";
2972
2973 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2974 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2975 VkPipelineObj pipe(m_device);
2976 pipe.AddColorAttachment();
2977 pipe.AddShader(&vs);
2978 pipe.AddShader(&fs);
2979 VkViewport view_port = {};
2980 m_viewports.push_back(view_port);
2981 pipe.SetViewport(m_viewports);
2982 VkRect2D rect = {};
2983 m_scissors.push_back(rect);
2984 pipe.SetScissor(m_scissors);
2985
2986 VkPipelineLayoutCreateInfo plci = {
2987 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2988 0, 0, nullptr, 0, nullptr
2989 };
2990 VkPipelineLayout pl;
2991 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2992 ASSERT_VK_SUCCESS(err);
2993 pipe.CreateVKPipeline(pl, rp);
2994
2995 BeginCommandBuffer();
2996
2997 VkRenderPassBeginInfo rpbi = {
2998 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2999 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
3000 };
3001
3002 // subtest 1: bind in the wrong subpass
3003 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3004 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3006 "built for subpass 0 but used in subpass 1");
3007 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3008 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3009 m_errorMonitor->VerifyFound();
3010
3011 vkCmdEndRenderPass(m_commandBuffer->handle());
3012
3013 // subtest 2: bind in correct subpass, then transition to next subpass
3014 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3015 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3016 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3018 "built for subpass 0 but used in subpass 1");
3019 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3020 m_errorMonitor->VerifyFound();
3021
3022 vkCmdEndRenderPass(m_commandBuffer->handle());
3023
3024 EndCommandBuffer();
3025
3026 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3027 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3028 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3029}
3030
Tony Barbour4e919972016-08-09 13:27:40 -06003031TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3032 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3033 "with extent outside of framebuffer");
3034 ASSERT_NO_FATAL_FAILURE(InitState());
3035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3036
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3038 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003039
3040 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3041 m_renderPassBeginInfo.renderArea.extent.width = 257;
3042 m_renderPassBeginInfo.renderArea.extent.height = 257;
3043 BeginCommandBuffer();
3044 m_errorMonitor->VerifyFound();
3045}
3046
3047TEST_F(VkLayerTest, DisabledIndependentBlend) {
3048 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3049 "blend and then specifying different blend states for two "
3050 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003051 VkPhysicalDeviceFeatures features = {};
3052 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003053 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003054
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3056 "Invalid Pipeline CreateInfo: If independent blend feature not "
3057 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003058
Cody Northropc31a84f2016-08-22 10:41:47 -06003059 VkDescriptorSetObj descriptorSet(m_device);
3060 descriptorSet.AppendDummy();
3061 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003062
Cody Northropc31a84f2016-08-22 10:41:47 -06003063 VkPipelineObj pipeline(m_device);
3064 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003065 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003066 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003067
Cody Northropc31a84f2016-08-22 10:41:47 -06003068 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3069 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3070 att_state1.blendEnable = VK_TRUE;
3071 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3072 att_state2.blendEnable = VK_FALSE;
3073 pipeline.AddColorAttachment(0, &att_state1);
3074 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003075 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003076 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003077}
3078
Chris Forbes26ec2122016-11-29 08:58:33 +13003079#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003080TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3081 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3082 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003083 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003084
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3086 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003087
3088 // Create a renderPass with a single color attachment
3089 VkAttachmentReference attach = {};
3090 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3091 VkSubpassDescription subpass = {};
3092 VkRenderPassCreateInfo rpci = {};
3093 rpci.subpassCount = 1;
3094 rpci.pSubpasses = &subpass;
3095 rpci.attachmentCount = 1;
3096 VkAttachmentDescription attach_desc = {};
3097 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3098 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3099 rpci.pAttachments = &attach_desc;
3100 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3101 VkRenderPass rp;
3102 subpass.pDepthStencilAttachment = &attach;
3103 subpass.pColorAttachments = NULL;
3104 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3105 m_errorMonitor->VerifyFound();
3106}
Chris Forbes26ec2122016-11-29 08:58:33 +13003107#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003108
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003109TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3110 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3111 "attachment reference of VK_ATTACHMENT_UNUSED");
3112
3113 ASSERT_NO_FATAL_FAILURE(InitState());
3114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3115
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003117
3118 VkAttachmentReference color_attach = {};
3119 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3120 color_attach.attachment = 0;
3121 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3122 VkSubpassDescription subpass = {};
3123 subpass.colorAttachmentCount = 1;
3124 subpass.pColorAttachments = &color_attach;
3125 subpass.preserveAttachmentCount = 1;
3126 subpass.pPreserveAttachments = &preserve_attachment;
3127
3128 VkRenderPassCreateInfo rpci = {};
3129 rpci.subpassCount = 1;
3130 rpci.pSubpasses = &subpass;
3131 rpci.attachmentCount = 1;
3132 VkAttachmentDescription attach_desc = {};
3133 attach_desc.format = VK_FORMAT_UNDEFINED;
3134 rpci.pAttachments = &attach_desc;
3135 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3136 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003137 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003138
3139 m_errorMonitor->VerifyFound();
3140
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003141 if (result == VK_SUCCESS) {
3142 vkDestroyRenderPass(m_device->device(), rp, NULL);
3143 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003144}
3145
Chris Forbesc5389742016-06-29 11:49:23 +12003146TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003147 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3148 "when the source of a subpass multisample resolve "
3149 "does not have multiple samples.");
3150
Chris Forbesc5389742016-06-29 11:49:23 +12003151 ASSERT_NO_FATAL_FAILURE(InitState());
3152
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3154 "Subpass 0 requests multisample resolve from attachment 0 which has "
3155 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003156
3157 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003158 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3159 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3160 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3161 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3162 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3163 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003164 };
3165
3166 VkAttachmentReference color = {
3167 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3168 };
3169
3170 VkAttachmentReference resolve = {
3171 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3172 };
3173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003174 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003176 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003177
3178 VkRenderPass rp;
3179 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3180
3181 m_errorMonitor->VerifyFound();
3182
3183 if (err == VK_SUCCESS)
3184 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3185}
3186
3187TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003188 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3189 "when a subpass multisample resolve operation is "
3190 "requested, and the destination of that resolve has "
3191 "multiple samples.");
3192
Chris Forbesc5389742016-06-29 11:49:23 +12003193 ASSERT_NO_FATAL_FAILURE(InitState());
3194
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3196 "Subpass 0 requests multisample resolve into attachment 1, which "
3197 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003198
3199 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003200 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3201 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3202 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3203 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3204 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3205 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003206 };
3207
3208 VkAttachmentReference color = {
3209 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3210 };
3211
3212 VkAttachmentReference resolve = {
3213 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3214 };
3215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003216 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003217
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003218 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003219
3220 VkRenderPass rp;
3221 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3222
3223 m_errorMonitor->VerifyFound();
3224
3225 if (err == VK_SUCCESS)
3226 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3227}
3228
Chris Forbes3f128ef2016-06-29 14:58:53 +12003229TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003230 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3231 "when the color and depth attachments used by a subpass "
3232 "have inconsistent sample counts");
3233
Chris Forbes3f128ef2016-06-29 14:58:53 +12003234 ASSERT_NO_FATAL_FAILURE(InitState());
3235
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3237 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003238
3239 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003240 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3241 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3242 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3243 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3244 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3245 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003246 };
3247
3248 VkAttachmentReference color[] = {
3249 {
3250 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3251 },
3252 {
3253 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3254 },
3255 };
3256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003257 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003258
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003259 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003260
3261 VkRenderPass rp;
3262 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3263
3264 m_errorMonitor->VerifyFound();
3265
3266 if (err == VK_SUCCESS)
3267 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3268}
3269
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003270TEST_F(VkLayerTest, FramebufferCreateErrors) {
3271 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003272 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003273 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003274 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3275 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3276 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3277 " 6. Framebuffer attachment where dimensions don't match\n"
3278 " 7. Framebuffer attachment w/o identity swizzle\n"
3279 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003280
3281 ASSERT_NO_FATAL_FAILURE(InitState());
3282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3283
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3285 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3286 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003287
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003288 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003289 VkAttachmentReference attach = {};
3290 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3291 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003292 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003293 VkRenderPassCreateInfo rpci = {};
3294 rpci.subpassCount = 1;
3295 rpci.pSubpasses = &subpass;
3296 rpci.attachmentCount = 1;
3297 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003298 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003299 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003300 rpci.pAttachments = &attach_desc;
3301 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3302 VkRenderPass rp;
3303 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3304 ASSERT_VK_SUCCESS(err);
3305
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003306 VkImageView ivs[2];
3307 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3308 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003309 VkFramebufferCreateInfo fb_info = {};
3310 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3311 fb_info.pNext = NULL;
3312 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003313 // Set mis-matching attachmentCount
3314 fb_info.attachmentCount = 2;
3315 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003316 fb_info.width = 100;
3317 fb_info.height = 100;
3318 fb_info.layers = 1;
3319
3320 VkFramebuffer fb;
3321 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3322
3323 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003324 if (err == VK_SUCCESS) {
3325 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3326 }
3327 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003328
3329 // Create a renderPass with a depth-stencil attachment created with
3330 // IMAGE_USAGE_COLOR_ATTACHMENT
3331 // Add our color attachment to pDepthStencilAttachment
3332 subpass.pDepthStencilAttachment = &attach;
3333 subpass.pColorAttachments = NULL;
3334 VkRenderPass rp_ds;
3335 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3336 ASSERT_VK_SUCCESS(err);
3337 // Set correct attachment count, but attachment has COLOR usage bit set
3338 fb_info.attachmentCount = 1;
3339 fb_info.renderPass = rp_ds;
3340
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003342 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3343
3344 m_errorMonitor->VerifyFound();
3345 if (err == VK_SUCCESS) {
3346 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3347 }
3348 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003349
3350 // Create new renderpass with alternate attachment format from fb
3351 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3352 subpass.pDepthStencilAttachment = NULL;
3353 subpass.pColorAttachments = &attach;
3354 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3355 ASSERT_VK_SUCCESS(err);
3356
3357 // Cause error due to mis-matched formats between rp & fb
3358 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3359 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3361 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003362 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3363
3364 m_errorMonitor->VerifyFound();
3365 if (err == VK_SUCCESS) {
3366 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3367 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003368 vkDestroyRenderPass(m_device->device(), rp, NULL);
3369
3370 // Create new renderpass with alternate sample count from fb
3371 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3372 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3373 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3374 ASSERT_VK_SUCCESS(err);
3375
3376 // Cause error due to mis-matched sample count between rp & fb
3377 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3379 "that do not match the "
3380 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003381 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3382
3383 m_errorMonitor->VerifyFound();
3384 if (err == VK_SUCCESS) {
3385 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3386 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003387
3388 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003389
3390 // Create a custom imageView with non-1 mip levels
3391 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003392 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 -06003393 ASSERT_TRUE(image.initialized());
3394
3395 VkImageView view;
3396 VkImageViewCreateInfo ivci = {};
3397 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3398 ivci.image = image.handle();
3399 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3400 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3401 ivci.subresourceRange.layerCount = 1;
3402 ivci.subresourceRange.baseMipLevel = 0;
3403 // Set level count 2 (only 1 is allowed for FB attachment)
3404 ivci.subresourceRange.levelCount = 2;
3405 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3406 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3407 ASSERT_VK_SUCCESS(err);
3408 // Re-create renderpass to have matching sample count
3409 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3410 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3411 ASSERT_VK_SUCCESS(err);
3412
3413 fb_info.renderPass = rp;
3414 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003416 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3417
3418 m_errorMonitor->VerifyFound();
3419 if (err == VK_SUCCESS) {
3420 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3421 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003422 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003423 // Update view to original color buffer and grow FB dimensions too big
3424 fb_info.pAttachments = ivs;
3425 fb_info.height = 1024;
3426 fb_info.width = 1024;
3427 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3429 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003430 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3431
3432 m_errorMonitor->VerifyFound();
3433 if (err == VK_SUCCESS) {
3434 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3435 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003436 // Create view attachment with non-identity swizzle
3437 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3438 ivci.image = image.handle();
3439 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3440 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3441 ivci.subresourceRange.layerCount = 1;
3442 ivci.subresourceRange.baseMipLevel = 0;
3443 ivci.subresourceRange.levelCount = 1;
3444 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3445 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3446 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3447 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3448 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3449 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3450 ASSERT_VK_SUCCESS(err);
3451
3452 fb_info.pAttachments = &view;
3453 fb_info.height = 100;
3454 fb_info.width = 100;
3455 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3457 "framebuffer attachments must have "
3458 "been created with the identity "
3459 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003460 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3461
3462 m_errorMonitor->VerifyFound();
3463 if (err == VK_SUCCESS) {
3464 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3465 }
3466 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003467 // Request fb that exceeds max dimensions
3468 // reset attachment to color attachment
3469 fb_info.pAttachments = ivs;
3470 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3471 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3472 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3474 "dimensions exceed physical device "
3475 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003476 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3477
3478 m_errorMonitor->VerifyFound();
3479 if (err == VK_SUCCESS) {
3480 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3481 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003482
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003483 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003484}
3485
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003486TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003487 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3488 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003489
Cody Northropc31a84f2016-08-22 10:41:47 -06003490 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003491 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3493 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003494 m_errorMonitor->VerifyFound();
3495}
3496
3497TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003498 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3499 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003500
Cody Northropc31a84f2016-08-22 10:41:47 -06003501 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003502 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3504 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003505 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003506}
3507
3508TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003509 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3510 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003511
Cody Northropc31a84f2016-08-22 10:41:47 -06003512 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003513 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003514 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 -06003515 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003516 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003517}
3518
3519TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003520 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3521 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003522
Cody Northropc31a84f2016-08-22 10:41:47 -06003523 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003524 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003525 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 -06003526 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003527 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003528}
3529
Cortd713fe82016-07-27 09:51:27 -07003530TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003531 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3532 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003533
3534 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003535 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3537 "Dynamic blend constants state not set for this command buffer");
3538 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003539 m_errorMonitor->VerifyFound();
3540}
3541
3542TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003543 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3544 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003545
3546 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003547 if (!m_device->phy().features().depthBounds) {
3548 printf("Device does not support depthBounds test; skipped.\n");
3549 return;
3550 }
3551 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3553 "Dynamic depth bounds state not set for this command buffer");
3554 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003555 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003556}
3557
3558TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003559 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3560 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003561
3562 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003563 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3565 "Dynamic stencil read mask state not set for this command buffer");
3566 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003567 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003568}
3569
3570TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003571 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3572 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003573
3574 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003575 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3577 "Dynamic stencil write mask state not set for this command buffer");
3578 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003579 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003580}
3581
3582TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003583 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3584 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003585
3586 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003587 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3589 "Dynamic stencil reference state not set for this command buffer");
3590 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003591 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003592}
3593
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003594TEST_F(VkLayerTest, IndexBufferNotBound) {
3595 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003596
3597 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3599 "Index buffer object not bound to this command buffer when Indexed ");
3600 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003601 m_errorMonitor->VerifyFound();
3602}
3603
Karl Schultz6addd812016-02-02 17:17:23 -07003604TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3606 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3607 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003608
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003609 ASSERT_NO_FATAL_FAILURE(InitState());
3610 ASSERT_NO_FATAL_FAILURE(InitViewport());
3611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3612
Karl Schultz6addd812016-02-02 17:17:23 -07003613 // We luck out b/c by default the framework creates CB w/ the
3614 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003615 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003616 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003617 EndCommandBuffer();
3618
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003619 // Bypass framework since it does the waits automatically
3620 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003621 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003622 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3623 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003624 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003625 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003626 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003627 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003628 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003629 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003630 submit_info.pSignalSemaphores = NULL;
3631
Chris Forbes40028e22016-06-13 09:59:34 +12003632 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003633 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003634 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003635
Karl Schultz6addd812016-02-02 17:17:23 -07003636 // Cause validation error by re-submitting cmd buffer that should only be
3637 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003638 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003639 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003640
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003641 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003642}
3643
Karl Schultz6addd812016-02-02 17:17:23 -07003644TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003645 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003646 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003647
3648 ASSERT_NO_FATAL_FAILURE(InitState());
3649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003650
Karl Schultz6addd812016-02-02 17:17:23 -07003651 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3652 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003653 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003654 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003655 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003656
3657 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003658 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3659 ds_pool_ci.pNext = NULL;
3660 ds_pool_ci.flags = 0;
3661 ds_pool_ci.maxSets = 1;
3662 ds_pool_ci.poolSizeCount = 1;
3663 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003664
3665 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003666 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003667 ASSERT_VK_SUCCESS(err);
3668
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003669 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3670 dsl_binding_samp.binding = 0;
3671 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3672 dsl_binding_samp.descriptorCount = 1;
3673 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3674 dsl_binding_samp.pImmutableSamplers = NULL;
3675
3676 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3677 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3678 ds_layout_ci.pNext = NULL;
3679 ds_layout_ci.bindingCount = 1;
3680 ds_layout_ci.pBindings = &dsl_binding_samp;
3681
3682 VkDescriptorSetLayout ds_layout_samp;
3683 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3684 ASSERT_VK_SUCCESS(err);
3685
3686 // Try to allocate 2 sets when pool only has 1 set
3687 VkDescriptorSet descriptor_sets[2];
3688 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3689 VkDescriptorSetAllocateInfo alloc_info = {};
3690 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3691 alloc_info.descriptorSetCount = 2;
3692 alloc_info.descriptorPool = ds_pool;
3693 alloc_info.pSetLayouts = set_layouts;
3694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3695 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3696 m_errorMonitor->VerifyFound();
3697
3698 alloc_info.descriptorSetCount = 1;
3699 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003700 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003701 dsl_binding.binding = 0;
3702 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3703 dsl_binding.descriptorCount = 1;
3704 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3705 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003706
Karl Schultz6addd812016-02-02 17:17:23 -07003707 ds_layout_ci.bindingCount = 1;
3708 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003709
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003710 VkDescriptorSetLayout ds_layout_ub;
3711 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003712 ASSERT_VK_SUCCESS(err);
3713
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003714 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003715 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003716 alloc_info.pSetLayouts = &ds_layout_ub;
3717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3718 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003719
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003720 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003721
Karl Schultz2825ab92016-12-02 08:23:14 -07003722 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003723 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003724 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003725}
3726
Karl Schultz6addd812016-02-02 17:17:23 -07003727TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3728 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003729
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3731 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3732 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003733
Tobin Ehlise735c692015-10-08 13:13:50 -06003734 ASSERT_NO_FATAL_FAILURE(InitState());
3735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003736
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003737 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003738 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3739 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003740
3741 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003742 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3743 ds_pool_ci.pNext = NULL;
3744 ds_pool_ci.maxSets = 1;
3745 ds_pool_ci.poolSizeCount = 1;
3746 ds_pool_ci.flags = 0;
3747 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3748 // app can only call vkResetDescriptorPool on this pool.;
3749 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003750
3751 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003752 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003753 ASSERT_VK_SUCCESS(err);
3754
3755 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003756 dsl_binding.binding = 0;
3757 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3758 dsl_binding.descriptorCount = 1;
3759 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3760 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003761
3762 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003763 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3764 ds_layout_ci.pNext = NULL;
3765 ds_layout_ci.bindingCount = 1;
3766 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003767
3768 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003769 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003770 ASSERT_VK_SUCCESS(err);
3771
3772 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003773 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003774 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003775 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003776 alloc_info.descriptorPool = ds_pool;
3777 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003778 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003779 ASSERT_VK_SUCCESS(err);
3780
3781 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003782 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003783
Chia-I Wuf7458c52015-10-26 21:10:41 +08003784 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3785 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003786}
3787
Karl Schultz6addd812016-02-02 17:17:23 -07003788TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003789 // Attempt to clear Descriptor Pool with bad object.
3790 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003791
3792 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003794 uint64_t fake_pool_handle = 0xbaad6001;
3795 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3796 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003797 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003798}
3799
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003800TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003801 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3802 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003803 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003804 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003805
3806 uint64_t fake_set_handle = 0xbaad6001;
3807 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003808 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003810
3811 ASSERT_NO_FATAL_FAILURE(InitState());
3812
3813 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3814 layout_bindings[0].binding = 0;
3815 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3816 layout_bindings[0].descriptorCount = 1;
3817 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3818 layout_bindings[0].pImmutableSamplers = NULL;
3819
3820 VkDescriptorSetLayout descriptor_set_layout;
3821 VkDescriptorSetLayoutCreateInfo dslci = {};
3822 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3823 dslci.pNext = NULL;
3824 dslci.bindingCount = 1;
3825 dslci.pBindings = layout_bindings;
3826 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003827 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003828
3829 VkPipelineLayout pipeline_layout;
3830 VkPipelineLayoutCreateInfo plci = {};
3831 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3832 plci.pNext = NULL;
3833 plci.setLayoutCount = 1;
3834 plci.pSetLayouts = &descriptor_set_layout;
3835 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003836 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003837
3838 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003839 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3840 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003841 m_errorMonitor->VerifyFound();
3842 EndCommandBuffer();
3843 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3844 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003845}
3846
Karl Schultz6addd812016-02-02 17:17:23 -07003847TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003848 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3849 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003850 uint64_t fake_layout_handle = 0xbaad6001;
3851 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003853 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003854 VkPipelineLayout pipeline_layout;
3855 VkPipelineLayoutCreateInfo plci = {};
3856 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3857 plci.pNext = NULL;
3858 plci.setLayoutCount = 1;
3859 plci.pSetLayouts = &bad_layout;
3860 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3861
3862 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003863}
3864
Mark Muellerd4914412016-06-13 17:52:06 -06003865TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3866 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3867 "1) A uniform buffer update must have a valid buffer index."
3868 "2) When using an array of descriptors in a single WriteDescriptor,"
3869 " the descriptor types and stageflags must all be the same."
3870 "3) Immutable Sampler state must match across descriptors");
3871
3872 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003873 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3874 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3875 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3876 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3877 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003878
Mark Muellerd4914412016-06-13 17:52:06 -06003879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3880
3881 ASSERT_NO_FATAL_FAILURE(InitState());
3882 VkDescriptorPoolSize ds_type_count[4] = {};
3883 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3884 ds_type_count[0].descriptorCount = 1;
3885 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3886 ds_type_count[1].descriptorCount = 1;
3887 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3888 ds_type_count[2].descriptorCount = 1;
3889 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3890 ds_type_count[3].descriptorCount = 1;
3891
3892 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3893 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3894 ds_pool_ci.maxSets = 1;
3895 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3896 ds_pool_ci.pPoolSizes = ds_type_count;
3897
3898 VkDescriptorPool ds_pool;
3899 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3900 ASSERT_VK_SUCCESS(err);
3901
Mark Muellerb9896722016-06-16 09:54:29 -06003902 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003903 layout_binding[0].binding = 0;
3904 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3905 layout_binding[0].descriptorCount = 1;
3906 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3907 layout_binding[0].pImmutableSamplers = NULL;
3908
3909 layout_binding[1].binding = 1;
3910 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3911 layout_binding[1].descriptorCount = 1;
3912 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3913 layout_binding[1].pImmutableSamplers = NULL;
3914
3915 VkSamplerCreateInfo sampler_ci = {};
3916 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3917 sampler_ci.pNext = NULL;
3918 sampler_ci.magFilter = VK_FILTER_NEAREST;
3919 sampler_ci.minFilter = VK_FILTER_NEAREST;
3920 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3921 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3922 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3923 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3924 sampler_ci.mipLodBias = 1.0;
3925 sampler_ci.anisotropyEnable = VK_FALSE;
3926 sampler_ci.maxAnisotropy = 1;
3927 sampler_ci.compareEnable = VK_FALSE;
3928 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3929 sampler_ci.minLod = 1.0;
3930 sampler_ci.maxLod = 1.0;
3931 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3932 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3933 VkSampler sampler;
3934
3935 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3936 ASSERT_VK_SUCCESS(err);
3937
3938 layout_binding[2].binding = 2;
3939 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3940 layout_binding[2].descriptorCount = 1;
3941 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3942 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3943
Mark Muellerd4914412016-06-13 17:52:06 -06003944 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3945 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3946 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3947 ds_layout_ci.pBindings = layout_binding;
3948 VkDescriptorSetLayout ds_layout;
3949 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3950 ASSERT_VK_SUCCESS(err);
3951
3952 VkDescriptorSetAllocateInfo alloc_info = {};
3953 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3954 alloc_info.descriptorSetCount = 1;
3955 alloc_info.descriptorPool = ds_pool;
3956 alloc_info.pSetLayouts = &ds_layout;
3957 VkDescriptorSet descriptorSet;
3958 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3959 ASSERT_VK_SUCCESS(err);
3960
3961 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3962 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3963 pipeline_layout_ci.pNext = NULL;
3964 pipeline_layout_ci.setLayoutCount = 1;
3965 pipeline_layout_ci.pSetLayouts = &ds_layout;
3966
3967 VkPipelineLayout pipeline_layout;
3968 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3969 ASSERT_VK_SUCCESS(err);
3970
Mark Mueller5c838ce2016-06-16 09:54:29 -06003971 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003972 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3973 descriptor_write.dstSet = descriptorSet;
3974 descriptor_write.dstBinding = 0;
3975 descriptor_write.descriptorCount = 1;
3976 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3977
Mark Mueller5c838ce2016-06-16 09:54:29 -06003978 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003979 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3980 m_errorMonitor->VerifyFound();
3981
3982 // Create a buffer to update the descriptor with
3983 uint32_t qfi = 0;
3984 VkBufferCreateInfo buffCI = {};
3985 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3986 buffCI.size = 1024;
3987 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3988 buffCI.queueFamilyIndexCount = 1;
3989 buffCI.pQueueFamilyIndices = &qfi;
3990
3991 VkBuffer dyub;
3992 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3993 ASSERT_VK_SUCCESS(err);
3994 VkDescriptorBufferInfo buffInfo = {};
3995 buffInfo.buffer = dyub;
3996 buffInfo.offset = 0;
3997 buffInfo.range = 1024;
3998
3999 descriptor_write.pBufferInfo = &buffInfo;
4000 descriptor_write.descriptorCount = 2;
4001
Mark Mueller5c838ce2016-06-16 09:54:29 -06004002 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4004 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4005 m_errorMonitor->VerifyFound();
4006
Mark Mueller5c838ce2016-06-16 09:54:29 -06004007 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4008 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004009 descriptor_write.dstBinding = 1;
4010 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004011
Mark Mueller5c838ce2016-06-16 09:54:29 -06004012 // Make pImageInfo index non-null to avoid complaints of it missing
4013 VkDescriptorImageInfo imageInfo = {};
4014 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4015 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4017 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4018 m_errorMonitor->VerifyFound();
4019
Mark Muellerd4914412016-06-13 17:52:06 -06004020 vkDestroyBuffer(m_device->device(), dyub, NULL);
4021 vkDestroySampler(m_device->device(), sampler, NULL);
4022 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4023 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4024 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4025}
4026
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004027TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4028 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4029 "due to a buffer dependency being destroyed.");
4030 ASSERT_NO_FATAL_FAILURE(InitState());
4031
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004032 VkBuffer buffer;
4033 VkDeviceMemory mem;
4034 VkMemoryRequirements mem_reqs;
4035
4036 VkBufferCreateInfo buf_info = {};
4037 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004038 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004039 buf_info.size = 256;
4040 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4041 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4042 ASSERT_VK_SUCCESS(err);
4043
4044 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4045
4046 VkMemoryAllocateInfo alloc_info = {};
4047 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4048 alloc_info.allocationSize = 256;
4049 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004050 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 -06004051 if (!pass) {
4052 vkDestroyBuffer(m_device->device(), buffer, NULL);
4053 return;
4054 }
4055 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4056 ASSERT_VK_SUCCESS(err);
4057
4058 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4059 ASSERT_VK_SUCCESS(err);
4060
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004061 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004062 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004063 m_commandBuffer->EndCommandBuffer();
4064
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004066 // Destroy buffer dependency prior to submit to cause ERROR
4067 vkDestroyBuffer(m_device->device(), buffer, NULL);
4068
4069 VkSubmitInfo submit_info = {};
4070 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4071 submit_info.commandBufferCount = 1;
4072 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4073 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4074
4075 m_errorMonitor->VerifyFound();
4076 vkFreeMemory(m_device->handle(), mem, NULL);
4077}
4078
Tobin Ehlisea413442016-09-28 10:23:59 -06004079TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4080 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4081
4082 ASSERT_NO_FATAL_FAILURE(InitState());
4083 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4084
4085 VkDescriptorPoolSize ds_type_count;
4086 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4087 ds_type_count.descriptorCount = 1;
4088
4089 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4090 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4091 ds_pool_ci.maxSets = 1;
4092 ds_pool_ci.poolSizeCount = 1;
4093 ds_pool_ci.pPoolSizes = &ds_type_count;
4094
4095 VkDescriptorPool ds_pool;
4096 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4097 ASSERT_VK_SUCCESS(err);
4098
4099 VkDescriptorSetLayoutBinding layout_binding;
4100 layout_binding.binding = 0;
4101 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4102 layout_binding.descriptorCount = 1;
4103 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4104 layout_binding.pImmutableSamplers = NULL;
4105
4106 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4107 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4108 ds_layout_ci.bindingCount = 1;
4109 ds_layout_ci.pBindings = &layout_binding;
4110 VkDescriptorSetLayout ds_layout;
4111 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4112 ASSERT_VK_SUCCESS(err);
4113
4114 VkDescriptorSetAllocateInfo alloc_info = {};
4115 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4116 alloc_info.descriptorSetCount = 1;
4117 alloc_info.descriptorPool = ds_pool;
4118 alloc_info.pSetLayouts = &ds_layout;
4119 VkDescriptorSet descriptor_set;
4120 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4121 ASSERT_VK_SUCCESS(err);
4122
4123 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4124 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4125 pipeline_layout_ci.pNext = NULL;
4126 pipeline_layout_ci.setLayoutCount = 1;
4127 pipeline_layout_ci.pSetLayouts = &ds_layout;
4128
4129 VkPipelineLayout pipeline_layout;
4130 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4131 ASSERT_VK_SUCCESS(err);
4132
4133 VkBuffer buffer;
4134 uint32_t queue_family_index = 0;
4135 VkBufferCreateInfo buffer_create_info = {};
4136 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4137 buffer_create_info.size = 1024;
4138 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4139 buffer_create_info.queueFamilyIndexCount = 1;
4140 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4141
4142 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4143 ASSERT_VK_SUCCESS(err);
4144
4145 VkMemoryRequirements memory_reqs;
4146 VkDeviceMemory buffer_memory;
4147
4148 VkMemoryAllocateInfo memory_info = {};
4149 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4150 memory_info.allocationSize = 0;
4151 memory_info.memoryTypeIndex = 0;
4152
4153 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4154 memory_info.allocationSize = memory_reqs.size;
4155 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4156 ASSERT_TRUE(pass);
4157
4158 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4159 ASSERT_VK_SUCCESS(err);
4160 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4161 ASSERT_VK_SUCCESS(err);
4162
4163 VkBufferView view;
4164 VkBufferViewCreateInfo bvci = {};
4165 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4166 bvci.buffer = buffer;
4167 bvci.format = VK_FORMAT_R8_UNORM;
4168 bvci.range = VK_WHOLE_SIZE;
4169
4170 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4171 ASSERT_VK_SUCCESS(err);
4172
4173 VkWriteDescriptorSet descriptor_write = {};
4174 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4175 descriptor_write.dstSet = descriptor_set;
4176 descriptor_write.dstBinding = 0;
4177 descriptor_write.descriptorCount = 1;
4178 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4179 descriptor_write.pTexelBufferView = &view;
4180
4181 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4182
4183 char const *vsSource = "#version 450\n"
4184 "\n"
4185 "out gl_PerVertex { \n"
4186 " vec4 gl_Position;\n"
4187 "};\n"
4188 "void main(){\n"
4189 " gl_Position = vec4(1);\n"
4190 "}\n";
4191 char const *fsSource = "#version 450\n"
4192 "\n"
4193 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4194 "layout(location=0) out vec4 x;\n"
4195 "void main(){\n"
4196 " x = imageLoad(s, 0);\n"
4197 "}\n";
4198 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4199 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4200 VkPipelineObj pipe(m_device);
4201 pipe.AddShader(&vs);
4202 pipe.AddShader(&fs);
4203 pipe.AddColorAttachment();
4204 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4205
4206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4208
4209 BeginCommandBuffer();
4210 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4211 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4212 VkRect2D scissor = {{0, 0}, {16, 16}};
4213 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4214 // Bind pipeline to cmd buffer
4215 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4216 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4217 &descriptor_set, 0, nullptr);
4218 Draw(1, 0, 0, 0);
4219 EndCommandBuffer();
4220
4221 // Delete BufferView in order to invalidate cmd buffer
4222 vkDestroyBufferView(m_device->device(), view, NULL);
4223 // Now attempt submit of cmd buffer
4224 VkSubmitInfo submit_info = {};
4225 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4226 submit_info.commandBufferCount = 1;
4227 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4228 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4229 m_errorMonitor->VerifyFound();
4230
4231 // Clean-up
4232 vkDestroyBuffer(m_device->device(), buffer, NULL);
4233 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4234 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4235 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4236 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4237}
4238
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004239TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4240 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4241 "due to an image dependency being destroyed.");
4242 ASSERT_NO_FATAL_FAILURE(InitState());
4243
4244 VkImage image;
4245 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4246 VkImageCreateInfo image_create_info = {};
4247 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4248 image_create_info.pNext = NULL;
4249 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4250 image_create_info.format = tex_format;
4251 image_create_info.extent.width = 32;
4252 image_create_info.extent.height = 32;
4253 image_create_info.extent.depth = 1;
4254 image_create_info.mipLevels = 1;
4255 image_create_info.arrayLayers = 1;
4256 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4257 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004258 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004259 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004260 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004261 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004262 // Have to bind memory to image before recording cmd in cmd buffer using it
4263 VkMemoryRequirements mem_reqs;
4264 VkDeviceMemory image_mem;
4265 bool pass;
4266 VkMemoryAllocateInfo mem_alloc = {};
4267 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4268 mem_alloc.pNext = NULL;
4269 mem_alloc.memoryTypeIndex = 0;
4270 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4271 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004272 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004273 ASSERT_TRUE(pass);
4274 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4275 ASSERT_VK_SUCCESS(err);
4276 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4277 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004278
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004279 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004280 VkClearColorValue ccv;
4281 ccv.float32[0] = 1.0f;
4282 ccv.float32[1] = 1.0f;
4283 ccv.float32[2] = 1.0f;
4284 ccv.float32[3] = 1.0f;
4285 VkImageSubresourceRange isr = {};
4286 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004287 isr.baseArrayLayer = 0;
4288 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004289 isr.layerCount = 1;
4290 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004291 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004292 m_commandBuffer->EndCommandBuffer();
4293
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004295 // Destroy image dependency prior to submit to cause ERROR
4296 vkDestroyImage(m_device->device(), image, NULL);
4297
4298 VkSubmitInfo submit_info = {};
4299 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4300 submit_info.commandBufferCount = 1;
4301 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4302 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4303
4304 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004305 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004306}
4307
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004308TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4309 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4310 "due to a framebuffer image dependency being destroyed.");
4311 VkFormatProperties format_properties;
4312 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004313 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4314 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004315 return;
4316 }
4317
4318 ASSERT_NO_FATAL_FAILURE(InitState());
4319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4320
4321 VkImageCreateInfo image_ci = {};
4322 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4323 image_ci.pNext = NULL;
4324 image_ci.imageType = VK_IMAGE_TYPE_2D;
4325 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4326 image_ci.extent.width = 32;
4327 image_ci.extent.height = 32;
4328 image_ci.extent.depth = 1;
4329 image_ci.mipLevels = 1;
4330 image_ci.arrayLayers = 1;
4331 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4332 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004333 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004334 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4335 image_ci.flags = 0;
4336 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004337 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004338
4339 VkMemoryRequirements memory_reqs;
4340 VkDeviceMemory image_memory;
4341 bool pass;
4342 VkMemoryAllocateInfo memory_info = {};
4343 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4344 memory_info.pNext = NULL;
4345 memory_info.allocationSize = 0;
4346 memory_info.memoryTypeIndex = 0;
4347 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4348 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004349 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004350 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004351 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004352 ASSERT_VK_SUCCESS(err);
4353 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4354 ASSERT_VK_SUCCESS(err);
4355
4356 VkImageViewCreateInfo ivci = {
4357 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4358 nullptr,
4359 0,
4360 image,
4361 VK_IMAGE_VIEW_TYPE_2D,
4362 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004363 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004364 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4365 };
4366 VkImageView view;
4367 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4368 ASSERT_VK_SUCCESS(err);
4369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004370 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004371 VkFramebuffer fb;
4372 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4373 ASSERT_VK_SUCCESS(err);
4374
4375 // Just use default renderpass with our framebuffer
4376 m_renderPassBeginInfo.framebuffer = fb;
4377 // Create Null cmd buffer for submit
4378 BeginCommandBuffer();
4379 EndCommandBuffer();
4380 // Destroy image attached to framebuffer to invalidate cmd buffer
4381 vkDestroyImage(m_device->device(), image, NULL);
4382 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004384 QueueCommandBuffer(false);
4385 m_errorMonitor->VerifyFound();
4386
4387 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4388 vkDestroyImageView(m_device->device(), view, nullptr);
4389 vkFreeMemory(m_device->device(), image_memory, nullptr);
4390}
4391
Tobin Ehlisb329f992016-10-12 13:20:29 -06004392TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4393 TEST_DESCRIPTION("Delete in-use framebuffer.");
4394 VkFormatProperties format_properties;
4395 VkResult err = VK_SUCCESS;
4396 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4397
4398 ASSERT_NO_FATAL_FAILURE(InitState());
4399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4400
4401 VkImageObj image(m_device);
4402 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4403 ASSERT_TRUE(image.initialized());
4404 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4405
4406 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4407 VkFramebuffer fb;
4408 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4409 ASSERT_VK_SUCCESS(err);
4410
4411 // Just use default renderpass with our framebuffer
4412 m_renderPassBeginInfo.framebuffer = fb;
4413 // Create Null cmd buffer for submit
4414 BeginCommandBuffer();
4415 EndCommandBuffer();
4416 // Submit cmd buffer to put it in-flight
4417 VkSubmitInfo submit_info = {};
4418 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4419 submit_info.commandBufferCount = 1;
4420 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4421 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4422 // Destroy framebuffer while in-flight
4423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4424 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4425 m_errorMonitor->VerifyFound();
4426 // Wait for queue to complete so we can safely destroy everything
4427 vkQueueWaitIdle(m_device->m_queue);
4428 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4429}
4430
Tobin Ehlis88becd72016-09-21 14:33:41 -06004431TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4432 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4433 VkFormatProperties format_properties;
4434 VkResult err = VK_SUCCESS;
4435 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004436
4437 ASSERT_NO_FATAL_FAILURE(InitState());
4438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4439
4440 VkImageCreateInfo image_ci = {};
4441 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4442 image_ci.pNext = NULL;
4443 image_ci.imageType = VK_IMAGE_TYPE_2D;
4444 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4445 image_ci.extent.width = 256;
4446 image_ci.extent.height = 256;
4447 image_ci.extent.depth = 1;
4448 image_ci.mipLevels = 1;
4449 image_ci.arrayLayers = 1;
4450 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4451 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004452 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004453 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4454 image_ci.flags = 0;
4455 VkImage image;
4456 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4457
4458 VkMemoryRequirements memory_reqs;
4459 VkDeviceMemory image_memory;
4460 bool pass;
4461 VkMemoryAllocateInfo memory_info = {};
4462 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4463 memory_info.pNext = NULL;
4464 memory_info.allocationSize = 0;
4465 memory_info.memoryTypeIndex = 0;
4466 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4467 memory_info.allocationSize = memory_reqs.size;
4468 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4469 ASSERT_TRUE(pass);
4470 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4471 ASSERT_VK_SUCCESS(err);
4472 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4473 ASSERT_VK_SUCCESS(err);
4474
4475 VkImageViewCreateInfo ivci = {
4476 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4477 nullptr,
4478 0,
4479 image,
4480 VK_IMAGE_VIEW_TYPE_2D,
4481 VK_FORMAT_B8G8R8A8_UNORM,
4482 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4483 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4484 };
4485 VkImageView view;
4486 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4487 ASSERT_VK_SUCCESS(err);
4488
4489 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4490 VkFramebuffer fb;
4491 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4492 ASSERT_VK_SUCCESS(err);
4493
4494 // Just use default renderpass with our framebuffer
4495 m_renderPassBeginInfo.framebuffer = fb;
4496 // Create Null cmd buffer for submit
4497 BeginCommandBuffer();
4498 EndCommandBuffer();
4499 // Submit cmd buffer to put it (and attached imageView) in-flight
4500 VkSubmitInfo submit_info = {};
4501 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4502 submit_info.commandBufferCount = 1;
4503 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4504 // Submit cmd buffer to put framebuffer and children in-flight
4505 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4506 // Destroy image attached to framebuffer while in-flight
4507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4508 vkDestroyImage(m_device->device(), image, NULL);
4509 m_errorMonitor->VerifyFound();
4510 // Wait for queue to complete so we can safely destroy image and other objects
4511 vkQueueWaitIdle(m_device->m_queue);
4512 vkDestroyImage(m_device->device(), image, NULL);
4513 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4514 vkDestroyImageView(m_device->device(), view, nullptr);
4515 vkFreeMemory(m_device->device(), image_memory, nullptr);
4516}
4517
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004518TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4519 TEST_DESCRIPTION("Delete in-use renderPass.");
4520
4521 ASSERT_NO_FATAL_FAILURE(InitState());
4522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4523
4524 // Create simple renderpass
4525 VkAttachmentReference attach = {};
4526 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4527 VkSubpassDescription subpass = {};
4528 subpass.pColorAttachments = &attach;
4529 VkRenderPassCreateInfo rpci = {};
4530 rpci.subpassCount = 1;
4531 rpci.pSubpasses = &subpass;
4532 rpci.attachmentCount = 1;
4533 VkAttachmentDescription attach_desc = {};
4534 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4535 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4536 rpci.pAttachments = &attach_desc;
4537 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4538 VkRenderPass rp;
4539 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4540 ASSERT_VK_SUCCESS(err);
4541
4542 // Create a pipeline that uses the given renderpass
4543 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4544 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4545
4546 VkPipelineLayout pipeline_layout;
4547 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4548 ASSERT_VK_SUCCESS(err);
4549
4550 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4551 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4552 vp_state_ci.viewportCount = 1;
4553 VkViewport vp = {}; // Just need dummy vp to point to
4554 vp_state_ci.pViewports = &vp;
4555 vp_state_ci.scissorCount = 1;
4556 VkRect2D scissors = {}; // Dummy scissors to point to
4557 vp_state_ci.pScissors = &scissors;
4558
4559 VkPipelineShaderStageCreateInfo shaderStages[2];
4560 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4561
4562 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4563 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4564 // but add it to be able to run on more devices
4565 shaderStages[0] = vs.GetStageCreateInfo();
4566 shaderStages[1] = fs.GetStageCreateInfo();
4567
4568 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4569 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4570
4571 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4572 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4573 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4574
4575 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4576 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4577 rs_ci.rasterizerDiscardEnable = true;
4578 rs_ci.lineWidth = 1.0f;
4579
4580 VkPipelineColorBlendAttachmentState att = {};
4581 att.blendEnable = VK_FALSE;
4582 att.colorWriteMask = 0xf;
4583
4584 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4585 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4586 cb_ci.attachmentCount = 1;
4587 cb_ci.pAttachments = &att;
4588
4589 VkGraphicsPipelineCreateInfo gp_ci = {};
4590 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4591 gp_ci.stageCount = 2;
4592 gp_ci.pStages = shaderStages;
4593 gp_ci.pVertexInputState = &vi_ci;
4594 gp_ci.pInputAssemblyState = &ia_ci;
4595 gp_ci.pViewportState = &vp_state_ci;
4596 gp_ci.pRasterizationState = &rs_ci;
4597 gp_ci.pColorBlendState = &cb_ci;
4598 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4599 gp_ci.layout = pipeline_layout;
4600 gp_ci.renderPass = rp;
4601
4602 VkPipelineCacheCreateInfo pc_ci = {};
4603 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4604
4605 VkPipeline pipeline;
4606 VkPipelineCache pipe_cache;
4607 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4608 ASSERT_VK_SUCCESS(err);
4609
4610 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4611 ASSERT_VK_SUCCESS(err);
4612 // Bind pipeline to cmd buffer, will also bind renderpass
4613 m_commandBuffer->BeginCommandBuffer();
4614 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4615 m_commandBuffer->EndCommandBuffer();
4616
4617 VkSubmitInfo submit_info = {};
4618 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4619 submit_info.commandBufferCount = 1;
4620 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4621 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4622
4623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4624 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4625 m_errorMonitor->VerifyFound();
4626
4627 // Wait for queue to complete so we can safely destroy everything
4628 vkQueueWaitIdle(m_device->m_queue);
4629 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4630 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4631 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4632 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4633}
4634
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004635TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004636 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004637 ASSERT_NO_FATAL_FAILURE(InitState());
4638
4639 VkImage image;
4640 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4641 VkImageCreateInfo image_create_info = {};
4642 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4643 image_create_info.pNext = NULL;
4644 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4645 image_create_info.format = tex_format;
4646 image_create_info.extent.width = 32;
4647 image_create_info.extent.height = 32;
4648 image_create_info.extent.depth = 1;
4649 image_create_info.mipLevels = 1;
4650 image_create_info.arrayLayers = 1;
4651 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4652 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004653 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004654 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004655 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004656 ASSERT_VK_SUCCESS(err);
4657 // Have to bind memory to image before recording cmd in cmd buffer using it
4658 VkMemoryRequirements mem_reqs;
4659 VkDeviceMemory image_mem;
4660 bool pass;
4661 VkMemoryAllocateInfo mem_alloc = {};
4662 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4663 mem_alloc.pNext = NULL;
4664 mem_alloc.memoryTypeIndex = 0;
4665 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4666 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004667 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004668 ASSERT_TRUE(pass);
4669 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4670 ASSERT_VK_SUCCESS(err);
4671
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004672 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004674 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004675
4676 m_commandBuffer->BeginCommandBuffer();
4677 VkClearColorValue ccv;
4678 ccv.float32[0] = 1.0f;
4679 ccv.float32[1] = 1.0f;
4680 ccv.float32[2] = 1.0f;
4681 ccv.float32[3] = 1.0f;
4682 VkImageSubresourceRange isr = {};
4683 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4684 isr.baseArrayLayer = 0;
4685 isr.baseMipLevel = 0;
4686 isr.layerCount = 1;
4687 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004688 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004689 m_commandBuffer->EndCommandBuffer();
4690
4691 m_errorMonitor->VerifyFound();
4692 vkDestroyImage(m_device->device(), image, NULL);
4693 vkFreeMemory(m_device->device(), image_mem, nullptr);
4694}
4695
4696TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004697 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004698 ASSERT_NO_FATAL_FAILURE(InitState());
4699
4700 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004701 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 -06004702 VK_IMAGE_TILING_OPTIMAL, 0);
4703 ASSERT_TRUE(image.initialized());
4704
4705 VkBuffer buffer;
4706 VkDeviceMemory mem;
4707 VkMemoryRequirements mem_reqs;
4708
4709 VkBufferCreateInfo buf_info = {};
4710 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004711 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004712 buf_info.size = 256;
4713 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4714 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4715 ASSERT_VK_SUCCESS(err);
4716
4717 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4718
4719 VkMemoryAllocateInfo alloc_info = {};
4720 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4721 alloc_info.allocationSize = 256;
4722 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004723 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 -06004724 if (!pass) {
4725 vkDestroyBuffer(m_device->device(), buffer, NULL);
4726 return;
4727 }
4728 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4729 ASSERT_VK_SUCCESS(err);
4730
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004731 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004733 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004734 VkBufferImageCopy region = {};
4735 region.bufferRowLength = 128;
4736 region.bufferImageHeight = 128;
4737 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4738
4739 region.imageSubresource.layerCount = 1;
4740 region.imageExtent.height = 4;
4741 region.imageExtent.width = 4;
4742 region.imageExtent.depth = 1;
4743 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004744 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4745 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004746 m_commandBuffer->EndCommandBuffer();
4747
4748 m_errorMonitor->VerifyFound();
4749
4750 vkDestroyBuffer(m_device->device(), buffer, NULL);
4751 vkFreeMemory(m_device->handle(), mem, NULL);
4752}
4753
Tobin Ehlis85940f52016-07-07 16:57:21 -06004754TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4755 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4756 "due to an event dependency being destroyed.");
4757 ASSERT_NO_FATAL_FAILURE(InitState());
4758
4759 VkEvent event;
4760 VkEventCreateInfo evci = {};
4761 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4762 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4763 ASSERT_VK_SUCCESS(result);
4764
4765 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004766 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004767 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 event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004770 // Destroy event dependency prior to submit to cause ERROR
4771 vkDestroyEvent(m_device->device(), event, 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 Ehlisdbea7552016-07-08 14:33:31 -06004782TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4783 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4784 "due to a query pool dependency being destroyed.");
4785 ASSERT_NO_FATAL_FAILURE(InitState());
4786
4787 VkQueryPool query_pool;
4788 VkQueryPoolCreateInfo qpci{};
4789 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4790 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4791 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004792 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004793 ASSERT_VK_SUCCESS(result);
4794
4795 m_commandBuffer->BeginCommandBuffer();
4796 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4797 m_commandBuffer->EndCommandBuffer();
4798
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004800 // Destroy query pool dependency prior to submit to cause ERROR
4801 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4802
4803 VkSubmitInfo submit_info = {};
4804 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4805 submit_info.commandBufferCount = 1;
4806 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4807 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4808
4809 m_errorMonitor->VerifyFound();
4810}
4811
Tobin Ehlis24130d92016-07-08 15:50:53 -06004812TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4813 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4814 "due to a pipeline dependency being destroyed.");
4815 ASSERT_NO_FATAL_FAILURE(InitState());
4816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4817
4818 VkResult err;
4819
4820 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4821 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4822
4823 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004824 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004825 ASSERT_VK_SUCCESS(err);
4826
4827 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4828 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4829 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004830 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004831 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004832 vp_state_ci.scissorCount = 1;
4833 VkRect2D scissors = {}; // Dummy scissors to point to
4834 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004835
4836 VkPipelineShaderStageCreateInfo shaderStages[2];
4837 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4838
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004839 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4840 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4841 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004842 shaderStages[0] = vs.GetStageCreateInfo();
4843 shaderStages[1] = fs.GetStageCreateInfo();
4844
4845 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4846 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4847
4848 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4849 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4850 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4851
4852 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4853 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004854 rs_ci.rasterizerDiscardEnable = true;
4855 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004856
4857 VkPipelineColorBlendAttachmentState att = {};
4858 att.blendEnable = VK_FALSE;
4859 att.colorWriteMask = 0xf;
4860
4861 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4862 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4863 cb_ci.attachmentCount = 1;
4864 cb_ci.pAttachments = &att;
4865
4866 VkGraphicsPipelineCreateInfo gp_ci = {};
4867 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4868 gp_ci.stageCount = 2;
4869 gp_ci.pStages = shaderStages;
4870 gp_ci.pVertexInputState = &vi_ci;
4871 gp_ci.pInputAssemblyState = &ia_ci;
4872 gp_ci.pViewportState = &vp_state_ci;
4873 gp_ci.pRasterizationState = &rs_ci;
4874 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004875 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4876 gp_ci.layout = pipeline_layout;
4877 gp_ci.renderPass = renderPass();
4878
4879 VkPipelineCacheCreateInfo pc_ci = {};
4880 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4881
4882 VkPipeline pipeline;
4883 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004884 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004885 ASSERT_VK_SUCCESS(err);
4886
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004887 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004888 ASSERT_VK_SUCCESS(err);
4889
4890 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004891 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004892 m_commandBuffer->EndCommandBuffer();
4893 // Now destroy pipeline in order to cause error when submitting
4894 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004897
4898 VkSubmitInfo submit_info = {};
4899 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4900 submit_info.commandBufferCount = 1;
4901 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4902 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4903
4904 m_errorMonitor->VerifyFound();
4905 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4906 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4907}
4908
Tobin Ehlis31289162016-08-17 14:57:58 -06004909TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4910 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4911 "due to a bound descriptor set with a buffer dependency "
4912 "being destroyed.");
4913 ASSERT_NO_FATAL_FAILURE(InitState());
4914 ASSERT_NO_FATAL_FAILURE(InitViewport());
4915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4916
4917 VkDescriptorPoolSize ds_type_count = {};
4918 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4919 ds_type_count.descriptorCount = 1;
4920
4921 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4922 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4923 ds_pool_ci.pNext = NULL;
4924 ds_pool_ci.maxSets = 1;
4925 ds_pool_ci.poolSizeCount = 1;
4926 ds_pool_ci.pPoolSizes = &ds_type_count;
4927
4928 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004929 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004930 ASSERT_VK_SUCCESS(err);
4931
4932 VkDescriptorSetLayoutBinding dsl_binding = {};
4933 dsl_binding.binding = 0;
4934 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4935 dsl_binding.descriptorCount = 1;
4936 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4937 dsl_binding.pImmutableSamplers = NULL;
4938
4939 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4940 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4941 ds_layout_ci.pNext = NULL;
4942 ds_layout_ci.bindingCount = 1;
4943 ds_layout_ci.pBindings = &dsl_binding;
4944 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004945 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004946 ASSERT_VK_SUCCESS(err);
4947
4948 VkDescriptorSet descriptorSet;
4949 VkDescriptorSetAllocateInfo alloc_info = {};
4950 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4951 alloc_info.descriptorSetCount = 1;
4952 alloc_info.descriptorPool = ds_pool;
4953 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004954 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004955 ASSERT_VK_SUCCESS(err);
4956
4957 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4958 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4959 pipeline_layout_ci.pNext = NULL;
4960 pipeline_layout_ci.setLayoutCount = 1;
4961 pipeline_layout_ci.pSetLayouts = &ds_layout;
4962
4963 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004964 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004965 ASSERT_VK_SUCCESS(err);
4966
4967 // Create a buffer to update the descriptor with
4968 uint32_t qfi = 0;
4969 VkBufferCreateInfo buffCI = {};
4970 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4971 buffCI.size = 1024;
4972 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4973 buffCI.queueFamilyIndexCount = 1;
4974 buffCI.pQueueFamilyIndices = &qfi;
4975
4976 VkBuffer buffer;
4977 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4978 ASSERT_VK_SUCCESS(err);
4979 // Allocate memory and bind to buffer so we can make it to the appropriate
4980 // error
4981 VkMemoryAllocateInfo mem_alloc = {};
4982 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4983 mem_alloc.pNext = NULL;
4984 mem_alloc.allocationSize = 1024;
4985 mem_alloc.memoryTypeIndex = 0;
4986
4987 VkMemoryRequirements memReqs;
4988 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004989 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004990 if (!pass) {
4991 vkDestroyBuffer(m_device->device(), buffer, NULL);
4992 return;
4993 }
4994
4995 VkDeviceMemory mem;
4996 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4997 ASSERT_VK_SUCCESS(err);
4998 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4999 ASSERT_VK_SUCCESS(err);
5000 // Correctly update descriptor to avoid "NOT_UPDATED" error
5001 VkDescriptorBufferInfo buffInfo = {};
5002 buffInfo.buffer = buffer;
5003 buffInfo.offset = 0;
5004 buffInfo.range = 1024;
5005
5006 VkWriteDescriptorSet descriptor_write;
5007 memset(&descriptor_write, 0, sizeof(descriptor_write));
5008 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5009 descriptor_write.dstSet = descriptorSet;
5010 descriptor_write.dstBinding = 0;
5011 descriptor_write.descriptorCount = 1;
5012 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5013 descriptor_write.pBufferInfo = &buffInfo;
5014
5015 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5016
5017 // Create PSO to be used for draw-time errors below
5018 char const *vsSource = "#version 450\n"
5019 "\n"
5020 "out gl_PerVertex { \n"
5021 " vec4 gl_Position;\n"
5022 "};\n"
5023 "void main(){\n"
5024 " gl_Position = vec4(1);\n"
5025 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005026 char const *fsSource = "#version 450\n"
5027 "\n"
5028 "layout(location=0) out vec4 x;\n"
5029 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5030 "void main(){\n"
5031 " x = vec4(bar.y);\n"
5032 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005033 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5034 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5035 VkPipelineObj pipe(m_device);
5036 pipe.AddShader(&vs);
5037 pipe.AddShader(&fs);
5038 pipe.AddColorAttachment();
5039 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5040
5041 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005042 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5043 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5044 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005045 Draw(1, 0, 0, 0);
5046 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005048 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5049 vkDestroyBuffer(m_device->device(), buffer, NULL);
5050 // Attempt to submit cmd buffer
5051 VkSubmitInfo submit_info = {};
5052 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5053 submit_info.commandBufferCount = 1;
5054 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5055 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5056 m_errorMonitor->VerifyFound();
5057 // Cleanup
5058 vkFreeMemory(m_device->device(), mem, NULL);
5059
5060 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5061 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5062 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5063}
5064
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005065TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5066 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5067 "due to a bound descriptor sets with a combined image "
5068 "sampler having their image, sampler, and descriptor set "
5069 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005070 "submit associated cmd buffers. Attempt to destroy a "
5071 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005072 ASSERT_NO_FATAL_FAILURE(InitState());
5073 ASSERT_NO_FATAL_FAILURE(InitViewport());
5074 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5075
5076 VkDescriptorPoolSize ds_type_count = {};
5077 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5078 ds_type_count.descriptorCount = 1;
5079
5080 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5081 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5082 ds_pool_ci.pNext = NULL;
5083 ds_pool_ci.maxSets = 1;
5084 ds_pool_ci.poolSizeCount = 1;
5085 ds_pool_ci.pPoolSizes = &ds_type_count;
5086
5087 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005088 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005089 ASSERT_VK_SUCCESS(err);
5090
5091 VkDescriptorSetLayoutBinding dsl_binding = {};
5092 dsl_binding.binding = 0;
5093 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5094 dsl_binding.descriptorCount = 1;
5095 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5096 dsl_binding.pImmutableSamplers = NULL;
5097
5098 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5099 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5100 ds_layout_ci.pNext = NULL;
5101 ds_layout_ci.bindingCount = 1;
5102 ds_layout_ci.pBindings = &dsl_binding;
5103 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005104 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005105 ASSERT_VK_SUCCESS(err);
5106
5107 VkDescriptorSet descriptorSet;
5108 VkDescriptorSetAllocateInfo alloc_info = {};
5109 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5110 alloc_info.descriptorSetCount = 1;
5111 alloc_info.descriptorPool = ds_pool;
5112 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005113 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005114 ASSERT_VK_SUCCESS(err);
5115
5116 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5117 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5118 pipeline_layout_ci.pNext = NULL;
5119 pipeline_layout_ci.setLayoutCount = 1;
5120 pipeline_layout_ci.pSetLayouts = &ds_layout;
5121
5122 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005123 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005124 ASSERT_VK_SUCCESS(err);
5125
5126 // Create images to update the descriptor with
5127 VkImage image;
5128 VkImage image2;
5129 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5130 const int32_t tex_width = 32;
5131 const int32_t tex_height = 32;
5132 VkImageCreateInfo image_create_info = {};
5133 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5134 image_create_info.pNext = NULL;
5135 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5136 image_create_info.format = tex_format;
5137 image_create_info.extent.width = tex_width;
5138 image_create_info.extent.height = tex_height;
5139 image_create_info.extent.depth = 1;
5140 image_create_info.mipLevels = 1;
5141 image_create_info.arrayLayers = 1;
5142 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5143 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5144 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5145 image_create_info.flags = 0;
5146 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5147 ASSERT_VK_SUCCESS(err);
5148 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5149 ASSERT_VK_SUCCESS(err);
5150
5151 VkMemoryRequirements memory_reqs;
5152 VkDeviceMemory image_memory;
5153 bool pass;
5154 VkMemoryAllocateInfo memory_info = {};
5155 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5156 memory_info.pNext = NULL;
5157 memory_info.allocationSize = 0;
5158 memory_info.memoryTypeIndex = 0;
5159 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5160 // Allocate enough memory for both images
5161 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005162 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005163 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005164 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005165 ASSERT_VK_SUCCESS(err);
5166 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5167 ASSERT_VK_SUCCESS(err);
5168 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005169 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005170 ASSERT_VK_SUCCESS(err);
5171
5172 VkImageViewCreateInfo image_view_create_info = {};
5173 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5174 image_view_create_info.image = image;
5175 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5176 image_view_create_info.format = tex_format;
5177 image_view_create_info.subresourceRange.layerCount = 1;
5178 image_view_create_info.subresourceRange.baseMipLevel = 0;
5179 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005180 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005181
5182 VkImageView view;
5183 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005184 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005185 ASSERT_VK_SUCCESS(err);
5186 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005187 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005188 ASSERT_VK_SUCCESS(err);
5189 // Create Samplers
5190 VkSamplerCreateInfo sampler_ci = {};
5191 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5192 sampler_ci.pNext = NULL;
5193 sampler_ci.magFilter = VK_FILTER_NEAREST;
5194 sampler_ci.minFilter = VK_FILTER_NEAREST;
5195 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5196 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5197 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5198 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5199 sampler_ci.mipLodBias = 1.0;
5200 sampler_ci.anisotropyEnable = VK_FALSE;
5201 sampler_ci.maxAnisotropy = 1;
5202 sampler_ci.compareEnable = VK_FALSE;
5203 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5204 sampler_ci.minLod = 1.0;
5205 sampler_ci.maxLod = 1.0;
5206 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5207 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5208 VkSampler sampler;
5209 VkSampler sampler2;
5210 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5211 ASSERT_VK_SUCCESS(err);
5212 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5213 ASSERT_VK_SUCCESS(err);
5214 // Update descriptor with image and sampler
5215 VkDescriptorImageInfo img_info = {};
5216 img_info.sampler = sampler;
5217 img_info.imageView = view;
5218 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5219
5220 VkWriteDescriptorSet descriptor_write;
5221 memset(&descriptor_write, 0, sizeof(descriptor_write));
5222 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5223 descriptor_write.dstSet = descriptorSet;
5224 descriptor_write.dstBinding = 0;
5225 descriptor_write.descriptorCount = 1;
5226 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5227 descriptor_write.pImageInfo = &img_info;
5228
5229 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5230
5231 // Create PSO to be used for draw-time errors below
5232 char const *vsSource = "#version 450\n"
5233 "\n"
5234 "out gl_PerVertex { \n"
5235 " vec4 gl_Position;\n"
5236 "};\n"
5237 "void main(){\n"
5238 " gl_Position = vec4(1);\n"
5239 "}\n";
5240 char const *fsSource = "#version 450\n"
5241 "\n"
5242 "layout(set=0, binding=0) uniform sampler2D s;\n"
5243 "layout(location=0) out vec4 x;\n"
5244 "void main(){\n"
5245 " x = texture(s, vec2(1));\n"
5246 "}\n";
5247 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5248 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5249 VkPipelineObj pipe(m_device);
5250 pipe.AddShader(&vs);
5251 pipe.AddShader(&fs);
5252 pipe.AddColorAttachment();
5253 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5254
5255 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005257 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005258 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5259 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5260 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005261 Draw(1, 0, 0, 0);
5262 EndCommandBuffer();
5263 // Destroy sampler invalidates the cmd buffer, causing error on submit
5264 vkDestroySampler(m_device->device(), sampler, NULL);
5265 // Attempt to submit cmd buffer
5266 VkSubmitInfo submit_info = {};
5267 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5268 submit_info.commandBufferCount = 1;
5269 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5270 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5271 m_errorMonitor->VerifyFound();
5272 // Now re-update descriptor with valid sampler and delete image
5273 img_info.sampler = sampler2;
5274 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005276 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005277 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5278 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5279 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005280 Draw(1, 0, 0, 0);
5281 EndCommandBuffer();
5282 // Destroy image invalidates the cmd buffer, causing error on submit
5283 vkDestroyImage(m_device->device(), image, NULL);
5284 // Attempt to submit cmd buffer
5285 submit_info = {};
5286 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5287 submit_info.commandBufferCount = 1;
5288 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5289 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5290 m_errorMonitor->VerifyFound();
5291 // Now update descriptor to be valid, but then free descriptor
5292 img_info.imageView = view2;
5293 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005295 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005296 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5297 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5298 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005299 Draw(1, 0, 0, 0);
5300 EndCommandBuffer();
5301 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005303 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005304 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005305 // Attempt to submit cmd buffer
5306 submit_info = {};
5307 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5308 submit_info.commandBufferCount = 1;
5309 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5310 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5311 m_errorMonitor->VerifyFound();
5312 // Cleanup
5313 vkFreeMemory(m_device->device(), image_memory, NULL);
5314 vkDestroySampler(m_device->device(), sampler2, NULL);
5315 vkDestroyImage(m_device->device(), image2, NULL);
5316 vkDestroyImageView(m_device->device(), view, NULL);
5317 vkDestroyImageView(m_device->device(), view2, NULL);
5318 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5319 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5320 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5321}
5322
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005323TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5324 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5325 ASSERT_NO_FATAL_FAILURE(InitState());
5326 ASSERT_NO_FATAL_FAILURE(InitViewport());
5327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5328
5329 VkDescriptorPoolSize ds_type_count = {};
5330 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5331 ds_type_count.descriptorCount = 1;
5332
5333 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5334 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5335 ds_pool_ci.pNext = NULL;
5336 ds_pool_ci.maxSets = 1;
5337 ds_pool_ci.poolSizeCount = 1;
5338 ds_pool_ci.pPoolSizes = &ds_type_count;
5339
5340 VkDescriptorPool ds_pool;
5341 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5342 ASSERT_VK_SUCCESS(err);
5343
5344 VkDescriptorSetLayoutBinding dsl_binding = {};
5345 dsl_binding.binding = 0;
5346 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5347 dsl_binding.descriptorCount = 1;
5348 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5349 dsl_binding.pImmutableSamplers = NULL;
5350
5351 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5352 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5353 ds_layout_ci.pNext = NULL;
5354 ds_layout_ci.bindingCount = 1;
5355 ds_layout_ci.pBindings = &dsl_binding;
5356 VkDescriptorSetLayout ds_layout;
5357 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5358 ASSERT_VK_SUCCESS(err);
5359
5360 VkDescriptorSet descriptor_set;
5361 VkDescriptorSetAllocateInfo alloc_info = {};
5362 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5363 alloc_info.descriptorSetCount = 1;
5364 alloc_info.descriptorPool = ds_pool;
5365 alloc_info.pSetLayouts = &ds_layout;
5366 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5367 ASSERT_VK_SUCCESS(err);
5368
5369 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5370 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5371 pipeline_layout_ci.pNext = NULL;
5372 pipeline_layout_ci.setLayoutCount = 1;
5373 pipeline_layout_ci.pSetLayouts = &ds_layout;
5374
5375 VkPipelineLayout pipeline_layout;
5376 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5377 ASSERT_VK_SUCCESS(err);
5378
5379 // Create image to update the descriptor with
5380 VkImageObj image(m_device);
5381 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5382 ASSERT_TRUE(image.initialized());
5383
5384 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5385 // Create Sampler
5386 VkSamplerCreateInfo sampler_ci = {};
5387 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5388 sampler_ci.pNext = NULL;
5389 sampler_ci.magFilter = VK_FILTER_NEAREST;
5390 sampler_ci.minFilter = VK_FILTER_NEAREST;
5391 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5392 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5393 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5394 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5395 sampler_ci.mipLodBias = 1.0;
5396 sampler_ci.anisotropyEnable = VK_FALSE;
5397 sampler_ci.maxAnisotropy = 1;
5398 sampler_ci.compareEnable = VK_FALSE;
5399 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5400 sampler_ci.minLod = 1.0;
5401 sampler_ci.maxLod = 1.0;
5402 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5403 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5404 VkSampler sampler;
5405 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5406 ASSERT_VK_SUCCESS(err);
5407 // Update descriptor with image and sampler
5408 VkDescriptorImageInfo img_info = {};
5409 img_info.sampler = sampler;
5410 img_info.imageView = view;
5411 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5412
5413 VkWriteDescriptorSet descriptor_write;
5414 memset(&descriptor_write, 0, sizeof(descriptor_write));
5415 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5416 descriptor_write.dstSet = descriptor_set;
5417 descriptor_write.dstBinding = 0;
5418 descriptor_write.descriptorCount = 1;
5419 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5420 descriptor_write.pImageInfo = &img_info;
5421
5422 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5423
5424 // Create PSO to be used for draw-time errors below
5425 char const *vsSource = "#version 450\n"
5426 "\n"
5427 "out gl_PerVertex { \n"
5428 " vec4 gl_Position;\n"
5429 "};\n"
5430 "void main(){\n"
5431 " gl_Position = vec4(1);\n"
5432 "}\n";
5433 char const *fsSource = "#version 450\n"
5434 "\n"
5435 "layout(set=0, binding=0) uniform sampler2D s;\n"
5436 "layout(location=0) out vec4 x;\n"
5437 "void main(){\n"
5438 " x = texture(s, vec2(1));\n"
5439 "}\n";
5440 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5441 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5442 VkPipelineObj pipe(m_device);
5443 pipe.AddShader(&vs);
5444 pipe.AddShader(&fs);
5445 pipe.AddColorAttachment();
5446 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5447
5448 BeginCommandBuffer();
5449 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5450 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5451 &descriptor_set, 0, NULL);
5452 Draw(1, 0, 0, 0);
5453 EndCommandBuffer();
5454 // Submit cmd buffer to put pool in-flight
5455 VkSubmitInfo submit_info = {};
5456 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5457 submit_info.commandBufferCount = 1;
5458 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5459 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5460 // Destroy pool while in-flight, causing error
5461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5463 m_errorMonitor->VerifyFound();
5464 vkQueueWaitIdle(m_device->m_queue);
5465 // Cleanup
5466 vkDestroySampler(m_device->device(), sampler, NULL);
5467 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5468 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5469 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5470}
5471
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005472TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5473 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5474 ASSERT_NO_FATAL_FAILURE(InitState());
5475 ASSERT_NO_FATAL_FAILURE(InitViewport());
5476 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5477
5478 VkDescriptorPoolSize ds_type_count = {};
5479 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5480 ds_type_count.descriptorCount = 1;
5481
5482 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5483 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5484 ds_pool_ci.pNext = NULL;
5485 ds_pool_ci.maxSets = 1;
5486 ds_pool_ci.poolSizeCount = 1;
5487 ds_pool_ci.pPoolSizes = &ds_type_count;
5488
5489 VkDescriptorPool ds_pool;
5490 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5491 ASSERT_VK_SUCCESS(err);
5492
5493 VkDescriptorSetLayoutBinding dsl_binding = {};
5494 dsl_binding.binding = 0;
5495 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5496 dsl_binding.descriptorCount = 1;
5497 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5498 dsl_binding.pImmutableSamplers = NULL;
5499
5500 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5501 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5502 ds_layout_ci.pNext = NULL;
5503 ds_layout_ci.bindingCount = 1;
5504 ds_layout_ci.pBindings = &dsl_binding;
5505 VkDescriptorSetLayout ds_layout;
5506 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5507 ASSERT_VK_SUCCESS(err);
5508
5509 VkDescriptorSet descriptorSet;
5510 VkDescriptorSetAllocateInfo alloc_info = {};
5511 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5512 alloc_info.descriptorSetCount = 1;
5513 alloc_info.descriptorPool = ds_pool;
5514 alloc_info.pSetLayouts = &ds_layout;
5515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5516 ASSERT_VK_SUCCESS(err);
5517
5518 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5519 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5520 pipeline_layout_ci.pNext = NULL;
5521 pipeline_layout_ci.setLayoutCount = 1;
5522 pipeline_layout_ci.pSetLayouts = &ds_layout;
5523
5524 VkPipelineLayout pipeline_layout;
5525 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5526 ASSERT_VK_SUCCESS(err);
5527
5528 // Create images to update the descriptor with
5529 VkImage image;
5530 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5531 const int32_t tex_width = 32;
5532 const int32_t tex_height = 32;
5533 VkImageCreateInfo image_create_info = {};
5534 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5535 image_create_info.pNext = NULL;
5536 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5537 image_create_info.format = tex_format;
5538 image_create_info.extent.width = tex_width;
5539 image_create_info.extent.height = tex_height;
5540 image_create_info.extent.depth = 1;
5541 image_create_info.mipLevels = 1;
5542 image_create_info.arrayLayers = 1;
5543 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5544 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5545 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5546 image_create_info.flags = 0;
5547 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5548 ASSERT_VK_SUCCESS(err);
5549 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5550 VkMemoryRequirements memory_reqs;
5551 VkDeviceMemory image_memory;
5552 bool pass;
5553 VkMemoryAllocateInfo memory_info = {};
5554 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5555 memory_info.pNext = NULL;
5556 memory_info.allocationSize = 0;
5557 memory_info.memoryTypeIndex = 0;
5558 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5559 // Allocate enough memory for image
5560 memory_info.allocationSize = memory_reqs.size;
5561 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5562 ASSERT_TRUE(pass);
5563 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5564 ASSERT_VK_SUCCESS(err);
5565 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5566 ASSERT_VK_SUCCESS(err);
5567
5568 VkImageViewCreateInfo image_view_create_info = {};
5569 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5570 image_view_create_info.image = image;
5571 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5572 image_view_create_info.format = tex_format;
5573 image_view_create_info.subresourceRange.layerCount = 1;
5574 image_view_create_info.subresourceRange.baseMipLevel = 0;
5575 image_view_create_info.subresourceRange.levelCount = 1;
5576 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5577
5578 VkImageView view;
5579 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5580 ASSERT_VK_SUCCESS(err);
5581 // Create Samplers
5582 VkSamplerCreateInfo sampler_ci = {};
5583 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5584 sampler_ci.pNext = NULL;
5585 sampler_ci.magFilter = VK_FILTER_NEAREST;
5586 sampler_ci.minFilter = VK_FILTER_NEAREST;
5587 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5588 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5589 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5590 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5591 sampler_ci.mipLodBias = 1.0;
5592 sampler_ci.anisotropyEnable = VK_FALSE;
5593 sampler_ci.maxAnisotropy = 1;
5594 sampler_ci.compareEnable = VK_FALSE;
5595 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5596 sampler_ci.minLod = 1.0;
5597 sampler_ci.maxLod = 1.0;
5598 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5599 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5600 VkSampler sampler;
5601 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5602 ASSERT_VK_SUCCESS(err);
5603 // Update descriptor with image and sampler
5604 VkDescriptorImageInfo img_info = {};
5605 img_info.sampler = sampler;
5606 img_info.imageView = view;
5607 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5608
5609 VkWriteDescriptorSet descriptor_write;
5610 memset(&descriptor_write, 0, sizeof(descriptor_write));
5611 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5612 descriptor_write.dstSet = descriptorSet;
5613 descriptor_write.dstBinding = 0;
5614 descriptor_write.descriptorCount = 1;
5615 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5616 descriptor_write.pImageInfo = &img_info;
5617 // Break memory binding and attempt update
5618 vkFreeMemory(m_device->device(), image_memory, nullptr);
5619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005620 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5622 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5623 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5624 m_errorMonitor->VerifyFound();
5625 // Cleanup
5626 vkDestroyImage(m_device->device(), image, NULL);
5627 vkDestroySampler(m_device->device(), sampler, NULL);
5628 vkDestroyImageView(m_device->device(), view, NULL);
5629 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5630 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5631 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5632}
5633
Karl Schultz6addd812016-02-02 17:17:23 -07005634TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005635 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5636 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005637 // Create a valid cmd buffer
5638 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005639 uint64_t fake_pipeline_handle = 0xbaad6001;
5640 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005641 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5643
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Karl Schultzbdb75952016-04-19 11:36:49 -06005645 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005646 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005647 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005648
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005649 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005650 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 -06005651 Draw(1, 0, 0, 0);
5652 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005653
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005654 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005655 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 +12005656 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005657 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5658 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005659}
5660
Karl Schultz6addd812016-02-02 17:17:23 -07005661TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005662 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005663 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005666
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005667 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005668 ASSERT_NO_FATAL_FAILURE(InitViewport());
5669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005670 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005671 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5672 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005673
5674 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005675 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5676 ds_pool_ci.pNext = NULL;
5677 ds_pool_ci.maxSets = 1;
5678 ds_pool_ci.poolSizeCount = 1;
5679 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005680
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005681 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005682 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005683 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005684
Tony Barboureb254902015-07-15 12:50:33 -06005685 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005686 dsl_binding.binding = 0;
5687 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5688 dsl_binding.descriptorCount = 1;
5689 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5690 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005691
Tony Barboureb254902015-07-15 12:50:33 -06005692 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005693 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5694 ds_layout_ci.pNext = NULL;
5695 ds_layout_ci.bindingCount = 1;
5696 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005697 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005698 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005699 ASSERT_VK_SUCCESS(err);
5700
5701 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005702 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005703 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005704 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005705 alloc_info.descriptorPool = ds_pool;
5706 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005707 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005708 ASSERT_VK_SUCCESS(err);
5709
Tony Barboureb254902015-07-15 12:50:33 -06005710 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005711 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5712 pipeline_layout_ci.pNext = NULL;
5713 pipeline_layout_ci.setLayoutCount = 1;
5714 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005715
5716 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005717 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005718 ASSERT_VK_SUCCESS(err);
5719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005720 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005721 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005722 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005723 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005724
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005725 VkPipelineObj pipe(m_device);
5726 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005727 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005728 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005729 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005730
5731 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005732 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5733 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5734 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005735
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005736 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005737
Chia-I Wuf7458c52015-10-26 21:10:41 +08005738 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5739 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5740 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005741}
5742
Karl Schultz6addd812016-02-02 17:17:23 -07005743TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005744 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005745 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005746
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005748
5749 ASSERT_NO_FATAL_FAILURE(InitState());
5750 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005751 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5752 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005753
5754 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005755 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5756 ds_pool_ci.pNext = NULL;
5757 ds_pool_ci.maxSets = 1;
5758 ds_pool_ci.poolSizeCount = 1;
5759 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005760
5761 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005762 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005763 ASSERT_VK_SUCCESS(err);
5764
5765 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005766 dsl_binding.binding = 0;
5767 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5768 dsl_binding.descriptorCount = 1;
5769 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5770 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005771
5772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5774 ds_layout_ci.pNext = NULL;
5775 ds_layout_ci.bindingCount = 1;
5776 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005777 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005779 ASSERT_VK_SUCCESS(err);
5780
5781 VkDescriptorSet descriptorSet;
5782 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005783 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005784 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005785 alloc_info.descriptorPool = ds_pool;
5786 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005787 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005788 ASSERT_VK_SUCCESS(err);
5789
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005790 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005791 VkWriteDescriptorSet descriptor_write;
5792 memset(&descriptor_write, 0, sizeof(descriptor_write));
5793 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5794 descriptor_write.dstSet = descriptorSet;
5795 descriptor_write.dstBinding = 0;
5796 descriptor_write.descriptorCount = 1;
5797 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5798 descriptor_write.pTexelBufferView = &view;
5799
5800 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5801
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005802 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005803
5804 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5805 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5806}
5807
Mark Youngd339ba32016-05-30 13:28:35 -06005808TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005809 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 -06005810
5811 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005813 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005814
5815 ASSERT_NO_FATAL_FAILURE(InitState());
5816
5817 // Create a buffer with no bound memory and then attempt to create
5818 // a buffer view.
5819 VkBufferCreateInfo buff_ci = {};
5820 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005821 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005822 buff_ci.size = 256;
5823 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5824 VkBuffer buffer;
5825 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5826 ASSERT_VK_SUCCESS(err);
5827
5828 VkBufferViewCreateInfo buff_view_ci = {};
5829 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5830 buff_view_ci.buffer = buffer;
5831 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5832 buff_view_ci.range = VK_WHOLE_SIZE;
5833 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005834 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005835
5836 m_errorMonitor->VerifyFound();
5837 vkDestroyBuffer(m_device->device(), buffer, NULL);
5838 // If last error is success, it still created the view, so delete it.
5839 if (err == VK_SUCCESS) {
5840 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5841 }
5842}
5843
Karl Schultz6addd812016-02-02 17:17:23 -07005844TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5845 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5846 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005847 // 1. No dynamicOffset supplied
5848 // 2. Too many dynamicOffsets supplied
5849 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005850 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5852 "0 dynamicOffsets are left in "
5853 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005854
5855 ASSERT_NO_FATAL_FAILURE(InitState());
5856 ASSERT_NO_FATAL_FAILURE(InitViewport());
5857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5858
5859 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005860 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5861 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005862
5863 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005864 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5865 ds_pool_ci.pNext = NULL;
5866 ds_pool_ci.maxSets = 1;
5867 ds_pool_ci.poolSizeCount = 1;
5868 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005869
5870 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005871 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005872 ASSERT_VK_SUCCESS(err);
5873
5874 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005875 dsl_binding.binding = 0;
5876 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5877 dsl_binding.descriptorCount = 1;
5878 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5879 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005880
5881 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005882 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5883 ds_layout_ci.pNext = NULL;
5884 ds_layout_ci.bindingCount = 1;
5885 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005886 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005887 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005888 ASSERT_VK_SUCCESS(err);
5889
5890 VkDescriptorSet descriptorSet;
5891 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005892 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005893 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005894 alloc_info.descriptorPool = ds_pool;
5895 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005896 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005897 ASSERT_VK_SUCCESS(err);
5898
5899 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005900 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5901 pipeline_layout_ci.pNext = NULL;
5902 pipeline_layout_ci.setLayoutCount = 1;
5903 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005904
5905 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005906 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005907 ASSERT_VK_SUCCESS(err);
5908
5909 // Create a buffer to update the descriptor with
5910 uint32_t qfi = 0;
5911 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005912 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5913 buffCI.size = 1024;
5914 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5915 buffCI.queueFamilyIndexCount = 1;
5916 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005917
5918 VkBuffer dyub;
5919 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5920 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005921 // Allocate memory and bind to buffer so we can make it to the appropriate
5922 // error
5923 VkMemoryAllocateInfo mem_alloc = {};
5924 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5925 mem_alloc.pNext = NULL;
5926 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005927 mem_alloc.memoryTypeIndex = 0;
5928
5929 VkMemoryRequirements memReqs;
5930 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005931 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005932 if (!pass) {
5933 vkDestroyBuffer(m_device->device(), dyub, NULL);
5934 return;
5935 }
5936
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005937 VkDeviceMemory mem;
5938 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5939 ASSERT_VK_SUCCESS(err);
5940 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5941 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005942 // Correctly update descriptor to avoid "NOT_UPDATED" error
5943 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005944 buffInfo.buffer = dyub;
5945 buffInfo.offset = 0;
5946 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005947
5948 VkWriteDescriptorSet descriptor_write;
5949 memset(&descriptor_write, 0, sizeof(descriptor_write));
5950 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5951 descriptor_write.dstSet = descriptorSet;
5952 descriptor_write.dstBinding = 0;
5953 descriptor_write.descriptorCount = 1;
5954 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5955 descriptor_write.pBufferInfo = &buffInfo;
5956
5957 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5958
5959 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005960 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5961 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005962 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005963 uint32_t pDynOff[2] = {512, 756};
5964 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5966 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5967 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5968 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005969 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005970 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5972 "offset 0 and range 1024 that "
5973 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005974 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005975 char const *vsSource = "#version 450\n"
5976 "\n"
5977 "out gl_PerVertex { \n"
5978 " vec4 gl_Position;\n"
5979 "};\n"
5980 "void main(){\n"
5981 " gl_Position = vec4(1);\n"
5982 "}\n";
5983 char const *fsSource = "#version 450\n"
5984 "\n"
5985 "layout(location=0) out vec4 x;\n"
5986 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5987 "void main(){\n"
5988 " x = vec4(bar.y);\n"
5989 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005990 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5991 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5992 VkPipelineObj pipe(m_device);
5993 pipe.AddShader(&vs);
5994 pipe.AddShader(&fs);
5995 pipe.AddColorAttachment();
5996 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5997
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005998 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005999 // This update should succeed, but offset size of 512 will overstep buffer
6000 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006001 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6002 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006003 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006004 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006005
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006006 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006007 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006008
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006009 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006010 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006011 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6012}
6013
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006014TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6015 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6016 "that doesn't have memory bound");
6017 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006019 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6021 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006022
6023 ASSERT_NO_FATAL_FAILURE(InitState());
6024 ASSERT_NO_FATAL_FAILURE(InitViewport());
6025 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6026
6027 VkDescriptorPoolSize ds_type_count = {};
6028 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6029 ds_type_count.descriptorCount = 1;
6030
6031 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6032 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6033 ds_pool_ci.pNext = NULL;
6034 ds_pool_ci.maxSets = 1;
6035 ds_pool_ci.poolSizeCount = 1;
6036 ds_pool_ci.pPoolSizes = &ds_type_count;
6037
6038 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006039 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006040 ASSERT_VK_SUCCESS(err);
6041
6042 VkDescriptorSetLayoutBinding dsl_binding = {};
6043 dsl_binding.binding = 0;
6044 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6045 dsl_binding.descriptorCount = 1;
6046 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6047 dsl_binding.pImmutableSamplers = NULL;
6048
6049 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6050 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6051 ds_layout_ci.pNext = NULL;
6052 ds_layout_ci.bindingCount = 1;
6053 ds_layout_ci.pBindings = &dsl_binding;
6054 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006055 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006056 ASSERT_VK_SUCCESS(err);
6057
6058 VkDescriptorSet descriptorSet;
6059 VkDescriptorSetAllocateInfo alloc_info = {};
6060 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6061 alloc_info.descriptorSetCount = 1;
6062 alloc_info.descriptorPool = ds_pool;
6063 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006064 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006065 ASSERT_VK_SUCCESS(err);
6066
6067 // Create a buffer to update the descriptor with
6068 uint32_t qfi = 0;
6069 VkBufferCreateInfo buffCI = {};
6070 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6071 buffCI.size = 1024;
6072 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6073 buffCI.queueFamilyIndexCount = 1;
6074 buffCI.pQueueFamilyIndices = &qfi;
6075
6076 VkBuffer dyub;
6077 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6078 ASSERT_VK_SUCCESS(err);
6079
6080 // Attempt to update descriptor without binding memory to it
6081 VkDescriptorBufferInfo buffInfo = {};
6082 buffInfo.buffer = dyub;
6083 buffInfo.offset = 0;
6084 buffInfo.range = 1024;
6085
6086 VkWriteDescriptorSet descriptor_write;
6087 memset(&descriptor_write, 0, sizeof(descriptor_write));
6088 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6089 descriptor_write.dstSet = descriptorSet;
6090 descriptor_write.dstBinding = 0;
6091 descriptor_write.descriptorCount = 1;
6092 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6093 descriptor_write.pBufferInfo = &buffInfo;
6094
6095 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6096 m_errorMonitor->VerifyFound();
6097
6098 vkDestroyBuffer(m_device->device(), dyub, NULL);
6099 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6100 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6101}
6102
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006103TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006104 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006105 ASSERT_NO_FATAL_FAILURE(InitState());
6106 ASSERT_NO_FATAL_FAILURE(InitViewport());
6107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6108
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006109 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006110 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006111 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6112 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6113 pipeline_layout_ci.pushConstantRangeCount = 1;
6114 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6115
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006116 //
6117 // Check for invalid push constant ranges in pipeline layouts.
6118 //
6119 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006120 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006121 char const *msg;
6122 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006123
Karl Schultzc81037d2016-05-12 08:11:23 -06006124 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6125 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6126 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6127 "vkCreatePipelineLayout() call has push constants index 0 with "
6128 "size 0."},
6129 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6130 "vkCreatePipelineLayout() call has push constants index 0 with "
6131 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006132 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006133 "vkCreatePipelineLayout() call has push constants index 0 with "
6134 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006135 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006136 "vkCreatePipelineLayout() call has push constants index 0 with "
6137 "size 0."},
6138 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6139 "vkCreatePipelineLayout() call has push constants index 0 with "
6140 "offset 1. Offset must"},
6141 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6142 "vkCreatePipelineLayout() call has push constants index 0 "
6143 "with offset "},
6144 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6145 "vkCreatePipelineLayout() call has push constants "
6146 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006147 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006148 "vkCreatePipelineLayout() call has push constants index 0 "
6149 "with offset "},
6150 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6151 "vkCreatePipelineLayout() call has push "
6152 "constants index 0 with offset "},
6153 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6154 "vkCreatePipelineLayout() call has push "
6155 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006156 }};
6157
6158 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006159 for (const auto &iter : range_tests) {
6160 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6162 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006163 m_errorMonitor->VerifyFound();
6164 if (VK_SUCCESS == err) {
6165 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6166 }
6167 }
6168
6169 // Check for invalid stage flag
6170 pc_range.offset = 0;
6171 pc_range.size = 16;
6172 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006173 m_errorMonitor->SetDesiredFailureMsg(
6174 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6175 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006176 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006177 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006178 if (VK_SUCCESS == err) {
6179 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6180 }
6181
6182 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006183 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006184 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006185 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006186 char const *msg;
6187 };
6188
Karl Schultzc81037d2016-05-12 08:11:23 -06006189 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006190 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6191 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6192 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6193 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6194 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006195 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006196 {
6197 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6198 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6199 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6200 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6201 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006202 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006203 },
6204 {
6205 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6206 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6207 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6208 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6209 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006210 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006211 },
6212 {
6213 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6214 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6215 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6216 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6217 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006218 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006219 },
6220 {
6221 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6222 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6223 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6224 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6225 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006226 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006227 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006228
Karl Schultzc81037d2016-05-12 08:11:23 -06006229 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006230 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006231 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6233 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006234 m_errorMonitor->VerifyFound();
6235 if (VK_SUCCESS == err) {
6236 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6237 }
6238 }
6239
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006240 //
6241 // CmdPushConstants tests
6242 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006243 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006244
6245 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006246 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6247 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006248 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6249 "vkCmdPushConstants() call has push constants with size 1. Size "
6250 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006251 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006252 "vkCmdPushConstants() call has push constants with size 1. Size "
6253 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006254 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006255 "vkCmdPushConstants() call has push constants with offset 1. "
6256 "Offset must be a multiple of 4."},
6257 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6258 "vkCmdPushConstants() call has push constants with offset 1. "
6259 "Offset must be a multiple of 4."},
6260 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6261 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6262 "0x1 not within flag-matching ranges in pipeline layout"},
6263 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6264 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6265 "0x1 not within flag-matching ranges in pipeline layout"},
6266 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6267 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6268 "0x1 not within flag-matching ranges in pipeline layout"},
6269 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6270 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6271 "0x1 not within flag-matching ranges in pipeline layout"},
6272 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6273 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6274 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006275 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006276 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6277 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006278 }};
6279
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006280 BeginCommandBuffer();
6281
6282 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006283 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006284 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006285 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006286 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006287 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006288 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006289 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006290 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6292 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006293 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006294 m_errorMonitor->VerifyFound();
6295 }
6296
6297 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006299 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006300 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006301 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006302
Karl Schultzc81037d2016-05-12 08:11:23 -06006303 // overlapping range tests with cmd
6304 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6305 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6306 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6307 "0x1 not within flag-matching ranges in pipeline layout"},
6308 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6309 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6310 "0x1 not within flag-matching ranges in pipeline layout"},
6311 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6312 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6313 "0x1 not within flag-matching ranges in pipeline layout"},
6314 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006315 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006316 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006317 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6318 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006319 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006320 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006321 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006322 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006323 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006324 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6326 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006327 iter.range.size, dummy_values);
6328 m_errorMonitor->VerifyFound();
6329 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006330 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6331
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006332 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006333}
6334
Karl Schultz6addd812016-02-02 17:17:23 -07006335TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006336 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006337 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006338
6339 ASSERT_NO_FATAL_FAILURE(InitState());
6340 ASSERT_NO_FATAL_FAILURE(InitViewport());
6341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6342
Mike Stroyanb8a61002016-06-20 16:00:28 -06006343 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6344 VkImageTiling tiling;
6345 VkFormatProperties format_properties;
6346 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006347 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006348 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006349 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006350 tiling = VK_IMAGE_TILING_OPTIMAL;
6351 } else {
6352 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6353 "skipped.\n");
6354 return;
6355 }
6356
Tobin Ehlis559c6382015-11-05 09:52:49 -07006357 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6358 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006359 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6360 ds_type_count[0].descriptorCount = 10;
6361 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6362 ds_type_count[1].descriptorCount = 2;
6363 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6364 ds_type_count[2].descriptorCount = 2;
6365 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6366 ds_type_count[3].descriptorCount = 5;
6367 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6368 // type
6369 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6370 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6371 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006372
6373 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006374 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6375 ds_pool_ci.pNext = NULL;
6376 ds_pool_ci.maxSets = 5;
6377 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6378 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006379
6380 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006381 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006382 ASSERT_VK_SUCCESS(err);
6383
6384 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6385 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006386 dsl_binding[0].binding = 0;
6387 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6388 dsl_binding[0].descriptorCount = 5;
6389 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6390 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006391
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006392 // Create layout identical to set0 layout but w/ different stageFlags
6393 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006394 dsl_fs_stage_only.binding = 0;
6395 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6396 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006397 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6398 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006399 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006400 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006401 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6402 ds_layout_ci.pNext = NULL;
6403 ds_layout_ci.bindingCount = 1;
6404 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006405 static const uint32_t NUM_LAYOUTS = 4;
6406 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006407 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006408 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6409 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006410 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006411 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006412 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006413 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006414 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006415 dsl_binding[0].binding = 0;
6416 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006417 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006418 dsl_binding[1].binding = 1;
6419 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6420 dsl_binding[1].descriptorCount = 2;
6421 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6422 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006423 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006424 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006425 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006426 ASSERT_VK_SUCCESS(err);
6427 dsl_binding[0].binding = 0;
6428 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006429 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006430 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006431 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006432 ASSERT_VK_SUCCESS(err);
6433 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006434 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006435 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006436 ASSERT_VK_SUCCESS(err);
6437
6438 static const uint32_t NUM_SETS = 4;
6439 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6440 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006441 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006442 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006443 alloc_info.descriptorPool = ds_pool;
6444 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006445 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006446 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006447 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006448 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006449 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006450 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006451 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006452
6453 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006454 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6455 pipeline_layout_ci.pNext = NULL;
6456 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6457 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006458
6459 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006460 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006461 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006462 // Create pipelineLayout with only one setLayout
6463 pipeline_layout_ci.setLayoutCount = 1;
6464 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006465 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006466 ASSERT_VK_SUCCESS(err);
6467 // Create pipelineLayout with 2 descriptor setLayout at index 0
6468 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6469 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006470 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006471 ASSERT_VK_SUCCESS(err);
6472 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6473 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6474 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006475 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006476 ASSERT_VK_SUCCESS(err);
6477 // Create pipelineLayout with UB type, but stageFlags for FS only
6478 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6479 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006480 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006481 ASSERT_VK_SUCCESS(err);
6482 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6483 VkDescriptorSetLayout pl_bad_s0[2] = {};
6484 pl_bad_s0[0] = ds_layout_fs_only;
6485 pl_bad_s0[1] = ds_layout[1];
6486 pipeline_layout_ci.setLayoutCount = 2;
6487 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6488 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006489 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006490 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006491
6492 // Create a buffer to update the descriptor with
6493 uint32_t qfi = 0;
6494 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006495 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6496 buffCI.size = 1024;
6497 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6498 buffCI.queueFamilyIndexCount = 1;
6499 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006500
6501 VkBuffer dyub;
6502 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6503 ASSERT_VK_SUCCESS(err);
6504 // Correctly update descriptor to avoid "NOT_UPDATED" error
6505 static const uint32_t NUM_BUFFS = 5;
6506 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006507 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006508 buffInfo[i].buffer = dyub;
6509 buffInfo[i].offset = 0;
6510 buffInfo[i].range = 1024;
6511 }
Karl Schultz6addd812016-02-02 17:17:23 -07006512 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006513 const int32_t tex_width = 32;
6514 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006515 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006516 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6517 image_create_info.pNext = NULL;
6518 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6519 image_create_info.format = tex_format;
6520 image_create_info.extent.width = tex_width;
6521 image_create_info.extent.height = tex_height;
6522 image_create_info.extent.depth = 1;
6523 image_create_info.mipLevels = 1;
6524 image_create_info.arrayLayers = 1;
6525 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006526 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006528 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006529 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6530 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006531
Karl Schultz6addd812016-02-02 17:17:23 -07006532 VkMemoryRequirements memReqs;
6533 VkDeviceMemory imageMem;
6534 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006535 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006536 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6537 memAlloc.pNext = NULL;
6538 memAlloc.allocationSize = 0;
6539 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006540 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6541 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006542 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006543 ASSERT_TRUE(pass);
6544 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6545 ASSERT_VK_SUCCESS(err);
6546 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6547 ASSERT_VK_SUCCESS(err);
6548
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006549 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006550 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6551 image_view_create_info.image = image;
6552 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6553 image_view_create_info.format = tex_format;
6554 image_view_create_info.subresourceRange.layerCount = 1;
6555 image_view_create_info.subresourceRange.baseMipLevel = 0;
6556 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006557 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006558
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006559 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006560 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006561 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006562 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006563 imageInfo[0].imageView = view;
6564 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6565 imageInfo[1].imageView = view;
6566 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006567 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006568 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006569 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006570 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006571
6572 static const uint32_t NUM_SET_UPDATES = 3;
6573 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6574 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6575 descriptor_write[0].dstSet = descriptorSet[0];
6576 descriptor_write[0].dstBinding = 0;
6577 descriptor_write[0].descriptorCount = 5;
6578 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6579 descriptor_write[0].pBufferInfo = buffInfo;
6580 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6581 descriptor_write[1].dstSet = descriptorSet[1];
6582 descriptor_write[1].dstBinding = 0;
6583 descriptor_write[1].descriptorCount = 2;
6584 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6585 descriptor_write[1].pImageInfo = imageInfo;
6586 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6587 descriptor_write[2].dstSet = descriptorSet[1];
6588 descriptor_write[2].dstBinding = 1;
6589 descriptor_write[2].descriptorCount = 2;
6590 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006591 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006592
6593 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006594
Tobin Ehlis88452832015-12-03 09:40:56 -07006595 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006596 char const *vsSource = "#version 450\n"
6597 "\n"
6598 "out gl_PerVertex {\n"
6599 " vec4 gl_Position;\n"
6600 "};\n"
6601 "void main(){\n"
6602 " gl_Position = vec4(1);\n"
6603 "}\n";
6604 char const *fsSource = "#version 450\n"
6605 "\n"
6606 "layout(location=0) out vec4 x;\n"
6607 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6608 "void main(){\n"
6609 " x = vec4(bar.y);\n"
6610 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006611 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6612 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006613 VkPipelineObj pipe(m_device);
6614 pipe.AddShader(&vs);
6615 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006616 pipe.AddColorAttachment();
6617 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006618
6619 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006621 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006622 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6623 // of PSO
6624 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6625 // cmd_pipeline.c
6626 // due to the fact that cmd_alloc_dset_data() has not been called in
6627 // cmd_bind_graphics_pipeline()
6628 // TODO : Want to cause various binding incompatibility issues here to test
6629 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006630 // First cause various verify_layout_compatibility() fails
6631 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006632 // verify_set_layout_compatibility fail cases:
6633 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006635 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6636 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006637 m_errorMonitor->VerifyFound();
6638
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006639 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6641 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6642 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006643 m_errorMonitor->VerifyFound();
6644
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006645 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006646 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6647 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6649 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6650 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006651 m_errorMonitor->VerifyFound();
6652
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006653 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6654 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6656 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6657 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006658 m_errorMonitor->VerifyFound();
6659
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006660 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6661 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6663 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6664 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6665 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006666 m_errorMonitor->VerifyFound();
6667
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006668 // Cause INFO messages due to disturbing previously bound Sets
6669 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006670 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6671 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006672 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6674 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6675 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006676 m_errorMonitor->VerifyFound();
6677
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006678 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6679 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006680 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6682 "any subsequent sets were disturbed ");
6683 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6684 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006685 m_errorMonitor->VerifyFound();
6686
Tobin Ehlis10fad692016-07-07 12:00:36 -06006687 // Now that we're done actively using the pipelineLayout that gfx pipeline
6688 // was created with, we should be able to delete it. Do that now to verify
6689 // that validation obeys pipelineLayout lifetime
6690 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6691
Tobin Ehlis88452832015-12-03 09:40:56 -07006692 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006693 // 1. Error due to not binding required set (we actually use same code as
6694 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006695 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6696 &descriptorSet[0], 0, NULL);
6697 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6698 &descriptorSet[1], 0, NULL);
6699 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 -07006700 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006701 m_errorMonitor->VerifyFound();
6702
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006703 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006704 // 2. Error due to bound set not being compatible with PSO's
6705 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006706 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6707 &descriptorSet[0], 0, NULL);
6708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006709 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006710 m_errorMonitor->VerifyFound();
6711
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006712 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006713 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006714 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6715 }
6716 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006717 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006718 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6719 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006720 vkFreeMemory(m_device->device(), imageMem, NULL);
6721 vkDestroyImage(m_device->device(), image, NULL);
6722 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006723}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006724
Karl Schultz6addd812016-02-02 17:17:23 -07006725TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006726
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6728 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006729
6730 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006731 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006732 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006733 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006734
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006735 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006736}
6737
Karl Schultz6addd812016-02-02 17:17:23 -07006738TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6739 VkResult err;
6740 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006741
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006743
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006744 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006745
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006746 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006747 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006748 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006749 cmd.commandPool = m_commandPool;
6750 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006751 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006752
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006753 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006754 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006755
6756 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006757 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006758 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006759 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006760 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006761 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 -07006762 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006763
6764 // The error should be caught by validation of the BeginCommandBuffer call
6765 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6766
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006767 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006768 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006769}
6770
Karl Schultz6addd812016-02-02 17:17:23 -07006771TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006772 // Cause error due to Begin while recording CB
6773 // Then cause 2 errors for attempting to reset CB w/o having
6774 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6775 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006777
6778 ASSERT_NO_FATAL_FAILURE(InitState());
6779
6780 // Calls AllocateCommandBuffers
6781 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6782
Karl Schultz6addd812016-02-02 17:17:23 -07006783 // Force the failure by setting the Renderpass and Framebuffer fields with
6784 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006785 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006786 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006787 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6788 cmd_buf_info.pNext = NULL;
6789 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006790 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006791
6792 // Begin CB to transition to recording state
6793 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6794 // Can't re-begin. This should trigger error
6795 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006796 m_errorMonitor->VerifyFound();
6797
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006799 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6800 // Reset attempt will trigger error due to incorrect CommandPool state
6801 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006802 m_errorMonitor->VerifyFound();
6803
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006805 // Transition CB to RECORDED state
6806 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6807 // Now attempting to Begin will implicitly reset, which triggers error
6808 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006809 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006810}
6811
Karl Schultz6addd812016-02-02 17:17:23 -07006812TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006813 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006814 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006815
Mike Weiblencce7ec72016-10-17 19:33:05 -06006816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006817
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006818 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006820
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006821 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006822 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6823 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006824
6825 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006826 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6827 ds_pool_ci.pNext = NULL;
6828 ds_pool_ci.maxSets = 1;
6829 ds_pool_ci.poolSizeCount = 1;
6830 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006831
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006832 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006833 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006834 ASSERT_VK_SUCCESS(err);
6835
Tony Barboureb254902015-07-15 12:50:33 -06006836 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006837 dsl_binding.binding = 0;
6838 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6839 dsl_binding.descriptorCount = 1;
6840 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6841 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006842
Tony Barboureb254902015-07-15 12:50:33 -06006843 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006844 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6845 ds_layout_ci.pNext = NULL;
6846 ds_layout_ci.bindingCount = 1;
6847 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006848
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006849 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006850 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006851 ASSERT_VK_SUCCESS(err);
6852
6853 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006854 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006855 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006856 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006857 alloc_info.descriptorPool = ds_pool;
6858 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006859 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006860 ASSERT_VK_SUCCESS(err);
6861
Tony Barboureb254902015-07-15 12:50:33 -06006862 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006863 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6864 pipeline_layout_ci.setLayoutCount = 1;
6865 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006866
6867 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006868 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006869 ASSERT_VK_SUCCESS(err);
6870
Tobin Ehlise68360f2015-10-01 11:15:13 -06006871 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006872 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006873
6874 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006875 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6876 vp_state_ci.scissorCount = 1;
6877 vp_state_ci.pScissors = &sc;
6878 vp_state_ci.viewportCount = 1;
6879 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006880
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006881 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6882 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6883 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6884 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6885 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6886 rs_state_ci.depthClampEnable = VK_FALSE;
6887 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6888 rs_state_ci.depthBiasEnable = VK_FALSE;
6889
Tony Barboureb254902015-07-15 12:50:33 -06006890 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006891 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6892 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006893 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006894 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6895 gp_ci.layout = pipeline_layout;
6896 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006897
6898 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006899 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6900 pc_ci.initialDataSize = 0;
6901 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006902
6903 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006904 VkPipelineCache pipelineCache;
6905
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006906 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006907 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006908 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006909
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006910 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006911
Chia-I Wuf7458c52015-10-26 21:10:41 +08006912 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6913 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6914 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6915 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006916}
Tobin Ehlis912df022015-09-17 08:46:18 -06006917/*// TODO : This test should be good, but needs Tess support in compiler to run
6918TEST_F(VkLayerTest, InvalidPatchControlPoints)
6919{
6920 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006921 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006922
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006924 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6925primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006926
Tobin Ehlis912df022015-09-17 08:46:18 -06006927 ASSERT_NO_FATAL_FAILURE(InitState());
6928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006929
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006930 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006931 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006932 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006933
6934 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6935 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6936 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006937 ds_pool_ci.poolSizeCount = 1;
6938 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006939
6940 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006941 err = vkCreateDescriptorPool(m_device->device(),
6942VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006943 ASSERT_VK_SUCCESS(err);
6944
6945 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006946 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006947 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006948 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006949 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6950 dsl_binding.pImmutableSamplers = NULL;
6951
6952 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006953 ds_layout_ci.sType =
6954VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006955 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006956 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006957 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006958
6959 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006960 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6961&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006962 ASSERT_VK_SUCCESS(err);
6963
6964 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006965 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6966VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006967 ASSERT_VK_SUCCESS(err);
6968
6969 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006970 pipeline_layout_ci.sType =
6971VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006972 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006973 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006974 pipeline_layout_ci.pSetLayouts = &ds_layout;
6975
6976 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006977 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6978&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006979 ASSERT_VK_SUCCESS(err);
6980
6981 VkPipelineShaderStageCreateInfo shaderStages[3];
6982 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6983
Karl Schultz6addd812016-02-02 17:17:23 -07006984 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6985this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006986 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006987 VkShaderObj
6988tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6989this);
6990 VkShaderObj
6991te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6992this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006993
Karl Schultz6addd812016-02-02 17:17:23 -07006994 shaderStages[0].sType =
6995VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006996 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006997 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006998 shaderStages[1].sType =
6999VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007000 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007001 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007002 shaderStages[2].sType =
7003VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007004 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007005 shaderStages[2].shader = te.handle();
7006
7007 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007008 iaCI.sType =
7009VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007010 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007011
7012 VkPipelineTessellationStateCreateInfo tsCI = {};
7013 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7014 tsCI.patchControlPoints = 0; // This will cause an error
7015
7016 VkGraphicsPipelineCreateInfo gp_ci = {};
7017 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7018 gp_ci.pNext = NULL;
7019 gp_ci.stageCount = 3;
7020 gp_ci.pStages = shaderStages;
7021 gp_ci.pVertexInputState = NULL;
7022 gp_ci.pInputAssemblyState = &iaCI;
7023 gp_ci.pTessellationState = &tsCI;
7024 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007025 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007026 gp_ci.pMultisampleState = NULL;
7027 gp_ci.pDepthStencilState = NULL;
7028 gp_ci.pColorBlendState = NULL;
7029 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7030 gp_ci.layout = pipeline_layout;
7031 gp_ci.renderPass = renderPass();
7032
7033 VkPipelineCacheCreateInfo pc_ci = {};
7034 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7035 pc_ci.pNext = NULL;
7036 pc_ci.initialSize = 0;
7037 pc_ci.initialData = 0;
7038 pc_ci.maxSize = 0;
7039
7040 VkPipeline pipeline;
7041 VkPipelineCache pipelineCache;
7042
Karl Schultz6addd812016-02-02 17:17:23 -07007043 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7044&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007045 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007046 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7047&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007048
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007049 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007050
Chia-I Wuf7458c52015-10-26 21:10:41 +08007051 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7052 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7053 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7054 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007055}
7056*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007057// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007058TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007059 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007060
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7062 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007063
Tobin Ehlise68360f2015-10-01 11:15:13 -06007064 ASSERT_NO_FATAL_FAILURE(InitState());
7065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007066
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007067 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007068 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7069 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007070
7071 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007072 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7073 ds_pool_ci.maxSets = 1;
7074 ds_pool_ci.poolSizeCount = 1;
7075 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007076
7077 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007078 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007079 ASSERT_VK_SUCCESS(err);
7080
7081 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007082 dsl_binding.binding = 0;
7083 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7084 dsl_binding.descriptorCount = 1;
7085 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007086
7087 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007088 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7089 ds_layout_ci.bindingCount = 1;
7090 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007091
7092 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007093 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007094 ASSERT_VK_SUCCESS(err);
7095
7096 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007097 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007098 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007099 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007100 alloc_info.descriptorPool = ds_pool;
7101 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007102 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007103 ASSERT_VK_SUCCESS(err);
7104
7105 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007106 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7107 pipeline_layout_ci.setLayoutCount = 1;
7108 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007109
7110 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007111 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007112 ASSERT_VK_SUCCESS(err);
7113
7114 VkViewport vp = {}; // Just need dummy vp to point to
7115
7116 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007117 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7118 vp_state_ci.scissorCount = 0;
7119 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7120 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007121
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007122 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7123 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7124 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7125 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7126 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7127 rs_state_ci.depthClampEnable = VK_FALSE;
7128 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7129 rs_state_ci.depthBiasEnable = VK_FALSE;
7130
Cody Northropeb3a6c12015-10-05 14:44:45 -06007131 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007132 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007133
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007134 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7135 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7136 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007137 shaderStages[0] = vs.GetStageCreateInfo();
7138 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007139
7140 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007141 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7142 gp_ci.stageCount = 2;
7143 gp_ci.pStages = shaderStages;
7144 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007145 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007146 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7147 gp_ci.layout = pipeline_layout;
7148 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007149
7150 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007151 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007152
7153 VkPipeline pipeline;
7154 VkPipelineCache pipelineCache;
7155
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007156 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007157 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007158 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007159
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007160 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161
Chia-I Wuf7458c52015-10-26 21:10:41 +08007162 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7163 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7164 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7165 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007166}
Karl Schultz6addd812016-02-02 17:17:23 -07007167// Don't set viewport state in PSO. This is an error b/c we always need this
7168// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007169// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007170TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007171 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007172 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007175
Tobin Ehlise68360f2015-10-01 11:15:13 -06007176 ASSERT_NO_FATAL_FAILURE(InitState());
7177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007178
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007179 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007180 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7181 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007182
7183 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007184 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7185 ds_pool_ci.maxSets = 1;
7186 ds_pool_ci.poolSizeCount = 1;
7187 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007188
7189 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007190 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007191 ASSERT_VK_SUCCESS(err);
7192
7193 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007194 dsl_binding.binding = 0;
7195 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7196 dsl_binding.descriptorCount = 1;
7197 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007198
7199 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007200 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7201 ds_layout_ci.bindingCount = 1;
7202 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007203
7204 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007205 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007206 ASSERT_VK_SUCCESS(err);
7207
7208 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007209 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007210 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007211 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007212 alloc_info.descriptorPool = ds_pool;
7213 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007214 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007215 ASSERT_VK_SUCCESS(err);
7216
7217 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007218 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7219 pipeline_layout_ci.setLayoutCount = 1;
7220 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007221
7222 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007223 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007224 ASSERT_VK_SUCCESS(err);
7225
7226 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7227 // Set scissor as dynamic to avoid second error
7228 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007229 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7230 dyn_state_ci.dynamicStateCount = 1;
7231 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007232
Cody Northropeb3a6c12015-10-05 14:44:45 -06007233 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007234 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007235
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007236 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7237 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7238 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007239 shaderStages[0] = vs.GetStageCreateInfo();
7240 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007241
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007242 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7243 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7244 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7245 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7246 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7247 rs_state_ci.depthClampEnable = VK_FALSE;
7248 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7249 rs_state_ci.depthBiasEnable = VK_FALSE;
7250
Tobin Ehlise68360f2015-10-01 11:15:13 -06007251 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007252 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7253 gp_ci.stageCount = 2;
7254 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007255 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007256 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7257 // should cause validation error
7258 gp_ci.pDynamicState = &dyn_state_ci;
7259 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7260 gp_ci.layout = pipeline_layout;
7261 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007262
7263 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007264 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007265
7266 VkPipeline pipeline;
7267 VkPipelineCache pipelineCache;
7268
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007269 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007270 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007271 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007272
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007273 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007274
Chia-I Wuf7458c52015-10-26 21:10:41 +08007275 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7276 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7277 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7278 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007279}
7280// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007281// Then run second test where dynamic scissor count doesn't match PSO scissor
7282// count
7283TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7284 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007285
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7287 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007288
Tobin Ehlise68360f2015-10-01 11:15:13 -06007289 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007290
7291 if (!m_device->phy().features().multiViewport) {
7292 printf("Device does not support multiple viewports/scissors; skipped.\n");
7293 return;
7294 }
7295
Tobin Ehlise68360f2015-10-01 11:15:13 -06007296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007297
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007298 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007299 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7300 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007301
7302 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007303 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7304 ds_pool_ci.maxSets = 1;
7305 ds_pool_ci.poolSizeCount = 1;
7306 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007307
7308 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007309 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007310 ASSERT_VK_SUCCESS(err);
7311
7312 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007313 dsl_binding.binding = 0;
7314 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7315 dsl_binding.descriptorCount = 1;
7316 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007317
7318 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007319 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7320 ds_layout_ci.bindingCount = 1;
7321 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007322
7323 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007324 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007325 ASSERT_VK_SUCCESS(err);
7326
7327 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007328 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007329 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007330 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007331 alloc_info.descriptorPool = ds_pool;
7332 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007333 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007334 ASSERT_VK_SUCCESS(err);
7335
7336 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007337 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7338 pipeline_layout_ci.setLayoutCount = 1;
7339 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007340
7341 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007342 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007343 ASSERT_VK_SUCCESS(err);
7344
7345 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007346 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7347 vp_state_ci.viewportCount = 1;
7348 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7349 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007350 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007351
7352 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7353 // Set scissor as dynamic to avoid that error
7354 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007355 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7356 dyn_state_ci.dynamicStateCount = 1;
7357 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007358
Cody Northropeb3a6c12015-10-05 14:44:45 -06007359 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007360 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007361
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007362 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7363 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7364 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007365 shaderStages[0] = vs.GetStageCreateInfo();
7366 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007367
Cody Northropf6622dc2015-10-06 10:33:21 -06007368 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7369 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7370 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007371 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007372 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007373 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007374 vi_ci.pVertexAttributeDescriptions = nullptr;
7375
7376 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7377 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7378 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7379
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007380 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007381 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007382 rs_ci.pNext = nullptr;
7383
Mark Youngc89c6312016-03-31 16:03:20 -06007384 VkPipelineColorBlendAttachmentState att = {};
7385 att.blendEnable = VK_FALSE;
7386 att.colorWriteMask = 0xf;
7387
Cody Northropf6622dc2015-10-06 10:33:21 -06007388 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7389 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7390 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007391 cb_ci.attachmentCount = 1;
7392 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007393
Tobin Ehlise68360f2015-10-01 11:15:13 -06007394 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007395 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7396 gp_ci.stageCount = 2;
7397 gp_ci.pStages = shaderStages;
7398 gp_ci.pVertexInputState = &vi_ci;
7399 gp_ci.pInputAssemblyState = &ia_ci;
7400 gp_ci.pViewportState = &vp_state_ci;
7401 gp_ci.pRasterizationState = &rs_ci;
7402 gp_ci.pColorBlendState = &cb_ci;
7403 gp_ci.pDynamicState = &dyn_state_ci;
7404 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7405 gp_ci.layout = pipeline_layout;
7406 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007407
7408 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007409 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007410
7411 VkPipeline pipeline;
7412 VkPipelineCache pipelineCache;
7413
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007414 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007415 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007416 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007417
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007418 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007419
Tobin Ehlisd332f282015-10-02 11:00:56 -06007420 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007421 // First need to successfully create the PSO from above by setting
7422 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007423 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 -07007424
7425 VkViewport vp = {}; // Just need dummy vp to point to
7426 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007427 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007428 ASSERT_VK_SUCCESS(err);
7429 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007430 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007431 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007432 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007433 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007434 Draw(1, 0, 0, 0);
7435
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007436 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007437
7438 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7439 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7440 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7441 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007442 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007443}
7444// Create PSO w/o non-zero scissorCount but no scissor data
7445// Then run second test where dynamic viewportCount doesn't match PSO
7446// viewportCount
7447TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7448 VkResult err;
7449
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007450 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 -07007451
7452 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007453
7454 if (!m_device->phy().features().multiViewport) {
7455 printf("Device does not support multiple viewports/scissors; skipped.\n");
7456 return;
7457 }
7458
Karl Schultz6addd812016-02-02 17:17:23 -07007459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7460
7461 VkDescriptorPoolSize ds_type_count = {};
7462 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7463 ds_type_count.descriptorCount = 1;
7464
7465 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7466 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7467 ds_pool_ci.maxSets = 1;
7468 ds_pool_ci.poolSizeCount = 1;
7469 ds_pool_ci.pPoolSizes = &ds_type_count;
7470
7471 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007472 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007473 ASSERT_VK_SUCCESS(err);
7474
7475 VkDescriptorSetLayoutBinding dsl_binding = {};
7476 dsl_binding.binding = 0;
7477 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7478 dsl_binding.descriptorCount = 1;
7479 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7480
7481 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7482 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7483 ds_layout_ci.bindingCount = 1;
7484 ds_layout_ci.pBindings = &dsl_binding;
7485
7486 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007487 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007488 ASSERT_VK_SUCCESS(err);
7489
7490 VkDescriptorSet descriptorSet;
7491 VkDescriptorSetAllocateInfo alloc_info = {};
7492 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7493 alloc_info.descriptorSetCount = 1;
7494 alloc_info.descriptorPool = ds_pool;
7495 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007496 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007497 ASSERT_VK_SUCCESS(err);
7498
7499 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7500 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7501 pipeline_layout_ci.setLayoutCount = 1;
7502 pipeline_layout_ci.pSetLayouts = &ds_layout;
7503
7504 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007505 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007506 ASSERT_VK_SUCCESS(err);
7507
7508 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7509 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7510 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007511 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007512 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007513 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007514
7515 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7516 // Set scissor as dynamic to avoid that error
7517 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7518 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7519 dyn_state_ci.dynamicStateCount = 1;
7520 dyn_state_ci.pDynamicStates = &vp_state;
7521
7522 VkPipelineShaderStageCreateInfo shaderStages[2];
7523 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7524
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007525 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7526 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7527 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007528 shaderStages[0] = vs.GetStageCreateInfo();
7529 shaderStages[1] = fs.GetStageCreateInfo();
7530
7531 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7532 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7533 vi_ci.pNext = nullptr;
7534 vi_ci.vertexBindingDescriptionCount = 0;
7535 vi_ci.pVertexBindingDescriptions = nullptr;
7536 vi_ci.vertexAttributeDescriptionCount = 0;
7537 vi_ci.pVertexAttributeDescriptions = nullptr;
7538
7539 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7540 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7541 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7542
7543 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7544 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7545 rs_ci.pNext = nullptr;
7546
Mark Youngc89c6312016-03-31 16:03:20 -06007547 VkPipelineColorBlendAttachmentState att = {};
7548 att.blendEnable = VK_FALSE;
7549 att.colorWriteMask = 0xf;
7550
Karl Schultz6addd812016-02-02 17:17:23 -07007551 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7552 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7553 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007554 cb_ci.attachmentCount = 1;
7555 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007556
7557 VkGraphicsPipelineCreateInfo gp_ci = {};
7558 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7559 gp_ci.stageCount = 2;
7560 gp_ci.pStages = shaderStages;
7561 gp_ci.pVertexInputState = &vi_ci;
7562 gp_ci.pInputAssemblyState = &ia_ci;
7563 gp_ci.pViewportState = &vp_state_ci;
7564 gp_ci.pRasterizationState = &rs_ci;
7565 gp_ci.pColorBlendState = &cb_ci;
7566 gp_ci.pDynamicState = &dyn_state_ci;
7567 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7568 gp_ci.layout = pipeline_layout;
7569 gp_ci.renderPass = renderPass();
7570
7571 VkPipelineCacheCreateInfo pc_ci = {};
7572 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7573
7574 VkPipeline pipeline;
7575 VkPipelineCache pipelineCache;
7576
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007577 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007578 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007579 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007580
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007581 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007582
7583 // Now hit second fail case where we set scissor w/ different count than PSO
7584 // First need to successfully create the PSO from above by setting
7585 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007586 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 -06007587
Tobin Ehlisd332f282015-10-02 11:00:56 -06007588 VkRect2D sc = {}; // Just need dummy vp to point to
7589 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007590 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007591 ASSERT_VK_SUCCESS(err);
7592 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007593 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007594 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007595 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007596 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007597 Draw(1, 0, 0, 0);
7598
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007599 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007600
Chia-I Wuf7458c52015-10-26 21:10:41 +08007601 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7602 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7603 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7604 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007605 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007606}
7607
Mark Young7394fdd2016-03-31 14:56:43 -06007608TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7609 VkResult err;
7610
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007612
7613 ASSERT_NO_FATAL_FAILURE(InitState());
7614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7615
7616 VkDescriptorPoolSize ds_type_count = {};
7617 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7618 ds_type_count.descriptorCount = 1;
7619
7620 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7621 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7622 ds_pool_ci.maxSets = 1;
7623 ds_pool_ci.poolSizeCount = 1;
7624 ds_pool_ci.pPoolSizes = &ds_type_count;
7625
7626 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007627 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007628 ASSERT_VK_SUCCESS(err);
7629
7630 VkDescriptorSetLayoutBinding dsl_binding = {};
7631 dsl_binding.binding = 0;
7632 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7633 dsl_binding.descriptorCount = 1;
7634 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7635
7636 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7637 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7638 ds_layout_ci.bindingCount = 1;
7639 ds_layout_ci.pBindings = &dsl_binding;
7640
7641 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007642 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007643 ASSERT_VK_SUCCESS(err);
7644
7645 VkDescriptorSet descriptorSet;
7646 VkDescriptorSetAllocateInfo alloc_info = {};
7647 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7648 alloc_info.descriptorSetCount = 1;
7649 alloc_info.descriptorPool = ds_pool;
7650 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007651 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007652 ASSERT_VK_SUCCESS(err);
7653
7654 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7655 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7656 pipeline_layout_ci.setLayoutCount = 1;
7657 pipeline_layout_ci.pSetLayouts = &ds_layout;
7658
7659 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007660 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007661 ASSERT_VK_SUCCESS(err);
7662
7663 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7664 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7665 vp_state_ci.scissorCount = 1;
7666 vp_state_ci.pScissors = NULL;
7667 vp_state_ci.viewportCount = 1;
7668 vp_state_ci.pViewports = NULL;
7669
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007670 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007671 // Set scissor as dynamic to avoid that error
7672 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7673 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7674 dyn_state_ci.dynamicStateCount = 2;
7675 dyn_state_ci.pDynamicStates = dynamic_states;
7676
7677 VkPipelineShaderStageCreateInfo shaderStages[2];
7678 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007680 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7681 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007682 this); // TODO - We shouldn't need a fragment shader
7683 // but add it to be able to run on more devices
7684 shaderStages[0] = vs.GetStageCreateInfo();
7685 shaderStages[1] = fs.GetStageCreateInfo();
7686
7687 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7688 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7689 vi_ci.pNext = nullptr;
7690 vi_ci.vertexBindingDescriptionCount = 0;
7691 vi_ci.pVertexBindingDescriptions = nullptr;
7692 vi_ci.vertexAttributeDescriptionCount = 0;
7693 vi_ci.pVertexAttributeDescriptions = nullptr;
7694
7695 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7696 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7697 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7698
7699 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7700 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7701 rs_ci.pNext = nullptr;
7702
Mark Young47107952016-05-02 15:59:55 -06007703 // Check too low (line width of -1.0f).
7704 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007705
7706 VkPipelineColorBlendAttachmentState att = {};
7707 att.blendEnable = VK_FALSE;
7708 att.colorWriteMask = 0xf;
7709
7710 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7711 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7712 cb_ci.pNext = nullptr;
7713 cb_ci.attachmentCount = 1;
7714 cb_ci.pAttachments = &att;
7715
7716 VkGraphicsPipelineCreateInfo gp_ci = {};
7717 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7718 gp_ci.stageCount = 2;
7719 gp_ci.pStages = shaderStages;
7720 gp_ci.pVertexInputState = &vi_ci;
7721 gp_ci.pInputAssemblyState = &ia_ci;
7722 gp_ci.pViewportState = &vp_state_ci;
7723 gp_ci.pRasterizationState = &rs_ci;
7724 gp_ci.pColorBlendState = &cb_ci;
7725 gp_ci.pDynamicState = &dyn_state_ci;
7726 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7727 gp_ci.layout = pipeline_layout;
7728 gp_ci.renderPass = renderPass();
7729
7730 VkPipelineCacheCreateInfo pc_ci = {};
7731 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7732
7733 VkPipeline pipeline;
7734 VkPipelineCache pipelineCache;
7735
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007737 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007738 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007739
7740 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007741 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007742
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007744
7745 // Check too high (line width of 65536.0f).
7746 rs_ci.lineWidth = 65536.0f;
7747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007748 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007749 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007750 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007751
7752 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007753 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007754
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007756
7757 dyn_state_ci.dynamicStateCount = 3;
7758
7759 rs_ci.lineWidth = 1.0f;
7760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007761 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007762 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007763 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007764 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007765 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007766
7767 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007768 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007769 m_errorMonitor->VerifyFound();
7770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007772
7773 // Check too high with dynamic setting.
7774 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7775 m_errorMonitor->VerifyFound();
7776 EndCommandBuffer();
7777
7778 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7779 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7780 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7781 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007782 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007783}
7784
Karl Schultz6addd812016-02-02 17:17:23 -07007785TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007786 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7788 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007789
7790 ASSERT_NO_FATAL_FAILURE(InitState());
7791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007792
Tony Barbourfe3351b2015-07-28 10:17:20 -06007793 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007794 // Don't care about RenderPass handle b/c error should be flagged before
7795 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007796 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007797
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007798 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007799}
7800
Karl Schultz6addd812016-02-02 17:17:23 -07007801TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007802 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7804 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007805
7806 ASSERT_NO_FATAL_FAILURE(InitState());
7807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007808
Tony Barbourfe3351b2015-07-28 10:17:20 -06007809 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007810 // Just create a dummy Renderpass that's non-NULL so we can get to the
7811 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007812 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007813
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007814 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007815}
7816
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007817TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7818 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7819 "the number of renderPass attachments that use loadOp"
7820 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7821
7822 ASSERT_NO_FATAL_FAILURE(InitState());
7823 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7824
7825 // Create a renderPass with a single attachment that uses loadOp CLEAR
7826 VkAttachmentReference attach = {};
7827 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7828 VkSubpassDescription subpass = {};
7829 subpass.inputAttachmentCount = 1;
7830 subpass.pInputAttachments = &attach;
7831 VkRenderPassCreateInfo rpci = {};
7832 rpci.subpassCount = 1;
7833 rpci.pSubpasses = &subpass;
7834 rpci.attachmentCount = 1;
7835 VkAttachmentDescription attach_desc = {};
7836 attach_desc.format = VK_FORMAT_UNDEFINED;
7837 // Set loadOp to CLEAR
7838 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7839 rpci.pAttachments = &attach_desc;
7840 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7841 VkRenderPass rp;
7842 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7843
7844 VkCommandBufferInheritanceInfo hinfo = {};
7845 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7846 hinfo.renderPass = VK_NULL_HANDLE;
7847 hinfo.subpass = 0;
7848 hinfo.framebuffer = VK_NULL_HANDLE;
7849 hinfo.occlusionQueryEnable = VK_FALSE;
7850 hinfo.queryFlags = 0;
7851 hinfo.pipelineStatistics = 0;
7852 VkCommandBufferBeginInfo info = {};
7853 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7854 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7855 info.pInheritanceInfo = &hinfo;
7856
7857 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7858 VkRenderPassBeginInfo rp_begin = {};
7859 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7860 rp_begin.pNext = NULL;
7861 rp_begin.renderPass = renderPass();
7862 rp_begin.framebuffer = framebuffer();
7863 rp_begin.clearValueCount = 0; // Should be 1
7864
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7866 "there must be at least 1 entries in "
7867 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007869 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007870
7871 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007872
7873 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007874}
7875
Cody Northrop3bb4d962016-05-09 16:15:57 -06007876TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7877
7878 TEST_DESCRIPTION("End a command buffer with an active render pass");
7879
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7881 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007882
7883 ASSERT_NO_FATAL_FAILURE(InitState());
7884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7885
7886 // The framework's BeginCommandBuffer calls CreateRenderPass
7887 BeginCommandBuffer();
7888
7889 // Call directly into vkEndCommandBuffer instead of the
7890 // the framework's EndCommandBuffer, which inserts a
7891 // vkEndRenderPass
7892 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7893
7894 m_errorMonitor->VerifyFound();
7895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007896 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7897 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007898}
7899
Karl Schultz6addd812016-02-02 17:17:23 -07007900TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007901 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7903 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007904
7905 ASSERT_NO_FATAL_FAILURE(InitState());
7906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007907
7908 // Renderpass is started here
7909 BeginCommandBuffer();
7910
7911 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007912 vk_testing::Buffer dstBuffer;
7913 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007914
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007915 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007916
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007917 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007918}
7919
Karl Schultz6addd812016-02-02 17:17:23 -07007920TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007921 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7923 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007924
7925 ASSERT_NO_FATAL_FAILURE(InitState());
7926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007927
7928 // Renderpass is started here
7929 BeginCommandBuffer();
7930
7931 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007932 vk_testing::Buffer dstBuffer;
7933 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007934
Karl Schultz6addd812016-02-02 17:17:23 -07007935 VkDeviceSize dstOffset = 0;
7936 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007937 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007939 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007940
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007941 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007942}
7943
Karl Schultz6addd812016-02-02 17:17:23 -07007944TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007945 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7947 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007948
7949 ASSERT_NO_FATAL_FAILURE(InitState());
7950 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007951
7952 // Renderpass is started here
7953 BeginCommandBuffer();
7954
Michael Lentine0a369f62016-02-03 16:51:46 -06007955 VkClearColorValue clear_color;
7956 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007957 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7958 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7959 const int32_t tex_width = 32;
7960 const int32_t tex_height = 32;
7961 VkImageCreateInfo image_create_info = {};
7962 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7963 image_create_info.pNext = NULL;
7964 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7965 image_create_info.format = tex_format;
7966 image_create_info.extent.width = tex_width;
7967 image_create_info.extent.height = tex_height;
7968 image_create_info.extent.depth = 1;
7969 image_create_info.mipLevels = 1;
7970 image_create_info.arrayLayers = 1;
7971 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7972 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7973 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007974
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007975 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007976 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007977
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007978 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007980 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007981
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007982 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007983}
7984
Karl Schultz6addd812016-02-02 17:17:23 -07007985TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007986 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7988 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007989
7990 ASSERT_NO_FATAL_FAILURE(InitState());
7991 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007992
7993 // Renderpass is started here
7994 BeginCommandBuffer();
7995
7996 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007997 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007998 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7999 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8000 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8001 image_create_info.extent.width = 64;
8002 image_create_info.extent.height = 64;
8003 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8004 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008005
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008006 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008007 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008008
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008009 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008011 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8012 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008013
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008014 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008015}
8016
Karl Schultz6addd812016-02-02 17:17:23 -07008017TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008018 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008019 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8022 "must be issued inside an active "
8023 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008024
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008025 ASSERT_NO_FATAL_FAILURE(InitState());
8026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008027
8028 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008029 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008030 ASSERT_VK_SUCCESS(err);
8031
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008032 VkClearAttachment color_attachment;
8033 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8034 color_attachment.clearValue.color.float32[0] = 0;
8035 color_attachment.clearValue.color.float32[1] = 0;
8036 color_attachment.clearValue.color.float32[2] = 0;
8037 color_attachment.clearValue.color.float32[3] = 0;
8038 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008039 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008040 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008041
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008042 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008043}
8044
Chris Forbes3b97e932016-09-07 11:29:24 +12008045TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8046 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8047 "called too many times in a renderpass instance");
8048
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8050 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008051
8052 ASSERT_NO_FATAL_FAILURE(InitState());
8053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8054
8055 BeginCommandBuffer();
8056
8057 // error here.
8058 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8059 m_errorMonitor->VerifyFound();
8060
8061 EndCommandBuffer();
8062}
8063
Chris Forbes6d624702016-09-07 13:57:05 +12008064TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8065 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8066 "called before the final subpass has been reached");
8067
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8069 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008070
8071 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008072 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8073 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008074
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008075 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008076
8077 VkRenderPass rp;
8078 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8079 ASSERT_VK_SUCCESS(err);
8080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008081 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008082
8083 VkFramebuffer fb;
8084 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8085 ASSERT_VK_SUCCESS(err);
8086
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008087 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008088
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008089 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 +12008090
8091 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8092
8093 // Error here.
8094 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8095 m_errorMonitor->VerifyFound();
8096
8097 // Clean up.
8098 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8099 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8100}
8101
Karl Schultz9e66a292016-04-21 15:57:51 -06008102TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8103 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8105 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008106
8107 ASSERT_NO_FATAL_FAILURE(InitState());
8108 BeginCommandBuffer();
8109
8110 VkBufferMemoryBarrier buf_barrier = {};
8111 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8112 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8113 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8114 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8115 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8116 buf_barrier.buffer = VK_NULL_HANDLE;
8117 buf_barrier.offset = 0;
8118 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008119 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8120 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008121
8122 m_errorMonitor->VerifyFound();
8123}
8124
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008125TEST_F(VkLayerTest, InvalidBarriers) {
8126 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8127
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008129
8130 ASSERT_NO_FATAL_FAILURE(InitState());
8131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8132
8133 VkMemoryBarrier mem_barrier = {};
8134 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8135 mem_barrier.pNext = NULL;
8136 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8137 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8138 BeginCommandBuffer();
8139 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008140 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008141 &mem_barrier, 0, nullptr, 0, nullptr);
8142 m_errorMonitor->VerifyFound();
8143
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008145 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008146 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 -06008147 ASSERT_TRUE(image.initialized());
8148 VkImageMemoryBarrier img_barrier = {};
8149 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8150 img_barrier.pNext = NULL;
8151 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8152 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8153 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8154 // New layout can't be UNDEFINED
8155 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8156 img_barrier.image = image.handle();
8157 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8158 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8159 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8160 img_barrier.subresourceRange.baseArrayLayer = 0;
8161 img_barrier.subresourceRange.baseMipLevel = 0;
8162 img_barrier.subresourceRange.layerCount = 1;
8163 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008164 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8165 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008166 m_errorMonitor->VerifyFound();
8167 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8170 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008171 // baseArrayLayer + layerCount must be <= image's arrayLayers
8172 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8174 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008175 m_errorMonitor->VerifyFound();
8176 img_barrier.subresourceRange.baseArrayLayer = 0;
8177
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008179 // baseMipLevel + levelCount must be <= image's mipLevels
8180 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008181 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8182 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008183 m_errorMonitor->VerifyFound();
8184 img_barrier.subresourceRange.baseMipLevel = 0;
8185
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008186 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 -06008187 vk_testing::Buffer buffer;
8188 buffer.init(*m_device, 256);
8189 VkBufferMemoryBarrier buf_barrier = {};
8190 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8191 buf_barrier.pNext = NULL;
8192 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8193 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8194 buf_barrier.buffer = buffer.handle();
8195 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8196 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8197 buf_barrier.offset = 0;
8198 buf_barrier.size = VK_WHOLE_SIZE;
8199 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008200 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8201 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008202 m_errorMonitor->VerifyFound();
8203 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8204
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008206 buf_barrier.offset = 257;
8207 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008208 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8209 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008210 m_errorMonitor->VerifyFound();
8211 buf_barrier.offset = 0;
8212
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008214 buf_barrier.size = 257;
8215 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008216 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8217 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008218 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008219
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008220 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008221 m_errorMonitor->SetDesiredFailureMsg(
8222 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8223 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8224 m_errorMonitor->SetDesiredFailureMsg(
8225 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8226 "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 -06008227 VkDepthStencilObj ds_image(m_device);
8228 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8229 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008230 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8231 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008232 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008233 // Use of COLOR aspect on DS image is error
8234 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008235 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8236 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008237 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008238 // Now test depth-only
8239 VkFormatProperties format_props;
8240
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008241 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8242 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8244 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8246 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008247 VkDepthStencilObj d_image(m_device);
8248 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8249 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008250 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008251 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008252 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008253 // Use of COLOR aspect on depth image is error
8254 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008255 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8256 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008257 m_errorMonitor->VerifyFound();
8258 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008259 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8260 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008261 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8263 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008264 VkDepthStencilObj s_image(m_device);
8265 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8266 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008267 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008268 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008269 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008270 // Use of COLOR aspect on depth image is error
8271 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008272 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8273 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008274 m_errorMonitor->VerifyFound();
8275 }
8276 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8278 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8280 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008281 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008282 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 -06008283 ASSERT_TRUE(c_image.initialized());
8284 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8285 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8286 img_barrier.image = c_image.handle();
8287 // Set aspect to depth (non-color)
8288 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008289 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8290 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008291 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008292}
8293
Tony Barbour18ba25c2016-09-29 13:42:40 -06008294TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8295 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8296
8297 m_errorMonitor->SetDesiredFailureMsg(
8298 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8299 "must have required access bit");
8300 ASSERT_NO_FATAL_FAILURE(InitState());
8301 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008302 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 -06008303 ASSERT_TRUE(image.initialized());
8304
8305 VkImageMemoryBarrier barrier = {};
8306 VkImageSubresourceRange range;
8307 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8308 barrier.srcAccessMask = 0;
8309 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8310 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8311 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8312 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8313 barrier.image = image.handle();
8314 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8315 range.baseMipLevel = 0;
8316 range.levelCount = 1;
8317 range.baseArrayLayer = 0;
8318 range.layerCount = 1;
8319 barrier.subresourceRange = range;
8320 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8321 cmdbuf.BeginCommandBuffer();
8322 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8323 &barrier);
8324 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8325 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8326 barrier.srcAccessMask = 0;
8327 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8328 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8329 &barrier);
8330
8331 m_errorMonitor->VerifyFound();
8332}
8333
Karl Schultz6addd812016-02-02 17:17:23 -07008334TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008335 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008336 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008337
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008339
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008340 ASSERT_NO_FATAL_FAILURE(InitState());
8341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008342 uint32_t qfi = 0;
8343 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008344 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8345 buffCI.size = 1024;
8346 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8347 buffCI.queueFamilyIndexCount = 1;
8348 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008349
8350 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008351 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008352 ASSERT_VK_SUCCESS(err);
8353
8354 BeginCommandBuffer();
8355 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008356 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8357 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008358 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008359 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008361 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008362
Chia-I Wuf7458c52015-10-26 21:10:41 +08008363 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008364}
8365
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008366TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8367 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8369 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8370 "of the indices specified when the device was created, via the "
8371 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008372
8373 ASSERT_NO_FATAL_FAILURE(InitState());
8374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8375 VkBufferCreateInfo buffCI = {};
8376 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8377 buffCI.size = 1024;
8378 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8379 buffCI.queueFamilyIndexCount = 1;
8380 // Introduce failure by specifying invalid queue_family_index
8381 uint32_t qfi = 777;
8382 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008383 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008384
8385 VkBuffer ib;
8386 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8387
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008388 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008389 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008390}
8391
Karl Schultz6addd812016-02-02 17:17:23 -07008392TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008393TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008394 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008395
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008396 ASSERT_NO_FATAL_FAILURE(InitState());
8397 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008398
Chris Forbesf29a84f2016-10-06 18:39:28 +13008399 // An empty primary command buffer
8400 VkCommandBufferObj cb(m_device, m_commandPool);
8401 cb.BeginCommandBuffer();
8402 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008403
Chris Forbesf29a84f2016-10-06 18:39:28 +13008404 m_commandBuffer->BeginCommandBuffer();
8405 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8406 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008407
Chris Forbesf29a84f2016-10-06 18:39:28 +13008408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8409 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008410 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008411}
8412
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008413TEST_F(VkLayerTest, DSUsageBitsErrors) {
8414 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8415 "that do not have correct usage bits sets.");
8416 VkResult err;
8417
8418 ASSERT_NO_FATAL_FAILURE(InitState());
8419 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8420 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8421 ds_type_count[i].type = VkDescriptorType(i);
8422 ds_type_count[i].descriptorCount = 1;
8423 }
8424 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8425 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8426 ds_pool_ci.pNext = NULL;
8427 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8428 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8429 ds_pool_ci.pPoolSizes = ds_type_count;
8430
8431 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008432 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008433 ASSERT_VK_SUCCESS(err);
8434
8435 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008436 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008437 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8438 dsl_binding[i].binding = 0;
8439 dsl_binding[i].descriptorType = VkDescriptorType(i);
8440 dsl_binding[i].descriptorCount = 1;
8441 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8442 dsl_binding[i].pImmutableSamplers = NULL;
8443 }
8444
8445 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8446 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8447 ds_layout_ci.pNext = NULL;
8448 ds_layout_ci.bindingCount = 1;
8449 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8450 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8451 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008452 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008453 ASSERT_VK_SUCCESS(err);
8454 }
8455 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8456 VkDescriptorSetAllocateInfo alloc_info = {};
8457 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8458 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8459 alloc_info.descriptorPool = ds_pool;
8460 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008461 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008462 ASSERT_VK_SUCCESS(err);
8463
8464 // Create a buffer & bufferView to be used for invalid updates
8465 VkBufferCreateInfo buff_ci = {};
8466 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8467 // This usage is not valid for any descriptor type
8468 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8469 buff_ci.size = 256;
8470 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8471 VkBuffer buffer;
8472 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8473 ASSERT_VK_SUCCESS(err);
8474
8475 VkBufferViewCreateInfo buff_view_ci = {};
8476 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8477 buff_view_ci.buffer = buffer;
8478 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8479 buff_view_ci.range = VK_WHOLE_SIZE;
8480 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008482 ASSERT_VK_SUCCESS(err);
8483
8484 // Create an image to be used for invalid updates
8485 VkImageCreateInfo image_ci = {};
8486 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8487 image_ci.imageType = VK_IMAGE_TYPE_2D;
8488 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8489 image_ci.extent.width = 64;
8490 image_ci.extent.height = 64;
8491 image_ci.extent.depth = 1;
8492 image_ci.mipLevels = 1;
8493 image_ci.arrayLayers = 1;
8494 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8495 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8496 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8497 // This usage is not valid for any descriptor type
8498 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8499 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8500 VkImage image;
8501 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8502 ASSERT_VK_SUCCESS(err);
8503 // Bind memory to image
8504 VkMemoryRequirements mem_reqs;
8505 VkDeviceMemory image_mem;
8506 bool pass;
8507 VkMemoryAllocateInfo mem_alloc = {};
8508 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8509 mem_alloc.pNext = NULL;
8510 mem_alloc.allocationSize = 0;
8511 mem_alloc.memoryTypeIndex = 0;
8512 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8513 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008514 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008515 ASSERT_TRUE(pass);
8516 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8517 ASSERT_VK_SUCCESS(err);
8518 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8519 ASSERT_VK_SUCCESS(err);
8520 // Now create view for image
8521 VkImageViewCreateInfo image_view_ci = {};
8522 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8523 image_view_ci.image = image;
8524 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8525 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8526 image_view_ci.subresourceRange.layerCount = 1;
8527 image_view_ci.subresourceRange.baseArrayLayer = 0;
8528 image_view_ci.subresourceRange.levelCount = 1;
8529 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8530 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008531 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008532 ASSERT_VK_SUCCESS(err);
8533
8534 VkDescriptorBufferInfo buff_info = {};
8535 buff_info.buffer = buffer;
8536 VkDescriptorImageInfo img_info = {};
8537 img_info.imageView = image_view;
8538 VkWriteDescriptorSet descriptor_write = {};
8539 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8540 descriptor_write.dstBinding = 0;
8541 descriptor_write.descriptorCount = 1;
8542 descriptor_write.pTexelBufferView = &buff_view;
8543 descriptor_write.pBufferInfo = &buff_info;
8544 descriptor_write.pImageInfo = &img_info;
8545
8546 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008547 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8548 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8549 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8550 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8551 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8552 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8553 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8554 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8555 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8556 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8557 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008558 // Start loop at 1 as SAMPLER desc type has no usage bit error
8559 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8560 descriptor_write.descriptorType = VkDescriptorType(i);
8561 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008563
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008564 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008565
8566 m_errorMonitor->VerifyFound();
8567 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8568 }
8569 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8570 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008571 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008572 vkDestroyImageView(m_device->device(), image_view, NULL);
8573 vkDestroyBuffer(m_device->device(), buffer, NULL);
8574 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008575 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008576 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8577}
8578
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008579TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008580 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8581 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8582 "1. offset value greater than buffer size\n"
8583 "2. range value of 0\n"
8584 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008585 VkResult err;
8586
8587 ASSERT_NO_FATAL_FAILURE(InitState());
8588 VkDescriptorPoolSize ds_type_count = {};
8589 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8590 ds_type_count.descriptorCount = 1;
8591
8592 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8593 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8594 ds_pool_ci.pNext = NULL;
8595 ds_pool_ci.maxSets = 1;
8596 ds_pool_ci.poolSizeCount = 1;
8597 ds_pool_ci.pPoolSizes = &ds_type_count;
8598
8599 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008600 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008601 ASSERT_VK_SUCCESS(err);
8602
8603 // Create layout with single uniform buffer descriptor
8604 VkDescriptorSetLayoutBinding dsl_binding = {};
8605 dsl_binding.binding = 0;
8606 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8607 dsl_binding.descriptorCount = 1;
8608 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8609 dsl_binding.pImmutableSamplers = NULL;
8610
8611 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8612 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8613 ds_layout_ci.pNext = NULL;
8614 ds_layout_ci.bindingCount = 1;
8615 ds_layout_ci.pBindings = &dsl_binding;
8616 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008617 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008618 ASSERT_VK_SUCCESS(err);
8619
8620 VkDescriptorSet descriptor_set = {};
8621 VkDescriptorSetAllocateInfo alloc_info = {};
8622 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8623 alloc_info.descriptorSetCount = 1;
8624 alloc_info.descriptorPool = ds_pool;
8625 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008626 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008627 ASSERT_VK_SUCCESS(err);
8628
8629 // Create a buffer to be used for invalid updates
8630 VkBufferCreateInfo buff_ci = {};
8631 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8632 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8633 buff_ci.size = 256;
8634 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8635 VkBuffer buffer;
8636 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8637 ASSERT_VK_SUCCESS(err);
8638 // Have to bind memory to buffer before descriptor update
8639 VkMemoryAllocateInfo mem_alloc = {};
8640 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8641 mem_alloc.pNext = NULL;
8642 mem_alloc.allocationSize = 256;
8643 mem_alloc.memoryTypeIndex = 0;
8644
8645 VkMemoryRequirements mem_reqs;
8646 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008648 if (!pass) {
8649 vkDestroyBuffer(m_device->device(), buffer, NULL);
8650 return;
8651 }
8652
8653 VkDeviceMemory mem;
8654 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8655 ASSERT_VK_SUCCESS(err);
8656 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8657 ASSERT_VK_SUCCESS(err);
8658
8659 VkDescriptorBufferInfo buff_info = {};
8660 buff_info.buffer = buffer;
8661 // First make offset 1 larger than buffer size
8662 buff_info.offset = 257;
8663 buff_info.range = VK_WHOLE_SIZE;
8664 VkWriteDescriptorSet descriptor_write = {};
8665 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8666 descriptor_write.dstBinding = 0;
8667 descriptor_write.descriptorCount = 1;
8668 descriptor_write.pTexelBufferView = nullptr;
8669 descriptor_write.pBufferInfo = &buff_info;
8670 descriptor_write.pImageInfo = nullptr;
8671
8672 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8673 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008675
8676 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8677
8678 m_errorMonitor->VerifyFound();
8679 // Now cause error due to range of 0
8680 buff_info.offset = 0;
8681 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8683 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008684
8685 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8686
8687 m_errorMonitor->VerifyFound();
8688 // Now cause error due to range exceeding buffer size - offset
8689 buff_info.offset = 128;
8690 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008691 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 -06008692
8693 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8694
8695 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008696 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008697 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8698 vkDestroyBuffer(m_device->device(), buffer, NULL);
8699 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8700 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8701}
8702
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008703TEST_F(VkLayerTest, DSAspectBitsErrors) {
8704 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8705 // are set, but could expand this test to hit more cases.
8706 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8707 "that do not have correct aspect bits sets.");
8708 VkResult err;
8709
8710 ASSERT_NO_FATAL_FAILURE(InitState());
8711 VkDescriptorPoolSize ds_type_count = {};
8712 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8713 ds_type_count.descriptorCount = 1;
8714
8715 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8716 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8717 ds_pool_ci.pNext = NULL;
8718 ds_pool_ci.maxSets = 5;
8719 ds_pool_ci.poolSizeCount = 1;
8720 ds_pool_ci.pPoolSizes = &ds_type_count;
8721
8722 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008723 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008724 ASSERT_VK_SUCCESS(err);
8725
8726 VkDescriptorSetLayoutBinding dsl_binding = {};
8727 dsl_binding.binding = 0;
8728 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8729 dsl_binding.descriptorCount = 1;
8730 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8731 dsl_binding.pImmutableSamplers = NULL;
8732
8733 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8734 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8735 ds_layout_ci.pNext = NULL;
8736 ds_layout_ci.bindingCount = 1;
8737 ds_layout_ci.pBindings = &dsl_binding;
8738 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008739 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008740 ASSERT_VK_SUCCESS(err);
8741
8742 VkDescriptorSet descriptor_set = {};
8743 VkDescriptorSetAllocateInfo alloc_info = {};
8744 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8745 alloc_info.descriptorSetCount = 1;
8746 alloc_info.descriptorPool = ds_pool;
8747 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008748 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008749 ASSERT_VK_SUCCESS(err);
8750
8751 // Create an image to be used for invalid updates
8752 VkImageCreateInfo image_ci = {};
8753 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8754 image_ci.imageType = VK_IMAGE_TYPE_2D;
8755 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8756 image_ci.extent.width = 64;
8757 image_ci.extent.height = 64;
8758 image_ci.extent.depth = 1;
8759 image_ci.mipLevels = 1;
8760 image_ci.arrayLayers = 1;
8761 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8762 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8763 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8764 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8765 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8766 VkImage image;
8767 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8768 ASSERT_VK_SUCCESS(err);
8769 // Bind memory to image
8770 VkMemoryRequirements mem_reqs;
8771 VkDeviceMemory image_mem;
8772 bool pass;
8773 VkMemoryAllocateInfo mem_alloc = {};
8774 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8775 mem_alloc.pNext = NULL;
8776 mem_alloc.allocationSize = 0;
8777 mem_alloc.memoryTypeIndex = 0;
8778 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8779 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008780 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008781 ASSERT_TRUE(pass);
8782 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8783 ASSERT_VK_SUCCESS(err);
8784 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8785 ASSERT_VK_SUCCESS(err);
8786 // Now create view for image
8787 VkImageViewCreateInfo image_view_ci = {};
8788 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8789 image_view_ci.image = image;
8790 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8791 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8792 image_view_ci.subresourceRange.layerCount = 1;
8793 image_view_ci.subresourceRange.baseArrayLayer = 0;
8794 image_view_ci.subresourceRange.levelCount = 1;
8795 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008796 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008797
8798 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008799 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008800 ASSERT_VK_SUCCESS(err);
8801
8802 VkDescriptorImageInfo img_info = {};
8803 img_info.imageView = image_view;
8804 VkWriteDescriptorSet descriptor_write = {};
8805 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8806 descriptor_write.dstBinding = 0;
8807 descriptor_write.descriptorCount = 1;
8808 descriptor_write.pTexelBufferView = NULL;
8809 descriptor_write.pBufferInfo = NULL;
8810 descriptor_write.pImageInfo = &img_info;
8811 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8812 descriptor_write.dstSet = descriptor_set;
8813 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8814 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008816
8817 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8818
8819 m_errorMonitor->VerifyFound();
8820 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8821 vkDestroyImage(m_device->device(), image, NULL);
8822 vkFreeMemory(m_device->device(), image_mem, NULL);
8823 vkDestroyImageView(m_device->device(), image_view, NULL);
8824 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8825 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8826}
8827
Karl Schultz6addd812016-02-02 17:17:23 -07008828TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008829 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008830 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008831
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8833 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8834 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008835
Tobin Ehlis3b780662015-05-28 12:11:26 -06008836 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008837 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008838 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008839 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8840 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008841
8842 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008843 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8844 ds_pool_ci.pNext = NULL;
8845 ds_pool_ci.maxSets = 1;
8846 ds_pool_ci.poolSizeCount = 1;
8847 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008848
Tobin Ehlis3b780662015-05-28 12:11:26 -06008849 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008850 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008851 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008852 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008853 dsl_binding.binding = 0;
8854 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8855 dsl_binding.descriptorCount = 1;
8856 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8857 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008858
Tony Barboureb254902015-07-15 12:50:33 -06008859 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008860 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8861 ds_layout_ci.pNext = NULL;
8862 ds_layout_ci.bindingCount = 1;
8863 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008864
Tobin Ehlis3b780662015-05-28 12:11:26 -06008865 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008866 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008867 ASSERT_VK_SUCCESS(err);
8868
8869 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008870 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008871 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008872 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008873 alloc_info.descriptorPool = ds_pool;
8874 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008875 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008876 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008877
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008878 VkSamplerCreateInfo sampler_ci = {};
8879 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8880 sampler_ci.pNext = NULL;
8881 sampler_ci.magFilter = VK_FILTER_NEAREST;
8882 sampler_ci.minFilter = VK_FILTER_NEAREST;
8883 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8884 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8885 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8886 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8887 sampler_ci.mipLodBias = 1.0;
8888 sampler_ci.anisotropyEnable = VK_FALSE;
8889 sampler_ci.maxAnisotropy = 1;
8890 sampler_ci.compareEnable = VK_FALSE;
8891 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8892 sampler_ci.minLod = 1.0;
8893 sampler_ci.maxLod = 1.0;
8894 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8895 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8896 VkSampler sampler;
8897 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8898 ASSERT_VK_SUCCESS(err);
8899
8900 VkDescriptorImageInfo info = {};
8901 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008902
8903 VkWriteDescriptorSet descriptor_write;
8904 memset(&descriptor_write, 0, sizeof(descriptor_write));
8905 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008906 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008907 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008908 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008909 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008910 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008911
8912 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8913
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008914 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008915
Chia-I Wuf7458c52015-10-26 21:10:41 +08008916 vkDestroySampler(m_device->device(), sampler, NULL);
8917 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8918 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008919}
8920
Karl Schultz6addd812016-02-02 17:17:23 -07008921TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008922 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008923 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008924
Tobin Ehlisf922ef82016-11-30 10:19:14 -07008925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008926
Tobin Ehlis3b780662015-05-28 12:11:26 -06008927 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008928 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008929 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008930 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8931 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008932
8933 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008934 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8935 ds_pool_ci.pNext = NULL;
8936 ds_pool_ci.maxSets = 1;
8937 ds_pool_ci.poolSizeCount = 1;
8938 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008939
Tobin Ehlis3b780662015-05-28 12:11:26 -06008940 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008941 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008942 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008943
Tony Barboureb254902015-07-15 12:50:33 -06008944 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008945 dsl_binding.binding = 0;
8946 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8947 dsl_binding.descriptorCount = 1;
8948 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8949 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008950
8951 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008952 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8953 ds_layout_ci.pNext = NULL;
8954 ds_layout_ci.bindingCount = 1;
8955 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008956
Tobin Ehlis3b780662015-05-28 12:11:26 -06008957 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008958 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008959 ASSERT_VK_SUCCESS(err);
8960
8961 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008962 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008963 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008964 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008965 alloc_info.descriptorPool = ds_pool;
8966 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008967 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008968 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008969
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008970 // Correctly update descriptor to avoid "NOT_UPDATED" error
8971 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008972 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008973 buff_info.offset = 0;
8974 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008975
8976 VkWriteDescriptorSet descriptor_write;
8977 memset(&descriptor_write, 0, sizeof(descriptor_write));
8978 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008979 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008980 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008981 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008982 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8983 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008984
8985 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8986
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008987 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008988
Chia-I Wuf7458c52015-10-26 21:10:41 +08008989 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8990 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008991}
8992
Karl Schultz6addd812016-02-02 17:17:23 -07008993TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008994 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07008995 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008996
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008998
Tobin Ehlis3b780662015-05-28 12:11:26 -06008999 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009000 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009001 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009002 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9003 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009004
9005 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009006 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9007 ds_pool_ci.pNext = NULL;
9008 ds_pool_ci.maxSets = 1;
9009 ds_pool_ci.poolSizeCount = 1;
9010 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009011
Tobin Ehlis3b780662015-05-28 12:11:26 -06009012 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009013 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
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 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009017 dsl_binding.binding = 0;
9018 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9019 dsl_binding.descriptorCount = 1;
9020 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9021 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009022
9023 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009024 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9025 ds_layout_ci.pNext = NULL;
9026 ds_layout_ci.bindingCount = 1;
9027 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009028 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009029 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009030 ASSERT_VK_SUCCESS(err);
9031
9032 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009033 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009034 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009035 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009036 alloc_info.descriptorPool = ds_pool;
9037 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009038 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009039 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009040
Tony Barboureb254902015-07-15 12:50:33 -06009041 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009042 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9043 sampler_ci.pNext = NULL;
9044 sampler_ci.magFilter = VK_FILTER_NEAREST;
9045 sampler_ci.minFilter = VK_FILTER_NEAREST;
9046 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9047 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9048 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9049 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9050 sampler_ci.mipLodBias = 1.0;
9051 sampler_ci.anisotropyEnable = VK_FALSE;
9052 sampler_ci.maxAnisotropy = 1;
9053 sampler_ci.compareEnable = VK_FALSE;
9054 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9055 sampler_ci.minLod = 1.0;
9056 sampler_ci.maxLod = 1.0;
9057 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9058 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009059
Tobin Ehlis3b780662015-05-28 12:11:26 -06009060 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009061 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009062 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009063
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009064 VkDescriptorImageInfo info = {};
9065 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009066
9067 VkWriteDescriptorSet descriptor_write;
9068 memset(&descriptor_write, 0, sizeof(descriptor_write));
9069 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009070 descriptor_write.dstSet = descriptorSet;
9071 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009072 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009073 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009074 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009075 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009076
9077 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9078
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009079 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009080
Chia-I Wuf7458c52015-10-26 21:10:41 +08009081 vkDestroySampler(m_device->device(), sampler, NULL);
9082 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9083 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009084}
9085
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009086TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9087 // Create layout w/ empty binding and attempt to update it
9088 VkResult err;
9089
9090 ASSERT_NO_FATAL_FAILURE(InitState());
9091
9092 VkDescriptorPoolSize ds_type_count = {};
9093 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9094 ds_type_count.descriptorCount = 1;
9095
9096 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9097 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9098 ds_pool_ci.pNext = NULL;
9099 ds_pool_ci.maxSets = 1;
9100 ds_pool_ci.poolSizeCount = 1;
9101 ds_pool_ci.pPoolSizes = &ds_type_count;
9102
9103 VkDescriptorPool ds_pool;
9104 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9105 ASSERT_VK_SUCCESS(err);
9106
9107 VkDescriptorSetLayoutBinding dsl_binding = {};
9108 dsl_binding.binding = 0;
9109 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9110 dsl_binding.descriptorCount = 0;
9111 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9112 dsl_binding.pImmutableSamplers = NULL;
9113
9114 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9115 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9116 ds_layout_ci.pNext = NULL;
9117 ds_layout_ci.bindingCount = 1;
9118 ds_layout_ci.pBindings = &dsl_binding;
9119 VkDescriptorSetLayout ds_layout;
9120 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9121 ASSERT_VK_SUCCESS(err);
9122
9123 VkDescriptorSet descriptor_set;
9124 VkDescriptorSetAllocateInfo alloc_info = {};
9125 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9126 alloc_info.descriptorSetCount = 1;
9127 alloc_info.descriptorPool = ds_pool;
9128 alloc_info.pSetLayouts = &ds_layout;
9129 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9130 ASSERT_VK_SUCCESS(err);
9131
9132 VkSamplerCreateInfo sampler_ci = {};
9133 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9134 sampler_ci.magFilter = VK_FILTER_NEAREST;
9135 sampler_ci.minFilter = VK_FILTER_NEAREST;
9136 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9137 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9138 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9139 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9140 sampler_ci.mipLodBias = 1.0;
9141 sampler_ci.maxAnisotropy = 1;
9142 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9143 sampler_ci.minLod = 1.0;
9144 sampler_ci.maxLod = 1.0;
9145 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9146
9147 VkSampler sampler;
9148 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9149 ASSERT_VK_SUCCESS(err);
9150
9151 VkDescriptorImageInfo info = {};
9152 info.sampler = sampler;
9153
9154 VkWriteDescriptorSet descriptor_write;
9155 memset(&descriptor_write, 0, sizeof(descriptor_write));
9156 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9157 descriptor_write.dstSet = descriptor_set;
9158 descriptor_write.dstBinding = 0;
9159 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9160 // This is the wrong type, but empty binding error will be flagged first
9161 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9162 descriptor_write.pImageInfo = &info;
9163
9164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9165 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9166 m_errorMonitor->VerifyFound();
9167
9168 vkDestroySampler(m_device->device(), sampler, NULL);
9169 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9170 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9171}
9172
Karl Schultz6addd812016-02-02 17:17:23 -07009173TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9174 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9175 // types
9176 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009177
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009178 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 -06009179
Tobin Ehlis3b780662015-05-28 12:11:26 -06009180 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009181
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009182 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009183 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9184 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009185
9186 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009187 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9188 ds_pool_ci.pNext = NULL;
9189 ds_pool_ci.maxSets = 1;
9190 ds_pool_ci.poolSizeCount = 1;
9191 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009192
Tobin Ehlis3b780662015-05-28 12:11:26 -06009193 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009194 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009195 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009196 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009197 dsl_binding.binding = 0;
9198 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9199 dsl_binding.descriptorCount = 1;
9200 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9201 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009202
Tony Barboureb254902015-07-15 12:50:33 -06009203 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009204 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9205 ds_layout_ci.pNext = NULL;
9206 ds_layout_ci.bindingCount = 1;
9207 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009208
Tobin Ehlis3b780662015-05-28 12:11:26 -06009209 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009210 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009211 ASSERT_VK_SUCCESS(err);
9212
9213 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009214 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009215 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009216 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009217 alloc_info.descriptorPool = ds_pool;
9218 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009219 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009220 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009221
Tony Barboureb254902015-07-15 12:50:33 -06009222 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009223 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9224 sampler_ci.pNext = NULL;
9225 sampler_ci.magFilter = VK_FILTER_NEAREST;
9226 sampler_ci.minFilter = VK_FILTER_NEAREST;
9227 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9228 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9229 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9230 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9231 sampler_ci.mipLodBias = 1.0;
9232 sampler_ci.anisotropyEnable = VK_FALSE;
9233 sampler_ci.maxAnisotropy = 1;
9234 sampler_ci.compareEnable = VK_FALSE;
9235 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9236 sampler_ci.minLod = 1.0;
9237 sampler_ci.maxLod = 1.0;
9238 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9239 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009240 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009241 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009242 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009243
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009244 VkDescriptorImageInfo info = {};
9245 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009246
9247 VkWriteDescriptorSet descriptor_write;
9248 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009249 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009250 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009251 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009252 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009253 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009254 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009255
9256 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9257
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009258 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009259
Chia-I Wuf7458c52015-10-26 21:10:41 +08009260 vkDestroySampler(m_device->device(), sampler, NULL);
9261 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9262 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009263}
9264
Karl Schultz6addd812016-02-02 17:17:23 -07009265TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009266 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009267 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009268
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9270 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009271
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009272 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009273 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9274 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009275 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009276 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9277 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009278
9279 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009280 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9281 ds_pool_ci.pNext = NULL;
9282 ds_pool_ci.maxSets = 1;
9283 ds_pool_ci.poolSizeCount = 1;
9284 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009285
9286 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009287 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009288 ASSERT_VK_SUCCESS(err);
9289
9290 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009291 dsl_binding.binding = 0;
9292 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9293 dsl_binding.descriptorCount = 1;
9294 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9295 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009296
9297 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009298 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9299 ds_layout_ci.pNext = NULL;
9300 ds_layout_ci.bindingCount = 1;
9301 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009302 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009303 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009304 ASSERT_VK_SUCCESS(err);
9305
9306 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009307 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009308 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009309 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009310 alloc_info.descriptorPool = ds_pool;
9311 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009312 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009313 ASSERT_VK_SUCCESS(err);
9314
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009315 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009316
9317 VkDescriptorImageInfo descriptor_info;
9318 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9319 descriptor_info.sampler = sampler;
9320
9321 VkWriteDescriptorSet descriptor_write;
9322 memset(&descriptor_write, 0, sizeof(descriptor_write));
9323 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009324 descriptor_write.dstSet = descriptorSet;
9325 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009326 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009327 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9328 descriptor_write.pImageInfo = &descriptor_info;
9329
9330 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9331
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009332 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009333
Chia-I Wuf7458c52015-10-26 21:10:41 +08009334 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9335 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009336}
9337
Karl Schultz6addd812016-02-02 17:17:23 -07009338TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9339 // Create a single combined Image/Sampler descriptor and send it an invalid
9340 // imageView
9341 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009342
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009344
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009345 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009346 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009347 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9348 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009349
9350 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009351 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9352 ds_pool_ci.pNext = NULL;
9353 ds_pool_ci.maxSets = 1;
9354 ds_pool_ci.poolSizeCount = 1;
9355 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009356
9357 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009358 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009359 ASSERT_VK_SUCCESS(err);
9360
9361 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009362 dsl_binding.binding = 0;
9363 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9364 dsl_binding.descriptorCount = 1;
9365 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9366 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009367
9368 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009369 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9370 ds_layout_ci.pNext = NULL;
9371 ds_layout_ci.bindingCount = 1;
9372 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009373 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009374 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009375 ASSERT_VK_SUCCESS(err);
9376
9377 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009378 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009379 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009380 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009381 alloc_info.descriptorPool = ds_pool;
9382 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009383 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009384 ASSERT_VK_SUCCESS(err);
9385
9386 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009387 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9388 sampler_ci.pNext = NULL;
9389 sampler_ci.magFilter = VK_FILTER_NEAREST;
9390 sampler_ci.minFilter = VK_FILTER_NEAREST;
9391 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9392 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9393 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9394 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9395 sampler_ci.mipLodBias = 1.0;
9396 sampler_ci.anisotropyEnable = VK_FALSE;
9397 sampler_ci.maxAnisotropy = 1;
9398 sampler_ci.compareEnable = VK_FALSE;
9399 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9400 sampler_ci.minLod = 1.0;
9401 sampler_ci.maxLod = 1.0;
9402 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9403 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009404
9405 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009406 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009407 ASSERT_VK_SUCCESS(err);
9408
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009409 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009410
9411 VkDescriptorImageInfo descriptor_info;
9412 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9413 descriptor_info.sampler = sampler;
9414 descriptor_info.imageView = view;
9415
9416 VkWriteDescriptorSet descriptor_write;
9417 memset(&descriptor_write, 0, sizeof(descriptor_write));
9418 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009419 descriptor_write.dstSet = descriptorSet;
9420 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009421 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009422 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9423 descriptor_write.pImageInfo = &descriptor_info;
9424
9425 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9426
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009427 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009428
Chia-I Wuf7458c52015-10-26 21:10:41 +08009429 vkDestroySampler(m_device->device(), sampler, NULL);
9430 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9431 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009432}
9433
Karl Schultz6addd812016-02-02 17:17:23 -07009434TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9435 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9436 // into the other
9437 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009438
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9440 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9441 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009442
Tobin Ehlis04356f92015-10-27 16:35:27 -06009443 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009444 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009445 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009446 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9447 ds_type_count[0].descriptorCount = 1;
9448 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9449 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009450
9451 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009452 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9453 ds_pool_ci.pNext = NULL;
9454 ds_pool_ci.maxSets = 1;
9455 ds_pool_ci.poolSizeCount = 2;
9456 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009457
9458 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009459 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009460 ASSERT_VK_SUCCESS(err);
9461 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009462 dsl_binding[0].binding = 0;
9463 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9464 dsl_binding[0].descriptorCount = 1;
9465 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9466 dsl_binding[0].pImmutableSamplers = NULL;
9467 dsl_binding[1].binding = 1;
9468 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9469 dsl_binding[1].descriptorCount = 1;
9470 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9471 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009472
9473 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009474 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9475 ds_layout_ci.pNext = NULL;
9476 ds_layout_ci.bindingCount = 2;
9477 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009478
9479 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009480 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009481 ASSERT_VK_SUCCESS(err);
9482
9483 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009484 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009485 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009486 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009487 alloc_info.descriptorPool = ds_pool;
9488 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009489 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009490 ASSERT_VK_SUCCESS(err);
9491
9492 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009493 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9494 sampler_ci.pNext = NULL;
9495 sampler_ci.magFilter = VK_FILTER_NEAREST;
9496 sampler_ci.minFilter = VK_FILTER_NEAREST;
9497 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9498 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9499 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9500 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9501 sampler_ci.mipLodBias = 1.0;
9502 sampler_ci.anisotropyEnable = VK_FALSE;
9503 sampler_ci.maxAnisotropy = 1;
9504 sampler_ci.compareEnable = VK_FALSE;
9505 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9506 sampler_ci.minLod = 1.0;
9507 sampler_ci.maxLod = 1.0;
9508 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9509 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009510
9511 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009512 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009513 ASSERT_VK_SUCCESS(err);
9514
9515 VkDescriptorImageInfo info = {};
9516 info.sampler = sampler;
9517
9518 VkWriteDescriptorSet descriptor_write;
9519 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9520 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009521 descriptor_write.dstSet = descriptorSet;
9522 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009523 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009524 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9525 descriptor_write.pImageInfo = &info;
9526 // This write update should succeed
9527 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9528 // Now perform a copy update that fails due to type mismatch
9529 VkCopyDescriptorSet copy_ds_update;
9530 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9531 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9532 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009533 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009534 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009535 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009536 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009537 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9538
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009539 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009540 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009541 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 -06009542 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9543 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9544 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009545 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009546 copy_ds_update.dstSet = descriptorSet;
9547 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009548 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009549 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9550
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009551 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009552
Tobin Ehlis04356f92015-10-27 16:35:27 -06009553 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9555 "update array offset of 0 and update of "
9556 "5 descriptors oversteps total number "
9557 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009558
Tobin Ehlis04356f92015-10-27 16:35:27 -06009559 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9560 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9561 copy_ds_update.srcSet = descriptorSet;
9562 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009563 copy_ds_update.dstSet = descriptorSet;
9564 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009565 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009566 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9567
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009568 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009569
Chia-I Wuf7458c52015-10-26 21:10:41 +08009570 vkDestroySampler(m_device->device(), sampler, NULL);
9571 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9572 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009573}
9574
Karl Schultz6addd812016-02-02 17:17:23 -07009575TEST_F(VkLayerTest, NumSamplesMismatch) {
9576 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9577 // sampleCount
9578 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009581
Tobin Ehlis3b780662015-05-28 12:11:26 -06009582 ASSERT_NO_FATAL_FAILURE(InitState());
9583 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009584 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009585 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009586 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009587
9588 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009589 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9590 ds_pool_ci.pNext = NULL;
9591 ds_pool_ci.maxSets = 1;
9592 ds_pool_ci.poolSizeCount = 1;
9593 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009594
Tobin Ehlis3b780662015-05-28 12:11:26 -06009595 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009596 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009597 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009598
Tony Barboureb254902015-07-15 12:50:33 -06009599 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009600 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009601 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009602 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009603 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9604 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009605
Tony Barboureb254902015-07-15 12:50:33 -06009606 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9607 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9608 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009609 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009610 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009611
Tobin Ehlis3b780662015-05-28 12:11:26 -06009612 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009613 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009614 ASSERT_VK_SUCCESS(err);
9615
9616 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009617 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009618 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009619 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009620 alloc_info.descriptorPool = ds_pool;
9621 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009622 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009623 ASSERT_VK_SUCCESS(err);
9624
Tony Barboureb254902015-07-15 12:50:33 -06009625 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009626 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009627 pipe_ms_state_ci.pNext = NULL;
9628 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9629 pipe_ms_state_ci.sampleShadingEnable = 0;
9630 pipe_ms_state_ci.minSampleShading = 1.0;
9631 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009632
Tony Barboureb254902015-07-15 12:50:33 -06009633 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009634 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9635 pipeline_layout_ci.pNext = NULL;
9636 pipeline_layout_ci.setLayoutCount = 1;
9637 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009638
9639 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009640 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009641 ASSERT_VK_SUCCESS(err);
9642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009643 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9644 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9645 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009646 VkPipelineObj pipe(m_device);
9647 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009648 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009649 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009650 pipe.SetMSAA(&pipe_ms_state_ci);
9651 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009652
Tony Barbourfe3351b2015-07-28 10:17:20 -06009653 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009654 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009655
Mark Young29927482016-05-04 14:38:51 -06009656 // Render triangle (the error should trigger on the attempt to draw).
9657 Draw(3, 1, 0, 0);
9658
9659 // Finalize recording of the command buffer
9660 EndCommandBuffer();
9661
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009662 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009663
Chia-I Wuf7458c52015-10-26 21:10:41 +08009664 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9665 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9666 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009667}
Mark Young29927482016-05-04 14:38:51 -06009668
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009669TEST_F(VkLayerTest, RenderPassIncompatible) {
9670 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9671 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009672 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009673 VkResult err;
9674
9675 ASSERT_NO_FATAL_FAILURE(InitState());
9676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9677
9678 VkDescriptorSetLayoutBinding dsl_binding = {};
9679 dsl_binding.binding = 0;
9680 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9681 dsl_binding.descriptorCount = 1;
9682 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9683 dsl_binding.pImmutableSamplers = NULL;
9684
9685 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9686 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9687 ds_layout_ci.pNext = NULL;
9688 ds_layout_ci.bindingCount = 1;
9689 ds_layout_ci.pBindings = &dsl_binding;
9690
9691 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009692 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009693 ASSERT_VK_SUCCESS(err);
9694
9695 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9696 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9697 pipeline_layout_ci.pNext = NULL;
9698 pipeline_layout_ci.setLayoutCount = 1;
9699 pipeline_layout_ci.pSetLayouts = &ds_layout;
9700
9701 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009702 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009703 ASSERT_VK_SUCCESS(err);
9704
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009705 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9706 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9707 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009708 // Create a renderpass that will be incompatible with default renderpass
9709 VkAttachmentReference attach = {};
9710 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9711 VkAttachmentReference color_att = {};
9712 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9713 VkSubpassDescription subpass = {};
9714 subpass.inputAttachmentCount = 1;
9715 subpass.pInputAttachments = &attach;
9716 subpass.colorAttachmentCount = 1;
9717 subpass.pColorAttachments = &color_att;
9718 VkRenderPassCreateInfo rpci = {};
9719 rpci.subpassCount = 1;
9720 rpci.pSubpasses = &subpass;
9721 rpci.attachmentCount = 1;
9722 VkAttachmentDescription attach_desc = {};
9723 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009724 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9725 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009726 rpci.pAttachments = &attach_desc;
9727 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9728 VkRenderPass rp;
9729 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9730 VkPipelineObj pipe(m_device);
9731 pipe.AddShader(&vs);
9732 pipe.AddShader(&fs);
9733 pipe.AddColorAttachment();
9734 VkViewport view_port = {};
9735 m_viewports.push_back(view_port);
9736 pipe.SetViewport(m_viewports);
9737 VkRect2D rect = {};
9738 m_scissors.push_back(rect);
9739 pipe.SetScissor(m_scissors);
9740 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9741
9742 VkCommandBufferInheritanceInfo cbii = {};
9743 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9744 cbii.renderPass = rp;
9745 cbii.subpass = 0;
9746 VkCommandBufferBeginInfo cbbi = {};
9747 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9748 cbbi.pInheritanceInfo = &cbii;
9749 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9750 VkRenderPassBeginInfo rpbi = {};
9751 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9752 rpbi.framebuffer = m_framebuffer;
9753 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009754 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9755 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009756
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009758 // Render triangle (the error should trigger on the attempt to draw).
9759 Draw(3, 1, 0, 0);
9760
9761 // Finalize recording of the command buffer
9762 EndCommandBuffer();
9763
9764 m_errorMonitor->VerifyFound();
9765
9766 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9767 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9768 vkDestroyRenderPass(m_device->device(), rp, NULL);
9769}
9770
Mark Youngc89c6312016-03-31 16:03:20 -06009771TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9772 // Create Pipeline where the number of blend attachments doesn't match the
9773 // number of color attachments. In this case, we don't add any color
9774 // blend attachments even though we have a color attachment.
9775 VkResult err;
9776
9777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009778 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009779
9780 ASSERT_NO_FATAL_FAILURE(InitState());
9781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9782 VkDescriptorPoolSize ds_type_count = {};
9783 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9784 ds_type_count.descriptorCount = 1;
9785
9786 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9787 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9788 ds_pool_ci.pNext = NULL;
9789 ds_pool_ci.maxSets = 1;
9790 ds_pool_ci.poolSizeCount = 1;
9791 ds_pool_ci.pPoolSizes = &ds_type_count;
9792
9793 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009794 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009795 ASSERT_VK_SUCCESS(err);
9796
9797 VkDescriptorSetLayoutBinding dsl_binding = {};
9798 dsl_binding.binding = 0;
9799 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9800 dsl_binding.descriptorCount = 1;
9801 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9802 dsl_binding.pImmutableSamplers = NULL;
9803
9804 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9805 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9806 ds_layout_ci.pNext = NULL;
9807 ds_layout_ci.bindingCount = 1;
9808 ds_layout_ci.pBindings = &dsl_binding;
9809
9810 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009811 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009812 ASSERT_VK_SUCCESS(err);
9813
9814 VkDescriptorSet descriptorSet;
9815 VkDescriptorSetAllocateInfo alloc_info = {};
9816 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9817 alloc_info.descriptorSetCount = 1;
9818 alloc_info.descriptorPool = ds_pool;
9819 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009820 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009821 ASSERT_VK_SUCCESS(err);
9822
9823 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009824 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009825 pipe_ms_state_ci.pNext = NULL;
9826 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9827 pipe_ms_state_ci.sampleShadingEnable = 0;
9828 pipe_ms_state_ci.minSampleShading = 1.0;
9829 pipe_ms_state_ci.pSampleMask = NULL;
9830
9831 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9832 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9833 pipeline_layout_ci.pNext = NULL;
9834 pipeline_layout_ci.setLayoutCount = 1;
9835 pipeline_layout_ci.pSetLayouts = &ds_layout;
9836
9837 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009838 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009839 ASSERT_VK_SUCCESS(err);
9840
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009841 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9842 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9843 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009844 VkPipelineObj pipe(m_device);
9845 pipe.AddShader(&vs);
9846 pipe.AddShader(&fs);
9847 pipe.SetMSAA(&pipe_ms_state_ci);
9848 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9849
9850 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009851 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009852
Mark Young29927482016-05-04 14:38:51 -06009853 // Render triangle (the error should trigger on the attempt to draw).
9854 Draw(3, 1, 0, 0);
9855
9856 // Finalize recording of the command buffer
9857 EndCommandBuffer();
9858
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009859 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009860
9861 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9862 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9863 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9864}
Mark Young29927482016-05-04 14:38:51 -06009865
Mark Muellerd4914412016-06-13 17:52:06 -06009866TEST_F(VkLayerTest, MissingClearAttachment) {
9867 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9868 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009869 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009871 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009872
9873 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9874 m_errorMonitor->VerifyFound();
9875}
9876
Karl Schultz6addd812016-02-02 17:17:23 -07009877TEST_F(VkLayerTest, ClearCmdNoDraw) {
9878 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9879 // to issuing a Draw
9880 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009881
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009883 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009884
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009885 ASSERT_NO_FATAL_FAILURE(InitState());
9886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009887
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009888 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009889 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9890 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009891
9892 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009893 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9894 ds_pool_ci.pNext = NULL;
9895 ds_pool_ci.maxSets = 1;
9896 ds_pool_ci.poolSizeCount = 1;
9897 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009898
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009899 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009900 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009901 ASSERT_VK_SUCCESS(err);
9902
Tony Barboureb254902015-07-15 12:50:33 -06009903 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009904 dsl_binding.binding = 0;
9905 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9906 dsl_binding.descriptorCount = 1;
9907 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9908 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009909
Tony Barboureb254902015-07-15 12:50:33 -06009910 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009911 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9912 ds_layout_ci.pNext = NULL;
9913 ds_layout_ci.bindingCount = 1;
9914 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009915
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009916 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009917 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009918 ASSERT_VK_SUCCESS(err);
9919
9920 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009921 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009922 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009923 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009924 alloc_info.descriptorPool = ds_pool;
9925 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009926 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009927 ASSERT_VK_SUCCESS(err);
9928
Tony Barboureb254902015-07-15 12:50:33 -06009929 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009930 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009931 pipe_ms_state_ci.pNext = NULL;
9932 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9933 pipe_ms_state_ci.sampleShadingEnable = 0;
9934 pipe_ms_state_ci.minSampleShading = 1.0;
9935 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009936
Tony Barboureb254902015-07-15 12:50:33 -06009937 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009938 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9939 pipeline_layout_ci.pNext = NULL;
9940 pipeline_layout_ci.setLayoutCount = 1;
9941 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009942
9943 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009944 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009945 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009946
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009947 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009948 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009949 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009951
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009952 VkPipelineObj pipe(m_device);
9953 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009954 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009955 pipe.SetMSAA(&pipe_ms_state_ci);
9956 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009957
9958 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009959
Karl Schultz6addd812016-02-02 17:17:23 -07009960 // Main thing we care about for this test is that the VkImage obj we're
9961 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009962 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009963 VkClearAttachment color_attachment;
9964 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9965 color_attachment.clearValue.color.float32[0] = 1.0;
9966 color_attachment.clearValue.color.float32[1] = 1.0;
9967 color_attachment.clearValue.color.float32[2] = 1.0;
9968 color_attachment.clearValue.color.float32[3] = 1.0;
9969 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009970 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009971
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009972 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009973
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009974 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009975
Chia-I Wuf7458c52015-10-26 21:10:41 +08009976 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9977 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9978 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009979}
9980
Karl Schultz6addd812016-02-02 17:17:23 -07009981TEST_F(VkLayerTest, VtxBufferBadIndex) {
9982 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9985 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009986
Tobin Ehlis502480b2015-06-24 15:53:07 -06009987 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009988 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009990
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009991 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009992 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9993 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009994
9995 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009996 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9997 ds_pool_ci.pNext = NULL;
9998 ds_pool_ci.maxSets = 1;
9999 ds_pool_ci.poolSizeCount = 1;
10000 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010001
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010002 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010003 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010004 ASSERT_VK_SUCCESS(err);
10005
Tony Barboureb254902015-07-15 12:50:33 -060010006 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010007 dsl_binding.binding = 0;
10008 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10009 dsl_binding.descriptorCount = 1;
10010 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10011 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010012
Tony Barboureb254902015-07-15 12:50:33 -060010013 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010014 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10015 ds_layout_ci.pNext = NULL;
10016 ds_layout_ci.bindingCount = 1;
10017 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010018
Tobin Ehlis502480b2015-06-24 15:53:07 -060010019 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010020 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010021 ASSERT_VK_SUCCESS(err);
10022
10023 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010024 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010025 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010026 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010027 alloc_info.descriptorPool = ds_pool;
10028 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010029 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010030 ASSERT_VK_SUCCESS(err);
10031
Tony Barboureb254902015-07-15 12:50:33 -060010032 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010033 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010034 pipe_ms_state_ci.pNext = NULL;
10035 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10036 pipe_ms_state_ci.sampleShadingEnable = 0;
10037 pipe_ms_state_ci.minSampleShading = 1.0;
10038 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010039
Tony Barboureb254902015-07-15 12:50:33 -060010040 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010041 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10042 pipeline_layout_ci.pNext = NULL;
10043 pipeline_layout_ci.setLayoutCount = 1;
10044 pipeline_layout_ci.pSetLayouts = &ds_layout;
10045 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010047 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010048 ASSERT_VK_SUCCESS(err);
10049
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010050 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10051 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10052 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010053 VkPipelineObj pipe(m_device);
10054 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010055 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010056 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010057 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010058 pipe.SetViewport(m_viewports);
10059 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010060 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010061
10062 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010063 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010064 // Don't care about actual data, just need to get to draw to flag error
10065 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010067 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010068 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010069
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010070 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010071
Chia-I Wuf7458c52015-10-26 21:10:41 +080010072 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10073 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10074 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010075}
Mark Muellerdfe37552016-07-07 14:47:42 -060010076
Mark Mueller2ee294f2016-08-04 12:59:48 -060010077TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10078 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10079 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010080 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010081
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010082 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10083 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010085 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10086 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010087
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010088 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010091 // The following test fails with recent NVidia drivers.
10092 // By the time core_validation is reached, the NVidia
10093 // driver has sanitized the invalid condition and core_validation
10094 // is not introduced to the failure condition. This is not the case
10095 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010096 // uint32_t count = static_cast<uint32_t>(~0);
10097 // VkPhysicalDevice physical_device;
10098 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10099 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010100
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010102 float queue_priority = 0.0;
10103
10104 VkDeviceQueueCreateInfo queue_create_info = {};
10105 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10106 queue_create_info.queueCount = 1;
10107 queue_create_info.pQueuePriorities = &queue_priority;
10108 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10109
10110 VkPhysicalDeviceFeatures features = m_device->phy().features();
10111 VkDevice testDevice;
10112 VkDeviceCreateInfo device_create_info = {};
10113 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10114 device_create_info.queueCreateInfoCount = 1;
10115 device_create_info.pQueueCreateInfos = &queue_create_info;
10116 device_create_info.pEnabledFeatures = &features;
10117 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10118 m_errorMonitor->VerifyFound();
10119
10120 queue_create_info.queueFamilyIndex = 1;
10121
10122 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10123 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10124 for (unsigned i = 0; i < feature_count; i++) {
10125 if (VK_FALSE == feature_array[i]) {
10126 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010128 device_create_info.pEnabledFeatures = &features;
10129 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10130 m_errorMonitor->VerifyFound();
10131 break;
10132 }
10133 }
10134}
10135
Tobin Ehlis16edf082016-11-21 12:33:49 -070010136TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10137 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10138
10139 ASSERT_NO_FATAL_FAILURE(InitState());
10140
10141 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10142 std::vector<VkDeviceQueueCreateInfo> queue_info;
10143 queue_info.reserve(queue_props.size());
10144 std::vector<std::vector<float>> queue_priorities;
10145 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10146 VkDeviceQueueCreateInfo qi{};
10147 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10148 qi.queueFamilyIndex = i;
10149 qi.queueCount = queue_props[i].queueCount;
10150 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10151 qi.pQueuePriorities = queue_priorities[i].data();
10152 queue_info.push_back(qi);
10153 }
10154
10155 std::vector<const char *> device_extension_names;
10156
10157 VkDevice local_device;
10158 VkDeviceCreateInfo device_create_info = {};
10159 auto features = m_device->phy().features();
10160 // Intentionally disable pipeline stats
10161 features.pipelineStatisticsQuery = VK_FALSE;
10162 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10163 device_create_info.pNext = NULL;
10164 device_create_info.queueCreateInfoCount = queue_info.size();
10165 device_create_info.pQueueCreateInfos = queue_info.data();
10166 device_create_info.enabledLayerCount = 0;
10167 device_create_info.ppEnabledLayerNames = NULL;
10168 device_create_info.pEnabledFeatures = &features;
10169 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10170 ASSERT_VK_SUCCESS(err);
10171
10172 VkQueryPoolCreateInfo qpci{};
10173 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10174 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10175 qpci.queryCount = 1;
10176 VkQueryPool query_pool;
10177
10178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10179 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10180 m_errorMonitor->VerifyFound();
10181
10182 vkDestroyDevice(local_device, nullptr);
10183}
10184
Mark Mueller2ee294f2016-08-04 12:59:48 -060010185TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10186 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10187 "End a command buffer with a query still in progress.");
10188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010189 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10190 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10191 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010193 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010196
10197 ASSERT_NO_FATAL_FAILURE(InitState());
10198
10199 VkEvent event;
10200 VkEventCreateInfo event_create_info{};
10201 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10202 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10203
Mark Mueller2ee294f2016-08-04 12:59:48 -060010204 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010205 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010206
10207 BeginCommandBuffer();
10208
10209 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010210 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 -060010211 ASSERT_TRUE(image.initialized());
10212 VkImageMemoryBarrier img_barrier = {};
10213 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10214 img_barrier.pNext = NULL;
10215 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10216 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10217 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10218 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10219 img_barrier.image = image.handle();
10220 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010221
10222 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10223 // that layer validation catches the case when it is not.
10224 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010225 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10226 img_barrier.subresourceRange.baseArrayLayer = 0;
10227 img_barrier.subresourceRange.baseMipLevel = 0;
10228 img_barrier.subresourceRange.layerCount = 1;
10229 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010230 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10231 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010232 m_errorMonitor->VerifyFound();
10233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010235
10236 VkQueryPool query_pool;
10237 VkQueryPoolCreateInfo query_pool_create_info = {};
10238 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10239 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10240 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010241 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010243 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010244 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10245
10246 vkEndCommandBuffer(m_commandBuffer->handle());
10247 m_errorMonitor->VerifyFound();
10248
10249 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10250 vkDestroyEvent(m_device->device(), event, nullptr);
10251}
10252
Mark Muellerdfe37552016-07-07 14:47:42 -060010253TEST_F(VkLayerTest, VertexBufferInvalid) {
10254 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10255 "delete a buffer twice, use an invalid offset for each "
10256 "buffer type, and attempt to bind a null buffer");
10257
10258 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10259 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010260 const char *invalid_offset_message = "vkBindBufferMemory(): "
10261 "memoryOffset is 0x";
10262 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10263 "storage memoryOffset "
10264 "is 0x";
10265 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10266 "texel memoryOffset "
10267 "is 0x";
10268 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10269 "uniform memoryOffset "
10270 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010271
10272 ASSERT_NO_FATAL_FAILURE(InitState());
10273 ASSERT_NO_FATAL_FAILURE(InitViewport());
10274 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10275
10276 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010277 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010278 pipe_ms_state_ci.pNext = NULL;
10279 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10280 pipe_ms_state_ci.sampleShadingEnable = 0;
10281 pipe_ms_state_ci.minSampleShading = 1.0;
10282 pipe_ms_state_ci.pSampleMask = nullptr;
10283
10284 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10285 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10286 VkPipelineLayout pipeline_layout;
10287
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010288 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010289 ASSERT_VK_SUCCESS(err);
10290
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010291 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10292 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010293 VkPipelineObj pipe(m_device);
10294 pipe.AddShader(&vs);
10295 pipe.AddShader(&fs);
10296 pipe.AddColorAttachment();
10297 pipe.SetMSAA(&pipe_ms_state_ci);
10298 pipe.SetViewport(m_viewports);
10299 pipe.SetScissor(m_scissors);
10300 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10301
10302 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010303 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010304
10305 {
10306 // Create and bind a vertex buffer in a reduced scope, which will cause
10307 // it to be deleted upon leaving this scope
10308 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010309 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010310 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10311 draw_verticies.AddVertexInputToPipe(pipe);
10312 }
10313
10314 Draw(1, 0, 0, 0);
10315
10316 EndCommandBuffer();
10317
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010319 QueueCommandBuffer(false);
10320 m_errorMonitor->VerifyFound();
10321
10322 {
10323 // Create and bind a vertex buffer in a reduced scope, and delete it
10324 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010325 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010327 buffer_test.TestDoubleDestroy();
10328 }
10329 m_errorMonitor->VerifyFound();
10330
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010331 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010332 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10334 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10335 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010336 m_errorMonitor->VerifyFound();
10337 }
10338
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010339 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10340 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010341 // Create and bind a memory buffer with an invalid offset again,
10342 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10344 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10345 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010346 m_errorMonitor->VerifyFound();
10347 }
10348
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010349 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010350 // Create and bind a memory buffer with an invalid offset again, but
10351 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10353 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10354 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010355 m_errorMonitor->VerifyFound();
10356 }
10357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010358 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010359 // Create and bind a memory buffer with an invalid offset again, but
10360 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10362 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10363 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010364 m_errorMonitor->VerifyFound();
10365 }
10366
10367 {
10368 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010370 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10371 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010372 m_errorMonitor->VerifyFound();
10373 }
10374
10375 {
10376 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010378 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10379 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010380 }
10381 m_errorMonitor->VerifyFound();
10382
10383 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10384}
10385
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010386// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10387TEST_F(VkLayerTest, InvalidImageLayout) {
10388 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010389 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10390 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010391 // 3 in ValidateCmdBufImageLayouts
10392 // * -1 Attempt to submit cmd buf w/ deleted image
10393 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10394 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010395
10396 ASSERT_NO_FATAL_FAILURE(InitState());
10397 // Create src & dst images to use for copy operations
10398 VkImage src_image;
10399 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010400 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010401
10402 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10403 const int32_t tex_width = 32;
10404 const int32_t tex_height = 32;
10405
10406 VkImageCreateInfo image_create_info = {};
10407 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10408 image_create_info.pNext = NULL;
10409 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10410 image_create_info.format = tex_format;
10411 image_create_info.extent.width = tex_width;
10412 image_create_info.extent.height = tex_height;
10413 image_create_info.extent.depth = 1;
10414 image_create_info.mipLevels = 1;
10415 image_create_info.arrayLayers = 4;
10416 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10417 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10418 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010419 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010420 image_create_info.flags = 0;
10421
10422 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10423 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010424 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010425 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10426 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010427 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10428 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10429 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10430 ASSERT_VK_SUCCESS(err);
10431
10432 // Allocate memory
10433 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010434 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010435 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010436 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10437 mem_alloc.pNext = NULL;
10438 mem_alloc.allocationSize = 0;
10439 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010440
10441 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010442 mem_alloc.allocationSize = img_mem_reqs.size;
10443 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010444 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010445 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010446 ASSERT_VK_SUCCESS(err);
10447
10448 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010449 mem_alloc.allocationSize = img_mem_reqs.size;
10450 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010451 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010452 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010453 ASSERT_VK_SUCCESS(err);
10454
10455 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010456 mem_alloc.allocationSize = img_mem_reqs.size;
10457 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010458 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010459 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010460 ASSERT_VK_SUCCESS(err);
10461
10462 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10463 ASSERT_VK_SUCCESS(err);
10464 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10465 ASSERT_VK_SUCCESS(err);
10466 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10467 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010468
10469 BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010470 VkImageCopy copy_region;
10471 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10472 copy_region.srcSubresource.mipLevel = 0;
10473 copy_region.srcSubresource.baseArrayLayer = 0;
10474 copy_region.srcSubresource.layerCount = 1;
10475 copy_region.srcOffset.x = 0;
10476 copy_region.srcOffset.y = 0;
10477 copy_region.srcOffset.z = 0;
10478 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10479 copy_region.dstSubresource.mipLevel = 0;
10480 copy_region.dstSubresource.baseArrayLayer = 0;
10481 copy_region.dstSubresource.layerCount = 1;
10482 copy_region.dstOffset.x = 0;
10483 copy_region.dstOffset.y = 0;
10484 copy_region.dstOffset.z = 0;
10485 copy_region.extent.width = 1;
10486 copy_region.extent.height = 1;
10487 copy_region.extent.depth = 1;
10488
10489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10490 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10491 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010492 m_errorMonitor->VerifyFound();
10493 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10495 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10496 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010497 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010498 m_errorMonitor->VerifyFound();
10499 // Final src error is due to bad layout type
10500 m_errorMonitor->SetDesiredFailureMsg(
10501 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10502 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010503 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010504 m_errorMonitor->VerifyFound();
10505 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10507 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010508 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010509 m_errorMonitor->VerifyFound();
10510 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10512 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10513 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010514 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010515 m_errorMonitor->VerifyFound();
10516 m_errorMonitor->SetDesiredFailureMsg(
10517 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10518 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010519 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010520 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010521
Cort3b021012016-12-07 12:00:57 -080010522 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10523 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10524 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10525 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10526 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10527 transfer_dst_image_barrier[0].srcAccessMask = 0;
10528 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10529 transfer_dst_image_barrier[0].image = dst_image;
10530 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10531 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10532 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10533 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10534 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10535 transfer_dst_image_barrier[0].image = depth_image;
10536 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10537 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10538 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10539
10540 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010541 VkClearColorValue color_clear_value = {};
10542 VkImageSubresourceRange clear_range;
10543 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10544 clear_range.baseMipLevel = 0;
10545 clear_range.baseArrayLayer = 0;
10546 clear_range.layerCount = 1;
10547 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010548
Cort3b021012016-12-07 12:00:57 -080010549 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10550 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010553 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010554 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010555 // Fail due to provided layout not matching actual current layout for color clear.
10556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010557 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010558 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010559
Cort530cf382016-12-08 09:59:47 -080010560 VkClearDepthStencilValue depth_clear_value = {};
10561 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010562
10563 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10564 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010567 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010568 m_errorMonitor->VerifyFound();
10569 // Fail due to provided layout not matching actual current layout for depth clear.
10570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010571 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010572 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010573
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010574 // Now cause error due to bad image layout transition in PipelineBarrier
10575 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010576 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010577 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010578 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010579 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010580 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10581 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010582 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10584 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10585 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10586 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10587 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010588 m_errorMonitor->VerifyFound();
10589
10590 // Finally some layout errors at RenderPass create time
10591 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10592 VkAttachmentReference attach = {};
10593 // perf warning for GENERAL layout w/ non-DS input attachment
10594 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10595 VkSubpassDescription subpass = {};
10596 subpass.inputAttachmentCount = 1;
10597 subpass.pInputAttachments = &attach;
10598 VkRenderPassCreateInfo rpci = {};
10599 rpci.subpassCount = 1;
10600 rpci.pSubpasses = &subpass;
10601 rpci.attachmentCount = 1;
10602 VkAttachmentDescription attach_desc = {};
10603 attach_desc.format = VK_FORMAT_UNDEFINED;
10604 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010605 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010606 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10608 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010609 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10610 m_errorMonitor->VerifyFound();
10611 // error w/ non-general layout
10612 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10613
10614 m_errorMonitor->SetDesiredFailureMsg(
10615 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10616 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10617 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10618 m_errorMonitor->VerifyFound();
10619 subpass.inputAttachmentCount = 0;
10620 subpass.colorAttachmentCount = 1;
10621 subpass.pColorAttachments = &attach;
10622 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10623 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10625 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010626 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10627 m_errorMonitor->VerifyFound();
10628 // error w/ non-color opt or GENERAL layout for color attachment
10629 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10630 m_errorMonitor->SetDesiredFailureMsg(
10631 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10632 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10633 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10634 m_errorMonitor->VerifyFound();
10635 subpass.colorAttachmentCount = 0;
10636 subpass.pDepthStencilAttachment = &attach;
10637 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10638 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10640 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010641 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10642 m_errorMonitor->VerifyFound();
10643 // error w/ non-ds opt or GENERAL layout for color attachment
10644 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10646 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10647 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010648 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10649 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010650 // For this error we need a valid renderpass so create default one
10651 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10652 attach.attachment = 0;
10653 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10654 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10655 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10656 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10657 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10658 // Can't do a CLEAR load on READ_ONLY initialLayout
10659 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10660 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10661 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10663 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10664 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010665 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10666 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010667
Cort3b021012016-12-07 12:00:57 -080010668 vkFreeMemory(m_device->device(), src_image_mem, NULL);
10669 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
10670 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010671 vkDestroyImage(m_device->device(), src_image, NULL);
10672 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080010673 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010674}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010675
Tobin Ehlise0936662016-10-11 08:10:51 -060010676TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10677 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10678 VkResult err;
10679
10680 ASSERT_NO_FATAL_FAILURE(InitState());
10681
10682 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10683 VkImageTiling tiling;
10684 VkFormatProperties format_properties;
10685 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10686 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10687 tiling = VK_IMAGE_TILING_LINEAR;
10688 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10689 tiling = VK_IMAGE_TILING_OPTIMAL;
10690 } else {
10691 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10692 "skipped.\n");
10693 return;
10694 }
10695
10696 VkDescriptorPoolSize ds_type = {};
10697 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10698 ds_type.descriptorCount = 1;
10699
10700 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10701 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10702 ds_pool_ci.maxSets = 1;
10703 ds_pool_ci.poolSizeCount = 1;
10704 ds_pool_ci.pPoolSizes = &ds_type;
10705 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10706
10707 VkDescriptorPool ds_pool;
10708 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10709 ASSERT_VK_SUCCESS(err);
10710
10711 VkDescriptorSetLayoutBinding dsl_binding = {};
10712 dsl_binding.binding = 0;
10713 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10714 dsl_binding.descriptorCount = 1;
10715 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10716 dsl_binding.pImmutableSamplers = NULL;
10717
10718 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10719 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10720 ds_layout_ci.pNext = NULL;
10721 ds_layout_ci.bindingCount = 1;
10722 ds_layout_ci.pBindings = &dsl_binding;
10723
10724 VkDescriptorSetLayout ds_layout;
10725 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10726 ASSERT_VK_SUCCESS(err);
10727
10728 VkDescriptorSetAllocateInfo alloc_info = {};
10729 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10730 alloc_info.descriptorSetCount = 1;
10731 alloc_info.descriptorPool = ds_pool;
10732 alloc_info.pSetLayouts = &ds_layout;
10733 VkDescriptorSet descriptor_set;
10734 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10735 ASSERT_VK_SUCCESS(err);
10736
10737 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10738 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10739 pipeline_layout_ci.pNext = NULL;
10740 pipeline_layout_ci.setLayoutCount = 1;
10741 pipeline_layout_ci.pSetLayouts = &ds_layout;
10742 VkPipelineLayout pipeline_layout;
10743 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10744 ASSERT_VK_SUCCESS(err);
10745
10746 VkImageObj image(m_device);
10747 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10748 ASSERT_TRUE(image.initialized());
10749 VkImageView view = image.targetView(tex_format);
10750
10751 VkDescriptorImageInfo image_info = {};
10752 image_info.imageView = view;
10753 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10754
10755 VkWriteDescriptorSet descriptor_write = {};
10756 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10757 descriptor_write.dstSet = descriptor_set;
10758 descriptor_write.dstBinding = 0;
10759 descriptor_write.descriptorCount = 1;
10760 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10761 descriptor_write.pImageInfo = &image_info;
10762
10763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10764 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10765 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10766 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10767 m_errorMonitor->VerifyFound();
10768
10769 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10770 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10771 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10772 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10773}
10774
Mark Mueller93b938f2016-08-18 10:27:40 -060010775TEST_F(VkLayerTest, SimultaneousUse) {
10776 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10777 "in primary and secondary command buffers.");
10778
10779 ASSERT_NO_FATAL_FAILURE(InitState());
10780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10781
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010782 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010783 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10784 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010785
10786 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010787 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010788 command_buffer_allocate_info.commandPool = m_commandPool;
10789 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10790 command_buffer_allocate_info.commandBufferCount = 1;
10791
10792 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010793 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010794 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10795 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010796 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010797 command_buffer_inheritance_info.renderPass = m_renderPass;
10798 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10799 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010800 command_buffer_begin_info.flags =
10801 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010802 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10803
10804 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010805 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10806 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010807 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010808 vkEndCommandBuffer(secondary_command_buffer);
10809
Mark Mueller93b938f2016-08-18 10:27:40 -060010810 VkSubmitInfo submit_info = {};
10811 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10812 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010813 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010814 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010815
Mark Mueller4042b652016-09-05 22:52:21 -060010816 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010817 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10819 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010820 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010821 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10822 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010823
10824 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010825 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10826
Mark Mueller4042b652016-09-05 22:52:21 -060010827 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010828 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010829 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010830
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10832 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010833 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010834 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10835 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010836}
10837
Mark Mueller917f6bc2016-08-30 10:57:19 -060010838TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10839 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10840 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010841 "Delete objects that are inuse. Call VkQueueSubmit "
10842 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010843
10844 ASSERT_NO_FATAL_FAILURE(InitState());
10845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10846
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010847 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10848 const char *cannot_delete_event_message = "Cannot delete event 0x";
10849 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10850 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010851
10852 BeginCommandBuffer();
10853
10854 VkEvent event;
10855 VkEventCreateInfo event_create_info = {};
10856 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10857 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010858 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010859
Mark Muellerc8d441e2016-08-23 17:36:00 -060010860 EndCommandBuffer();
10861 vkDestroyEvent(m_device->device(), event, nullptr);
10862
10863 VkSubmitInfo submit_info = {};
10864 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10865 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010866 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010868 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10869 m_errorMonitor->VerifyFound();
10870
10871 m_errorMonitor->SetDesiredFailureMsg(0, "");
10872 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10873
10874 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10875
Mark Mueller917f6bc2016-08-30 10:57:19 -060010876 VkSemaphoreCreateInfo semaphore_create_info = {};
10877 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10878 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010879 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010880 VkFenceCreateInfo fence_create_info = {};
10881 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10882 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010883 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010884
10885 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010886 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010887 descriptor_pool_type_count.descriptorCount = 1;
10888
10889 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10890 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10891 descriptor_pool_create_info.maxSets = 1;
10892 descriptor_pool_create_info.poolSizeCount = 1;
10893 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010894 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010895
10896 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010897 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010898
10899 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010900 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010901 descriptorset_layout_binding.descriptorCount = 1;
10902 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10903
10904 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010905 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010906 descriptorset_layout_create_info.bindingCount = 1;
10907 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10908
10909 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010910 ASSERT_VK_SUCCESS(
10911 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010912
10913 VkDescriptorSet descriptorset;
10914 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010915 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010916 descriptorset_allocate_info.descriptorSetCount = 1;
10917 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10918 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010919 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010920
Mark Mueller4042b652016-09-05 22:52:21 -060010921 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10922
10923 VkDescriptorBufferInfo buffer_info = {};
10924 buffer_info.buffer = buffer_test.GetBuffer();
10925 buffer_info.offset = 0;
10926 buffer_info.range = 1024;
10927
10928 VkWriteDescriptorSet write_descriptor_set = {};
10929 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10930 write_descriptor_set.dstSet = descriptorset;
10931 write_descriptor_set.descriptorCount = 1;
10932 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10933 write_descriptor_set.pBufferInfo = &buffer_info;
10934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010935 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010936
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010937 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10938 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010939
10940 VkPipelineObj pipe(m_device);
10941 pipe.AddColorAttachment();
10942 pipe.AddShader(&vs);
10943 pipe.AddShader(&fs);
10944
10945 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010946 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010947 pipeline_layout_create_info.setLayoutCount = 1;
10948 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10949
10950 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010951 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010952
10953 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10954
Mark Muellerc8d441e2016-08-23 17:36:00 -060010955 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010956 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010958 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10959 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10960 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010961
Mark Muellerc8d441e2016-08-23 17:36:00 -060010962 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010963
Mark Mueller917f6bc2016-08-30 10:57:19 -060010964 submit_info.signalSemaphoreCount = 1;
10965 submit_info.pSignalSemaphores = &semaphore;
10966 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010969 vkDestroyEvent(m_device->device(), event, nullptr);
10970 m_errorMonitor->VerifyFound();
10971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010973 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10974 m_errorMonitor->VerifyFound();
10975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010977 vkDestroyFence(m_device->device(), fence, nullptr);
10978 m_errorMonitor->VerifyFound();
10979
Tobin Ehlis122207b2016-09-01 08:50:06 -070010980 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010981 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10982 vkDestroyFence(m_device->device(), fence, nullptr);
10983 vkDestroyEvent(m_device->device(), event, nullptr);
10984 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010985 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010986 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10987}
10988
Tobin Ehlis2adda372016-09-01 08:51:06 -070010989TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10990 TEST_DESCRIPTION("Delete in-use query pool.");
10991
10992 ASSERT_NO_FATAL_FAILURE(InitState());
10993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10994
10995 VkQueryPool query_pool;
10996 VkQueryPoolCreateInfo query_pool_ci{};
10997 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10998 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10999 query_pool_ci.queryCount = 1;
11000 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
11001 BeginCommandBuffer();
11002 // Reset query pool to create binding with cmd buffer
11003 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11004
11005 EndCommandBuffer();
11006
11007 VkSubmitInfo submit_info = {};
11008 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11009 submit_info.commandBufferCount = 1;
11010 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11011 // Submit cmd buffer and then destroy query pool while in-flight
11012 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11013
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070011015 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11016 m_errorMonitor->VerifyFound();
11017
11018 vkQueueWaitIdle(m_device->m_queue);
11019 // Now that cmd buffer done we can safely destroy query_pool
11020 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11021}
11022
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011023TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11024 TEST_DESCRIPTION("Delete in-use pipeline.");
11025
11026 ASSERT_NO_FATAL_FAILURE(InitState());
11027 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11028
11029 // Empty pipeline layout used for binding PSO
11030 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11031 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11032 pipeline_layout_ci.setLayoutCount = 0;
11033 pipeline_layout_ci.pSetLayouts = NULL;
11034
11035 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011036 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011037 ASSERT_VK_SUCCESS(err);
11038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011040 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011041 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11042 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011043 // Store pipeline handle so we can actually delete it before test finishes
11044 VkPipeline delete_this_pipeline;
11045 { // Scope pipeline so it will be auto-deleted
11046 VkPipelineObj pipe(m_device);
11047 pipe.AddShader(&vs);
11048 pipe.AddShader(&fs);
11049 pipe.AddColorAttachment();
11050 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11051 delete_this_pipeline = pipe.handle();
11052
11053 BeginCommandBuffer();
11054 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011055 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011056
11057 EndCommandBuffer();
11058
11059 VkSubmitInfo submit_info = {};
11060 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11061 submit_info.commandBufferCount = 1;
11062 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11063 // Submit cmd buffer and then pipeline destroyed while in-flight
11064 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11065 } // Pipeline deletion triggered here
11066 m_errorMonitor->VerifyFound();
11067 // Make sure queue finished and then actually delete pipeline
11068 vkQueueWaitIdle(m_device->m_queue);
11069 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11070 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11071}
11072
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011073TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11074 TEST_DESCRIPTION("Delete in-use imageView.");
11075
11076 ASSERT_NO_FATAL_FAILURE(InitState());
11077 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11078
11079 VkDescriptorPoolSize ds_type_count;
11080 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11081 ds_type_count.descriptorCount = 1;
11082
11083 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11084 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11085 ds_pool_ci.maxSets = 1;
11086 ds_pool_ci.poolSizeCount = 1;
11087 ds_pool_ci.pPoolSizes = &ds_type_count;
11088
11089 VkDescriptorPool ds_pool;
11090 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11091 ASSERT_VK_SUCCESS(err);
11092
11093 VkSamplerCreateInfo sampler_ci = {};
11094 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11095 sampler_ci.pNext = NULL;
11096 sampler_ci.magFilter = VK_FILTER_NEAREST;
11097 sampler_ci.minFilter = VK_FILTER_NEAREST;
11098 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11099 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11100 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11101 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11102 sampler_ci.mipLodBias = 1.0;
11103 sampler_ci.anisotropyEnable = VK_FALSE;
11104 sampler_ci.maxAnisotropy = 1;
11105 sampler_ci.compareEnable = VK_FALSE;
11106 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11107 sampler_ci.minLod = 1.0;
11108 sampler_ci.maxLod = 1.0;
11109 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11110 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11111 VkSampler sampler;
11112
11113 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11114 ASSERT_VK_SUCCESS(err);
11115
11116 VkDescriptorSetLayoutBinding layout_binding;
11117 layout_binding.binding = 0;
11118 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11119 layout_binding.descriptorCount = 1;
11120 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11121 layout_binding.pImmutableSamplers = NULL;
11122
11123 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11124 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11125 ds_layout_ci.bindingCount = 1;
11126 ds_layout_ci.pBindings = &layout_binding;
11127 VkDescriptorSetLayout ds_layout;
11128 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11129 ASSERT_VK_SUCCESS(err);
11130
11131 VkDescriptorSetAllocateInfo alloc_info = {};
11132 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11133 alloc_info.descriptorSetCount = 1;
11134 alloc_info.descriptorPool = ds_pool;
11135 alloc_info.pSetLayouts = &ds_layout;
11136 VkDescriptorSet descriptor_set;
11137 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11138 ASSERT_VK_SUCCESS(err);
11139
11140 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11141 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11142 pipeline_layout_ci.pNext = NULL;
11143 pipeline_layout_ci.setLayoutCount = 1;
11144 pipeline_layout_ci.pSetLayouts = &ds_layout;
11145
11146 VkPipelineLayout pipeline_layout;
11147 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11148 ASSERT_VK_SUCCESS(err);
11149
11150 VkImageObj image(m_device);
11151 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11152 ASSERT_TRUE(image.initialized());
11153
11154 VkImageView view;
11155 VkImageViewCreateInfo ivci = {};
11156 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11157 ivci.image = image.handle();
11158 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11159 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11160 ivci.subresourceRange.layerCount = 1;
11161 ivci.subresourceRange.baseMipLevel = 0;
11162 ivci.subresourceRange.levelCount = 1;
11163 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11164
11165 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11166 ASSERT_VK_SUCCESS(err);
11167
11168 VkDescriptorImageInfo image_info{};
11169 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11170 image_info.imageView = view;
11171 image_info.sampler = sampler;
11172
11173 VkWriteDescriptorSet descriptor_write = {};
11174 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11175 descriptor_write.dstSet = descriptor_set;
11176 descriptor_write.dstBinding = 0;
11177 descriptor_write.descriptorCount = 1;
11178 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11179 descriptor_write.pImageInfo = &image_info;
11180
11181 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11182
11183 // Create PSO to use the sampler
11184 char const *vsSource = "#version 450\n"
11185 "\n"
11186 "out gl_PerVertex { \n"
11187 " vec4 gl_Position;\n"
11188 "};\n"
11189 "void main(){\n"
11190 " gl_Position = vec4(1);\n"
11191 "}\n";
11192 char const *fsSource = "#version 450\n"
11193 "\n"
11194 "layout(set=0, binding=0) uniform sampler2D s;\n"
11195 "layout(location=0) out vec4 x;\n"
11196 "void main(){\n"
11197 " x = texture(s, vec2(1));\n"
11198 "}\n";
11199 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11200 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11201 VkPipelineObj pipe(m_device);
11202 pipe.AddShader(&vs);
11203 pipe.AddShader(&fs);
11204 pipe.AddColorAttachment();
11205 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11206
11207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11208
11209 BeginCommandBuffer();
11210 // Bind pipeline to cmd buffer
11211 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11212 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11213 &descriptor_set, 0, nullptr);
11214 Draw(1, 0, 0, 0);
11215 EndCommandBuffer();
11216 // Submit cmd buffer then destroy sampler
11217 VkSubmitInfo submit_info = {};
11218 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11219 submit_info.commandBufferCount = 1;
11220 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11221 // Submit cmd buffer and then destroy imageView while in-flight
11222 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11223
11224 vkDestroyImageView(m_device->device(), view, nullptr);
11225 m_errorMonitor->VerifyFound();
11226 vkQueueWaitIdle(m_device->m_queue);
11227 // Now we can actually destroy imageView
11228 vkDestroyImageView(m_device->device(), view, NULL);
11229 vkDestroySampler(m_device->device(), sampler, nullptr);
11230 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11231 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11232 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11233}
11234
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011235TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11236 TEST_DESCRIPTION("Delete in-use bufferView.");
11237
11238 ASSERT_NO_FATAL_FAILURE(InitState());
11239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11240
11241 VkDescriptorPoolSize ds_type_count;
11242 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11243 ds_type_count.descriptorCount = 1;
11244
11245 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11246 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11247 ds_pool_ci.maxSets = 1;
11248 ds_pool_ci.poolSizeCount = 1;
11249 ds_pool_ci.pPoolSizes = &ds_type_count;
11250
11251 VkDescriptorPool ds_pool;
11252 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11253 ASSERT_VK_SUCCESS(err);
11254
11255 VkDescriptorSetLayoutBinding layout_binding;
11256 layout_binding.binding = 0;
11257 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11258 layout_binding.descriptorCount = 1;
11259 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11260 layout_binding.pImmutableSamplers = NULL;
11261
11262 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11263 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11264 ds_layout_ci.bindingCount = 1;
11265 ds_layout_ci.pBindings = &layout_binding;
11266 VkDescriptorSetLayout ds_layout;
11267 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11268 ASSERT_VK_SUCCESS(err);
11269
11270 VkDescriptorSetAllocateInfo alloc_info = {};
11271 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11272 alloc_info.descriptorSetCount = 1;
11273 alloc_info.descriptorPool = ds_pool;
11274 alloc_info.pSetLayouts = &ds_layout;
11275 VkDescriptorSet descriptor_set;
11276 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11277 ASSERT_VK_SUCCESS(err);
11278
11279 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11280 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11281 pipeline_layout_ci.pNext = NULL;
11282 pipeline_layout_ci.setLayoutCount = 1;
11283 pipeline_layout_ci.pSetLayouts = &ds_layout;
11284
11285 VkPipelineLayout pipeline_layout;
11286 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11287 ASSERT_VK_SUCCESS(err);
11288
11289 VkBuffer buffer;
11290 uint32_t queue_family_index = 0;
11291 VkBufferCreateInfo buffer_create_info = {};
11292 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11293 buffer_create_info.size = 1024;
11294 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11295 buffer_create_info.queueFamilyIndexCount = 1;
11296 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11297
11298 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11299 ASSERT_VK_SUCCESS(err);
11300
11301 VkMemoryRequirements memory_reqs;
11302 VkDeviceMemory buffer_memory;
11303
11304 VkMemoryAllocateInfo memory_info = {};
11305 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11306 memory_info.allocationSize = 0;
11307 memory_info.memoryTypeIndex = 0;
11308
11309 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11310 memory_info.allocationSize = memory_reqs.size;
11311 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11312 ASSERT_TRUE(pass);
11313
11314 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11315 ASSERT_VK_SUCCESS(err);
11316 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11317 ASSERT_VK_SUCCESS(err);
11318
11319 VkBufferView view;
11320 VkBufferViewCreateInfo bvci = {};
11321 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11322 bvci.buffer = buffer;
11323 bvci.format = VK_FORMAT_R8_UNORM;
11324 bvci.range = VK_WHOLE_SIZE;
11325
11326 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11327 ASSERT_VK_SUCCESS(err);
11328
11329 VkWriteDescriptorSet descriptor_write = {};
11330 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11331 descriptor_write.dstSet = descriptor_set;
11332 descriptor_write.dstBinding = 0;
11333 descriptor_write.descriptorCount = 1;
11334 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11335 descriptor_write.pTexelBufferView = &view;
11336
11337 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11338
11339 char const *vsSource = "#version 450\n"
11340 "\n"
11341 "out gl_PerVertex { \n"
11342 " vec4 gl_Position;\n"
11343 "};\n"
11344 "void main(){\n"
11345 " gl_Position = vec4(1);\n"
11346 "}\n";
11347 char const *fsSource = "#version 450\n"
11348 "\n"
11349 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11350 "layout(location=0) out vec4 x;\n"
11351 "void main(){\n"
11352 " x = imageLoad(s, 0);\n"
11353 "}\n";
11354 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11355 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11356 VkPipelineObj pipe(m_device);
11357 pipe.AddShader(&vs);
11358 pipe.AddShader(&fs);
11359 pipe.AddColorAttachment();
11360 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11361
11362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11363
11364 BeginCommandBuffer();
11365 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11366 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11367 VkRect2D scissor = {{0, 0}, {16, 16}};
11368 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11369 // Bind pipeline to cmd buffer
11370 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11371 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11372 &descriptor_set, 0, nullptr);
11373 Draw(1, 0, 0, 0);
11374 EndCommandBuffer();
11375
11376 VkSubmitInfo submit_info = {};
11377 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11378 submit_info.commandBufferCount = 1;
11379 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11380 // Submit cmd buffer and then destroy bufferView while in-flight
11381 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11382
11383 vkDestroyBufferView(m_device->device(), view, nullptr);
11384 m_errorMonitor->VerifyFound();
11385 vkQueueWaitIdle(m_device->m_queue);
11386 // Now we can actually destroy bufferView
11387 vkDestroyBufferView(m_device->device(), view, NULL);
11388 vkDestroyBuffer(m_device->device(), buffer, NULL);
11389 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11390 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11391 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11392 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11393}
11394
Tobin Ehlis209532e2016-09-07 13:52:18 -060011395TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11396 TEST_DESCRIPTION("Delete in-use sampler.");
11397
11398 ASSERT_NO_FATAL_FAILURE(InitState());
11399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11400
11401 VkDescriptorPoolSize ds_type_count;
11402 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11403 ds_type_count.descriptorCount = 1;
11404
11405 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11406 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11407 ds_pool_ci.maxSets = 1;
11408 ds_pool_ci.poolSizeCount = 1;
11409 ds_pool_ci.pPoolSizes = &ds_type_count;
11410
11411 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011412 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011413 ASSERT_VK_SUCCESS(err);
11414
11415 VkSamplerCreateInfo sampler_ci = {};
11416 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11417 sampler_ci.pNext = NULL;
11418 sampler_ci.magFilter = VK_FILTER_NEAREST;
11419 sampler_ci.minFilter = VK_FILTER_NEAREST;
11420 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11421 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11422 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11423 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11424 sampler_ci.mipLodBias = 1.0;
11425 sampler_ci.anisotropyEnable = VK_FALSE;
11426 sampler_ci.maxAnisotropy = 1;
11427 sampler_ci.compareEnable = VK_FALSE;
11428 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11429 sampler_ci.minLod = 1.0;
11430 sampler_ci.maxLod = 1.0;
11431 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11432 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11433 VkSampler sampler;
11434
11435 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11436 ASSERT_VK_SUCCESS(err);
11437
11438 VkDescriptorSetLayoutBinding layout_binding;
11439 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011440 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011441 layout_binding.descriptorCount = 1;
11442 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11443 layout_binding.pImmutableSamplers = NULL;
11444
11445 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11446 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11447 ds_layout_ci.bindingCount = 1;
11448 ds_layout_ci.pBindings = &layout_binding;
11449 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011450 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011451 ASSERT_VK_SUCCESS(err);
11452
11453 VkDescriptorSetAllocateInfo alloc_info = {};
11454 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11455 alloc_info.descriptorSetCount = 1;
11456 alloc_info.descriptorPool = ds_pool;
11457 alloc_info.pSetLayouts = &ds_layout;
11458 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011460 ASSERT_VK_SUCCESS(err);
11461
11462 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11463 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11464 pipeline_layout_ci.pNext = NULL;
11465 pipeline_layout_ci.setLayoutCount = 1;
11466 pipeline_layout_ci.pSetLayouts = &ds_layout;
11467
11468 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011469 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011470 ASSERT_VK_SUCCESS(err);
11471
11472 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011473 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 -060011474 ASSERT_TRUE(image.initialized());
11475
11476 VkImageView view;
11477 VkImageViewCreateInfo ivci = {};
11478 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11479 ivci.image = image.handle();
11480 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11481 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11482 ivci.subresourceRange.layerCount = 1;
11483 ivci.subresourceRange.baseMipLevel = 0;
11484 ivci.subresourceRange.levelCount = 1;
11485 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11486
11487 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11488 ASSERT_VK_SUCCESS(err);
11489
11490 VkDescriptorImageInfo image_info{};
11491 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11492 image_info.imageView = view;
11493 image_info.sampler = sampler;
11494
11495 VkWriteDescriptorSet descriptor_write = {};
11496 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11497 descriptor_write.dstSet = descriptor_set;
11498 descriptor_write.dstBinding = 0;
11499 descriptor_write.descriptorCount = 1;
11500 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11501 descriptor_write.pImageInfo = &image_info;
11502
11503 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11504
11505 // Create PSO to use the sampler
11506 char const *vsSource = "#version 450\n"
11507 "\n"
11508 "out gl_PerVertex { \n"
11509 " vec4 gl_Position;\n"
11510 "};\n"
11511 "void main(){\n"
11512 " gl_Position = vec4(1);\n"
11513 "}\n";
11514 char const *fsSource = "#version 450\n"
11515 "\n"
11516 "layout(set=0, binding=0) uniform sampler2D s;\n"
11517 "layout(location=0) out vec4 x;\n"
11518 "void main(){\n"
11519 " x = texture(s, vec2(1));\n"
11520 "}\n";
11521 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11522 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11523 VkPipelineObj pipe(m_device);
11524 pipe.AddShader(&vs);
11525 pipe.AddShader(&fs);
11526 pipe.AddColorAttachment();
11527 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011530
11531 BeginCommandBuffer();
11532 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011533 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11534 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11535 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011536 Draw(1, 0, 0, 0);
11537 EndCommandBuffer();
11538 // Submit cmd buffer then destroy sampler
11539 VkSubmitInfo submit_info = {};
11540 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11541 submit_info.commandBufferCount = 1;
11542 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11543 // Submit cmd buffer and then destroy sampler while in-flight
11544 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11545
11546 vkDestroySampler(m_device->device(), sampler, nullptr);
11547 m_errorMonitor->VerifyFound();
11548 vkQueueWaitIdle(m_device->m_queue);
11549 // Now we can actually destroy sampler
11550 vkDestroySampler(m_device->device(), sampler, nullptr);
11551 vkDestroyImageView(m_device->device(), view, NULL);
11552 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11553 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11554 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11555}
11556
Mark Mueller1cd9f412016-08-25 13:23:52 -060011557TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011558 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011559 "signaled but not waited on by the queue. Wait on a "
11560 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011561
11562 ASSERT_NO_FATAL_FAILURE(InitState());
11563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11564
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011565 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11566 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11567 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011568
11569 BeginCommandBuffer();
11570 EndCommandBuffer();
11571
11572 VkSemaphoreCreateInfo semaphore_create_info = {};
11573 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11574 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011575 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011576 VkSubmitInfo submit_info = {};
11577 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11578 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011579 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011580 submit_info.signalSemaphoreCount = 1;
11581 submit_info.pSignalSemaphores = &semaphore;
11582 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11583 m_errorMonitor->SetDesiredFailureMsg(0, "");
11584 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11585 BeginCommandBuffer();
11586 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011588 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11589 m_errorMonitor->VerifyFound();
11590
Mark Mueller1cd9f412016-08-25 13:23:52 -060011591 VkFenceCreateInfo fence_create_info = {};
11592 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11593 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011594 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011597 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11598 m_errorMonitor->VerifyFound();
11599
Mark Mueller4042b652016-09-05 22:52:21 -060011600 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011601 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011602 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11603}
11604
Tobin Ehlis4af23302016-07-19 10:50:30 -060011605TEST_F(VkLayerTest, FramebufferIncompatible) {
11606 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11607 "that does not match the framebuffer for the active "
11608 "renderpass.");
11609 ASSERT_NO_FATAL_FAILURE(InitState());
11610 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11611
11612 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011613 VkAttachmentDescription attachment = {0,
11614 VK_FORMAT_B8G8R8A8_UNORM,
11615 VK_SAMPLE_COUNT_1_BIT,
11616 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11617 VK_ATTACHMENT_STORE_OP_STORE,
11618 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11619 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11620 VK_IMAGE_LAYOUT_UNDEFINED,
11621 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011623 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011624
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011625 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011626
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011627 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011628
11629 VkRenderPass rp;
11630 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11631 ASSERT_VK_SUCCESS(err);
11632
11633 // A compatible framebuffer.
11634 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011635 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 -060011636 ASSERT_TRUE(image.initialized());
11637
11638 VkImageViewCreateInfo ivci = {
11639 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11640 nullptr,
11641 0,
11642 image.handle(),
11643 VK_IMAGE_VIEW_TYPE_2D,
11644 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011645 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11646 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011647 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11648 };
11649 VkImageView view;
11650 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11651 ASSERT_VK_SUCCESS(err);
11652
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011653 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011654 VkFramebuffer fb;
11655 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11656 ASSERT_VK_SUCCESS(err);
11657
11658 VkCommandBufferAllocateInfo cbai = {};
11659 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11660 cbai.commandPool = m_commandPool;
11661 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11662 cbai.commandBufferCount = 1;
11663
11664 VkCommandBuffer sec_cb;
11665 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11666 ASSERT_VK_SUCCESS(err);
11667 VkCommandBufferBeginInfo cbbi = {};
11668 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011669 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011670 cbii.renderPass = renderPass();
11671 cbii.framebuffer = fb;
11672 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11673 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011674 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 -060011675 cbbi.pInheritanceInfo = &cbii;
11676 vkBeginCommandBuffer(sec_cb, &cbbi);
11677 vkEndCommandBuffer(sec_cb);
11678
Chris Forbes3400bc52016-09-13 18:10:34 +120011679 VkCommandBufferBeginInfo cbbi2 = {
11680 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11681 0, nullptr
11682 };
11683 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11684 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011685
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011687 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011688 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11689 m_errorMonitor->VerifyFound();
11690 // Cleanup
11691 vkDestroyImageView(m_device->device(), view, NULL);
11692 vkDestroyRenderPass(m_device->device(), rp, NULL);
11693 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11694}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011695
11696TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11697 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11698 "invalid value. If logicOp is not available, attempt to "
11699 "use it and verify that we see the correct error.");
11700 ASSERT_NO_FATAL_FAILURE(InitState());
11701 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11702
11703 auto features = m_device->phy().features();
11704 // Set the expected error depending on whether or not logicOp available
11705 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11707 "enabled, logicOpEnable must be "
11708 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011709 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011711 }
11712 // Create a pipeline using logicOp
11713 VkResult err;
11714
11715 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11716 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11717
11718 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011719 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011720 ASSERT_VK_SUCCESS(err);
11721
11722 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11723 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11724 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011725 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011726 vp_state_ci.pViewports = &vp;
11727 vp_state_ci.scissorCount = 1;
11728 VkRect2D scissors = {}; // Dummy scissors to point to
11729 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011730
11731 VkPipelineShaderStageCreateInfo shaderStages[2];
11732 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11733
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011734 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11735 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011736 shaderStages[0] = vs.GetStageCreateInfo();
11737 shaderStages[1] = fs.GetStageCreateInfo();
11738
11739 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11740 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11741
11742 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11743 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11744 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11745
11746 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11747 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011748 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011749
11750 VkPipelineColorBlendAttachmentState att = {};
11751 att.blendEnable = VK_FALSE;
11752 att.colorWriteMask = 0xf;
11753
11754 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11755 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11756 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11757 cb_ci.logicOpEnable = VK_TRUE;
11758 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11759 cb_ci.attachmentCount = 1;
11760 cb_ci.pAttachments = &att;
11761
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011762 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11763 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11764 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11765
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011766 VkGraphicsPipelineCreateInfo gp_ci = {};
11767 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11768 gp_ci.stageCount = 2;
11769 gp_ci.pStages = shaderStages;
11770 gp_ci.pVertexInputState = &vi_ci;
11771 gp_ci.pInputAssemblyState = &ia_ci;
11772 gp_ci.pViewportState = &vp_state_ci;
11773 gp_ci.pRasterizationState = &rs_ci;
11774 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011775 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011776 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11777 gp_ci.layout = pipeline_layout;
11778 gp_ci.renderPass = renderPass();
11779
11780 VkPipelineCacheCreateInfo pc_ci = {};
11781 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11782
11783 VkPipeline pipeline;
11784 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011785 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011786 ASSERT_VK_SUCCESS(err);
11787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011788 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011789 m_errorMonitor->VerifyFound();
11790 if (VK_SUCCESS == err) {
11791 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11792 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011793 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11794 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11795}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011796#endif // DRAW_STATE_TESTS
11797
Tobin Ehlis0788f522015-05-26 16:11:58 -060011798#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011799#if GTEST_IS_THREADSAFE
11800struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011801 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011802 VkEvent event;
11803 bool bailout;
11804};
11805
Karl Schultz6addd812016-02-02 17:17:23 -070011806extern "C" void *AddToCommandBuffer(void *arg) {
11807 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011808
Mike Stroyana6d14942016-07-13 15:10:05 -060011809 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011810 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011811 if (data->bailout) {
11812 break;
11813 }
11814 }
11815 return NULL;
11816}
11817
Karl Schultz6addd812016-02-02 17:17:23 -070011818TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011819 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011822
Mike Stroyanaccf7692015-05-12 16:00:45 -060011823 ASSERT_NO_FATAL_FAILURE(InitState());
11824 ASSERT_NO_FATAL_FAILURE(InitViewport());
11825 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11826
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011827 // Calls AllocateCommandBuffers
11828 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011829
11830 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011831 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011832
11833 VkEventCreateInfo event_info;
11834 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011835 VkResult err;
11836
11837 memset(&event_info, 0, sizeof(event_info));
11838 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11839
Chia-I Wuf7458c52015-10-26 21:10:41 +080011840 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011841 ASSERT_VK_SUCCESS(err);
11842
Mike Stroyanaccf7692015-05-12 16:00:45 -060011843 err = vkResetEvent(device(), event);
11844 ASSERT_VK_SUCCESS(err);
11845
11846 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011847 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011848 data.event = event;
11849 data.bailout = false;
11850 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011851
11852 // First do some correct operations using multiple threads.
11853 // Add many entries to command buffer from another thread.
11854 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11855 // Make non-conflicting calls from this thread at the same time.
11856 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011857 uint32_t count;
11858 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011859 }
11860 test_platform_thread_join(thread, NULL);
11861
11862 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011863 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011864 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011865 // Add many entries to command buffer from this thread at the same time.
11866 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011867
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011868 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011869 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011870
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011871 m_errorMonitor->SetBailout(NULL);
11872
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011873 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011874
Chia-I Wuf7458c52015-10-26 21:10:41 +080011875 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011876}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011877#endif // GTEST_IS_THREADSAFE
11878#endif // THREADING_TESTS
11879
Chris Forbes9f7ff632015-05-25 11:13:08 +120011880#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011881TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011882 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11883 "with an impossible code size");
11884
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011886
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011887 ASSERT_NO_FATAL_FAILURE(InitState());
11888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11889
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011890 VkShaderModule module;
11891 VkShaderModuleCreateInfo moduleCreateInfo;
11892 struct icd_spv_header spv;
11893
11894 spv.magic = ICD_SPV_MAGIC;
11895 spv.version = ICD_SPV_VERSION;
11896 spv.gen_magic = 0;
11897
11898 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11899 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011900 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011901 moduleCreateInfo.codeSize = 4;
11902 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011903 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011904
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011905 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011906}
11907
Karl Schultz6addd812016-02-02 17:17:23 -070011908TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011909 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11910 "with a bad magic number");
11911
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011913
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011914 ASSERT_NO_FATAL_FAILURE(InitState());
11915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11916
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011917 VkShaderModule module;
11918 VkShaderModuleCreateInfo moduleCreateInfo;
11919 struct icd_spv_header spv;
11920
11921 spv.magic = ~ICD_SPV_MAGIC;
11922 spv.version = ICD_SPV_VERSION;
11923 spv.gen_magic = 0;
11924
11925 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11926 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011927 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011928 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11929 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011930 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011931
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011932 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011933}
11934
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011935#if 0
11936// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011937TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011939 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011940
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011941 ASSERT_NO_FATAL_FAILURE(InitState());
11942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11943
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011944 VkShaderModule module;
11945 VkShaderModuleCreateInfo moduleCreateInfo;
11946 struct icd_spv_header spv;
11947
11948 spv.magic = ICD_SPV_MAGIC;
11949 spv.version = ~ICD_SPV_VERSION;
11950 spv.gen_magic = 0;
11951
11952 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11953 moduleCreateInfo.pNext = NULL;
11954
Karl Schultz6addd812016-02-02 17:17:23 -070011955 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011956 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11957 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011958 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011959
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011960 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011961}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011962#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011963
Karl Schultz6addd812016-02-02 17:17:23 -070011964TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011965 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11966 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011968
Chris Forbes9f7ff632015-05-25 11:13:08 +120011969 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011972 char const *vsSource = "#version 450\n"
11973 "\n"
11974 "layout(location=0) out float x;\n"
11975 "out gl_PerVertex {\n"
11976 " vec4 gl_Position;\n"
11977 "};\n"
11978 "void main(){\n"
11979 " gl_Position = vec4(1);\n"
11980 " x = 0;\n"
11981 "}\n";
11982 char const *fsSource = "#version 450\n"
11983 "\n"
11984 "layout(location=0) out vec4 color;\n"
11985 "void main(){\n"
11986 " color = vec4(1);\n"
11987 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011988
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011989 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11990 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011991
11992 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011993 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011994 pipe.AddShader(&vs);
11995 pipe.AddShader(&fs);
11996
Chris Forbes9f7ff632015-05-25 11:13:08 +120011997 VkDescriptorSetObj descriptorSet(m_device);
11998 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011999 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012000
Tony Barbour5781e8f2015-08-04 16:23:11 -060012001 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012002
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012003 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012004}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012005
Mark Mueller098c9cb2016-09-08 09:01:57 -060012006TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12007 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12008
12009 ASSERT_NO_FATAL_FAILURE(InitState());
12010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12011
12012 const char *bad_specialization_message =
12013 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12014
12015 char const *vsSource =
12016 "#version 450\n"
12017 "\n"
12018 "out gl_PerVertex {\n"
12019 " vec4 gl_Position;\n"
12020 "};\n"
12021 "void main(){\n"
12022 " gl_Position = vec4(1);\n"
12023 "}\n";
12024
12025 char const *fsSource =
12026 "#version 450\n"
12027 "\n"
12028 "layout (constant_id = 0) const float r = 0.0f;\n"
12029 "layout(location = 0) out vec4 uFragColor;\n"
12030 "void main(){\n"
12031 " uFragColor = vec4(r,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
12040 VkPipelineLayout pipeline_layout;
12041 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12042
12043 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12044 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12045 vp_state_create_info.viewportCount = 1;
12046 VkViewport viewport = {};
12047 vp_state_create_info.pViewports = &viewport;
12048 vp_state_create_info.scissorCount = 1;
12049 VkRect2D scissors = {};
12050 vp_state_create_info.pScissors = &scissors;
12051
12052 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12053
12054 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12055 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12056 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12057 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12058
12059 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12060 vs.GetStageCreateInfo(),
12061 fs.GetStageCreateInfo()
12062 };
12063
12064 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12065 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12066
12067 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12068 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12069 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12070
12071 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12072 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12073 rasterization_state_create_info.pNext = nullptr;
12074 rasterization_state_create_info.lineWidth = 1.0f;
12075 rasterization_state_create_info.rasterizerDiscardEnable = true;
12076
12077 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12078 color_blend_attachment_state.blendEnable = VK_FALSE;
12079 color_blend_attachment_state.colorWriteMask = 0xf;
12080
12081 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12082 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12083 color_blend_state_create_info.attachmentCount = 1;
12084 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12085
12086 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12087 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12088 graphicspipe_create_info.stageCount = 2;
12089 graphicspipe_create_info.pStages = shader_stage_create_info;
12090 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12091 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12092 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12093 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12094 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12095 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12096 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12097 graphicspipe_create_info.layout = pipeline_layout;
12098 graphicspipe_create_info.renderPass = renderPass();
12099
12100 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12101 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12102
12103 VkPipelineCache pipelineCache;
12104 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12105
12106 // This structure maps constant ids to data locations.
12107 const VkSpecializationMapEntry entry =
12108 // id, offset, size
12109 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12110
12111 uint32_t data = 1;
12112
12113 // Set up the info describing spec map and data
12114 const VkSpecializationInfo specialization_info = {
12115 1,
12116 &entry,
12117 1 * sizeof(float),
12118 &data,
12119 };
12120 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12121
12122 VkPipeline pipeline;
12123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12124 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12125 m_errorMonitor->VerifyFound();
12126
12127 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12128 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12129}
12130
12131TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12132 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12133
12134 ASSERT_NO_FATAL_FAILURE(InitState());
12135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12136
12137 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12138
12139 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12140 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12141 descriptor_pool_type_count[0].descriptorCount = 1;
12142 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12143 descriptor_pool_type_count[1].descriptorCount = 1;
12144
12145 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12146 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12147 descriptor_pool_create_info.maxSets = 1;
12148 descriptor_pool_create_info.poolSizeCount = 2;
12149 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12150 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12151
12152 VkDescriptorPool descriptorset_pool;
12153 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12154
12155 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12156 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12157 descriptorset_layout_binding.descriptorCount = 1;
12158 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12159
12160 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12161 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12162 descriptorset_layout_create_info.bindingCount = 1;
12163 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12164
12165 VkDescriptorSetLayout descriptorset_layout;
12166 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12167
12168 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12169 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12170 descriptorset_allocate_info.descriptorSetCount = 1;
12171 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12172 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12173 VkDescriptorSet descriptorset;
12174 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12175
12176 // Challenge core_validation with a non uniform buffer type.
12177 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12178
Mark Mueller098c9cb2016-09-08 09:01:57 -060012179 char const *vsSource =
12180 "#version 450\n"
12181 "\n"
12182 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12183 " mat4 mvp;\n"
12184 "} ubuf;\n"
12185 "out gl_PerVertex {\n"
12186 " vec4 gl_Position;\n"
12187 "};\n"
12188 "void main(){\n"
12189 " gl_Position = ubuf.mvp * vec4(1);\n"
12190 "}\n";
12191
12192 char const *fsSource =
12193 "#version 450\n"
12194 "\n"
12195 "layout(location = 0) out vec4 uFragColor;\n"
12196 "void main(){\n"
12197 " uFragColor = vec4(0,1,0,1);\n"
12198 "}\n";
12199
12200 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12201 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12202
12203 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12204 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12205 pipeline_layout_create_info.setLayoutCount = 1;
12206 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12207
12208 VkPipelineLayout pipeline_layout;
12209 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12210
12211 VkPipelineObj pipe(m_device);
12212 pipe.AddColorAttachment();
12213 pipe.AddShader(&vs);
12214 pipe.AddShader(&fs);
12215
12216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12217 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12218 m_errorMonitor->VerifyFound();
12219
12220 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12221 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12222 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12223}
12224
12225TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12226 TEST_DESCRIPTION(
12227 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12228
12229 ASSERT_NO_FATAL_FAILURE(InitState());
12230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12231
12232 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12233
12234 VkDescriptorPoolSize descriptor_pool_type_count = {};
12235 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12236 descriptor_pool_type_count.descriptorCount = 1;
12237
12238 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12239 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12240 descriptor_pool_create_info.maxSets = 1;
12241 descriptor_pool_create_info.poolSizeCount = 1;
12242 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12243 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12244
12245 VkDescriptorPool descriptorset_pool;
12246 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12247
12248 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12249 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12250 descriptorset_layout_binding.descriptorCount = 1;
12251 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12252 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12253
12254 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12255 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12256 descriptorset_layout_create_info.bindingCount = 1;
12257 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12258
12259 VkDescriptorSetLayout descriptorset_layout;
12260 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12261 nullptr, &descriptorset_layout));
12262
12263 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12264 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12265 descriptorset_allocate_info.descriptorSetCount = 1;
12266 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12267 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12268 VkDescriptorSet descriptorset;
12269 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12270
12271 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12272
Mark Mueller098c9cb2016-09-08 09:01:57 -060012273 char const *vsSource =
12274 "#version 450\n"
12275 "\n"
12276 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12277 " mat4 mvp;\n"
12278 "} ubuf;\n"
12279 "out gl_PerVertex {\n"
12280 " vec4 gl_Position;\n"
12281 "};\n"
12282 "void main(){\n"
12283 " gl_Position = ubuf.mvp * vec4(1);\n"
12284 "}\n";
12285
12286 char const *fsSource =
12287 "#version 450\n"
12288 "\n"
12289 "layout(location = 0) out vec4 uFragColor;\n"
12290 "void main(){\n"
12291 " uFragColor = vec4(0,1,0,1);\n"
12292 "}\n";
12293
12294 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12295 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12296
12297 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12298 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12299 pipeline_layout_create_info.setLayoutCount = 1;
12300 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12301
12302 VkPipelineLayout pipeline_layout;
12303 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12304
12305 VkPipelineObj pipe(m_device);
12306 pipe.AddColorAttachment();
12307 pipe.AddShader(&vs);
12308 pipe.AddShader(&fs);
12309
12310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12311 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12312 m_errorMonitor->VerifyFound();
12313
12314 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12315 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12316 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12317}
12318
12319TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12320 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12321 "accessible from the current shader stage.");
12322
12323 ASSERT_NO_FATAL_FAILURE(InitState());
12324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12325
12326 const char *push_constant_not_accessible_message =
12327 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12328
12329 char const *vsSource =
12330 "#version 450\n"
12331 "\n"
12332 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12333 "out gl_PerVertex {\n"
12334 " vec4 gl_Position;\n"
12335 "};\n"
12336 "void main(){\n"
12337 " gl_Position = vec4(consts.x);\n"
12338 "}\n";
12339
12340 char const *fsSource =
12341 "#version 450\n"
12342 "\n"
12343 "layout(location = 0) out vec4 uFragColor;\n"
12344 "void main(){\n"
12345 " uFragColor = vec4(0,1,0,1);\n"
12346 "}\n";
12347
12348 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12349 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12350
12351 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12352 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12353
12354 // Set up a push constant range
12355 VkPushConstantRange push_constant_ranges = {};
12356 // Set to the wrong stage to challenge core_validation
12357 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12358 push_constant_ranges.size = 4;
12359
12360 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12361 pipeline_layout_create_info.pushConstantRangeCount = 1;
12362
12363 VkPipelineLayout pipeline_layout;
12364 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12365
12366 VkPipelineObj pipe(m_device);
12367 pipe.AddColorAttachment();
12368 pipe.AddShader(&vs);
12369 pipe.AddShader(&fs);
12370
12371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12372 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12373 m_errorMonitor->VerifyFound();
12374
12375 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12376}
12377
12378TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12379 TEST_DESCRIPTION(
12380 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12381
12382 ASSERT_NO_FATAL_FAILURE(InitState());
12383 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12384
12385 const char *feature_not_enabled_message =
12386 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12387
12388 // Some awkward steps are required to test with custom device features.
12389 std::vector<const char *> device_extension_names;
12390 auto features = m_device->phy().features();
12391 // Disable support for 64 bit floats
12392 features.shaderFloat64 = false;
12393 // The sacrificial device object
12394 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12395
12396 char const *vsSource = "#version 450\n"
12397 "\n"
12398 "out gl_PerVertex {\n"
12399 " vec4 gl_Position;\n"
12400 "};\n"
12401 "void main(){\n"
12402 " gl_Position = vec4(1);\n"
12403 "}\n";
12404 char const *fsSource = "#version 450\n"
12405 "\n"
12406 "layout(location=0) out vec4 color;\n"
12407 "void main(){\n"
12408 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12409 " color = vec4(green);\n"
12410 "}\n";
12411
12412 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12413 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12414
12415 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012416
12417 VkPipelineObj pipe(&test_device);
12418 pipe.AddColorAttachment();
12419 pipe.AddShader(&vs);
12420 pipe.AddShader(&fs);
12421
12422 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12423 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12424 VkPipelineLayout pipeline_layout;
12425 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12426
12427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12428 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12429 m_errorMonitor->VerifyFound();
12430
12431 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12432}
12433
12434TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12435 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12436
12437 ASSERT_NO_FATAL_FAILURE(InitState());
12438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12439
12440 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12441
12442 char const *vsSource = "#version 450\n"
12443 "\n"
12444 "out gl_PerVertex {\n"
12445 " vec4 gl_Position;\n"
12446 "};\n"
12447 "layout(xfb_buffer = 1) out;"
12448 "void main(){\n"
12449 " gl_Position = vec4(1);\n"
12450 "}\n";
12451 char const *fsSource = "#version 450\n"
12452 "\n"
12453 "layout(location=0) out vec4 color;\n"
12454 "void main(){\n"
12455 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12456 " color = vec4(green);\n"
12457 "}\n";
12458
12459 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12460 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12461
12462 VkPipelineObj pipe(m_device);
12463 pipe.AddColorAttachment();
12464 pipe.AddShader(&vs);
12465 pipe.AddShader(&fs);
12466
12467 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12468 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12469 VkPipelineLayout pipeline_layout;
12470 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12471
12472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12473 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12474 m_errorMonitor->VerifyFound();
12475
12476 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12477}
12478
Karl Schultz6addd812016-02-02 17:17:23 -070012479TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012480 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12481 "which is not present in the outputs of the previous stage");
12482
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012484
Chris Forbes59cb88d2015-05-25 11:13:13 +120012485 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012488 char const *vsSource = "#version 450\n"
12489 "\n"
12490 "out gl_PerVertex {\n"
12491 " vec4 gl_Position;\n"
12492 "};\n"
12493 "void main(){\n"
12494 " gl_Position = vec4(1);\n"
12495 "}\n";
12496 char const *fsSource = "#version 450\n"
12497 "\n"
12498 "layout(location=0) in float x;\n"
12499 "layout(location=0) out vec4 color;\n"
12500 "void main(){\n"
12501 " color = vec4(x);\n"
12502 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012503
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012504 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12505 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012506
12507 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012508 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012509 pipe.AddShader(&vs);
12510 pipe.AddShader(&fs);
12511
Chris Forbes59cb88d2015-05-25 11:13:13 +120012512 VkDescriptorSetObj descriptorSet(m_device);
12513 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012514 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012515
Tony Barbour5781e8f2015-08-04 16:23:11 -060012516 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012517
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012518 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012519}
12520
Karl Schultz6addd812016-02-02 17:17:23 -070012521TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012522 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12523 "within an interace block, which is not present in the outputs "
12524 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012526
12527 ASSERT_NO_FATAL_FAILURE(InitState());
12528 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12529
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012530 char const *vsSource = "#version 450\n"
12531 "\n"
12532 "out gl_PerVertex {\n"
12533 " vec4 gl_Position;\n"
12534 "};\n"
12535 "void main(){\n"
12536 " gl_Position = vec4(1);\n"
12537 "}\n";
12538 char const *fsSource = "#version 450\n"
12539 "\n"
12540 "in block { layout(location=0) float x; } ins;\n"
12541 "layout(location=0) out vec4 color;\n"
12542 "void main(){\n"
12543 " color = vec4(ins.x);\n"
12544 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012545
12546 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12547 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12548
12549 VkPipelineObj pipe(m_device);
12550 pipe.AddColorAttachment();
12551 pipe.AddShader(&vs);
12552 pipe.AddShader(&fs);
12553
12554 VkDescriptorSetObj descriptorSet(m_device);
12555 descriptorSet.AppendDummy();
12556 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12557
12558 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12559
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012560 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012561}
12562
Karl Schultz6addd812016-02-02 17:17:23 -070012563TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012564 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012565 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12567 "output arr[2] of float32' vs 'ptr to "
12568 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012569
12570 ASSERT_NO_FATAL_FAILURE(InitState());
12571 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012573 char const *vsSource = "#version 450\n"
12574 "\n"
12575 "layout(location=0) out float x[2];\n"
12576 "out gl_PerVertex {\n"
12577 " vec4 gl_Position;\n"
12578 "};\n"
12579 "void main(){\n"
12580 " x[0] = 0; x[1] = 0;\n"
12581 " gl_Position = vec4(1);\n"
12582 "}\n";
12583 char const *fsSource = "#version 450\n"
12584 "\n"
12585 "layout(location=0) in float x[3];\n"
12586 "layout(location=0) out vec4 color;\n"
12587 "void main(){\n"
12588 " color = vec4(x[0] + x[1] + x[2]);\n"
12589 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012590
12591 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12592 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12593
12594 VkPipelineObj pipe(m_device);
12595 pipe.AddColorAttachment();
12596 pipe.AddShader(&vs);
12597 pipe.AddShader(&fs);
12598
12599 VkDescriptorSetObj descriptorSet(m_device);
12600 descriptorSet.AppendDummy();
12601 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12602
12603 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12604
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012605 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012606}
12607
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012608
Karl Schultz6addd812016-02-02 17:17:23 -070012609TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012610 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012611 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012613
Chris Forbesb56af562015-05-25 11:13:17 +120012614 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012617 char const *vsSource = "#version 450\n"
12618 "\n"
12619 "layout(location=0) out int x;\n"
12620 "out gl_PerVertex {\n"
12621 " vec4 gl_Position;\n"
12622 "};\n"
12623 "void main(){\n"
12624 " x = 0;\n"
12625 " gl_Position = vec4(1);\n"
12626 "}\n";
12627 char const *fsSource = "#version 450\n"
12628 "\n"
12629 "layout(location=0) in float x;\n" /* VS writes int */
12630 "layout(location=0) out vec4 color;\n"
12631 "void main(){\n"
12632 " color = vec4(x);\n"
12633 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012634
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012635 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12636 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012637
12638 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012639 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012640 pipe.AddShader(&vs);
12641 pipe.AddShader(&fs);
12642
Chris Forbesb56af562015-05-25 11:13:17 +120012643 VkDescriptorSetObj descriptorSet(m_device);
12644 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012645 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012646
Tony Barbour5781e8f2015-08-04 16:23:11 -060012647 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012648
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012649 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012650}
12651
Karl Schultz6addd812016-02-02 17:17:23 -070012652TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012653 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012654 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012655 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012657
12658 ASSERT_NO_FATAL_FAILURE(InitState());
12659 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12660
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012661 char const *vsSource = "#version 450\n"
12662 "\n"
12663 "out block { layout(location=0) int x; } outs;\n"
12664 "out gl_PerVertex {\n"
12665 " vec4 gl_Position;\n"
12666 "};\n"
12667 "void main(){\n"
12668 " outs.x = 0;\n"
12669 " gl_Position = vec4(1);\n"
12670 "}\n";
12671 char const *fsSource = "#version 450\n"
12672 "\n"
12673 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12674 "layout(location=0) out vec4 color;\n"
12675 "void main(){\n"
12676 " color = vec4(ins.x);\n"
12677 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012678
12679 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12680 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12681
12682 VkPipelineObj pipe(m_device);
12683 pipe.AddColorAttachment();
12684 pipe.AddShader(&vs);
12685 pipe.AddShader(&fs);
12686
12687 VkDescriptorSetObj descriptorSet(m_device);
12688 descriptorSet.AppendDummy();
12689 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12690
12691 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12692
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012693 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012694}
12695
12696TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012697 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012698 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012699 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012700 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 +130012701
12702 ASSERT_NO_FATAL_FAILURE(InitState());
12703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012705 char const *vsSource = "#version 450\n"
12706 "\n"
12707 "out block { layout(location=1) float x; } outs;\n"
12708 "out gl_PerVertex {\n"
12709 " vec4 gl_Position;\n"
12710 "};\n"
12711 "void main(){\n"
12712 " outs.x = 0;\n"
12713 " gl_Position = vec4(1);\n"
12714 "}\n";
12715 char const *fsSource = "#version 450\n"
12716 "\n"
12717 "in block { layout(location=0) float x; } ins;\n"
12718 "layout(location=0) out vec4 color;\n"
12719 "void main(){\n"
12720 " color = vec4(ins.x);\n"
12721 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012722
12723 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12724 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12725
12726 VkPipelineObj pipe(m_device);
12727 pipe.AddColorAttachment();
12728 pipe.AddShader(&vs);
12729 pipe.AddShader(&fs);
12730
12731 VkDescriptorSetObj descriptorSet(m_device);
12732 descriptorSet.AppendDummy();
12733 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12734
12735 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12736
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012737 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012738}
12739
12740TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012741 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012742 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012743 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012744 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 +130012745
12746 ASSERT_NO_FATAL_FAILURE(InitState());
12747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012749 char const *vsSource = "#version 450\n"
12750 "\n"
12751 "out block { layout(location=0, component=0) float x; } outs;\n"
12752 "out gl_PerVertex {\n"
12753 " vec4 gl_Position;\n"
12754 "};\n"
12755 "void main(){\n"
12756 " outs.x = 0;\n"
12757 " gl_Position = vec4(1);\n"
12758 "}\n";
12759 char const *fsSource = "#version 450\n"
12760 "\n"
12761 "in block { layout(location=0, component=1) float x; } ins;\n"
12762 "layout(location=0) out vec4 color;\n"
12763 "void main(){\n"
12764 " color = vec4(ins.x);\n"
12765 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012766
12767 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12768 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12769
12770 VkPipelineObj pipe(m_device);
12771 pipe.AddColorAttachment();
12772 pipe.AddShader(&vs);
12773 pipe.AddShader(&fs);
12774
12775 VkDescriptorSetObj descriptorSet(m_device);
12776 descriptorSet.AppendDummy();
12777 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12778
12779 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12780
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012781 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012782}
12783
Chris Forbes1f3b0152016-11-30 12:48:40 +130012784TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
12785 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
12786
12787 ASSERT_NO_FATAL_FAILURE(InitState());
12788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12789
12790 char const *vsSource = "#version 450\n"
12791 "layout(location=0) out mediump float x;\n"
12792 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
12793 char const *fsSource = "#version 450\n"
12794 "layout(location=0) in highp float x;\n"
12795 "layout(location=0) out vec4 color;\n"
12796 "void main() { color = vec4(x); }\n";
12797
12798 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12799 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12800
12801 VkPipelineObj pipe(m_device);
12802 pipe.AddColorAttachment();
12803 pipe.AddShader(&vs);
12804 pipe.AddShader(&fs);
12805
12806 VkDescriptorSetObj descriptorSet(m_device);
12807 descriptorSet.AppendDummy();
12808 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12809
12810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
12811
12812 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12813
12814 m_errorMonitor->VerifyFound();
12815}
12816
Chris Forbes870a39e2016-11-30 12:55:56 +130012817TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
12818 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
12819
12820 ASSERT_NO_FATAL_FAILURE(InitState());
12821 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12822
12823 char const *vsSource = "#version 450\n"
12824 "out block { layout(location=0) mediump float x; };\n"
12825 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
12826 char const *fsSource = "#version 450\n"
12827 "in block { layout(location=0) highp float x; };\n"
12828 "layout(location=0) out vec4 color;\n"
12829 "void main() { color = vec4(x); }\n";
12830
12831 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12832 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12833
12834 VkPipelineObj pipe(m_device);
12835 pipe.AddColorAttachment();
12836 pipe.AddShader(&vs);
12837 pipe.AddShader(&fs);
12838
12839 VkDescriptorSetObj descriptorSet(m_device);
12840 descriptorSet.AppendDummy();
12841 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12842
12843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
12844
12845 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12846
12847 m_errorMonitor->VerifyFound();
12848}
12849
Karl Schultz6addd812016-02-02 17:17:23 -070012850TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012851 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12852 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012854
Chris Forbesde136e02015-05-25 11:13:28 +120012855 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012857
12858 VkVertexInputBindingDescription input_binding;
12859 memset(&input_binding, 0, sizeof(input_binding));
12860
12861 VkVertexInputAttributeDescription input_attrib;
12862 memset(&input_attrib, 0, sizeof(input_attrib));
12863 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012865 char const *vsSource = "#version 450\n"
12866 "\n"
12867 "out gl_PerVertex {\n"
12868 " vec4 gl_Position;\n"
12869 "};\n"
12870 "void main(){\n"
12871 " gl_Position = vec4(1);\n"
12872 "}\n";
12873 char const *fsSource = "#version 450\n"
12874 "\n"
12875 "layout(location=0) out vec4 color;\n"
12876 "void main(){\n"
12877 " color = vec4(1);\n"
12878 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012879
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012880 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12881 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012882
12883 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012884 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012885 pipe.AddShader(&vs);
12886 pipe.AddShader(&fs);
12887
12888 pipe.AddVertexInputBindings(&input_binding, 1);
12889 pipe.AddVertexInputAttribs(&input_attrib, 1);
12890
Chris Forbesde136e02015-05-25 11:13:28 +120012891 VkDescriptorSetObj descriptorSet(m_device);
12892 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012893 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012894
Tony Barbour5781e8f2015-08-04 16:23:11 -060012895 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012896
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012897 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012898}
12899
Karl Schultz6addd812016-02-02 17:17:23 -070012900TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012901 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12902 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012904
12905 ASSERT_NO_FATAL_FAILURE(InitState());
12906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12907
12908 VkVertexInputBindingDescription input_binding;
12909 memset(&input_binding, 0, sizeof(input_binding));
12910
12911 VkVertexInputAttributeDescription input_attrib;
12912 memset(&input_attrib, 0, sizeof(input_attrib));
12913 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12914
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012915 char const *vsSource = "#version 450\n"
12916 "\n"
12917 "layout(location=1) in float x;\n"
12918 "out gl_PerVertex {\n"
12919 " vec4 gl_Position;\n"
12920 "};\n"
12921 "void main(){\n"
12922 " gl_Position = vec4(x);\n"
12923 "}\n";
12924 char const *fsSource = "#version 450\n"
12925 "\n"
12926 "layout(location=0) out vec4 color;\n"
12927 "void main(){\n"
12928 " color = vec4(1);\n"
12929 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012930
12931 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12932 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12933
12934 VkPipelineObj pipe(m_device);
12935 pipe.AddColorAttachment();
12936 pipe.AddShader(&vs);
12937 pipe.AddShader(&fs);
12938
12939 pipe.AddVertexInputBindings(&input_binding, 1);
12940 pipe.AddVertexInputAttribs(&input_attrib, 1);
12941
12942 VkDescriptorSetObj descriptorSet(m_device);
12943 descriptorSet.AppendDummy();
12944 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12945
12946 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12947
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012948 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012949}
12950
Karl Schultz6addd812016-02-02 17:17:23 -070012951TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012952 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012953 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012954 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 -060012955
Chris Forbes62e8e502015-05-25 11:13:29 +120012956 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012959 char const *vsSource = "#version 450\n"
12960 "\n"
12961 "layout(location=0) in vec4 x;\n" /* not provided */
12962 "out gl_PerVertex {\n"
12963 " vec4 gl_Position;\n"
12964 "};\n"
12965 "void main(){\n"
12966 " gl_Position = x;\n"
12967 "}\n";
12968 char const *fsSource = "#version 450\n"
12969 "\n"
12970 "layout(location=0) out vec4 color;\n"
12971 "void main(){\n"
12972 " color = vec4(1);\n"
12973 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012974
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012975 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12976 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012977
12978 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012979 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012980 pipe.AddShader(&vs);
12981 pipe.AddShader(&fs);
12982
Chris Forbes62e8e502015-05-25 11:13:29 +120012983 VkDescriptorSetObj descriptorSet(m_device);
12984 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012985 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012986
Tony Barbour5781e8f2015-08-04 16:23:11 -060012987 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012988
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012989 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012990}
12991
Karl Schultz6addd812016-02-02 17:17:23 -070012992TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012993 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12994 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012995 "vertex shader input that consumes it");
12996 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 -060012997
Chris Forbesc97d98e2015-05-25 11:13:31 +120012998 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013000
13001 VkVertexInputBindingDescription input_binding;
13002 memset(&input_binding, 0, sizeof(input_binding));
13003
13004 VkVertexInputAttributeDescription input_attrib;
13005 memset(&input_attrib, 0, sizeof(input_attrib));
13006 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013008 char const *vsSource = "#version 450\n"
13009 "\n"
13010 "layout(location=0) in int x;\n" /* attrib provided float */
13011 "out gl_PerVertex {\n"
13012 " vec4 gl_Position;\n"
13013 "};\n"
13014 "void main(){\n"
13015 " gl_Position = vec4(x);\n"
13016 "}\n";
13017 char const *fsSource = "#version 450\n"
13018 "\n"
13019 "layout(location=0) out vec4 color;\n"
13020 "void main(){\n"
13021 " color = vec4(1);\n"
13022 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013023
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013024 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13025 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013026
13027 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013028 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013029 pipe.AddShader(&vs);
13030 pipe.AddShader(&fs);
13031
13032 pipe.AddVertexInputBindings(&input_binding, 1);
13033 pipe.AddVertexInputAttribs(&input_attrib, 1);
13034
Chris Forbesc97d98e2015-05-25 11:13:31 +120013035 VkDescriptorSetObj descriptorSet(m_device);
13036 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013037 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013038
Tony Barbour5781e8f2015-08-04 16:23:11 -060013039 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013040
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013041 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013042}
13043
Chris Forbesc68b43c2016-04-06 11:18:47 +120013044TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013045 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13046 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13048 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013049
13050 ASSERT_NO_FATAL_FAILURE(InitState());
13051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013053 char const *vsSource = "#version 450\n"
13054 "\n"
13055 "out gl_PerVertex {\n"
13056 " vec4 gl_Position;\n"
13057 "};\n"
13058 "void main(){\n"
13059 " gl_Position = vec4(1);\n"
13060 "}\n";
13061 char const *fsSource = "#version 450\n"
13062 "\n"
13063 "layout(location=0) out vec4 color;\n"
13064 "void main(){\n"
13065 " color = vec4(1);\n"
13066 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013067
13068 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13069 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13070
13071 VkPipelineObj pipe(m_device);
13072 pipe.AddColorAttachment();
13073 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013074 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013075 pipe.AddShader(&fs);
13076
13077 VkDescriptorSetObj descriptorSet(m_device);
13078 descriptorSet.AppendDummy();
13079 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13080
13081 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13082
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013083 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013084}
13085
Chris Forbes82ff92a2016-09-09 10:50:24 +120013086TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13088 "No entrypoint found named `foo`");
13089
13090 ASSERT_NO_FATAL_FAILURE(InitState());
13091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13092
13093 char const *vsSource = "#version 450\n"
13094 "out gl_PerVertex {\n"
13095 " vec4 gl_Position;\n"
13096 "};\n"
13097 "void main(){\n"
13098 " gl_Position = vec4(0);\n"
13099 "}\n";
13100 char const *fsSource = "#version 450\n"
13101 "\n"
13102 "layout(location=0) out vec4 color;\n"
13103 "void main(){\n"
13104 " color = vec4(1);\n"
13105 "}\n";
13106
13107 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13108 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13109
13110 VkPipelineObj pipe(m_device);
13111 pipe.AddColorAttachment();
13112 pipe.AddShader(&vs);
13113 pipe.AddShader(&fs);
13114
13115 VkDescriptorSetObj descriptorSet(m_device);
13116 descriptorSet.AppendDummy();
13117 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13118
13119 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13120
13121 m_errorMonitor->VerifyFound();
13122}
13123
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013124TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13125 m_errorMonitor->SetDesiredFailureMsg(
13126 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13127 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13128 "uses a depth/stencil attachment");
13129
13130 ASSERT_NO_FATAL_FAILURE(InitState());
13131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13132
13133 char const *vsSource = "#version 450\n"
13134 "void main(){ gl_Position = vec4(0); }\n";
13135 char const *fsSource = "#version 450\n"
13136 "\n"
13137 "layout(location=0) out vec4 color;\n"
13138 "void main(){\n"
13139 " color = vec4(1);\n"
13140 "}\n";
13141
13142 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13143 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13144
13145 VkPipelineObj pipe(m_device);
13146 pipe.AddColorAttachment();
13147 pipe.AddShader(&vs);
13148 pipe.AddShader(&fs);
13149
13150 VkDescriptorSetObj descriptorSet(m_device);
13151 descriptorSet.AppendDummy();
13152 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13153
13154 VkAttachmentDescription attachments[] = {
13155 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13156 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13157 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13158 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13159 },
13160 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13161 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13162 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13163 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13164 },
13165 };
13166 VkAttachmentReference refs[] = {
13167 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13168 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13169 };
13170 VkSubpassDescription subpass = {
13171 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13172 1, &refs[0], nullptr, &refs[1],
13173 0, nullptr
13174 };
13175 VkRenderPassCreateInfo rpci = {
13176 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13177 0, 2, attachments, 1, &subpass, 0, nullptr
13178 };
13179 VkRenderPass rp;
13180 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13181 ASSERT_VK_SUCCESS(err);
13182
13183 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13184
13185 m_errorMonitor->VerifyFound();
13186
13187 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13188}
13189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013190TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013191 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13192 "the TCS without the patch decoration, but consumed in the TES "
13193 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13195 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013196
13197 ASSERT_NO_FATAL_FAILURE(InitState());
13198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13199
Chris Forbesc1e852d2016-04-04 19:26:42 +120013200 if (!m_device->phy().features().tessellationShader) {
13201 printf("Device does not support tessellation shaders; skipped.\n");
13202 return;
13203 }
13204
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013205 char const *vsSource = "#version 450\n"
13206 "void main(){}\n";
13207 char const *tcsSource = "#version 450\n"
13208 "layout(location=0) out int x[];\n"
13209 "layout(vertices=3) out;\n"
13210 "void main(){\n"
13211 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13212 " gl_TessLevelInner[0] = 1;\n"
13213 " x[gl_InvocationID] = gl_InvocationID;\n"
13214 "}\n";
13215 char const *tesSource = "#version 450\n"
13216 "layout(triangles, equal_spacing, cw) in;\n"
13217 "layout(location=0) patch in int x;\n"
13218 "out gl_PerVertex { vec4 gl_Position; };\n"
13219 "void main(){\n"
13220 " gl_Position.xyz = gl_TessCoord;\n"
13221 " gl_Position.w = x;\n"
13222 "}\n";
13223 char const *fsSource = "#version 450\n"
13224 "layout(location=0) out vec4 color;\n"
13225 "void main(){\n"
13226 " color = vec4(1);\n"
13227 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013228
13229 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13230 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13231 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13232 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013234 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13235 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013237 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013238
13239 VkPipelineObj pipe(m_device);
13240 pipe.SetInputAssembly(&iasci);
13241 pipe.SetTessellation(&tsci);
13242 pipe.AddColorAttachment();
13243 pipe.AddShader(&vs);
13244 pipe.AddShader(&tcs);
13245 pipe.AddShader(&tes);
13246 pipe.AddShader(&fs);
13247
13248 VkDescriptorSetObj descriptorSet(m_device);
13249 descriptorSet.AppendDummy();
13250 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13251
13252 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13253
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013254 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013255}
13256
Karl Schultz6addd812016-02-02 17:17:23 -070013257TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013258 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13259 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13261 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013262
Chris Forbes280ba2c2015-06-12 11:16:41 +120013263 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013265
13266 /* Two binding descriptions for binding 0 */
13267 VkVertexInputBindingDescription input_bindings[2];
13268 memset(input_bindings, 0, sizeof(input_bindings));
13269
13270 VkVertexInputAttributeDescription input_attrib;
13271 memset(&input_attrib, 0, sizeof(input_attrib));
13272 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13273
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013274 char const *vsSource = "#version 450\n"
13275 "\n"
13276 "layout(location=0) in float x;\n" /* attrib provided float */
13277 "out gl_PerVertex {\n"
13278 " vec4 gl_Position;\n"
13279 "};\n"
13280 "void main(){\n"
13281 " gl_Position = vec4(x);\n"
13282 "}\n";
13283 char const *fsSource = "#version 450\n"
13284 "\n"
13285 "layout(location=0) out vec4 color;\n"
13286 "void main(){\n"
13287 " color = vec4(1);\n"
13288 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013289
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013290 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13291 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013292
13293 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013294 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013295 pipe.AddShader(&vs);
13296 pipe.AddShader(&fs);
13297
13298 pipe.AddVertexInputBindings(input_bindings, 2);
13299 pipe.AddVertexInputAttribs(&input_attrib, 1);
13300
Chris Forbes280ba2c2015-06-12 11:16:41 +120013301 VkDescriptorSetObj descriptorSet(m_device);
13302 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013303 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013304
Tony Barbour5781e8f2015-08-04 16:23:11 -060013305 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013306
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013307 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013308}
Chris Forbes8f68b562015-05-25 11:13:32 +120013309
Karl Schultz6addd812016-02-02 17:17:23 -070013310TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013311 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013312 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013314
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013315 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013316
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013317 char const *vsSource = "#version 450\n"
13318 "\n"
13319 "out gl_PerVertex {\n"
13320 " vec4 gl_Position;\n"
13321 "};\n"
13322 "void main(){\n"
13323 " gl_Position = vec4(1);\n"
13324 "}\n";
13325 char const *fsSource = "#version 450\n"
13326 "\n"
13327 "void main(){\n"
13328 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013329
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013330 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13331 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013332
13333 VkPipelineObj pipe(m_device);
13334 pipe.AddShader(&vs);
13335 pipe.AddShader(&fs);
13336
Chia-I Wu08accc62015-07-07 11:50:03 +080013337 /* set up CB 0, not written */
13338 pipe.AddColorAttachment();
13339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013340
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013341 VkDescriptorSetObj descriptorSet(m_device);
13342 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013343 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013344
Tony Barbour5781e8f2015-08-04 16:23:11 -060013345 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013346
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013347 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013348}
13349
Karl Schultz6addd812016-02-02 17:17:23 -070013350TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013351 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013352 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013354 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013355
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013356 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013358 char const *vsSource = "#version 450\n"
13359 "\n"
13360 "out gl_PerVertex {\n"
13361 " vec4 gl_Position;\n"
13362 "};\n"
13363 "void main(){\n"
13364 " gl_Position = vec4(1);\n"
13365 "}\n";
13366 char const *fsSource = "#version 450\n"
13367 "\n"
13368 "layout(location=0) out vec4 x;\n"
13369 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13370 "void main(){\n"
13371 " x = vec4(1);\n"
13372 " y = vec4(1);\n"
13373 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013374
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013375 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13376 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013377
13378 VkPipelineObj pipe(m_device);
13379 pipe.AddShader(&vs);
13380 pipe.AddShader(&fs);
13381
Chia-I Wu08accc62015-07-07 11:50:03 +080013382 /* set up CB 0, not written */
13383 pipe.AddColorAttachment();
13384 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013385 /* FS writes CB 1, but we don't configure it */
13386
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013387 VkDescriptorSetObj descriptorSet(m_device);
13388 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013389 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013390
Tony Barbour5781e8f2015-08-04 16:23:11 -060013391 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013392
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013393 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013394}
13395
Karl Schultz6addd812016-02-02 17:17:23 -070013396TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013397 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013398 "type of an fragment shader output variable, and the format of the corresponding attachment");
13399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013400
Chris Forbesa36d69e2015-05-25 11:13:44 +120013401 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013403 char const *vsSource = "#version 450\n"
13404 "\n"
13405 "out gl_PerVertex {\n"
13406 " vec4 gl_Position;\n"
13407 "};\n"
13408 "void main(){\n"
13409 " gl_Position = vec4(1);\n"
13410 "}\n";
13411 char const *fsSource = "#version 450\n"
13412 "\n"
13413 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13414 "void main(){\n"
13415 " x = ivec4(1);\n"
13416 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013417
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013418 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13419 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013420
13421 VkPipelineObj pipe(m_device);
13422 pipe.AddShader(&vs);
13423 pipe.AddShader(&fs);
13424
Chia-I Wu08accc62015-07-07 11:50:03 +080013425 /* set up CB 0; type is UNORM by default */
13426 pipe.AddColorAttachment();
13427 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013428
Chris Forbesa36d69e2015-05-25 11:13:44 +120013429 VkDescriptorSetObj descriptorSet(m_device);
13430 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013431 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013432
Tony Barbour5781e8f2015-08-04 16:23:11 -060013433 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013434
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013435 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013436}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013437
Karl Schultz6addd812016-02-02 17:17:23 -070013438TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013439 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13440 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013442
Chris Forbes556c76c2015-08-14 12:04:59 +120013443 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013445 char const *vsSource = "#version 450\n"
13446 "\n"
13447 "out gl_PerVertex {\n"
13448 " vec4 gl_Position;\n"
13449 "};\n"
13450 "void main(){\n"
13451 " gl_Position = vec4(1);\n"
13452 "}\n";
13453 char const *fsSource = "#version 450\n"
13454 "\n"
13455 "layout(location=0) out vec4 x;\n"
13456 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13457 "void main(){\n"
13458 " x = vec4(bar.y);\n"
13459 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013460
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013461 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13462 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013463
Chris Forbes556c76c2015-08-14 12:04:59 +120013464 VkPipelineObj pipe(m_device);
13465 pipe.AddShader(&vs);
13466 pipe.AddShader(&fs);
13467
13468 /* set up CB 0; type is UNORM by default */
13469 pipe.AddColorAttachment();
13470 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13471
13472 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013473 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013474
13475 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13476
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013477 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013478}
13479
Chris Forbes5c59e902016-02-26 16:56:09 +130013480TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013481 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13482 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013484
13485 ASSERT_NO_FATAL_FAILURE(InitState());
13486
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013487 char const *vsSource = "#version 450\n"
13488 "\n"
13489 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13490 "out gl_PerVertex {\n"
13491 " vec4 gl_Position;\n"
13492 "};\n"
13493 "void main(){\n"
13494 " gl_Position = vec4(consts.x);\n"
13495 "}\n";
13496 char const *fsSource = "#version 450\n"
13497 "\n"
13498 "layout(location=0) out vec4 x;\n"
13499 "void main(){\n"
13500 " x = vec4(1);\n"
13501 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013502
13503 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13504 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13505
13506 VkPipelineObj pipe(m_device);
13507 pipe.AddShader(&vs);
13508 pipe.AddShader(&fs);
13509
13510 /* set up CB 0; type is UNORM by default */
13511 pipe.AddColorAttachment();
13512 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13513
13514 VkDescriptorSetObj descriptorSet(m_device);
13515 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13516
13517 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13518
13519 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013520 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013521}
13522
Chris Forbes3fb17902016-08-22 14:57:55 +120013523TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13524 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13525 "which is not included in the subpass description");
13526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13527 "consumes input attachment index 0 but not provided in subpass");
13528
13529 ASSERT_NO_FATAL_FAILURE(InitState());
13530
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013531 char const *vsSource = "#version 450\n"
13532 "\n"
13533 "out gl_PerVertex {\n"
13534 " vec4 gl_Position;\n"
13535 "};\n"
13536 "void main(){\n"
13537 " gl_Position = vec4(1);\n"
13538 "}\n";
13539 char const *fsSource = "#version 450\n"
13540 "\n"
13541 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13542 "layout(location=0) out vec4 color;\n"
13543 "void main() {\n"
13544 " color = subpassLoad(x);\n"
13545 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013546
13547 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13548 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13549
13550 VkPipelineObj pipe(m_device);
13551 pipe.AddShader(&vs);
13552 pipe.AddShader(&fs);
13553 pipe.AddColorAttachment();
13554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13555
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013556 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13557 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013558 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013559 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013560 ASSERT_VK_SUCCESS(err);
13561
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013562 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013563 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013564 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013565 ASSERT_VK_SUCCESS(err);
13566
13567 // error here.
13568 pipe.CreateVKPipeline(pl, renderPass());
13569
13570 m_errorMonitor->VerifyFound();
13571
13572 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13573 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13574}
13575
Chris Forbes5a9a0472016-08-22 16:02:09 +120013576TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13577 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13578 "with a format having a different fundamental type");
13579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13580 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13581
13582 ASSERT_NO_FATAL_FAILURE(InitState());
13583
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013584 char const *vsSource = "#version 450\n"
13585 "\n"
13586 "out gl_PerVertex {\n"
13587 " vec4 gl_Position;\n"
13588 "};\n"
13589 "void main(){\n"
13590 " gl_Position = vec4(1);\n"
13591 "}\n";
13592 char const *fsSource = "#version 450\n"
13593 "\n"
13594 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13595 "layout(location=0) out vec4 color;\n"
13596 "void main() {\n"
13597 " color = subpassLoad(x);\n"
13598 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013599
13600 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13601 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13602
13603 VkPipelineObj pipe(m_device);
13604 pipe.AddShader(&vs);
13605 pipe.AddShader(&fs);
13606 pipe.AddColorAttachment();
13607 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013609 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13610 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013611 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013612 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013613 ASSERT_VK_SUCCESS(err);
13614
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013615 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013616 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013617 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013618 ASSERT_VK_SUCCESS(err);
13619
13620 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013621 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13622 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13623 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13624 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13625 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 +120013626 };
13627 VkAttachmentReference color = {
13628 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13629 };
13630 VkAttachmentReference input = {
13631 1, VK_IMAGE_LAYOUT_GENERAL,
13632 };
13633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013634 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013635
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013636 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013637 VkRenderPass rp;
13638 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13639 ASSERT_VK_SUCCESS(err);
13640
13641 // error here.
13642 pipe.CreateVKPipeline(pl, rp);
13643
13644 m_errorMonitor->VerifyFound();
13645
13646 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13647 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13648 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13649}
13650
Chris Forbes541f7b02016-08-22 15:30:27 +120013651TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13652 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13653 "which is not included in the subpass description -- array case");
13654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13655 "consumes input attachment index 1 but not provided in subpass");
13656
13657 ASSERT_NO_FATAL_FAILURE(InitState());
13658
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013659 char const *vsSource = "#version 450\n"
13660 "\n"
13661 "out gl_PerVertex {\n"
13662 " vec4 gl_Position;\n"
13663 "};\n"
13664 "void main(){\n"
13665 " gl_Position = vec4(1);\n"
13666 "}\n";
13667 char const *fsSource = "#version 450\n"
13668 "\n"
13669 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13670 "layout(location=0) out vec4 color;\n"
13671 "void main() {\n"
13672 " color = subpassLoad(xs[1]);\n"
13673 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013674
13675 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13676 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13677
13678 VkPipelineObj pipe(m_device);
13679 pipe.AddShader(&vs);
13680 pipe.AddShader(&fs);
13681 pipe.AddColorAttachment();
13682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13683
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013684 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13685 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013686 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013687 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013688 ASSERT_VK_SUCCESS(err);
13689
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013690 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013691 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013692 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013693 ASSERT_VK_SUCCESS(err);
13694
13695 // error here.
13696 pipe.CreateVKPipeline(pl, renderPass());
13697
13698 m_errorMonitor->VerifyFound();
13699
13700 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13701 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13702}
13703
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013704TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013705 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13706 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013708
13709 ASSERT_NO_FATAL_FAILURE(InitState());
13710
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013711 char const *csSource = "#version 450\n"
13712 "\n"
13713 "layout(local_size_x=1) in;\n"
13714 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13715 "void main(){\n"
13716 " x = vec4(1);\n"
13717 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013718
13719 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13720
13721 VkDescriptorSetObj descriptorSet(m_device);
13722 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013724 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13725 nullptr,
13726 0,
13727 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13728 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13729 descriptorSet.GetPipelineLayout(),
13730 VK_NULL_HANDLE,
13731 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013732
13733 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013734 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013735
13736 m_errorMonitor->VerifyFound();
13737
13738 if (err == VK_SUCCESS) {
13739 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13740 }
13741}
13742
Chris Forbes22a9b092016-07-19 14:34:05 +120013743TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013744 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13745 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13747 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013748
13749 ASSERT_NO_FATAL_FAILURE(InitState());
13750
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013751 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13752 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013753 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013754 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013755 ASSERT_VK_SUCCESS(err);
13756
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013757 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013758 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013759 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013760 ASSERT_VK_SUCCESS(err);
13761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013762 char const *csSource = "#version 450\n"
13763 "\n"
13764 "layout(local_size_x=1) in;\n"
13765 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13766 "void main() {\n"
13767 " x.x = 1.0f;\n"
13768 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013769 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13770
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013771 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13772 nullptr,
13773 0,
13774 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13775 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13776 pl,
13777 VK_NULL_HANDLE,
13778 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013779
13780 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013781 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013782
13783 m_errorMonitor->VerifyFound();
13784
13785 if (err == VK_SUCCESS) {
13786 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13787 }
13788
13789 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13790 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13791}
13792
Chris Forbes50020592016-07-27 13:52:41 +120013793TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13794 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13795 "does not match the dimensionality declared in the shader");
13796
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013797 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 +120013798
13799 ASSERT_NO_FATAL_FAILURE(InitState());
13800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13801
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013802 char const *vsSource = "#version 450\n"
13803 "\n"
13804 "out gl_PerVertex { vec4 gl_Position; };\n"
13805 "void main() { gl_Position = vec4(0); }\n";
13806 char const *fsSource = "#version 450\n"
13807 "\n"
13808 "layout(set=0, binding=0) uniform sampler3D s;\n"
13809 "layout(location=0) out vec4 color;\n"
13810 "void main() {\n"
13811 " color = texture(s, vec3(0));\n"
13812 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013813 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13814 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13815
13816 VkPipelineObj pipe(m_device);
13817 pipe.AddShader(&vs);
13818 pipe.AddShader(&fs);
13819 pipe.AddColorAttachment();
13820
13821 VkTextureObj texture(m_device, nullptr);
13822 VkSamplerObj sampler(m_device);
13823
13824 VkDescriptorSetObj descriptorSet(m_device);
13825 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13826 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13827
13828 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13829 ASSERT_VK_SUCCESS(err);
13830
13831 BeginCommandBuffer();
13832
13833 m_commandBuffer->BindPipeline(pipe);
13834 m_commandBuffer->BindDescriptorSet(descriptorSet);
13835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013836 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013837 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013838 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013839 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13840
13841 // error produced here.
13842 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13843
13844 m_errorMonitor->VerifyFound();
13845
13846 EndCommandBuffer();
13847}
13848
Chris Forbes5533bfc2016-07-27 14:12:34 +120013849TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13850 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13851 "are consumed via singlesample images types in the shader, or vice versa.");
13852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013854
13855 ASSERT_NO_FATAL_FAILURE(InitState());
13856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13857
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013858 char const *vsSource = "#version 450\n"
13859 "\n"
13860 "out gl_PerVertex { vec4 gl_Position; };\n"
13861 "void main() { gl_Position = vec4(0); }\n";
13862 char const *fsSource = "#version 450\n"
13863 "\n"
13864 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13865 "layout(location=0) out vec4 color;\n"
13866 "void main() {\n"
13867 " color = texelFetch(s, ivec2(0), 0);\n"
13868 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013869 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13870 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13871
13872 VkPipelineObj pipe(m_device);
13873 pipe.AddShader(&vs);
13874 pipe.AddShader(&fs);
13875 pipe.AddColorAttachment();
13876
13877 VkTextureObj texture(m_device, nullptr);
13878 VkSamplerObj sampler(m_device);
13879
13880 VkDescriptorSetObj descriptorSet(m_device);
13881 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13882 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13883
13884 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13885 ASSERT_VK_SUCCESS(err);
13886
13887 BeginCommandBuffer();
13888
13889 m_commandBuffer->BindPipeline(pipe);
13890 m_commandBuffer->BindDescriptorSet(descriptorSet);
13891
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013892 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013893 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013894 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013895 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13896
13897 // error produced here.
13898 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13899
13900 m_errorMonitor->VerifyFound();
13901
13902 EndCommandBuffer();
13903}
13904
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013905#endif // SHADER_CHECKER_TESTS
13906
13907#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013908TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013910
13911 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013912
13913 // Create an image
13914 VkImage image;
13915
Karl Schultz6addd812016-02-02 17:17:23 -070013916 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13917 const int32_t tex_width = 32;
13918 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013919
13920 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013921 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13922 image_create_info.pNext = NULL;
13923 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13924 image_create_info.format = tex_format;
13925 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013926 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013927 image_create_info.extent.depth = 1;
13928 image_create_info.mipLevels = 1;
13929 image_create_info.arrayLayers = 1;
13930 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13931 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13932 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13933 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013934
13935 // Introduce error by sending down a bogus width extent
13936 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013937 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013938
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013939 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013940}
13941
Mark Youngc48c4c12016-04-11 14:26:49 -060013942TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13944 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013945
13946 ASSERT_NO_FATAL_FAILURE(InitState());
13947
13948 // Create an image
13949 VkImage image;
13950
13951 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13952 const int32_t tex_width = 32;
13953 const int32_t tex_height = 32;
13954
13955 VkImageCreateInfo image_create_info = {};
13956 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13957 image_create_info.pNext = NULL;
13958 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13959 image_create_info.format = tex_format;
13960 image_create_info.extent.width = tex_width;
13961 image_create_info.extent.height = tex_height;
13962 image_create_info.extent.depth = 1;
13963 image_create_info.mipLevels = 1;
13964 image_create_info.arrayLayers = 1;
13965 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13966 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13967 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13968 image_create_info.flags = 0;
13969
13970 // Introduce error by sending down a bogus width extent
13971 image_create_info.extent.width = 0;
13972 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13973
13974 m_errorMonitor->VerifyFound();
13975}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013976#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013977
Tobin Ehliscde08892015-09-22 10:11:37 -060013978#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013979
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013980TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13981 TEST_DESCRIPTION("Create a render pass with an attachment description "
13982 "format set to VK_FORMAT_UNDEFINED");
13983
13984 ASSERT_NO_FATAL_FAILURE(InitState());
13985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013988
13989 VkAttachmentReference color_attach = {};
13990 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13991 color_attach.attachment = 0;
13992 VkSubpassDescription subpass = {};
13993 subpass.colorAttachmentCount = 1;
13994 subpass.pColorAttachments = &color_attach;
13995
13996 VkRenderPassCreateInfo rpci = {};
13997 rpci.subpassCount = 1;
13998 rpci.pSubpasses = &subpass;
13999 rpci.attachmentCount = 1;
14000 VkAttachmentDescription attach_desc = {};
14001 attach_desc.format = VK_FORMAT_UNDEFINED;
14002 rpci.pAttachments = &attach_desc;
14003 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14004 VkRenderPass rp;
14005 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14006
14007 m_errorMonitor->VerifyFound();
14008
14009 if (result == VK_SUCCESS) {
14010 vkDestroyRenderPass(m_device->device(), rp, NULL);
14011 }
14012}
14013
Karl Schultz6addd812016-02-02 17:17:23 -070014014TEST_F(VkLayerTest, InvalidImageView) {
14015 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014018
Tobin Ehliscde08892015-09-22 10:11:37 -060014019 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014020
Mike Stroyana3082432015-09-25 13:39:21 -060014021 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014022 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014023
Karl Schultz6addd812016-02-02 17:17:23 -070014024 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14025 const int32_t tex_width = 32;
14026 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014027
14028 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014029 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14030 image_create_info.pNext = NULL;
14031 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14032 image_create_info.format = tex_format;
14033 image_create_info.extent.width = tex_width;
14034 image_create_info.extent.height = tex_height;
14035 image_create_info.extent.depth = 1;
14036 image_create_info.mipLevels = 1;
14037 image_create_info.arrayLayers = 1;
14038 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14039 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14040 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14041 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014042
Chia-I Wuf7458c52015-10-26 21:10:41 +080014043 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014044 ASSERT_VK_SUCCESS(err);
14045
14046 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014047 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014048 image_view_create_info.image = image;
14049 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14050 image_view_create_info.format = tex_format;
14051 image_view_create_info.subresourceRange.layerCount = 1;
14052 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14053 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014054 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014055
14056 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014057 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014058
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014059 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014060 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014061}
Mike Stroyana3082432015-09-25 13:39:21 -060014062
Mark Youngd339ba32016-05-30 13:28:35 -060014063TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14064 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014066 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014067
14068 ASSERT_NO_FATAL_FAILURE(InitState());
14069
14070 // Create an image and try to create a view with no memory backing the image
14071 VkImage image;
14072
14073 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14074 const int32_t tex_width = 32;
14075 const int32_t tex_height = 32;
14076
14077 VkImageCreateInfo image_create_info = {};
14078 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14079 image_create_info.pNext = NULL;
14080 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14081 image_create_info.format = tex_format;
14082 image_create_info.extent.width = tex_width;
14083 image_create_info.extent.height = tex_height;
14084 image_create_info.extent.depth = 1;
14085 image_create_info.mipLevels = 1;
14086 image_create_info.arrayLayers = 1;
14087 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14088 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14089 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14090 image_create_info.flags = 0;
14091
14092 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14093 ASSERT_VK_SUCCESS(err);
14094
14095 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014096 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014097 image_view_create_info.image = image;
14098 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14099 image_view_create_info.format = tex_format;
14100 image_view_create_info.subresourceRange.layerCount = 1;
14101 image_view_create_info.subresourceRange.baseMipLevel = 0;
14102 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014103 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014104
14105 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014106 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014107
14108 m_errorMonitor->VerifyFound();
14109 vkDestroyImage(m_device->device(), image, NULL);
14110 // If last error is success, it still created the view, so delete it.
14111 if (err == VK_SUCCESS) {
14112 vkDestroyImageView(m_device->device(), view, NULL);
14113 }
Mark Youngd339ba32016-05-30 13:28:35 -060014114}
14115
Karl Schultz6addd812016-02-02 17:17:23 -070014116TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014117 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014119 "formats must have ONLY the "
14120 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14122 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014123
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014124 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014125
Karl Schultz6addd812016-02-02 17:17:23 -070014126 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014127 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014128 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014129 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014130
14131 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014132 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014133 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014134 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14135 image_view_create_info.format = tex_format;
14136 image_view_create_info.subresourceRange.baseMipLevel = 0;
14137 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014138 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014139 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014140 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014141
14142 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014143 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014144
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014145 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014146}
14147
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014148TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014149 VkResult err;
14150 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14153 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014154
Mike Stroyana3082432015-09-25 13:39:21 -060014155 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014156
14157 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014158 VkImage srcImage;
14159 VkImage dstImage;
14160 VkDeviceMemory srcMem;
14161 VkDeviceMemory destMem;
14162 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014163
14164 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014165 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14166 image_create_info.pNext = NULL;
14167 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14168 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14169 image_create_info.extent.width = 32;
14170 image_create_info.extent.height = 32;
14171 image_create_info.extent.depth = 1;
14172 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014173 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014174 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14175 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14176 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14177 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014179 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014180 ASSERT_VK_SUCCESS(err);
14181
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014182 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014183 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014184 ASSERT_VK_SUCCESS(err);
14185
14186 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014187 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014188 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14189 memAlloc.pNext = NULL;
14190 memAlloc.allocationSize = 0;
14191 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014192
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014193 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014194 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014195 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014196 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014197 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014198 ASSERT_VK_SUCCESS(err);
14199
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014200 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014201 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014202 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014203 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014204 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014205 ASSERT_VK_SUCCESS(err);
14206
14207 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14208 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014209 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014210 ASSERT_VK_SUCCESS(err);
14211
14212 BeginCommandBuffer();
14213 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014214 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014215 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014216 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014217 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014218 copyRegion.srcOffset.x = 0;
14219 copyRegion.srcOffset.y = 0;
14220 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014221 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014222 copyRegion.dstSubresource.mipLevel = 0;
14223 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014224 // Introduce failure by forcing the dst layerCount to differ from src
14225 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014226 copyRegion.dstOffset.x = 0;
14227 copyRegion.dstOffset.y = 0;
14228 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014229 copyRegion.extent.width = 1;
14230 copyRegion.extent.height = 1;
14231 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014232 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014233 EndCommandBuffer();
14234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014235 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014236
Chia-I Wuf7458c52015-10-26 21:10:41 +080014237 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014238 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014239 vkFreeMemory(m_device->device(), srcMem, NULL);
14240 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014241}
14242
Tony Barbourd6673642016-05-05 14:46:39 -060014243TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14244
14245 TEST_DESCRIPTION("Creating images with unsuported formats ");
14246
14247 ASSERT_NO_FATAL_FAILURE(InitState());
14248 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14249 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014250 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 -060014251 VK_IMAGE_TILING_OPTIMAL, 0);
14252 ASSERT_TRUE(image.initialized());
14253
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014254 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014255 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014256 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014257 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14258 image_create_info.format = VK_FORMAT_UNDEFINED;
14259 image_create_info.extent.width = 32;
14260 image_create_info.extent.height = 32;
14261 image_create_info.extent.depth = 1;
14262 image_create_info.mipLevels = 1;
14263 image_create_info.arrayLayers = 1;
14264 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14265 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14266 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14269 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014270
14271 VkImage localImage;
14272 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14273 m_errorMonitor->VerifyFound();
14274
Tony Barbourd6673642016-05-05 14:46:39 -060014275 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014276 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014277 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14278 VkFormat format = static_cast<VkFormat>(f);
14279 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014280 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014281 unsupported = format;
14282 break;
14283 }
14284 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014285
Tony Barbourd6673642016-05-05 14:46:39 -060014286 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014287 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014289
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014290 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014291 m_errorMonitor->VerifyFound();
14292 }
14293}
14294
14295TEST_F(VkLayerTest, ImageLayerViewTests) {
14296 VkResult ret;
14297 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14298
14299 ASSERT_NO_FATAL_FAILURE(InitState());
14300
14301 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014302 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 -060014303 VK_IMAGE_TILING_OPTIMAL, 0);
14304 ASSERT_TRUE(image.initialized());
14305
14306 VkImageView imgView;
14307 VkImageViewCreateInfo imgViewInfo = {};
14308 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14309 imgViewInfo.image = image.handle();
14310 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14311 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14312 imgViewInfo.subresourceRange.layerCount = 1;
14313 imgViewInfo.subresourceRange.baseMipLevel = 0;
14314 imgViewInfo.subresourceRange.levelCount = 1;
14315 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14316
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014318 // View can't have baseMipLevel >= image's mipLevels - Expect
14319 // VIEW_CREATE_ERROR
14320 imgViewInfo.subresourceRange.baseMipLevel = 1;
14321 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14322 m_errorMonitor->VerifyFound();
14323 imgViewInfo.subresourceRange.baseMipLevel = 0;
14324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014326 // View can't have baseArrayLayer >= image's arraySize - Expect
14327 // VIEW_CREATE_ERROR
14328 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14329 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14330 m_errorMonitor->VerifyFound();
14331 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14332
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14334 "pCreateInfo->subresourceRange."
14335 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014336 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14337 imgViewInfo.subresourceRange.levelCount = 0;
14338 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14339 m_errorMonitor->VerifyFound();
14340 imgViewInfo.subresourceRange.levelCount = 1;
14341
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14343 "pCreateInfo->subresourceRange."
14344 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014345 m_errorMonitor->SetDesiredFailureMsg(
14346 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14347 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014348 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14349 imgViewInfo.subresourceRange.layerCount = 0;
14350 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14351 m_errorMonitor->VerifyFound();
14352 imgViewInfo.subresourceRange.layerCount = 1;
14353
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14356 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14357 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014358 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14359 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14360 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14361 m_errorMonitor->VerifyFound();
14362 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14365 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14366 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014367 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14368 // VIEW_CREATE_ERROR
14369 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14370 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14371 m_errorMonitor->VerifyFound();
14372 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14373
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14375 "differing formats but they must be "
14376 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014377 // TODO: Update framework to easily passing mutable flag into ImageObj init
14378 // For now just allowing image for this one test to not have memory bound
14379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14380 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014381 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14382 // VIEW_CREATE_ERROR
14383 VkImageCreateInfo mutImgInfo = image.create_info();
14384 VkImage mutImage;
14385 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014386 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014387 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14388 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14389 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14390 ASSERT_VK_SUCCESS(ret);
14391 imgViewInfo.image = mutImage;
14392 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14393 m_errorMonitor->VerifyFound();
14394 imgViewInfo.image = image.handle();
14395 vkDestroyImage(m_device->handle(), mutImage, NULL);
14396}
14397
14398TEST_F(VkLayerTest, MiscImageLayerTests) {
14399
14400 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14401
14402 ASSERT_NO_FATAL_FAILURE(InitState());
14403
14404 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014405 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 -060014406 VK_IMAGE_TILING_OPTIMAL, 0);
14407 ASSERT_TRUE(image.initialized());
14408
Tony Barbourd6673642016-05-05 14:46:39 -060014409 vk_testing::Buffer buffer;
14410 VkMemoryPropertyFlags reqs = 0;
14411 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14412 VkBufferImageCopy region = {};
14413 region.bufferRowLength = 128;
14414 region.bufferImageHeight = 128;
14415 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14416 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014417 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014418 region.imageExtent.height = 4;
14419 region.imageExtent.width = 4;
14420 region.imageExtent.depth = 1;
14421 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014422
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014423 // Image must have offset.z of 0 and extent.depth of 1
14424 // Introduce failure by setting imageExtent.depth to 0
14425 region.imageExtent.depth = 0;
14426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14427 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14428 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14429 m_errorMonitor->VerifyFound();
14430
14431 region.imageExtent.depth = 1;
14432
14433 // Image must have offset.z of 0 and extent.depth of 1
14434 // Introduce failure by setting imageOffset.z to 4
14435 region.imageOffset.z = 4;
14436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14437 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14438 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14439 m_errorMonitor->VerifyFound();
14440
14441 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014442 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14443 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14444 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014446 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14447 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014448 m_errorMonitor->VerifyFound();
14449
14450 // BufferOffset must be a multiple of 4
14451 // Introduce failure by setting bufferOffset to a value not divisible by 4
14452 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014454 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14455 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014456 m_errorMonitor->VerifyFound();
14457
14458 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14459 region.bufferOffset = 0;
14460 region.imageExtent.height = 128;
14461 region.imageExtent.width = 128;
14462 // Introduce failure by setting bufferRowLength > 0 but less than width
14463 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014465 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14466 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014467 m_errorMonitor->VerifyFound();
14468
14469 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14470 region.bufferRowLength = 128;
14471 // Introduce failure by setting bufferRowHeight > 0 but less than height
14472 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014474 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14475 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014476 m_errorMonitor->VerifyFound();
14477
14478 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14480 "If the format of srcImage is a depth, stencil, depth stencil or "
14481 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014482 // Expect INVALID_FILTER
14483 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014484 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 -060014485 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014486 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 -060014487 VkImageBlit blitRegion = {};
14488 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14489 blitRegion.srcSubresource.baseArrayLayer = 0;
14490 blitRegion.srcSubresource.layerCount = 1;
14491 blitRegion.srcSubresource.mipLevel = 0;
14492 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14493 blitRegion.dstSubresource.baseArrayLayer = 0;
14494 blitRegion.dstSubresource.layerCount = 1;
14495 blitRegion.dstSubresource.mipLevel = 0;
14496
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014497 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14498 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014499 m_errorMonitor->VerifyFound();
14500
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014501 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14503 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14504 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014505 m_errorMonitor->VerifyFound();
14506
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014508 VkImageMemoryBarrier img_barrier;
14509 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14510 img_barrier.pNext = NULL;
14511 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14512 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14513 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14514 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14515 img_barrier.image = image.handle();
14516 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14517 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14518 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14519 img_barrier.subresourceRange.baseArrayLayer = 0;
14520 img_barrier.subresourceRange.baseMipLevel = 0;
14521 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14522 img_barrier.subresourceRange.layerCount = 0;
14523 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014524 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14525 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014526 m_errorMonitor->VerifyFound();
14527 img_barrier.subresourceRange.layerCount = 1;
14528}
14529
14530TEST_F(VkLayerTest, ImageFormatLimits) {
14531
14532 TEST_DESCRIPTION("Exceed the limits of image format ");
14533
Cody Northropc31a84f2016-08-22 10:41:47 -060014534 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014536 VkImageCreateInfo image_create_info = {};
14537 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14538 image_create_info.pNext = NULL;
14539 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14540 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14541 image_create_info.extent.width = 32;
14542 image_create_info.extent.height = 32;
14543 image_create_info.extent.depth = 1;
14544 image_create_info.mipLevels = 1;
14545 image_create_info.arrayLayers = 1;
14546 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14547 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14548 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14549 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14550 image_create_info.flags = 0;
14551
14552 VkImage nullImg;
14553 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014554 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14555 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014556 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14557 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14558 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14559 m_errorMonitor->VerifyFound();
14560 image_create_info.extent.depth = 1;
14561
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014563 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14564 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14565 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14566 m_errorMonitor->VerifyFound();
14567 image_create_info.mipLevels = 1;
14568
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014570 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14571 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14572 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14573 m_errorMonitor->VerifyFound();
14574 image_create_info.arrayLayers = 1;
14575
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014577 int samples = imgFmtProps.sampleCounts >> 1;
14578 image_create_info.samples = (VkSampleCountFlagBits)samples;
14579 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14580 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14581 m_errorMonitor->VerifyFound();
14582 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14583
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14585 "VK_IMAGE_LAYOUT_UNDEFINED or "
14586 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014587 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14588 // Expect INVALID_LAYOUT
14589 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14590 m_errorMonitor->VerifyFound();
14591 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14592}
14593
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014594TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14595
14596 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014598
14599 ASSERT_NO_FATAL_FAILURE(InitState());
14600
14601 VkImageObj src_image(m_device);
14602 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14603 VkImageObj dst_image(m_device);
14604 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14605
14606 BeginCommandBuffer();
14607 VkImageCopy copy_region;
14608 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14609 copy_region.srcSubresource.mipLevel = 0;
14610 copy_region.srcSubresource.baseArrayLayer = 0;
14611 copy_region.srcSubresource.layerCount = 0;
14612 copy_region.srcOffset.x = 0;
14613 copy_region.srcOffset.y = 0;
14614 copy_region.srcOffset.z = 0;
14615 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14616 copy_region.dstSubresource.mipLevel = 0;
14617 copy_region.dstSubresource.baseArrayLayer = 0;
14618 copy_region.dstSubresource.layerCount = 0;
14619 copy_region.dstOffset.x = 0;
14620 copy_region.dstOffset.y = 0;
14621 copy_region.dstOffset.z = 0;
14622 copy_region.extent.width = 64;
14623 copy_region.extent.height = 64;
14624 copy_region.extent.depth = 1;
14625 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14626 &copy_region);
14627 EndCommandBuffer();
14628
14629 m_errorMonitor->VerifyFound();
14630}
14631
14632TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14633
14634 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014636
14637 ASSERT_NO_FATAL_FAILURE(InitState());
14638
14639 VkImageObj src_image(m_device);
14640 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14641 VkImageObj dst_image(m_device);
14642 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14643
14644 BeginCommandBuffer();
14645 VkImageCopy copy_region;
14646 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14647 copy_region.srcSubresource.mipLevel = 0;
14648 copy_region.srcSubresource.baseArrayLayer = 0;
14649 copy_region.srcSubresource.layerCount = 0;
14650 copy_region.srcOffset.x = 0;
14651 copy_region.srcOffset.y = 0;
14652 copy_region.srcOffset.z = 0;
14653 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14654 copy_region.dstSubresource.mipLevel = 0;
14655 copy_region.dstSubresource.baseArrayLayer = 0;
14656 copy_region.dstSubresource.layerCount = 0;
14657 copy_region.dstOffset.x = 0;
14658 copy_region.dstOffset.y = 0;
14659 copy_region.dstOffset.z = 0;
14660 copy_region.extent.width = 64;
14661 copy_region.extent.height = 64;
14662 copy_region.extent.depth = 1;
14663 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14664 &copy_region);
14665 EndCommandBuffer();
14666
14667 m_errorMonitor->VerifyFound();
14668}
14669
Karl Schultz6addd812016-02-02 17:17:23 -070014670TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014671 VkResult err;
14672 bool pass;
14673
14674 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14676 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014677
14678 ASSERT_NO_FATAL_FAILURE(InitState());
14679
14680 // Create two images of different types and try to copy between them
14681 VkImage srcImage;
14682 VkImage dstImage;
14683 VkDeviceMemory srcMem;
14684 VkDeviceMemory destMem;
14685 VkMemoryRequirements memReqs;
14686
14687 VkImageCreateInfo image_create_info = {};
14688 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14689 image_create_info.pNext = NULL;
14690 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14691 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14692 image_create_info.extent.width = 32;
14693 image_create_info.extent.height = 32;
14694 image_create_info.extent.depth = 1;
14695 image_create_info.mipLevels = 1;
14696 image_create_info.arrayLayers = 1;
14697 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14698 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14699 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14700 image_create_info.flags = 0;
14701
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014702 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014703 ASSERT_VK_SUCCESS(err);
14704
14705 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14706 // Introduce failure by creating second image with a different-sized format.
14707 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014709 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014710 ASSERT_VK_SUCCESS(err);
14711
14712 // Allocate memory
14713 VkMemoryAllocateInfo memAlloc = {};
14714 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14715 memAlloc.pNext = NULL;
14716 memAlloc.allocationSize = 0;
14717 memAlloc.memoryTypeIndex = 0;
14718
14719 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14720 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014721 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014722 ASSERT_TRUE(pass);
14723 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14724 ASSERT_VK_SUCCESS(err);
14725
14726 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14727 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014728 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014729 ASSERT_TRUE(pass);
14730 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14731 ASSERT_VK_SUCCESS(err);
14732
14733 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14734 ASSERT_VK_SUCCESS(err);
14735 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14736 ASSERT_VK_SUCCESS(err);
14737
14738 BeginCommandBuffer();
14739 VkImageCopy copyRegion;
14740 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14741 copyRegion.srcSubresource.mipLevel = 0;
14742 copyRegion.srcSubresource.baseArrayLayer = 0;
14743 copyRegion.srcSubresource.layerCount = 0;
14744 copyRegion.srcOffset.x = 0;
14745 copyRegion.srcOffset.y = 0;
14746 copyRegion.srcOffset.z = 0;
14747 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14748 copyRegion.dstSubresource.mipLevel = 0;
14749 copyRegion.dstSubresource.baseArrayLayer = 0;
14750 copyRegion.dstSubresource.layerCount = 0;
14751 copyRegion.dstOffset.x = 0;
14752 copyRegion.dstOffset.y = 0;
14753 copyRegion.dstOffset.z = 0;
14754 copyRegion.extent.width = 1;
14755 copyRegion.extent.height = 1;
14756 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014757 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014758 EndCommandBuffer();
14759
14760 m_errorMonitor->VerifyFound();
14761
14762 vkDestroyImage(m_device->device(), srcImage, NULL);
14763 vkDestroyImage(m_device->device(), dstImage, NULL);
14764 vkFreeMemory(m_device->device(), srcMem, NULL);
14765 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014766}
14767
Karl Schultz6addd812016-02-02 17:17:23 -070014768TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14769 VkResult err;
14770 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014771
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014772 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14774 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014775
Mike Stroyana3082432015-09-25 13:39:21 -060014776 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014777
14778 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014779 VkImage srcImage;
14780 VkImage dstImage;
14781 VkDeviceMemory srcMem;
14782 VkDeviceMemory destMem;
14783 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014784
14785 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014786 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14787 image_create_info.pNext = NULL;
14788 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14789 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14790 image_create_info.extent.width = 32;
14791 image_create_info.extent.height = 32;
14792 image_create_info.extent.depth = 1;
14793 image_create_info.mipLevels = 1;
14794 image_create_info.arrayLayers = 1;
14795 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14796 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14797 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14798 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014800 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014801 ASSERT_VK_SUCCESS(err);
14802
Karl Schultzbdb75952016-04-19 11:36:49 -060014803 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14804
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014805 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014806 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014807 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014808 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014809
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014810 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014811 ASSERT_VK_SUCCESS(err);
14812
14813 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014814 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014815 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14816 memAlloc.pNext = NULL;
14817 memAlloc.allocationSize = 0;
14818 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014819
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014820 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014821 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014822 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014823 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014824 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014825 ASSERT_VK_SUCCESS(err);
14826
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014827 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014828 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014829 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014830 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014831 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014832 ASSERT_VK_SUCCESS(err);
14833
14834 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14835 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014836 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014837 ASSERT_VK_SUCCESS(err);
14838
14839 BeginCommandBuffer();
14840 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014841 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014842 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014843 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014844 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014845 copyRegion.srcOffset.x = 0;
14846 copyRegion.srcOffset.y = 0;
14847 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014848 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014849 copyRegion.dstSubresource.mipLevel = 0;
14850 copyRegion.dstSubresource.baseArrayLayer = 0;
14851 copyRegion.dstSubresource.layerCount = 0;
14852 copyRegion.dstOffset.x = 0;
14853 copyRegion.dstOffset.y = 0;
14854 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014855 copyRegion.extent.width = 1;
14856 copyRegion.extent.height = 1;
14857 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014858 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014859 EndCommandBuffer();
14860
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014861 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014862
Chia-I Wuf7458c52015-10-26 21:10:41 +080014863 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014864 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014865 vkFreeMemory(m_device->device(), srcMem, NULL);
14866 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014867}
14868
Karl Schultz6addd812016-02-02 17:17:23 -070014869TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14870 VkResult err;
14871 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014872
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14874 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014875
Mike Stroyana3082432015-09-25 13:39:21 -060014876 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014877
14878 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014879 VkImage srcImage;
14880 VkImage dstImage;
14881 VkDeviceMemory srcMem;
14882 VkDeviceMemory destMem;
14883 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014884
14885 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014886 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14887 image_create_info.pNext = NULL;
14888 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14889 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14890 image_create_info.extent.width = 32;
14891 image_create_info.extent.height = 1;
14892 image_create_info.extent.depth = 1;
14893 image_create_info.mipLevels = 1;
14894 image_create_info.arrayLayers = 1;
14895 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14896 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14897 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14898 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014899
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014900 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014901 ASSERT_VK_SUCCESS(err);
14902
Karl Schultz6addd812016-02-02 17:17:23 -070014903 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014904
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014905 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014906 ASSERT_VK_SUCCESS(err);
14907
14908 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014909 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014910 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14911 memAlloc.pNext = NULL;
14912 memAlloc.allocationSize = 0;
14913 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014914
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014915 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014916 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014917 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014918 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014919 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014920 ASSERT_VK_SUCCESS(err);
14921
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014922 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014923 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014924 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014925 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014926 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014927 ASSERT_VK_SUCCESS(err);
14928
14929 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14930 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014931 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014932 ASSERT_VK_SUCCESS(err);
14933
14934 BeginCommandBuffer();
14935 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014936 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14937 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014938 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014939 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014940 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014941 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014942 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014943 resolveRegion.srcOffset.x = 0;
14944 resolveRegion.srcOffset.y = 0;
14945 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014946 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014947 resolveRegion.dstSubresource.mipLevel = 0;
14948 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014949 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014950 resolveRegion.dstOffset.x = 0;
14951 resolveRegion.dstOffset.y = 0;
14952 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014953 resolveRegion.extent.width = 1;
14954 resolveRegion.extent.height = 1;
14955 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014956 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014957 EndCommandBuffer();
14958
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014959 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014960
Chia-I Wuf7458c52015-10-26 21:10:41 +080014961 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014962 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014963 vkFreeMemory(m_device->device(), srcMem, NULL);
14964 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014965}
14966
Karl Schultz6addd812016-02-02 17:17:23 -070014967TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14968 VkResult err;
14969 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014970
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14972 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014973
Mike Stroyana3082432015-09-25 13:39:21 -060014974 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014975
Chris Forbesa7530692016-05-08 12:35:39 +120014976 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014977 VkImage srcImage;
14978 VkImage dstImage;
14979 VkDeviceMemory srcMem;
14980 VkDeviceMemory destMem;
14981 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014982
14983 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014984 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14985 image_create_info.pNext = NULL;
14986 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14987 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14988 image_create_info.extent.width = 32;
14989 image_create_info.extent.height = 1;
14990 image_create_info.extent.depth = 1;
14991 image_create_info.mipLevels = 1;
14992 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014993 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014994 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14995 // Note: Some implementations expect color attachment usage for any
14996 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014997 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014998 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014999
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015000 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015001 ASSERT_VK_SUCCESS(err);
15002
Karl Schultz6addd812016-02-02 17:17:23 -070015003 // Note: Some implementations expect color attachment usage for any
15004 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015005 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015007 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015008 ASSERT_VK_SUCCESS(err);
15009
15010 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015011 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015012 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15013 memAlloc.pNext = NULL;
15014 memAlloc.allocationSize = 0;
15015 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015016
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015017 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015018 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015019 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015020 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015021 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015022 ASSERT_VK_SUCCESS(err);
15023
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015024 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015025 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015026 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015027 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015028 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015029 ASSERT_VK_SUCCESS(err);
15030
15031 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15032 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015033 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015034 ASSERT_VK_SUCCESS(err);
15035
15036 BeginCommandBuffer();
15037 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015038 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15039 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015040 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015041 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015042 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015043 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015044 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015045 resolveRegion.srcOffset.x = 0;
15046 resolveRegion.srcOffset.y = 0;
15047 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015048 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015049 resolveRegion.dstSubresource.mipLevel = 0;
15050 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015051 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015052 resolveRegion.dstOffset.x = 0;
15053 resolveRegion.dstOffset.y = 0;
15054 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015055 resolveRegion.extent.width = 1;
15056 resolveRegion.extent.height = 1;
15057 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015058 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015059 EndCommandBuffer();
15060
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015061 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015062
Chia-I Wuf7458c52015-10-26 21:10:41 +080015063 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015064 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015065 vkFreeMemory(m_device->device(), srcMem, NULL);
15066 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015067}
15068
Karl Schultz6addd812016-02-02 17:17:23 -070015069TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15070 VkResult err;
15071 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015072
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15074 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015075
Mike Stroyana3082432015-09-25 13:39:21 -060015076 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015077
15078 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015079 VkImage srcImage;
15080 VkImage dstImage;
15081 VkDeviceMemory srcMem;
15082 VkDeviceMemory destMem;
15083 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015084
15085 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015086 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15087 image_create_info.pNext = NULL;
15088 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15089 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15090 image_create_info.extent.width = 32;
15091 image_create_info.extent.height = 1;
15092 image_create_info.extent.depth = 1;
15093 image_create_info.mipLevels = 1;
15094 image_create_info.arrayLayers = 1;
15095 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15096 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15097 // Note: Some implementations expect color attachment usage for any
15098 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015099 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015100 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015101
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015102 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015103 ASSERT_VK_SUCCESS(err);
15104
Karl Schultz6addd812016-02-02 17:17:23 -070015105 // Set format to something other than source image
15106 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15107 // Note: Some implementations expect color attachment usage for any
15108 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015109 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015110 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015112 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015113 ASSERT_VK_SUCCESS(err);
15114
15115 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015116 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015117 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15118 memAlloc.pNext = NULL;
15119 memAlloc.allocationSize = 0;
15120 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015121
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015122 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015123 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015124 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015125 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015126 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015127 ASSERT_VK_SUCCESS(err);
15128
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015129 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015130 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015131 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015132 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015133 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015134 ASSERT_VK_SUCCESS(err);
15135
15136 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15137 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015138 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015139 ASSERT_VK_SUCCESS(err);
15140
15141 BeginCommandBuffer();
15142 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015143 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15144 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015145 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015146 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015147 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015148 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015149 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015150 resolveRegion.srcOffset.x = 0;
15151 resolveRegion.srcOffset.y = 0;
15152 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015153 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015154 resolveRegion.dstSubresource.mipLevel = 0;
15155 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015156 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015157 resolveRegion.dstOffset.x = 0;
15158 resolveRegion.dstOffset.y = 0;
15159 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015160 resolveRegion.extent.width = 1;
15161 resolveRegion.extent.height = 1;
15162 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015163 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015164 EndCommandBuffer();
15165
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015166 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015167
Chia-I Wuf7458c52015-10-26 21:10:41 +080015168 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015169 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015170 vkFreeMemory(m_device->device(), srcMem, NULL);
15171 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015172}
15173
Karl Schultz6addd812016-02-02 17:17:23 -070015174TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15175 VkResult err;
15176 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15179 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015180
Mike Stroyana3082432015-09-25 13:39:21 -060015181 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015182
15183 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015184 VkImage srcImage;
15185 VkImage dstImage;
15186 VkDeviceMemory srcMem;
15187 VkDeviceMemory destMem;
15188 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015189
15190 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015191 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15192 image_create_info.pNext = NULL;
15193 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15194 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15195 image_create_info.extent.width = 32;
15196 image_create_info.extent.height = 1;
15197 image_create_info.extent.depth = 1;
15198 image_create_info.mipLevels = 1;
15199 image_create_info.arrayLayers = 1;
15200 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15201 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15202 // Note: Some implementations expect color attachment usage for any
15203 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015204 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015205 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015207 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015208 ASSERT_VK_SUCCESS(err);
15209
Karl Schultz6addd812016-02-02 17:17:23 -070015210 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15211 // Note: Some implementations expect color attachment usage for any
15212 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015213 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015214 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015215
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015216 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015217 ASSERT_VK_SUCCESS(err);
15218
15219 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015220 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015221 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15222 memAlloc.pNext = NULL;
15223 memAlloc.allocationSize = 0;
15224 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015225
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015226 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015227 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015228 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015229 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015230 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015231 ASSERT_VK_SUCCESS(err);
15232
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015233 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015234 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015235 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015236 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015237 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015238 ASSERT_VK_SUCCESS(err);
15239
15240 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15241 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015242 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015243 ASSERT_VK_SUCCESS(err);
15244
15245 BeginCommandBuffer();
15246 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015247 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15248 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015249 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015250 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015251 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015252 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015253 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015254 resolveRegion.srcOffset.x = 0;
15255 resolveRegion.srcOffset.y = 0;
15256 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015257 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015258 resolveRegion.dstSubresource.mipLevel = 0;
15259 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015260 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015261 resolveRegion.dstOffset.x = 0;
15262 resolveRegion.dstOffset.y = 0;
15263 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015264 resolveRegion.extent.width = 1;
15265 resolveRegion.extent.height = 1;
15266 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015267 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015268 EndCommandBuffer();
15269
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015270 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015271
Chia-I Wuf7458c52015-10-26 21:10:41 +080015272 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015273 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015274 vkFreeMemory(m_device->device(), srcMem, NULL);
15275 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015276}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015277
Karl Schultz6addd812016-02-02 17:17:23 -070015278TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015279 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015280 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15281 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015282 // The image format check comes 2nd in validation so we trigger it first,
15283 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015284 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015285
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15287 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015288
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015289 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015290
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015291 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015292 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15293 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015294
15295 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015296 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15297 ds_pool_ci.pNext = NULL;
15298 ds_pool_ci.maxSets = 1;
15299 ds_pool_ci.poolSizeCount = 1;
15300 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015301
15302 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015303 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015304 ASSERT_VK_SUCCESS(err);
15305
15306 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015307 dsl_binding.binding = 0;
15308 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15309 dsl_binding.descriptorCount = 1;
15310 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15311 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015312
15313 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015314 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15315 ds_layout_ci.pNext = NULL;
15316 ds_layout_ci.bindingCount = 1;
15317 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015318 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015319 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015320 ASSERT_VK_SUCCESS(err);
15321
15322 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015323 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015324 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015325 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015326 alloc_info.descriptorPool = ds_pool;
15327 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015328 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015329 ASSERT_VK_SUCCESS(err);
15330
Karl Schultz6addd812016-02-02 17:17:23 -070015331 VkImage image_bad;
15332 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015333 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015334 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015335 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015336 const int32_t tex_width = 32;
15337 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015338
15339 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015340 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15341 image_create_info.pNext = NULL;
15342 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15343 image_create_info.format = tex_format_bad;
15344 image_create_info.extent.width = tex_width;
15345 image_create_info.extent.height = tex_height;
15346 image_create_info.extent.depth = 1;
15347 image_create_info.mipLevels = 1;
15348 image_create_info.arrayLayers = 1;
15349 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15350 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015351 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015352 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015353
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015354 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015355 ASSERT_VK_SUCCESS(err);
15356 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015357 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15358 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015359 ASSERT_VK_SUCCESS(err);
15360
15361 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015362 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015363 image_view_create_info.image = image_bad;
15364 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15365 image_view_create_info.format = tex_format_bad;
15366 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15367 image_view_create_info.subresourceRange.baseMipLevel = 0;
15368 image_view_create_info.subresourceRange.layerCount = 1;
15369 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015370 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015371
15372 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015373 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015374
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015375 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015376
Chia-I Wuf7458c52015-10-26 21:10:41 +080015377 vkDestroyImage(m_device->device(), image_bad, NULL);
15378 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015381}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015382
15383TEST_F(VkLayerTest, ClearImageErrors) {
15384 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15385 "ClearDepthStencilImage with a color image.");
15386
15387 ASSERT_NO_FATAL_FAILURE(InitState());
15388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15389
15390 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15391 BeginCommandBuffer();
15392 m_commandBuffer->EndRenderPass();
15393
15394 // Color image
15395 VkClearColorValue clear_color;
15396 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15397 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15398 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15399 const int32_t img_width = 32;
15400 const int32_t img_height = 32;
15401 VkImageCreateInfo image_create_info = {};
15402 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15403 image_create_info.pNext = NULL;
15404 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15405 image_create_info.format = color_format;
15406 image_create_info.extent.width = img_width;
15407 image_create_info.extent.height = img_height;
15408 image_create_info.extent.depth = 1;
15409 image_create_info.mipLevels = 1;
15410 image_create_info.arrayLayers = 1;
15411 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15412 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15413 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15414
15415 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015416 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015418 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015419
15420 // Depth/Stencil image
15421 VkClearDepthStencilValue clear_value = {0};
15422 reqs = 0; // don't need HOST_VISIBLE DS image
15423 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15424 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15425 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15426 ds_image_create_info.extent.width = 64;
15427 ds_image_create_info.extent.height = 64;
15428 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15429 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15430
15431 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015432 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015434 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 -060015435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015438 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015439 &color_range);
15440
15441 m_errorMonitor->VerifyFound();
15442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15444 "image created without "
15445 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015447 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015448 &color_range);
15449
15450 m_errorMonitor->VerifyFound();
15451
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015452 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15454 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015456 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15457 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015458
15459 m_errorMonitor->VerifyFound();
15460}
Tobin Ehliscde08892015-09-22 10:11:37 -060015461#endif // IMAGE_TESTS
15462
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015463
15464// WSI Enabled Tests
15465//
Chris Forbes09368e42016-10-13 11:59:22 +130015466#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015467TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15468
15469#if defined(VK_USE_PLATFORM_XCB_KHR)
15470 VkSurfaceKHR surface = VK_NULL_HANDLE;
15471
15472 VkResult err;
15473 bool pass;
15474 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15475 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15476 // uint32_t swapchain_image_count = 0;
15477 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15478 // uint32_t image_index = 0;
15479 // VkPresentInfoKHR present_info = {};
15480
15481 ASSERT_NO_FATAL_FAILURE(InitState());
15482
15483 // Use the create function from one of the VK_KHR_*_surface extension in
15484 // order to create a surface, testing all known errors in the process,
15485 // before successfully creating a surface:
15486 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15488 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15489 pass = (err != VK_SUCCESS);
15490 ASSERT_TRUE(pass);
15491 m_errorMonitor->VerifyFound();
15492
15493 // Next, try to create a surface with the wrong
15494 // VkXcbSurfaceCreateInfoKHR::sType:
15495 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15496 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15498 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15499 pass = (err != VK_SUCCESS);
15500 ASSERT_TRUE(pass);
15501 m_errorMonitor->VerifyFound();
15502
15503 // Create a native window, and then correctly create a surface:
15504 xcb_connection_t *connection;
15505 xcb_screen_t *screen;
15506 xcb_window_t xcb_window;
15507 xcb_intern_atom_reply_t *atom_wm_delete_window;
15508
15509 const xcb_setup_t *setup;
15510 xcb_screen_iterator_t iter;
15511 int scr;
15512 uint32_t value_mask, value_list[32];
15513 int width = 1;
15514 int height = 1;
15515
15516 connection = xcb_connect(NULL, &scr);
15517 ASSERT_TRUE(connection != NULL);
15518 setup = xcb_get_setup(connection);
15519 iter = xcb_setup_roots_iterator(setup);
15520 while (scr-- > 0)
15521 xcb_screen_next(&iter);
15522 screen = iter.data;
15523
15524 xcb_window = xcb_generate_id(connection);
15525
15526 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15527 value_list[0] = screen->black_pixel;
15528 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15529
15530 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15531 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15532
15533 /* Magic code that will send notification when window is destroyed */
15534 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15535 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15536
15537 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15538 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15539 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15540 free(reply);
15541
15542 xcb_map_window(connection, xcb_window);
15543
15544 // Force the x/y coordinates to 100,100 results are identical in consecutive
15545 // runs
15546 const uint32_t coords[] = { 100, 100 };
15547 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15548
15549 // Finally, try to correctly create a surface:
15550 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15551 xcb_create_info.pNext = NULL;
15552 xcb_create_info.flags = 0;
15553 xcb_create_info.connection = connection;
15554 xcb_create_info.window = xcb_window;
15555 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15556 pass = (err == VK_SUCCESS);
15557 ASSERT_TRUE(pass);
15558
15559 // Check if surface supports presentation:
15560
15561 // 1st, do so without having queried the queue families:
15562 VkBool32 supported = false;
15563 // TODO: Get the following error to come out:
15564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15565 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15566 "function");
15567 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15568 pass = (err != VK_SUCCESS);
15569 // ASSERT_TRUE(pass);
15570 // m_errorMonitor->VerifyFound();
15571
15572 // Next, query a queue family index that's too large:
15573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15574 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15575 pass = (err != VK_SUCCESS);
15576 ASSERT_TRUE(pass);
15577 m_errorMonitor->VerifyFound();
15578
15579 // Finally, do so correctly:
15580 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15581 // SUPPORTED
15582 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15583 pass = (err == VK_SUCCESS);
15584 ASSERT_TRUE(pass);
15585
15586 // Before proceeding, try to create a swapchain without having called
15587 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15588 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15589 swapchain_create_info.pNext = NULL;
15590 swapchain_create_info.flags = 0;
15591 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15592 swapchain_create_info.surface = surface;
15593 swapchain_create_info.imageArrayLayers = 1;
15594 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15595 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15597 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15598 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15599 pass = (err != VK_SUCCESS);
15600 ASSERT_TRUE(pass);
15601 m_errorMonitor->VerifyFound();
15602
15603 // Get the surface capabilities:
15604 VkSurfaceCapabilitiesKHR surface_capabilities;
15605
15606 // Do so correctly (only error logged by this entrypoint is if the
15607 // extension isn't enabled):
15608 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15609 pass = (err == VK_SUCCESS);
15610 ASSERT_TRUE(pass);
15611
15612 // Get the surface formats:
15613 uint32_t surface_format_count;
15614
15615 // First, try without a pointer to surface_format_count:
15616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15617 "specified as NULL");
15618 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15619 pass = (err == VK_SUCCESS);
15620 ASSERT_TRUE(pass);
15621 m_errorMonitor->VerifyFound();
15622
15623 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15624 // correctly done a 1st try (to get the count):
15625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15626 surface_format_count = 0;
15627 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15628 pass = (err == VK_SUCCESS);
15629 ASSERT_TRUE(pass);
15630 m_errorMonitor->VerifyFound();
15631
15632 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15633 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15634 pass = (err == VK_SUCCESS);
15635 ASSERT_TRUE(pass);
15636
15637 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15638 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15639
15640 // Next, do a 2nd try with surface_format_count being set too high:
15641 surface_format_count += 5;
15642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15643 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15644 pass = (err == VK_SUCCESS);
15645 ASSERT_TRUE(pass);
15646 m_errorMonitor->VerifyFound();
15647
15648 // Finally, do a correct 1st and 2nd try:
15649 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15650 pass = (err == VK_SUCCESS);
15651 ASSERT_TRUE(pass);
15652 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15653 pass = (err == VK_SUCCESS);
15654 ASSERT_TRUE(pass);
15655
15656 // Get the surface present modes:
15657 uint32_t surface_present_mode_count;
15658
15659 // First, try without a pointer to surface_format_count:
15660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15661 "specified as NULL");
15662
15663 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15664 pass = (err == VK_SUCCESS);
15665 ASSERT_TRUE(pass);
15666 m_errorMonitor->VerifyFound();
15667
15668 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15669 // correctly done a 1st try (to get the count):
15670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15671 surface_present_mode_count = 0;
15672 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15673 (VkPresentModeKHR *)&surface_present_mode_count);
15674 pass = (err == VK_SUCCESS);
15675 ASSERT_TRUE(pass);
15676 m_errorMonitor->VerifyFound();
15677
15678 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15679 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15680 pass = (err == VK_SUCCESS);
15681 ASSERT_TRUE(pass);
15682
15683 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15684 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15685
15686 // Next, do a 2nd try with surface_format_count being set too high:
15687 surface_present_mode_count += 5;
15688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15689 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15690 pass = (err == VK_SUCCESS);
15691 ASSERT_TRUE(pass);
15692 m_errorMonitor->VerifyFound();
15693
15694 // Finally, do a correct 1st and 2nd try:
15695 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15696 pass = (err == VK_SUCCESS);
15697 ASSERT_TRUE(pass);
15698 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15699 pass = (err == VK_SUCCESS);
15700 ASSERT_TRUE(pass);
15701
15702 // Create a swapchain:
15703
15704 // First, try without a pointer to swapchain_create_info:
15705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15706 "specified as NULL");
15707
15708 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15709 pass = (err != VK_SUCCESS);
15710 ASSERT_TRUE(pass);
15711 m_errorMonitor->VerifyFound();
15712
15713 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15714 // sType:
15715 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15717
15718 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15719 pass = (err != VK_SUCCESS);
15720 ASSERT_TRUE(pass);
15721 m_errorMonitor->VerifyFound();
15722
15723 // Next, call with a NULL swapchain pointer:
15724 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15725 swapchain_create_info.pNext = NULL;
15726 swapchain_create_info.flags = 0;
15727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15728 "specified as NULL");
15729
15730 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15731 pass = (err != VK_SUCCESS);
15732 ASSERT_TRUE(pass);
15733 m_errorMonitor->VerifyFound();
15734
15735 // TODO: Enhance swapchain layer so that
15736 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15737
15738 // Next, call with a queue family index that's too large:
15739 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15740 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15741 swapchain_create_info.queueFamilyIndexCount = 2;
15742 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15744 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15745 pass = (err != VK_SUCCESS);
15746 ASSERT_TRUE(pass);
15747 m_errorMonitor->VerifyFound();
15748
15749 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15750 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15751 swapchain_create_info.queueFamilyIndexCount = 1;
15752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15753 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15754 "pCreateInfo->pQueueFamilyIndices).");
15755 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15756 pass = (err != VK_SUCCESS);
15757 ASSERT_TRUE(pass);
15758 m_errorMonitor->VerifyFound();
15759
15760 // Next, call with an invalid imageSharingMode:
15761 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15762 swapchain_create_info.queueFamilyIndexCount = 1;
15763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15764 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15765 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15766 pass = (err != VK_SUCCESS);
15767 ASSERT_TRUE(pass);
15768 m_errorMonitor->VerifyFound();
15769 // Fix for the future:
15770 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15771 // SUPPORTED
15772 swapchain_create_info.queueFamilyIndexCount = 0;
15773 queueFamilyIndex[0] = 0;
15774 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15775
15776 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15777 // Get the images from a swapchain:
15778 // Acquire an image from a swapchain:
15779 // Present an image to a swapchain:
15780 // Destroy the swapchain:
15781
15782 // TODOs:
15783 //
15784 // - Try destroying the device without first destroying the swapchain
15785 //
15786 // - Try destroying the device without first destroying the surface
15787 //
15788 // - Try destroying the surface without first destroying the swapchain
15789
15790 // Destroy the surface:
15791 vkDestroySurfaceKHR(instance(), surface, NULL);
15792
15793 // Tear down the window:
15794 xcb_destroy_window(connection, xcb_window);
15795 xcb_disconnect(connection);
15796
15797#else // VK_USE_PLATFORM_XCB_KHR
15798 return;
15799#endif // VK_USE_PLATFORM_XCB_KHR
15800}
Chris Forbes09368e42016-10-13 11:59:22 +130015801#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015802
15803//
15804// POSITIVE VALIDATION TESTS
15805//
15806// These tests do not expect to encounter ANY validation errors pass only if this is true
15807
Tobin Ehlise0006882016-11-03 10:14:28 -060015808TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15809 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15810 "by a transition in the primary.");
15811 VkResult err;
15812 m_errorMonitor->ExpectSuccess();
15813 ASSERT_NO_FATAL_FAILURE(InitState());
15814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15815 // Allocate a secondary and primary cmd buffer
15816 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15817 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15818 command_buffer_allocate_info.commandPool = m_commandPool;
15819 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15820 command_buffer_allocate_info.commandBufferCount = 1;
15821
15822 VkCommandBuffer secondary_command_buffer;
15823 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15824 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15825 VkCommandBuffer primary_command_buffer;
15826 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15827 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15828 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15829 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15830 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15831 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15832 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15833
15834 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15835 ASSERT_VK_SUCCESS(err);
15836 VkImageObj image(m_device);
15837 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15838 ASSERT_TRUE(image.initialized());
15839 VkImageMemoryBarrier img_barrier = {};
15840 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15841 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15842 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15843 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15844 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15845 img_barrier.image = image.handle();
15846 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15847 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15848 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15849 img_barrier.subresourceRange.baseArrayLayer = 0;
15850 img_barrier.subresourceRange.baseMipLevel = 0;
15851 img_barrier.subresourceRange.layerCount = 1;
15852 img_barrier.subresourceRange.levelCount = 1;
15853 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15854 0, nullptr, 1, &img_barrier);
15855 err = vkEndCommandBuffer(secondary_command_buffer);
15856 ASSERT_VK_SUCCESS(err);
15857
15858 // Now update primary cmd buffer to execute secondary and transitions image
15859 command_buffer_begin_info.pInheritanceInfo = nullptr;
15860 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15861 ASSERT_VK_SUCCESS(err);
15862 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15863 VkImageMemoryBarrier img_barrier2 = {};
15864 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15865 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15866 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15867 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15868 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15869 img_barrier2.image = image.handle();
15870 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15871 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15872 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15873 img_barrier2.subresourceRange.baseArrayLayer = 0;
15874 img_barrier2.subresourceRange.baseMipLevel = 0;
15875 img_barrier2.subresourceRange.layerCount = 1;
15876 img_barrier2.subresourceRange.levelCount = 1;
15877 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15878 nullptr, 1, &img_barrier2);
15879 err = vkEndCommandBuffer(primary_command_buffer);
15880 ASSERT_VK_SUCCESS(err);
15881 VkSubmitInfo submit_info = {};
15882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15883 submit_info.commandBufferCount = 1;
15884 submit_info.pCommandBuffers = &primary_command_buffer;
15885 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15886 ASSERT_VK_SUCCESS(err);
15887 m_errorMonitor->VerifyNotFound();
15888 err = vkDeviceWaitIdle(m_device->device());
15889 ASSERT_VK_SUCCESS(err);
15890 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15891 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15892}
15893
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015894// This is a positive test. No failures are expected.
15895TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15896 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15897 "is ignoring VkWriteDescriptorSet members that are not "
15898 "related to the descriptor type specified by "
15899 "VkWriteDescriptorSet::descriptorType. Correct "
15900 "validation behavior will result in the test running to "
15901 "completion without validation errors.");
15902
15903 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15904
15905 ASSERT_NO_FATAL_FAILURE(InitState());
15906
15907 // Image Case
15908 {
15909 m_errorMonitor->ExpectSuccess();
15910
15911 VkImage image;
15912 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15913 const int32_t tex_width = 32;
15914 const int32_t tex_height = 32;
15915 VkImageCreateInfo image_create_info = {};
15916 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15917 image_create_info.pNext = NULL;
15918 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15919 image_create_info.format = tex_format;
15920 image_create_info.extent.width = tex_width;
15921 image_create_info.extent.height = tex_height;
15922 image_create_info.extent.depth = 1;
15923 image_create_info.mipLevels = 1;
15924 image_create_info.arrayLayers = 1;
15925 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15926 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15927 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15928 image_create_info.flags = 0;
15929 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15930 ASSERT_VK_SUCCESS(err);
15931
15932 VkMemoryRequirements memory_reqs;
15933 VkDeviceMemory image_memory;
15934 bool pass;
15935 VkMemoryAllocateInfo memory_info = {};
15936 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15937 memory_info.pNext = NULL;
15938 memory_info.allocationSize = 0;
15939 memory_info.memoryTypeIndex = 0;
15940 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15941 memory_info.allocationSize = memory_reqs.size;
15942 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15943 ASSERT_TRUE(pass);
15944 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15945 ASSERT_VK_SUCCESS(err);
15946 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15947 ASSERT_VK_SUCCESS(err);
15948
15949 VkImageViewCreateInfo image_view_create_info = {};
15950 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15951 image_view_create_info.image = image;
15952 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15953 image_view_create_info.format = tex_format;
15954 image_view_create_info.subresourceRange.layerCount = 1;
15955 image_view_create_info.subresourceRange.baseMipLevel = 0;
15956 image_view_create_info.subresourceRange.levelCount = 1;
15957 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15958
15959 VkImageView view;
15960 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15961 ASSERT_VK_SUCCESS(err);
15962
15963 VkDescriptorPoolSize ds_type_count = {};
15964 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15965 ds_type_count.descriptorCount = 1;
15966
15967 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15968 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15969 ds_pool_ci.pNext = NULL;
15970 ds_pool_ci.maxSets = 1;
15971 ds_pool_ci.poolSizeCount = 1;
15972 ds_pool_ci.pPoolSizes = &ds_type_count;
15973
15974 VkDescriptorPool ds_pool;
15975 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15976 ASSERT_VK_SUCCESS(err);
15977
15978 VkDescriptorSetLayoutBinding dsl_binding = {};
15979 dsl_binding.binding = 0;
15980 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15981 dsl_binding.descriptorCount = 1;
15982 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15983 dsl_binding.pImmutableSamplers = NULL;
15984
15985 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15986 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15987 ds_layout_ci.pNext = NULL;
15988 ds_layout_ci.bindingCount = 1;
15989 ds_layout_ci.pBindings = &dsl_binding;
15990 VkDescriptorSetLayout ds_layout;
15991 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15992 ASSERT_VK_SUCCESS(err);
15993
15994 VkDescriptorSet descriptor_set;
15995 VkDescriptorSetAllocateInfo alloc_info = {};
15996 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15997 alloc_info.descriptorSetCount = 1;
15998 alloc_info.descriptorPool = ds_pool;
15999 alloc_info.pSetLayouts = &ds_layout;
16000 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16001 ASSERT_VK_SUCCESS(err);
16002
16003 VkDescriptorImageInfo image_info = {};
16004 image_info.imageView = view;
16005 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16006
16007 VkWriteDescriptorSet descriptor_write;
16008 memset(&descriptor_write, 0, sizeof(descriptor_write));
16009 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16010 descriptor_write.dstSet = descriptor_set;
16011 descriptor_write.dstBinding = 0;
16012 descriptor_write.descriptorCount = 1;
16013 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16014 descriptor_write.pImageInfo = &image_info;
16015
16016 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16017 // be
16018 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16019 // This will most likely produce a crash if the parameter_validation
16020 // layer
16021 // does not correctly ignore pBufferInfo.
16022 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16023 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16024
16025 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16026
16027 m_errorMonitor->VerifyNotFound();
16028
16029 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16030 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16031 vkDestroyImageView(m_device->device(), view, NULL);
16032 vkDestroyImage(m_device->device(), image, NULL);
16033 vkFreeMemory(m_device->device(), image_memory, NULL);
16034 }
16035
16036 // Buffer Case
16037 {
16038 m_errorMonitor->ExpectSuccess();
16039
16040 VkBuffer buffer;
16041 uint32_t queue_family_index = 0;
16042 VkBufferCreateInfo buffer_create_info = {};
16043 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16044 buffer_create_info.size = 1024;
16045 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16046 buffer_create_info.queueFamilyIndexCount = 1;
16047 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16048
16049 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16050 ASSERT_VK_SUCCESS(err);
16051
16052 VkMemoryRequirements memory_reqs;
16053 VkDeviceMemory buffer_memory;
16054 bool pass;
16055 VkMemoryAllocateInfo memory_info = {};
16056 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16057 memory_info.pNext = NULL;
16058 memory_info.allocationSize = 0;
16059 memory_info.memoryTypeIndex = 0;
16060
16061 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16062 memory_info.allocationSize = memory_reqs.size;
16063 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16064 ASSERT_TRUE(pass);
16065
16066 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16067 ASSERT_VK_SUCCESS(err);
16068 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16069 ASSERT_VK_SUCCESS(err);
16070
16071 VkDescriptorPoolSize ds_type_count = {};
16072 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16073 ds_type_count.descriptorCount = 1;
16074
16075 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16076 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16077 ds_pool_ci.pNext = NULL;
16078 ds_pool_ci.maxSets = 1;
16079 ds_pool_ci.poolSizeCount = 1;
16080 ds_pool_ci.pPoolSizes = &ds_type_count;
16081
16082 VkDescriptorPool ds_pool;
16083 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16084 ASSERT_VK_SUCCESS(err);
16085
16086 VkDescriptorSetLayoutBinding dsl_binding = {};
16087 dsl_binding.binding = 0;
16088 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16089 dsl_binding.descriptorCount = 1;
16090 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16091 dsl_binding.pImmutableSamplers = NULL;
16092
16093 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16094 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16095 ds_layout_ci.pNext = NULL;
16096 ds_layout_ci.bindingCount = 1;
16097 ds_layout_ci.pBindings = &dsl_binding;
16098 VkDescriptorSetLayout ds_layout;
16099 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16100 ASSERT_VK_SUCCESS(err);
16101
16102 VkDescriptorSet descriptor_set;
16103 VkDescriptorSetAllocateInfo alloc_info = {};
16104 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16105 alloc_info.descriptorSetCount = 1;
16106 alloc_info.descriptorPool = ds_pool;
16107 alloc_info.pSetLayouts = &ds_layout;
16108 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16109 ASSERT_VK_SUCCESS(err);
16110
16111 VkDescriptorBufferInfo buffer_info = {};
16112 buffer_info.buffer = buffer;
16113 buffer_info.offset = 0;
16114 buffer_info.range = 1024;
16115
16116 VkWriteDescriptorSet descriptor_write;
16117 memset(&descriptor_write, 0, sizeof(descriptor_write));
16118 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16119 descriptor_write.dstSet = descriptor_set;
16120 descriptor_write.dstBinding = 0;
16121 descriptor_write.descriptorCount = 1;
16122 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16123 descriptor_write.pBufferInfo = &buffer_info;
16124
16125 // Set pImageInfo and pTexelBufferView to invalid values, which should
16126 // be
16127 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16128 // This will most likely produce a crash if the parameter_validation
16129 // layer
16130 // does not correctly ignore pImageInfo.
16131 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16132 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16133
16134 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16135
16136 m_errorMonitor->VerifyNotFound();
16137
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016138 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16139 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16140 vkDestroyBuffer(m_device->device(), buffer, NULL);
16141 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16142 }
16143
16144 // Texel Buffer Case
16145 {
16146 m_errorMonitor->ExpectSuccess();
16147
16148 VkBuffer buffer;
16149 uint32_t queue_family_index = 0;
16150 VkBufferCreateInfo buffer_create_info = {};
16151 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16152 buffer_create_info.size = 1024;
16153 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16154 buffer_create_info.queueFamilyIndexCount = 1;
16155 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16156
16157 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16158 ASSERT_VK_SUCCESS(err);
16159
16160 VkMemoryRequirements memory_reqs;
16161 VkDeviceMemory buffer_memory;
16162 bool pass;
16163 VkMemoryAllocateInfo memory_info = {};
16164 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16165 memory_info.pNext = NULL;
16166 memory_info.allocationSize = 0;
16167 memory_info.memoryTypeIndex = 0;
16168
16169 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16170 memory_info.allocationSize = memory_reqs.size;
16171 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16172 ASSERT_TRUE(pass);
16173
16174 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16175 ASSERT_VK_SUCCESS(err);
16176 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16177 ASSERT_VK_SUCCESS(err);
16178
16179 VkBufferViewCreateInfo buff_view_ci = {};
16180 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16181 buff_view_ci.buffer = buffer;
16182 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16183 buff_view_ci.range = VK_WHOLE_SIZE;
16184 VkBufferView buffer_view;
16185 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16186
16187 VkDescriptorPoolSize ds_type_count = {};
16188 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16189 ds_type_count.descriptorCount = 1;
16190
16191 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16192 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16193 ds_pool_ci.pNext = NULL;
16194 ds_pool_ci.maxSets = 1;
16195 ds_pool_ci.poolSizeCount = 1;
16196 ds_pool_ci.pPoolSizes = &ds_type_count;
16197
16198 VkDescriptorPool ds_pool;
16199 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16200 ASSERT_VK_SUCCESS(err);
16201
16202 VkDescriptorSetLayoutBinding dsl_binding = {};
16203 dsl_binding.binding = 0;
16204 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16205 dsl_binding.descriptorCount = 1;
16206 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16207 dsl_binding.pImmutableSamplers = NULL;
16208
16209 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16210 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16211 ds_layout_ci.pNext = NULL;
16212 ds_layout_ci.bindingCount = 1;
16213 ds_layout_ci.pBindings = &dsl_binding;
16214 VkDescriptorSetLayout ds_layout;
16215 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16216 ASSERT_VK_SUCCESS(err);
16217
16218 VkDescriptorSet descriptor_set;
16219 VkDescriptorSetAllocateInfo alloc_info = {};
16220 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16221 alloc_info.descriptorSetCount = 1;
16222 alloc_info.descriptorPool = ds_pool;
16223 alloc_info.pSetLayouts = &ds_layout;
16224 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16225 ASSERT_VK_SUCCESS(err);
16226
16227 VkWriteDescriptorSet descriptor_write;
16228 memset(&descriptor_write, 0, sizeof(descriptor_write));
16229 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16230 descriptor_write.dstSet = descriptor_set;
16231 descriptor_write.dstBinding = 0;
16232 descriptor_write.descriptorCount = 1;
16233 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16234 descriptor_write.pTexelBufferView = &buffer_view;
16235
16236 // Set pImageInfo and pBufferInfo to invalid values, which should be
16237 // ignored for descriptorType ==
16238 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16239 // This will most likely produce a crash if the parameter_validation
16240 // layer
16241 // does not correctly ignore pImageInfo and pBufferInfo.
16242 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16243 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16244
16245 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16246
16247 m_errorMonitor->VerifyNotFound();
16248
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016249 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16250 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16251 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16252 vkDestroyBuffer(m_device->device(), buffer, NULL);
16253 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16254 }
16255}
16256
Tobin Ehlisf7428442016-10-25 07:58:24 -060016257TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16258 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16259
16260 ASSERT_NO_FATAL_FAILURE(InitState());
16261 // Create layout where two binding #s are "1"
16262 static const uint32_t NUM_BINDINGS = 3;
16263 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16264 dsl_binding[0].binding = 1;
16265 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16266 dsl_binding[0].descriptorCount = 1;
16267 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16268 dsl_binding[0].pImmutableSamplers = NULL;
16269 dsl_binding[1].binding = 0;
16270 dsl_binding[1].descriptorCount = 1;
16271 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16272 dsl_binding[1].descriptorCount = 1;
16273 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16274 dsl_binding[1].pImmutableSamplers = NULL;
16275 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16276 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16277 dsl_binding[2].descriptorCount = 1;
16278 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16279 dsl_binding[2].pImmutableSamplers = NULL;
16280
16281 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16282 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16283 ds_layout_ci.pNext = NULL;
16284 ds_layout_ci.bindingCount = NUM_BINDINGS;
16285 ds_layout_ci.pBindings = dsl_binding;
16286 VkDescriptorSetLayout ds_layout;
16287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16288 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16289 m_errorMonitor->VerifyFound();
16290}
16291
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016292TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016293 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16294
16295 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016296
16297 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016298
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016299 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16300
16301 {
16302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16303 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16304 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16305 m_errorMonitor->VerifyFound();
16306 }
16307
16308 {
16309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16310 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16311 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16312 m_errorMonitor->VerifyFound();
16313 }
16314
16315 {
16316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16317 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16318 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16319 m_errorMonitor->VerifyFound();
16320 }
16321
16322 {
16323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16324 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16325 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16326 m_errorMonitor->VerifyFound();
16327 }
16328
16329 {
16330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16331 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16332 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16333 m_errorMonitor->VerifyFound();
16334 }
16335
16336 {
16337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16338 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16339 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16340 m_errorMonitor->VerifyFound();
16341 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016342
16343 {
16344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16345 VkRect2D scissor = {{-1, 0}, {16, 16}};
16346 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16347 m_errorMonitor->VerifyFound();
16348 }
16349
16350 {
16351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16352 VkRect2D scissor = {{0, -2}, {16, 16}};
16353 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16354 m_errorMonitor->VerifyFound();
16355 }
16356
16357 {
16358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16359 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16360 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16361 m_errorMonitor->VerifyFound();
16362 }
16363
16364 {
16365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16366 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16367 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16368 m_errorMonitor->VerifyFound();
16369 }
16370
16371 EndCommandBuffer();
16372}
16373
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016374// This is a positive test. No failures are expected.
16375TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16376 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16377 VkResult err;
16378
16379 ASSERT_NO_FATAL_FAILURE(InitState());
16380 m_errorMonitor->ExpectSuccess();
16381 VkDescriptorPoolSize ds_type_count = {};
16382 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16383 ds_type_count.descriptorCount = 2;
16384
16385 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16386 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16387 ds_pool_ci.pNext = NULL;
16388 ds_pool_ci.maxSets = 1;
16389 ds_pool_ci.poolSizeCount = 1;
16390 ds_pool_ci.pPoolSizes = &ds_type_count;
16391
16392 VkDescriptorPool ds_pool;
16393 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16394 ASSERT_VK_SUCCESS(err);
16395
16396 // Create layout with two uniform buffer descriptors w/ empty binding between them
16397 static const uint32_t NUM_BINDINGS = 3;
16398 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16399 dsl_binding[0].binding = 0;
16400 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16401 dsl_binding[0].descriptorCount = 1;
16402 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16403 dsl_binding[0].pImmutableSamplers = NULL;
16404 dsl_binding[1].binding = 1;
16405 dsl_binding[1].descriptorCount = 0; // empty binding
16406 dsl_binding[2].binding = 2;
16407 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16408 dsl_binding[2].descriptorCount = 1;
16409 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16410 dsl_binding[2].pImmutableSamplers = NULL;
16411
16412 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16413 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16414 ds_layout_ci.pNext = NULL;
16415 ds_layout_ci.bindingCount = NUM_BINDINGS;
16416 ds_layout_ci.pBindings = dsl_binding;
16417 VkDescriptorSetLayout ds_layout;
16418 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16419 ASSERT_VK_SUCCESS(err);
16420
16421 VkDescriptorSet descriptor_set = {};
16422 VkDescriptorSetAllocateInfo alloc_info = {};
16423 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16424 alloc_info.descriptorSetCount = 1;
16425 alloc_info.descriptorPool = ds_pool;
16426 alloc_info.pSetLayouts = &ds_layout;
16427 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16428 ASSERT_VK_SUCCESS(err);
16429
16430 // Create a buffer to be used for update
16431 VkBufferCreateInfo buff_ci = {};
16432 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16433 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16434 buff_ci.size = 256;
16435 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16436 VkBuffer buffer;
16437 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16438 ASSERT_VK_SUCCESS(err);
16439 // Have to bind memory to buffer before descriptor update
16440 VkMemoryAllocateInfo mem_alloc = {};
16441 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16442 mem_alloc.pNext = NULL;
16443 mem_alloc.allocationSize = 512; // one allocation for both buffers
16444 mem_alloc.memoryTypeIndex = 0;
16445
16446 VkMemoryRequirements mem_reqs;
16447 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16448 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16449 if (!pass) {
16450 vkDestroyBuffer(m_device->device(), buffer, NULL);
16451 return;
16452 }
16453
16454 VkDeviceMemory mem;
16455 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16456 ASSERT_VK_SUCCESS(err);
16457 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16458 ASSERT_VK_SUCCESS(err);
16459
16460 // Only update the descriptor at binding 2
16461 VkDescriptorBufferInfo buff_info = {};
16462 buff_info.buffer = buffer;
16463 buff_info.offset = 0;
16464 buff_info.range = VK_WHOLE_SIZE;
16465 VkWriteDescriptorSet descriptor_write = {};
16466 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16467 descriptor_write.dstBinding = 2;
16468 descriptor_write.descriptorCount = 1;
16469 descriptor_write.pTexelBufferView = nullptr;
16470 descriptor_write.pBufferInfo = &buff_info;
16471 descriptor_write.pImageInfo = nullptr;
16472 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16473 descriptor_write.dstSet = descriptor_set;
16474
16475 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16476
16477 m_errorMonitor->VerifyNotFound();
16478 // Cleanup
16479 vkFreeMemory(m_device->device(), mem, NULL);
16480 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16481 vkDestroyBuffer(m_device->device(), buffer, NULL);
16482 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16483}
16484
16485// This is a positive test. No failures are expected.
16486TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16487 VkResult err;
16488 bool pass;
16489
16490 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16491 "the buffer, create an image, and bind the same memory to "
16492 "it");
16493
16494 m_errorMonitor->ExpectSuccess();
16495
16496 ASSERT_NO_FATAL_FAILURE(InitState());
16497
16498 VkBuffer buffer;
16499 VkImage image;
16500 VkDeviceMemory mem;
16501 VkMemoryRequirements mem_reqs;
16502
16503 VkBufferCreateInfo buf_info = {};
16504 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16505 buf_info.pNext = NULL;
16506 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16507 buf_info.size = 256;
16508 buf_info.queueFamilyIndexCount = 0;
16509 buf_info.pQueueFamilyIndices = NULL;
16510 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16511 buf_info.flags = 0;
16512 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16513 ASSERT_VK_SUCCESS(err);
16514
16515 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16516
16517 VkMemoryAllocateInfo alloc_info = {};
16518 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16519 alloc_info.pNext = NULL;
16520 alloc_info.memoryTypeIndex = 0;
16521
16522 // Ensure memory is big enough for both bindings
16523 alloc_info.allocationSize = 0x10000;
16524
16525 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16526 if (!pass) {
16527 vkDestroyBuffer(m_device->device(), buffer, NULL);
16528 return;
16529 }
16530
16531 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16532 ASSERT_VK_SUCCESS(err);
16533
16534 uint8_t *pData;
16535 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16536 ASSERT_VK_SUCCESS(err);
16537
16538 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16539
16540 vkUnmapMemory(m_device->device(), mem);
16541
16542 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16543 ASSERT_VK_SUCCESS(err);
16544
16545 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16546 // memory. In fact, it was never used by the GPU.
16547 // Just be be sure, wait for idle.
16548 vkDestroyBuffer(m_device->device(), buffer, NULL);
16549 vkDeviceWaitIdle(m_device->device());
16550
16551 VkImageCreateInfo image_create_info = {};
16552 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16553 image_create_info.pNext = NULL;
16554 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16555 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16556 image_create_info.extent.width = 64;
16557 image_create_info.extent.height = 64;
16558 image_create_info.extent.depth = 1;
16559 image_create_info.mipLevels = 1;
16560 image_create_info.arrayLayers = 1;
16561 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16562 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16563 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16564 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16565 image_create_info.queueFamilyIndexCount = 0;
16566 image_create_info.pQueueFamilyIndices = NULL;
16567 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16568 image_create_info.flags = 0;
16569
16570 VkMemoryAllocateInfo mem_alloc = {};
16571 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16572 mem_alloc.pNext = NULL;
16573 mem_alloc.allocationSize = 0;
16574 mem_alloc.memoryTypeIndex = 0;
16575
16576 /* Create a mappable image. It will be the texture if linear images are ok
16577 * to be textures or it will be the staging image if they are not.
16578 */
16579 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16580 ASSERT_VK_SUCCESS(err);
16581
16582 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16583
16584 mem_alloc.allocationSize = mem_reqs.size;
16585
16586 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16587 if (!pass) {
16588 vkDestroyImage(m_device->device(), image, NULL);
16589 return;
16590 }
16591
16592 // VALIDATION FAILURE:
16593 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16594 ASSERT_VK_SUCCESS(err);
16595
16596 m_errorMonitor->VerifyNotFound();
16597
16598 vkFreeMemory(m_device->device(), mem, NULL);
16599 vkDestroyBuffer(m_device->device(), buffer, NULL);
16600 vkDestroyImage(m_device->device(), image, NULL);
16601}
16602
Tobin Ehlis953e8392016-11-17 10:54:13 -070016603TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16604 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16605 // We previously had a bug where dynamic offset of inactive bindings was still being used
16606 VkResult err;
16607 m_errorMonitor->ExpectSuccess();
16608
16609 ASSERT_NO_FATAL_FAILURE(InitState());
16610 ASSERT_NO_FATAL_FAILURE(InitViewport());
16611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16612
16613 VkDescriptorPoolSize ds_type_count = {};
16614 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16615 ds_type_count.descriptorCount = 3;
16616
16617 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16618 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16619 ds_pool_ci.pNext = NULL;
16620 ds_pool_ci.maxSets = 1;
16621 ds_pool_ci.poolSizeCount = 1;
16622 ds_pool_ci.pPoolSizes = &ds_type_count;
16623
16624 VkDescriptorPool ds_pool;
16625 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16626 ASSERT_VK_SUCCESS(err);
16627
16628 const uint32_t BINDING_COUNT = 3;
16629 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016630 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016631 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16632 dsl_binding[0].descriptorCount = 1;
16633 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16634 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016635 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016636 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16637 dsl_binding[1].descriptorCount = 1;
16638 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16639 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016640 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016641 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16642 dsl_binding[2].descriptorCount = 1;
16643 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16644 dsl_binding[2].pImmutableSamplers = NULL;
16645
16646 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16647 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16648 ds_layout_ci.pNext = NULL;
16649 ds_layout_ci.bindingCount = BINDING_COUNT;
16650 ds_layout_ci.pBindings = dsl_binding;
16651 VkDescriptorSetLayout ds_layout;
16652 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16653 ASSERT_VK_SUCCESS(err);
16654
16655 VkDescriptorSet descriptor_set;
16656 VkDescriptorSetAllocateInfo alloc_info = {};
16657 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16658 alloc_info.descriptorSetCount = 1;
16659 alloc_info.descriptorPool = ds_pool;
16660 alloc_info.pSetLayouts = &ds_layout;
16661 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16662 ASSERT_VK_SUCCESS(err);
16663
16664 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16665 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16666 pipeline_layout_ci.pNext = NULL;
16667 pipeline_layout_ci.setLayoutCount = 1;
16668 pipeline_layout_ci.pSetLayouts = &ds_layout;
16669
16670 VkPipelineLayout pipeline_layout;
16671 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16672 ASSERT_VK_SUCCESS(err);
16673
16674 // Create two buffers to update the descriptors with
16675 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16676 uint32_t qfi = 0;
16677 VkBufferCreateInfo buffCI = {};
16678 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16679 buffCI.size = 2048;
16680 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16681 buffCI.queueFamilyIndexCount = 1;
16682 buffCI.pQueueFamilyIndices = &qfi;
16683
16684 VkBuffer dyub1;
16685 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16686 ASSERT_VK_SUCCESS(err);
16687 // buffer2
16688 buffCI.size = 1024;
16689 VkBuffer dyub2;
16690 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16691 ASSERT_VK_SUCCESS(err);
16692 // Allocate memory and bind to buffers
16693 VkMemoryAllocateInfo mem_alloc[2] = {};
16694 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16695 mem_alloc[0].pNext = NULL;
16696 mem_alloc[0].memoryTypeIndex = 0;
16697 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16698 mem_alloc[1].pNext = NULL;
16699 mem_alloc[1].memoryTypeIndex = 0;
16700
16701 VkMemoryRequirements mem_reqs1;
16702 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16703 VkMemoryRequirements mem_reqs2;
16704 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16705 mem_alloc[0].allocationSize = mem_reqs1.size;
16706 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16707 mem_alloc[1].allocationSize = mem_reqs2.size;
16708 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16709 if (!pass) {
16710 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16711 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16712 return;
16713 }
16714
16715 VkDeviceMemory mem1;
16716 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16717 ASSERT_VK_SUCCESS(err);
16718 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16719 ASSERT_VK_SUCCESS(err);
16720 VkDeviceMemory mem2;
16721 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16722 ASSERT_VK_SUCCESS(err);
16723 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16724 ASSERT_VK_SUCCESS(err);
16725 // Update descriptors
16726 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16727 buff_info[0].buffer = dyub1;
16728 buff_info[0].offset = 0;
16729 buff_info[0].range = 256;
16730 buff_info[1].buffer = dyub1;
16731 buff_info[1].offset = 256;
16732 buff_info[1].range = 512;
16733 buff_info[2].buffer = dyub2;
16734 buff_info[2].offset = 0;
16735 buff_info[2].range = 512;
16736
16737 VkWriteDescriptorSet descriptor_write;
16738 memset(&descriptor_write, 0, sizeof(descriptor_write));
16739 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16740 descriptor_write.dstSet = descriptor_set;
16741 descriptor_write.dstBinding = 0;
16742 descriptor_write.descriptorCount = BINDING_COUNT;
16743 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16744 descriptor_write.pBufferInfo = buff_info;
16745
16746 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16747
16748 BeginCommandBuffer();
16749
16750 // Create PSO to be used for draw-time errors below
16751 char const *vsSource = "#version 450\n"
16752 "\n"
16753 "out gl_PerVertex { \n"
16754 " vec4 gl_Position;\n"
16755 "};\n"
16756 "void main(){\n"
16757 " gl_Position = vec4(1);\n"
16758 "}\n";
16759 char const *fsSource = "#version 450\n"
16760 "\n"
16761 "layout(location=0) out vec4 x;\n"
16762 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16763 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16764 "void main(){\n"
16765 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16766 "}\n";
16767 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16768 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16769 VkPipelineObj pipe(m_device);
16770 pipe.SetViewport(m_viewports);
16771 pipe.SetScissor(m_scissors);
16772 pipe.AddShader(&vs);
16773 pipe.AddShader(&fs);
16774 pipe.AddColorAttachment();
16775 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16776
16777 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16778 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16779 // we used to have a bug in this case.
16780 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16781 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16782 &descriptor_set, BINDING_COUNT, dyn_off);
16783 Draw(1, 0, 0, 0);
16784 m_errorMonitor->VerifyNotFound();
16785
16786 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16787 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16788 vkFreeMemory(m_device->device(), mem1, NULL);
16789 vkFreeMemory(m_device->device(), mem2, NULL);
16790
16791 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16792 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16793 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16794}
16795
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016796TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16797
16798 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16799 "mapping while using VK_WHOLE_SIZE does not cause access "
16800 "violations");
16801 VkResult err;
16802 uint8_t *pData;
16803 ASSERT_NO_FATAL_FAILURE(InitState());
16804
16805 VkDeviceMemory mem;
16806 VkMemoryRequirements mem_reqs;
16807 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016808 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016809 VkMemoryAllocateInfo alloc_info = {};
16810 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16811 alloc_info.pNext = NULL;
16812 alloc_info.memoryTypeIndex = 0;
16813
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016814 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016815 alloc_info.allocationSize = allocation_size;
16816
16817 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16818 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16819 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16820 if (!pass) {
16821 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16822 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16823 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16824 if (!pass) {
16825 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16826 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16827 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16828 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16829 if (!pass) {
16830 return;
16831 }
16832 }
16833 }
16834
16835 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16836 ASSERT_VK_SUCCESS(err);
16837
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016838 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016839 m_errorMonitor->ExpectSuccess();
16840 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16841 ASSERT_VK_SUCCESS(err);
16842 VkMappedMemoryRange mmr = {};
16843 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16844 mmr.memory = mem;
16845 mmr.offset = 0;
16846 mmr.size = VK_WHOLE_SIZE;
16847 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16848 ASSERT_VK_SUCCESS(err);
16849 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16850 ASSERT_VK_SUCCESS(err);
16851 m_errorMonitor->VerifyNotFound();
16852 vkUnmapMemory(m_device->device(), mem);
16853
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016854 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016855 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016856 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016857 ASSERT_VK_SUCCESS(err);
16858 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16859 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016860 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016861 mmr.size = VK_WHOLE_SIZE;
16862 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16863 ASSERT_VK_SUCCESS(err);
16864 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16865 ASSERT_VK_SUCCESS(err);
16866 m_errorMonitor->VerifyNotFound();
16867 vkUnmapMemory(m_device->device(), mem);
16868
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016869 // Map with offset and size
16870 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016871 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016872 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016873 ASSERT_VK_SUCCESS(err);
16874 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16875 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016876 mmr.offset = 4 * atom_size;
16877 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016878 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16879 ASSERT_VK_SUCCESS(err);
16880 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16881 ASSERT_VK_SUCCESS(err);
16882 m_errorMonitor->VerifyNotFound();
16883 vkUnmapMemory(m_device->device(), mem);
16884
16885 // Map without offset and flush WHOLE_SIZE with two separate offsets
16886 m_errorMonitor->ExpectSuccess();
16887 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16888 ASSERT_VK_SUCCESS(err);
16889 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16890 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016891 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016892 mmr.size = VK_WHOLE_SIZE;
16893 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16894 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016895 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016896 mmr.size = VK_WHOLE_SIZE;
16897 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16898 ASSERT_VK_SUCCESS(err);
16899 m_errorMonitor->VerifyNotFound();
16900 vkUnmapMemory(m_device->device(), mem);
16901
16902 vkFreeMemory(m_device->device(), mem, NULL);
16903}
16904
16905// This is a positive test. We used to expect error in this case but spec now allows it
16906TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16907 m_errorMonitor->ExpectSuccess();
16908 vk_testing::Fence testFence;
16909 VkFenceCreateInfo fenceInfo = {};
16910 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16911 fenceInfo.pNext = NULL;
16912
16913 ASSERT_NO_FATAL_FAILURE(InitState());
16914 testFence.init(*m_device, fenceInfo);
16915 VkFence fences[1] = { testFence.handle() };
16916 VkResult result = vkResetFences(m_device->device(), 1, fences);
16917 ASSERT_VK_SUCCESS(result);
16918
16919 m_errorMonitor->VerifyNotFound();
16920}
16921
16922TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16923 m_errorMonitor->ExpectSuccess();
16924
16925 ASSERT_NO_FATAL_FAILURE(InitState());
16926 VkResult err;
16927
16928 // Record (empty!) command buffer that can be submitted multiple times
16929 // simultaneously.
16930 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16931 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16932 m_commandBuffer->BeginCommandBuffer(&cbbi);
16933 m_commandBuffer->EndCommandBuffer();
16934
16935 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16936 VkFence fence;
16937 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16938 ASSERT_VK_SUCCESS(err);
16939
16940 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16941 VkSemaphore s1, s2;
16942 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16943 ASSERT_VK_SUCCESS(err);
16944 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16945 ASSERT_VK_SUCCESS(err);
16946
16947 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16948 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16949 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16950 ASSERT_VK_SUCCESS(err);
16951
16952 // Submit CB again, signaling s2.
16953 si.pSignalSemaphores = &s2;
16954 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16955 ASSERT_VK_SUCCESS(err);
16956
16957 // Wait for fence.
16958 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16959 ASSERT_VK_SUCCESS(err);
16960
16961 // CB is still in flight from second submission, but semaphore s1 is no
16962 // longer in flight. delete it.
16963 vkDestroySemaphore(m_device->device(), s1, nullptr);
16964
16965 m_errorMonitor->VerifyNotFound();
16966
16967 // Force device idle and clean up remaining objects
16968 vkDeviceWaitIdle(m_device->device());
16969 vkDestroySemaphore(m_device->device(), s2, nullptr);
16970 vkDestroyFence(m_device->device(), fence, nullptr);
16971}
16972
16973TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16974 m_errorMonitor->ExpectSuccess();
16975
16976 ASSERT_NO_FATAL_FAILURE(InitState());
16977 VkResult err;
16978
16979 // A fence created signaled
16980 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16981 VkFence f1;
16982 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16983 ASSERT_VK_SUCCESS(err);
16984
16985 // A fence created not
16986 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16987 VkFence f2;
16988 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16989 ASSERT_VK_SUCCESS(err);
16990
16991 // Submit the unsignaled fence
16992 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16993 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16994
16995 // Wait on both fences, with signaled first.
16996 VkFence fences[] = { f1, f2 };
16997 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16998
16999 // Should have both retired!
17000 vkDestroyFence(m_device->device(), f1, nullptr);
17001 vkDestroyFence(m_device->device(), f2, nullptr);
17002
17003 m_errorMonitor->VerifyNotFound();
17004}
17005
17006TEST_F(VkPositiveLayerTest, ValidUsage) {
17007 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17008 "doesn't generate validation errors");
17009
17010 ASSERT_NO_FATAL_FAILURE(InitState());
17011
17012 m_errorMonitor->ExpectSuccess();
17013 // Verify that we can create a view with usage INPUT_ATTACHMENT
17014 VkImageObj image(m_device);
17015 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17016 ASSERT_TRUE(image.initialized());
17017 VkImageView imageView;
17018 VkImageViewCreateInfo ivci = {};
17019 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17020 ivci.image = image.handle();
17021 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17022 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17023 ivci.subresourceRange.layerCount = 1;
17024 ivci.subresourceRange.baseMipLevel = 0;
17025 ivci.subresourceRange.levelCount = 1;
17026 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17027
17028 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17029 m_errorMonitor->VerifyNotFound();
17030 vkDestroyImageView(m_device->device(), imageView, NULL);
17031}
17032
17033// This is a positive test. No failures are expected.
17034TEST_F(VkPositiveLayerTest, BindSparse) {
17035 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17036 "and then free the memory");
17037
17038 ASSERT_NO_FATAL_FAILURE(InitState());
17039
17040 auto index = m_device->graphics_queue_node_index_;
17041 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17042 return;
17043
17044 m_errorMonitor->ExpectSuccess();
17045
17046 VkImage image;
17047 VkImageCreateInfo image_create_info = {};
17048 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17049 image_create_info.pNext = NULL;
17050 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17051 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17052 image_create_info.extent.width = 64;
17053 image_create_info.extent.height = 64;
17054 image_create_info.extent.depth = 1;
17055 image_create_info.mipLevels = 1;
17056 image_create_info.arrayLayers = 1;
17057 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17058 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17059 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17060 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17061 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17062 ASSERT_VK_SUCCESS(err);
17063
17064 VkMemoryRequirements memory_reqs;
17065 VkDeviceMemory memory_one, memory_two;
17066 bool pass;
17067 VkMemoryAllocateInfo memory_info = {};
17068 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17069 memory_info.pNext = NULL;
17070 memory_info.allocationSize = 0;
17071 memory_info.memoryTypeIndex = 0;
17072 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17073 // Find an image big enough to allow sparse mapping of 2 memory regions
17074 // Increase the image size until it is at least twice the
17075 // size of the required alignment, to ensure we can bind both
17076 // allocated memory blocks to the image on aligned offsets.
17077 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17078 vkDestroyImage(m_device->device(), image, nullptr);
17079 image_create_info.extent.width *= 2;
17080 image_create_info.extent.height *= 2;
17081 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17082 ASSERT_VK_SUCCESS(err);
17083 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17084 }
17085 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17086 // at the end of the first
17087 memory_info.allocationSize = memory_reqs.alignment;
17088 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17089 ASSERT_TRUE(pass);
17090 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17091 ASSERT_VK_SUCCESS(err);
17092 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17093 ASSERT_VK_SUCCESS(err);
17094 VkSparseMemoryBind binds[2];
17095 binds[0].flags = 0;
17096 binds[0].memory = memory_one;
17097 binds[0].memoryOffset = 0;
17098 binds[0].resourceOffset = 0;
17099 binds[0].size = memory_info.allocationSize;
17100 binds[1].flags = 0;
17101 binds[1].memory = memory_two;
17102 binds[1].memoryOffset = 0;
17103 binds[1].resourceOffset = memory_info.allocationSize;
17104 binds[1].size = memory_info.allocationSize;
17105
17106 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17107 opaqueBindInfo.image = image;
17108 opaqueBindInfo.bindCount = 2;
17109 opaqueBindInfo.pBinds = binds;
17110
17111 VkFence fence = VK_NULL_HANDLE;
17112 VkBindSparseInfo bindSparseInfo = {};
17113 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17114 bindSparseInfo.imageOpaqueBindCount = 1;
17115 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17116
17117 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17118 vkQueueWaitIdle(m_device->m_queue);
17119 vkDestroyImage(m_device->device(), image, NULL);
17120 vkFreeMemory(m_device->device(), memory_one, NULL);
17121 vkFreeMemory(m_device->device(), memory_two, NULL);
17122 m_errorMonitor->VerifyNotFound();
17123}
17124
17125TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17126 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17127 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17128 "the command buffer has prior knowledge of that "
17129 "attachment's layout.");
17130
17131 m_errorMonitor->ExpectSuccess();
17132
17133 ASSERT_NO_FATAL_FAILURE(InitState());
17134
17135 // A renderpass with one color attachment.
17136 VkAttachmentDescription attachment = { 0,
17137 VK_FORMAT_R8G8B8A8_UNORM,
17138 VK_SAMPLE_COUNT_1_BIT,
17139 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17140 VK_ATTACHMENT_STORE_OP_STORE,
17141 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17142 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17143 VK_IMAGE_LAYOUT_UNDEFINED,
17144 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17145
17146 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17147
17148 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17149
17150 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17151
17152 VkRenderPass rp;
17153 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17154 ASSERT_VK_SUCCESS(err);
17155
17156 // A compatible framebuffer.
17157 VkImageObj image(m_device);
17158 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17159 ASSERT_TRUE(image.initialized());
17160
17161 VkImageViewCreateInfo ivci = {
17162 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17163 nullptr,
17164 0,
17165 image.handle(),
17166 VK_IMAGE_VIEW_TYPE_2D,
17167 VK_FORMAT_R8G8B8A8_UNORM,
17168 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17169 VK_COMPONENT_SWIZZLE_IDENTITY },
17170 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17171 };
17172 VkImageView view;
17173 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17174 ASSERT_VK_SUCCESS(err);
17175
17176 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17177 VkFramebuffer fb;
17178 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17179 ASSERT_VK_SUCCESS(err);
17180
17181 // Record a single command buffer which uses this renderpass twice. The
17182 // bug is triggered at the beginning of the second renderpass, when the
17183 // command buffer already has a layout recorded for the attachment.
17184 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17185 BeginCommandBuffer();
17186 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17187 vkCmdEndRenderPass(m_commandBuffer->handle());
17188 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17189
17190 m_errorMonitor->VerifyNotFound();
17191
17192 vkCmdEndRenderPass(m_commandBuffer->handle());
17193 EndCommandBuffer();
17194
17195 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17196 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17197 vkDestroyImageView(m_device->device(), view, nullptr);
17198}
17199
17200TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17201 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17202 "command buffer, bind them together, then destroy "
17203 "command pool and framebuffer and verify there are no "
17204 "errors.");
17205
17206 m_errorMonitor->ExpectSuccess();
17207
17208 ASSERT_NO_FATAL_FAILURE(InitState());
17209
17210 // A renderpass with one color attachment.
17211 VkAttachmentDescription attachment = { 0,
17212 VK_FORMAT_R8G8B8A8_UNORM,
17213 VK_SAMPLE_COUNT_1_BIT,
17214 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17215 VK_ATTACHMENT_STORE_OP_STORE,
17216 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17217 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17218 VK_IMAGE_LAYOUT_UNDEFINED,
17219 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17220
17221 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17222
17223 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17224
17225 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17226
17227 VkRenderPass rp;
17228 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17229 ASSERT_VK_SUCCESS(err);
17230
17231 // A compatible framebuffer.
17232 VkImageObj image(m_device);
17233 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17234 ASSERT_TRUE(image.initialized());
17235
17236 VkImageViewCreateInfo ivci = {
17237 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17238 nullptr,
17239 0,
17240 image.handle(),
17241 VK_IMAGE_VIEW_TYPE_2D,
17242 VK_FORMAT_R8G8B8A8_UNORM,
17243 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17244 VK_COMPONENT_SWIZZLE_IDENTITY },
17245 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17246 };
17247 VkImageView view;
17248 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17249 ASSERT_VK_SUCCESS(err);
17250
17251 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17252 VkFramebuffer fb;
17253 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17254 ASSERT_VK_SUCCESS(err);
17255
17256 // Explicitly create a command buffer to bind the FB to so that we can then
17257 // destroy the command pool in order to implicitly free command buffer
17258 VkCommandPool command_pool;
17259 VkCommandPoolCreateInfo pool_create_info{};
17260 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17261 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17262 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17263 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17264
17265 VkCommandBuffer command_buffer;
17266 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17267 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17268 command_buffer_allocate_info.commandPool = command_pool;
17269 command_buffer_allocate_info.commandBufferCount = 1;
17270 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17271 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17272
17273 // Begin our cmd buffer with renderpass using our framebuffer
17274 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17275 VkCommandBufferBeginInfo begin_info{};
17276 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17277 vkBeginCommandBuffer(command_buffer, &begin_info);
17278
17279 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17280 vkCmdEndRenderPass(command_buffer);
17281 vkEndCommandBuffer(command_buffer);
17282 vkDestroyImageView(m_device->device(), view, nullptr);
17283 // Destroy command pool to implicitly free command buffer
17284 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17285 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17286 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17287 m_errorMonitor->VerifyNotFound();
17288}
17289
17290TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17291 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17292 "transitions for the first subpass");
17293
17294 m_errorMonitor->ExpectSuccess();
17295
17296 ASSERT_NO_FATAL_FAILURE(InitState());
17297
17298 // A renderpass with one color attachment.
17299 VkAttachmentDescription attachment = { 0,
17300 VK_FORMAT_R8G8B8A8_UNORM,
17301 VK_SAMPLE_COUNT_1_BIT,
17302 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17303 VK_ATTACHMENT_STORE_OP_STORE,
17304 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17305 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17306 VK_IMAGE_LAYOUT_UNDEFINED,
17307 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17308
17309 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17310
17311 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17312
17313 VkSubpassDependency dep = { 0,
17314 0,
17315 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17316 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17317 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17318 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17319 VK_DEPENDENCY_BY_REGION_BIT };
17320
17321 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17322
17323 VkResult err;
17324 VkRenderPass rp;
17325 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17326 ASSERT_VK_SUCCESS(err);
17327
17328 // A compatible framebuffer.
17329 VkImageObj image(m_device);
17330 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17331 ASSERT_TRUE(image.initialized());
17332
17333 VkImageViewCreateInfo ivci = {
17334 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17335 nullptr,
17336 0,
17337 image.handle(),
17338 VK_IMAGE_VIEW_TYPE_2D,
17339 VK_FORMAT_R8G8B8A8_UNORM,
17340 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17341 VK_COMPONENT_SWIZZLE_IDENTITY },
17342 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17343 };
17344 VkImageView view;
17345 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17346 ASSERT_VK_SUCCESS(err);
17347
17348 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17349 VkFramebuffer fb;
17350 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17351 ASSERT_VK_SUCCESS(err);
17352
17353 // Record a single command buffer which issues a pipeline barrier w/
17354 // image memory barrier for the attachment. This detects the previously
17355 // missing tracking of the subpass layout by throwing a validation error
17356 // if it doesn't occur.
17357 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17358 BeginCommandBuffer();
17359 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17360
17361 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17362 nullptr,
17363 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17364 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17365 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17366 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17367 VK_QUEUE_FAMILY_IGNORED,
17368 VK_QUEUE_FAMILY_IGNORED,
17369 image.handle(),
17370 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17371 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17372 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17373 &imb);
17374
17375 vkCmdEndRenderPass(m_commandBuffer->handle());
17376 m_errorMonitor->VerifyNotFound();
17377 EndCommandBuffer();
17378
17379 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17380 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17381 vkDestroyImageView(m_device->device(), view, nullptr);
17382}
17383
17384TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17385 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17386 "is used as a depth/stencil framebuffer attachment, the "
17387 "aspectMask is ignored and both depth and stencil image "
17388 "subresources are used.");
17389
17390 VkFormatProperties format_properties;
17391 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17392 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17393 return;
17394 }
17395
17396 m_errorMonitor->ExpectSuccess();
17397
17398 ASSERT_NO_FATAL_FAILURE(InitState());
17399
17400 VkAttachmentDescription attachment = { 0,
17401 VK_FORMAT_D32_SFLOAT_S8_UINT,
17402 VK_SAMPLE_COUNT_1_BIT,
17403 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17404 VK_ATTACHMENT_STORE_OP_STORE,
17405 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17406 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17407 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17408 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17409
17410 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17411
17412 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17413
17414 VkSubpassDependency dep = { 0,
17415 0,
17416 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17417 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17418 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17419 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17420 VK_DEPENDENCY_BY_REGION_BIT};
17421
17422 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17423
17424 VkResult err;
17425 VkRenderPass rp;
17426 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17427 ASSERT_VK_SUCCESS(err);
17428
17429 VkImageObj image(m_device);
17430 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17431 0x26, // usage
17432 VK_IMAGE_TILING_OPTIMAL, 0);
17433 ASSERT_TRUE(image.initialized());
17434 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17435
17436 VkImageViewCreateInfo ivci = {
17437 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17438 nullptr,
17439 0,
17440 image.handle(),
17441 VK_IMAGE_VIEW_TYPE_2D,
17442 VK_FORMAT_D32_SFLOAT_S8_UINT,
17443 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17444 { 0x2, 0, 1, 0, 1 },
17445 };
17446 VkImageView view;
17447 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17448 ASSERT_VK_SUCCESS(err);
17449
17450 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17451 VkFramebuffer fb;
17452 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17453 ASSERT_VK_SUCCESS(err);
17454
17455 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17456 BeginCommandBuffer();
17457 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17458
17459 VkImageMemoryBarrier imb = {};
17460 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17461 imb.pNext = nullptr;
17462 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17463 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17464 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17465 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17466 imb.srcQueueFamilyIndex = 0;
17467 imb.dstQueueFamilyIndex = 0;
17468 imb.image = image.handle();
17469 imb.subresourceRange.aspectMask = 0x6;
17470 imb.subresourceRange.baseMipLevel = 0;
17471 imb.subresourceRange.levelCount = 0x1;
17472 imb.subresourceRange.baseArrayLayer = 0;
17473 imb.subresourceRange.layerCount = 0x1;
17474
17475 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17476 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17477 &imb);
17478
17479 vkCmdEndRenderPass(m_commandBuffer->handle());
17480 EndCommandBuffer();
17481 QueueCommandBuffer(false);
17482 m_errorMonitor->VerifyNotFound();
17483
17484 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17485 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17486 vkDestroyImageView(m_device->device(), view, nullptr);
17487}
17488
17489TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17490 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17491 "errors, when an attachment reference is "
17492 "VK_ATTACHMENT_UNUSED");
17493
17494 m_errorMonitor->ExpectSuccess();
17495
17496 ASSERT_NO_FATAL_FAILURE(InitState());
17497
17498 // A renderpass with no attachments
17499 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17500
17501 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17502
17503 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17504
17505 VkRenderPass rp;
17506 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17507 ASSERT_VK_SUCCESS(err);
17508
17509 // A compatible framebuffer.
17510 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17511 VkFramebuffer fb;
17512 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17513 ASSERT_VK_SUCCESS(err);
17514
17515 // Record a command buffer which just begins and ends the renderpass. The
17516 // bug manifests in BeginRenderPass.
17517 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17518 BeginCommandBuffer();
17519 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17520 vkCmdEndRenderPass(m_commandBuffer->handle());
17521 m_errorMonitor->VerifyNotFound();
17522 EndCommandBuffer();
17523
17524 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17525 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17526}
17527
17528// This is a positive test. No errors are expected.
17529TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17530 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17531 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17532 VkResult result = VK_SUCCESS;
17533 VkImageFormatProperties formatProps;
17534 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17535 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17536 &formatProps);
17537 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17538 return;
17539 }
17540
17541 ASSERT_NO_FATAL_FAILURE(InitState());
17542 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17543 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17544 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17545 VkAttachmentDescription att = {};
17546 VkAttachmentReference ref = {};
17547 att.format = depth_stencil_fmt;
17548 att.samples = VK_SAMPLE_COUNT_1_BIT;
17549 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17550 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17551 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17552 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17553 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17554 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17555
17556 VkClearValue clear;
17557 clear.depthStencil.depth = 1.0;
17558 clear.depthStencil.stencil = 0;
17559 ref.attachment = 0;
17560 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17561
17562 VkSubpassDescription subpass = {};
17563 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17564 subpass.flags = 0;
17565 subpass.inputAttachmentCount = 0;
17566 subpass.pInputAttachments = NULL;
17567 subpass.colorAttachmentCount = 0;
17568 subpass.pColorAttachments = NULL;
17569 subpass.pResolveAttachments = NULL;
17570 subpass.pDepthStencilAttachment = &ref;
17571 subpass.preserveAttachmentCount = 0;
17572 subpass.pPreserveAttachments = NULL;
17573
17574 VkRenderPass rp;
17575 VkRenderPassCreateInfo rp_info = {};
17576 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17577 rp_info.attachmentCount = 1;
17578 rp_info.pAttachments = &att;
17579 rp_info.subpassCount = 1;
17580 rp_info.pSubpasses = &subpass;
17581 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17582 ASSERT_VK_SUCCESS(result);
17583
17584 VkImageView *depthView = m_depthStencil->BindInfo();
17585 VkFramebufferCreateInfo fb_info = {};
17586 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17587 fb_info.pNext = NULL;
17588 fb_info.renderPass = rp;
17589 fb_info.attachmentCount = 1;
17590 fb_info.pAttachments = depthView;
17591 fb_info.width = 100;
17592 fb_info.height = 100;
17593 fb_info.layers = 1;
17594 VkFramebuffer fb;
17595 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17596 ASSERT_VK_SUCCESS(result);
17597
17598 VkRenderPassBeginInfo rpbinfo = {};
17599 rpbinfo.clearValueCount = 1;
17600 rpbinfo.pClearValues = &clear;
17601 rpbinfo.pNext = NULL;
17602 rpbinfo.renderPass = rp;
17603 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17604 rpbinfo.renderArea.extent.width = 100;
17605 rpbinfo.renderArea.extent.height = 100;
17606 rpbinfo.renderArea.offset.x = 0;
17607 rpbinfo.renderArea.offset.y = 0;
17608 rpbinfo.framebuffer = fb;
17609
17610 VkFence fence = {};
17611 VkFenceCreateInfo fence_ci = {};
17612 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17613 fence_ci.pNext = nullptr;
17614 fence_ci.flags = 0;
17615 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17616 ASSERT_VK_SUCCESS(result);
17617
17618 m_commandBuffer->BeginCommandBuffer();
17619 m_commandBuffer->BeginRenderPass(rpbinfo);
17620 m_commandBuffer->EndRenderPass();
17621 m_commandBuffer->EndCommandBuffer();
17622 m_commandBuffer->QueueCommandBuffer(fence);
17623
17624 VkImageObj destImage(m_device);
17625 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17626 VK_IMAGE_TILING_OPTIMAL, 0);
17627 VkImageMemoryBarrier barrier = {};
17628 VkImageSubresourceRange range;
17629 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17630 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17631 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17632 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17633 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17634 barrier.image = m_depthStencil->handle();
17635 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17636 range.baseMipLevel = 0;
17637 range.levelCount = 1;
17638 range.baseArrayLayer = 0;
17639 range.layerCount = 1;
17640 barrier.subresourceRange = range;
17641 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17642 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17643 cmdbuf.BeginCommandBuffer();
17644 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17645 &barrier);
17646 barrier.srcAccessMask = 0;
17647 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17648 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17649 barrier.image = destImage.handle();
17650 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17651 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17652 &barrier);
17653 VkImageCopy cregion;
17654 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17655 cregion.srcSubresource.mipLevel = 0;
17656 cregion.srcSubresource.baseArrayLayer = 0;
17657 cregion.srcSubresource.layerCount = 1;
17658 cregion.srcOffset.x = 0;
17659 cregion.srcOffset.y = 0;
17660 cregion.srcOffset.z = 0;
17661 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17662 cregion.dstSubresource.mipLevel = 0;
17663 cregion.dstSubresource.baseArrayLayer = 0;
17664 cregion.dstSubresource.layerCount = 1;
17665 cregion.dstOffset.x = 0;
17666 cregion.dstOffset.y = 0;
17667 cregion.dstOffset.z = 0;
17668 cregion.extent.width = 100;
17669 cregion.extent.height = 100;
17670 cregion.extent.depth = 1;
17671 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17672 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17673 cmdbuf.EndCommandBuffer();
17674
17675 VkSubmitInfo submit_info;
17676 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17677 submit_info.pNext = NULL;
17678 submit_info.waitSemaphoreCount = 0;
17679 submit_info.pWaitSemaphores = NULL;
17680 submit_info.pWaitDstStageMask = NULL;
17681 submit_info.commandBufferCount = 1;
17682 submit_info.pCommandBuffers = &cmdbuf.handle();
17683 submit_info.signalSemaphoreCount = 0;
17684 submit_info.pSignalSemaphores = NULL;
17685
17686 m_errorMonitor->ExpectSuccess();
17687 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17688 m_errorMonitor->VerifyNotFound();
17689
17690 vkQueueWaitIdle(m_device->m_queue);
17691 vkDestroyFence(m_device->device(), fence, nullptr);
17692 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17693 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17694}
17695
17696// This is a positive test. No errors should be generated.
17697TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17698 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17699
17700 m_errorMonitor->ExpectSuccess();
17701 ASSERT_NO_FATAL_FAILURE(InitState());
17702
17703 VkEvent event;
17704 VkEventCreateInfo event_create_info{};
17705 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17706 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17707
17708 VkCommandPool command_pool;
17709 VkCommandPoolCreateInfo pool_create_info{};
17710 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17711 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17712 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17713 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17714
17715 VkCommandBuffer command_buffer;
17716 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17717 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17718 command_buffer_allocate_info.commandPool = command_pool;
17719 command_buffer_allocate_info.commandBufferCount = 1;
17720 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17721 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17722
17723 VkQueue queue = VK_NULL_HANDLE;
17724 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17725
17726 {
17727 VkCommandBufferBeginInfo begin_info{};
17728 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17729 vkBeginCommandBuffer(command_buffer, &begin_info);
17730
17731 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17732 nullptr, 0, nullptr);
17733 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17734 vkEndCommandBuffer(command_buffer);
17735 }
17736 {
17737 VkSubmitInfo submit_info{};
17738 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17739 submit_info.commandBufferCount = 1;
17740 submit_info.pCommandBuffers = &command_buffer;
17741 submit_info.signalSemaphoreCount = 0;
17742 submit_info.pSignalSemaphores = nullptr;
17743 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17744 }
17745 { vkSetEvent(m_device->device(), event); }
17746
17747 vkQueueWaitIdle(queue);
17748
17749 vkDestroyEvent(m_device->device(), event, nullptr);
17750 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17751 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17752
17753 m_errorMonitor->VerifyNotFound();
17754}
17755// This is a positive test. No errors should be generated.
17756TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17757 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17758
17759 ASSERT_NO_FATAL_FAILURE(InitState());
17760 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17761 return;
17762
17763 m_errorMonitor->ExpectSuccess();
17764
17765 VkQueryPool query_pool;
17766 VkQueryPoolCreateInfo query_pool_create_info{};
17767 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17768 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17769 query_pool_create_info.queryCount = 1;
17770 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17771
17772 VkCommandPool command_pool;
17773 VkCommandPoolCreateInfo pool_create_info{};
17774 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17775 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17776 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17777 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17778
17779 VkCommandBuffer command_buffer;
17780 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17781 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17782 command_buffer_allocate_info.commandPool = command_pool;
17783 command_buffer_allocate_info.commandBufferCount = 1;
17784 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17785 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17786
17787 VkCommandBuffer secondary_command_buffer;
17788 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17789 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17790
17791 VkQueue queue = VK_NULL_HANDLE;
17792 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17793
17794 uint32_t qfi = 0;
17795 VkBufferCreateInfo buff_create_info = {};
17796 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17797 buff_create_info.size = 1024;
17798 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17799 buff_create_info.queueFamilyIndexCount = 1;
17800 buff_create_info.pQueueFamilyIndices = &qfi;
17801
17802 VkResult err;
17803 VkBuffer buffer;
17804 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17805 ASSERT_VK_SUCCESS(err);
17806 VkMemoryAllocateInfo mem_alloc = {};
17807 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17808 mem_alloc.pNext = NULL;
17809 mem_alloc.allocationSize = 1024;
17810 mem_alloc.memoryTypeIndex = 0;
17811
17812 VkMemoryRequirements memReqs;
17813 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17814 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17815 if (!pass) {
17816 vkDestroyBuffer(m_device->device(), buffer, NULL);
17817 return;
17818 }
17819
17820 VkDeviceMemory mem;
17821 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17822 ASSERT_VK_SUCCESS(err);
17823 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17824 ASSERT_VK_SUCCESS(err);
17825
17826 VkCommandBufferInheritanceInfo hinfo = {};
17827 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17828 hinfo.renderPass = VK_NULL_HANDLE;
17829 hinfo.subpass = 0;
17830 hinfo.framebuffer = VK_NULL_HANDLE;
17831 hinfo.occlusionQueryEnable = VK_FALSE;
17832 hinfo.queryFlags = 0;
17833 hinfo.pipelineStatistics = 0;
17834
17835 {
17836 VkCommandBufferBeginInfo begin_info{};
17837 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17838 begin_info.pInheritanceInfo = &hinfo;
17839 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17840
17841 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17842 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17843
17844 vkEndCommandBuffer(secondary_command_buffer);
17845
17846 begin_info.pInheritanceInfo = nullptr;
17847 vkBeginCommandBuffer(command_buffer, &begin_info);
17848
17849 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17850 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17851
17852 vkEndCommandBuffer(command_buffer);
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;
17859 submit_info.signalSemaphoreCount = 0;
17860 submit_info.pSignalSemaphores = nullptr;
17861 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17862 }
17863
17864 vkQueueWaitIdle(queue);
17865
17866 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17867 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17868 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17869 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17870 vkDestroyBuffer(m_device->device(), buffer, NULL);
17871 vkFreeMemory(m_device->device(), mem, NULL);
17872
17873 m_errorMonitor->VerifyNotFound();
17874}
17875
17876// This is a positive test. No errors should be generated.
17877TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17878 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17879
17880 ASSERT_NO_FATAL_FAILURE(InitState());
17881 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17882 return;
17883
17884 m_errorMonitor->ExpectSuccess();
17885
17886 VkQueryPool query_pool;
17887 VkQueryPoolCreateInfo query_pool_create_info{};
17888 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17889 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17890 query_pool_create_info.queryCount = 1;
17891 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17892
17893 VkCommandPool command_pool;
17894 VkCommandPoolCreateInfo pool_create_info{};
17895 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17896 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17897 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17898 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17899
17900 VkCommandBuffer command_buffer[2];
17901 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17902 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17903 command_buffer_allocate_info.commandPool = command_pool;
17904 command_buffer_allocate_info.commandBufferCount = 2;
17905 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17906 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17907
17908 VkQueue queue = VK_NULL_HANDLE;
17909 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17910
17911 uint32_t qfi = 0;
17912 VkBufferCreateInfo buff_create_info = {};
17913 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17914 buff_create_info.size = 1024;
17915 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17916 buff_create_info.queueFamilyIndexCount = 1;
17917 buff_create_info.pQueueFamilyIndices = &qfi;
17918
17919 VkResult err;
17920 VkBuffer buffer;
17921 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17922 ASSERT_VK_SUCCESS(err);
17923 VkMemoryAllocateInfo mem_alloc = {};
17924 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17925 mem_alloc.pNext = NULL;
17926 mem_alloc.allocationSize = 1024;
17927 mem_alloc.memoryTypeIndex = 0;
17928
17929 VkMemoryRequirements memReqs;
17930 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17931 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17932 if (!pass) {
17933 vkDestroyBuffer(m_device->device(), buffer, NULL);
17934 return;
17935 }
17936
17937 VkDeviceMemory mem;
17938 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17939 ASSERT_VK_SUCCESS(err);
17940 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17941 ASSERT_VK_SUCCESS(err);
17942
17943 {
17944 VkCommandBufferBeginInfo begin_info{};
17945 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17946 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17947
17948 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17949 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17950
17951 vkEndCommandBuffer(command_buffer[0]);
17952
17953 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17954
17955 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17956
17957 vkEndCommandBuffer(command_buffer[1]);
17958 }
17959 {
17960 VkSubmitInfo submit_info{};
17961 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17962 submit_info.commandBufferCount = 2;
17963 submit_info.pCommandBuffers = command_buffer;
17964 submit_info.signalSemaphoreCount = 0;
17965 submit_info.pSignalSemaphores = nullptr;
17966 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17967 }
17968
17969 vkQueueWaitIdle(queue);
17970
17971 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17972 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17973 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17974 vkDestroyBuffer(m_device->device(), buffer, NULL);
17975 vkFreeMemory(m_device->device(), mem, NULL);
17976
17977 m_errorMonitor->VerifyNotFound();
17978}
17979
Tony Barbourc46924f2016-11-04 11:49:52 -060017980TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017981 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17982
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017983 ASSERT_NO_FATAL_FAILURE(InitState());
17984 VkEvent event;
17985 VkEventCreateInfo event_create_info{};
17986 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17987 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17988
17989 VkCommandPool command_pool;
17990 VkCommandPoolCreateInfo pool_create_info{};
17991 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17992 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17993 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17994 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17995
17996 VkCommandBuffer command_buffer;
17997 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17998 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17999 command_buffer_allocate_info.commandPool = command_pool;
18000 command_buffer_allocate_info.commandBufferCount = 1;
18001 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18002 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18003
18004 VkQueue queue = VK_NULL_HANDLE;
18005 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18006
18007 {
18008 VkCommandBufferBeginInfo begin_info{};
18009 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18010 vkBeginCommandBuffer(command_buffer, &begin_info);
18011
18012 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018013 vkEndCommandBuffer(command_buffer);
18014 }
18015 {
18016 VkSubmitInfo submit_info{};
18017 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18018 submit_info.commandBufferCount = 1;
18019 submit_info.pCommandBuffers = &command_buffer;
18020 submit_info.signalSemaphoreCount = 0;
18021 submit_info.pSignalSemaphores = nullptr;
18022 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18023 }
18024 {
18025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18026 "command buffer.");
18027 vkSetEvent(m_device->device(), event);
18028 m_errorMonitor->VerifyFound();
18029 }
18030
18031 vkQueueWaitIdle(queue);
18032
18033 vkDestroyEvent(m_device->device(), event, nullptr);
18034 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18035 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18036}
18037
18038// This is a positive test. No errors should be generated.
18039TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18040 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18041 "run through a Submit & WaitForFences cycle 3 times. This "
18042 "previously revealed a bug so running this positive test "
18043 "to prevent a regression.");
18044 m_errorMonitor->ExpectSuccess();
18045
18046 ASSERT_NO_FATAL_FAILURE(InitState());
18047 VkQueue queue = VK_NULL_HANDLE;
18048 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18049
18050 static const uint32_t NUM_OBJECTS = 2;
18051 static const uint32_t NUM_FRAMES = 3;
18052 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18053 VkFence fences[NUM_OBJECTS] = {};
18054
18055 VkCommandPool cmd_pool;
18056 VkCommandPoolCreateInfo cmd_pool_ci = {};
18057 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18058 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18059 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18060 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18061 ASSERT_VK_SUCCESS(err);
18062
18063 VkCommandBufferAllocateInfo cmd_buf_info = {};
18064 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18065 cmd_buf_info.commandPool = cmd_pool;
18066 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18067 cmd_buf_info.commandBufferCount = 1;
18068
18069 VkFenceCreateInfo fence_ci = {};
18070 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18071 fence_ci.pNext = nullptr;
18072 fence_ci.flags = 0;
18073
18074 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18075 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18076 ASSERT_VK_SUCCESS(err);
18077 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18078 ASSERT_VK_SUCCESS(err);
18079 }
18080
18081 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18082 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18083 // Create empty cmd buffer
18084 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18085 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18086
18087 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18088 ASSERT_VK_SUCCESS(err);
18089 err = vkEndCommandBuffer(cmd_buffers[obj]);
18090 ASSERT_VK_SUCCESS(err);
18091
18092 VkSubmitInfo submit_info = {};
18093 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18094 submit_info.commandBufferCount = 1;
18095 submit_info.pCommandBuffers = &cmd_buffers[obj];
18096 // Submit cmd buffer and wait for fence
18097 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18098 ASSERT_VK_SUCCESS(err);
18099 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18100 ASSERT_VK_SUCCESS(err);
18101 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18102 ASSERT_VK_SUCCESS(err);
18103 }
18104 }
18105 m_errorMonitor->VerifyNotFound();
18106 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18107 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18108 vkDestroyFence(m_device->device(), fences[i], nullptr);
18109 }
18110}
18111// This is a positive test. No errors should be generated.
18112TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18113
18114 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18115 "submitted on separate queues followed by a QueueWaitIdle.");
18116
18117 ASSERT_NO_FATAL_FAILURE(InitState());
18118 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18119 return;
18120
18121 m_errorMonitor->ExpectSuccess();
18122
18123 VkSemaphore semaphore;
18124 VkSemaphoreCreateInfo semaphore_create_info{};
18125 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18126 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18127
18128 VkCommandPool command_pool;
18129 VkCommandPoolCreateInfo pool_create_info{};
18130 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18131 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18132 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18133 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18134
18135 VkCommandBuffer command_buffer[2];
18136 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18137 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18138 command_buffer_allocate_info.commandPool = command_pool;
18139 command_buffer_allocate_info.commandBufferCount = 2;
18140 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18141 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18142
18143 VkQueue queue = VK_NULL_HANDLE;
18144 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18145
18146 {
18147 VkCommandBufferBeginInfo begin_info{};
18148 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18149 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18150
18151 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18152 nullptr, 0, nullptr, 0, nullptr);
18153
18154 VkViewport viewport{};
18155 viewport.maxDepth = 1.0f;
18156 viewport.minDepth = 0.0f;
18157 viewport.width = 512;
18158 viewport.height = 512;
18159 viewport.x = 0;
18160 viewport.y = 0;
18161 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18162 vkEndCommandBuffer(command_buffer[0]);
18163 }
18164 {
18165 VkCommandBufferBeginInfo begin_info{};
18166 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18167 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18168
18169 VkViewport viewport{};
18170 viewport.maxDepth = 1.0f;
18171 viewport.minDepth = 0.0f;
18172 viewport.width = 512;
18173 viewport.height = 512;
18174 viewport.x = 0;
18175 viewport.y = 0;
18176 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18177 vkEndCommandBuffer(command_buffer[1]);
18178 }
18179 {
18180 VkSubmitInfo submit_info{};
18181 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18182 submit_info.commandBufferCount = 1;
18183 submit_info.pCommandBuffers = &command_buffer[0];
18184 submit_info.signalSemaphoreCount = 1;
18185 submit_info.pSignalSemaphores = &semaphore;
18186 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18187 }
18188 {
18189 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18190 VkSubmitInfo submit_info{};
18191 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18192 submit_info.commandBufferCount = 1;
18193 submit_info.pCommandBuffers = &command_buffer[1];
18194 submit_info.waitSemaphoreCount = 1;
18195 submit_info.pWaitSemaphores = &semaphore;
18196 submit_info.pWaitDstStageMask = flags;
18197 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18198 }
18199
18200 vkQueueWaitIdle(m_device->m_queue);
18201
18202 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18203 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18204 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18205
18206 m_errorMonitor->VerifyNotFound();
18207}
18208
18209// This is a positive test. No errors should be generated.
18210TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18211
18212 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18213 "submitted on separate queues, the second having a fence"
18214 "followed by a QueueWaitIdle.");
18215
18216 ASSERT_NO_FATAL_FAILURE(InitState());
18217 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18218 return;
18219
18220 m_errorMonitor->ExpectSuccess();
18221
18222 VkFence fence;
18223 VkFenceCreateInfo fence_create_info{};
18224 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18225 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18226
18227 VkSemaphore semaphore;
18228 VkSemaphoreCreateInfo semaphore_create_info{};
18229 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18230 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18231
18232 VkCommandPool command_pool;
18233 VkCommandPoolCreateInfo pool_create_info{};
18234 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18235 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18236 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18237 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18238
18239 VkCommandBuffer command_buffer[2];
18240 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18241 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18242 command_buffer_allocate_info.commandPool = command_pool;
18243 command_buffer_allocate_info.commandBufferCount = 2;
18244 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18245 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18246
18247 VkQueue queue = VK_NULL_HANDLE;
18248 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18249
18250 {
18251 VkCommandBufferBeginInfo begin_info{};
18252 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18253 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18254
18255 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18256 nullptr, 0, nullptr, 0, nullptr);
18257
18258 VkViewport viewport{};
18259 viewport.maxDepth = 1.0f;
18260 viewport.minDepth = 0.0f;
18261 viewport.width = 512;
18262 viewport.height = 512;
18263 viewport.x = 0;
18264 viewport.y = 0;
18265 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18266 vkEndCommandBuffer(command_buffer[0]);
18267 }
18268 {
18269 VkCommandBufferBeginInfo begin_info{};
18270 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18271 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18272
18273 VkViewport viewport{};
18274 viewport.maxDepth = 1.0f;
18275 viewport.minDepth = 0.0f;
18276 viewport.width = 512;
18277 viewport.height = 512;
18278 viewport.x = 0;
18279 viewport.y = 0;
18280 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18281 vkEndCommandBuffer(command_buffer[1]);
18282 }
18283 {
18284 VkSubmitInfo submit_info{};
18285 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18286 submit_info.commandBufferCount = 1;
18287 submit_info.pCommandBuffers = &command_buffer[0];
18288 submit_info.signalSemaphoreCount = 1;
18289 submit_info.pSignalSemaphores = &semaphore;
18290 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18291 }
18292 {
18293 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18294 VkSubmitInfo submit_info{};
18295 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18296 submit_info.commandBufferCount = 1;
18297 submit_info.pCommandBuffers = &command_buffer[1];
18298 submit_info.waitSemaphoreCount = 1;
18299 submit_info.pWaitSemaphores = &semaphore;
18300 submit_info.pWaitDstStageMask = flags;
18301 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18302 }
18303
18304 vkQueueWaitIdle(m_device->m_queue);
18305
18306 vkDestroyFence(m_device->device(), fence, nullptr);
18307 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18308 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18309 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18310
18311 m_errorMonitor->VerifyNotFound();
18312}
18313
18314// This is a positive test. No errors should be generated.
18315TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18316
18317 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18318 "submitted on separate queues, the second having a fence"
18319 "followed by two consecutive WaitForFences calls on the same fence.");
18320
18321 ASSERT_NO_FATAL_FAILURE(InitState());
18322 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18323 return;
18324
18325 m_errorMonitor->ExpectSuccess();
18326
18327 VkFence fence;
18328 VkFenceCreateInfo fence_create_info{};
18329 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18330 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18331
18332 VkSemaphore semaphore;
18333 VkSemaphoreCreateInfo semaphore_create_info{};
18334 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18335 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18336
18337 VkCommandPool command_pool;
18338 VkCommandPoolCreateInfo pool_create_info{};
18339 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18340 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18341 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18342 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18343
18344 VkCommandBuffer command_buffer[2];
18345 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18346 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18347 command_buffer_allocate_info.commandPool = command_pool;
18348 command_buffer_allocate_info.commandBufferCount = 2;
18349 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18350 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18351
18352 VkQueue queue = VK_NULL_HANDLE;
18353 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18354
18355 {
18356 VkCommandBufferBeginInfo begin_info{};
18357 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18358 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18359
18360 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18361 nullptr, 0, nullptr, 0, nullptr);
18362
18363 VkViewport viewport{};
18364 viewport.maxDepth = 1.0f;
18365 viewport.minDepth = 0.0f;
18366 viewport.width = 512;
18367 viewport.height = 512;
18368 viewport.x = 0;
18369 viewport.y = 0;
18370 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18371 vkEndCommandBuffer(command_buffer[0]);
18372 }
18373 {
18374 VkCommandBufferBeginInfo begin_info{};
18375 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18376 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18377
18378 VkViewport viewport{};
18379 viewport.maxDepth = 1.0f;
18380 viewport.minDepth = 0.0f;
18381 viewport.width = 512;
18382 viewport.height = 512;
18383 viewport.x = 0;
18384 viewport.y = 0;
18385 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18386 vkEndCommandBuffer(command_buffer[1]);
18387 }
18388 {
18389 VkSubmitInfo submit_info{};
18390 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18391 submit_info.commandBufferCount = 1;
18392 submit_info.pCommandBuffers = &command_buffer[0];
18393 submit_info.signalSemaphoreCount = 1;
18394 submit_info.pSignalSemaphores = &semaphore;
18395 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18396 }
18397 {
18398 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18399 VkSubmitInfo submit_info{};
18400 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18401 submit_info.commandBufferCount = 1;
18402 submit_info.pCommandBuffers = &command_buffer[1];
18403 submit_info.waitSemaphoreCount = 1;
18404 submit_info.pWaitSemaphores = &semaphore;
18405 submit_info.pWaitDstStageMask = flags;
18406 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18407 }
18408
18409 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18410 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18411
18412 vkDestroyFence(m_device->device(), fence, nullptr);
18413 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18414 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18415 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18416
18417 m_errorMonitor->VerifyNotFound();
18418}
18419
18420TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18421
18422 ASSERT_NO_FATAL_FAILURE(InitState());
18423 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18424 printf("Test requires two queues, skipping\n");
18425 return;
18426 }
18427
18428 VkResult err;
18429
18430 m_errorMonitor->ExpectSuccess();
18431
18432 VkQueue q0 = m_device->m_queue;
18433 VkQueue q1 = nullptr;
18434 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18435 ASSERT_NE(q1, nullptr);
18436
18437 // An (empty) command buffer. We must have work in the first submission --
18438 // the layer treats unfenced work differently from fenced work.
18439 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18440 VkCommandPool pool;
18441 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18442 ASSERT_VK_SUCCESS(err);
18443 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18444 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18445 VkCommandBuffer cb;
18446 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18447 ASSERT_VK_SUCCESS(err);
18448 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18449 err = vkBeginCommandBuffer(cb, &cbbi);
18450 ASSERT_VK_SUCCESS(err);
18451 err = vkEndCommandBuffer(cb);
18452 ASSERT_VK_SUCCESS(err);
18453
18454 // A semaphore
18455 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18456 VkSemaphore s;
18457 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18458 ASSERT_VK_SUCCESS(err);
18459
18460 // First submission, to q0
18461 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18462
18463 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18464 ASSERT_VK_SUCCESS(err);
18465
18466 // Second submission, to q1, waiting on s
18467 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18468 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18469
18470 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18471 ASSERT_VK_SUCCESS(err);
18472
18473 // Wait for q0 idle
18474 err = vkQueueWaitIdle(q0);
18475 ASSERT_VK_SUCCESS(err);
18476
18477 // Command buffer should have been completed (it was on q0); reset the pool.
18478 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18479
18480 m_errorMonitor->VerifyNotFound();
18481
18482 // Force device completely idle and clean up resources
18483 vkDeviceWaitIdle(m_device->device());
18484 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18485 vkDestroySemaphore(m_device->device(), s, nullptr);
18486}
18487
18488// This is a positive test. No errors should be generated.
18489TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18490
18491 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18492 "submitted on separate queues, the second having a fence, "
18493 "followed by a WaitForFences call.");
18494
18495 ASSERT_NO_FATAL_FAILURE(InitState());
18496 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18497 return;
18498
18499 m_errorMonitor->ExpectSuccess();
18500
18501 ASSERT_NO_FATAL_FAILURE(InitState());
18502 VkFence fence;
18503 VkFenceCreateInfo fence_create_info{};
18504 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18505 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18506
18507 VkSemaphore semaphore;
18508 VkSemaphoreCreateInfo semaphore_create_info{};
18509 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18510 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18511
18512 VkCommandPool command_pool;
18513 VkCommandPoolCreateInfo pool_create_info{};
18514 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18515 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18516 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18517 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18518
18519 VkCommandBuffer command_buffer[2];
18520 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18521 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18522 command_buffer_allocate_info.commandPool = command_pool;
18523 command_buffer_allocate_info.commandBufferCount = 2;
18524 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18525 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18526
18527 VkQueue queue = VK_NULL_HANDLE;
18528 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18529
18530 {
18531 VkCommandBufferBeginInfo begin_info{};
18532 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18533 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18534
18535 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18536 nullptr, 0, nullptr, 0, nullptr);
18537
18538 VkViewport viewport{};
18539 viewport.maxDepth = 1.0f;
18540 viewport.minDepth = 0.0f;
18541 viewport.width = 512;
18542 viewport.height = 512;
18543 viewport.x = 0;
18544 viewport.y = 0;
18545 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18546 vkEndCommandBuffer(command_buffer[0]);
18547 }
18548 {
18549 VkCommandBufferBeginInfo begin_info{};
18550 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18551 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18552
18553 VkViewport viewport{};
18554 viewport.maxDepth = 1.0f;
18555 viewport.minDepth = 0.0f;
18556 viewport.width = 512;
18557 viewport.height = 512;
18558 viewport.x = 0;
18559 viewport.y = 0;
18560 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18561 vkEndCommandBuffer(command_buffer[1]);
18562 }
18563 {
18564 VkSubmitInfo submit_info{};
18565 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18566 submit_info.commandBufferCount = 1;
18567 submit_info.pCommandBuffers = &command_buffer[0];
18568 submit_info.signalSemaphoreCount = 1;
18569 submit_info.pSignalSemaphores = &semaphore;
18570 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18571 }
18572 {
18573 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18574 VkSubmitInfo submit_info{};
18575 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18576 submit_info.commandBufferCount = 1;
18577 submit_info.pCommandBuffers = &command_buffer[1];
18578 submit_info.waitSemaphoreCount = 1;
18579 submit_info.pWaitSemaphores = &semaphore;
18580 submit_info.pWaitDstStageMask = flags;
18581 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18582 }
18583
18584 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18585
18586 vkDestroyFence(m_device->device(), fence, nullptr);
18587 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18588 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18589 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18590
18591 m_errorMonitor->VerifyNotFound();
18592}
18593
18594// This is a positive test. No errors should be generated.
18595TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18596
18597 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18598 "on the same queue, sharing a signal/wait semaphore, the "
18599 "second having a fence, "
18600 "followed by a WaitForFences call.");
18601
18602 m_errorMonitor->ExpectSuccess();
18603
18604 ASSERT_NO_FATAL_FAILURE(InitState());
18605 VkFence fence;
18606 VkFenceCreateInfo fence_create_info{};
18607 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18608 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18609
18610 VkSemaphore semaphore;
18611 VkSemaphoreCreateInfo semaphore_create_info{};
18612 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18613 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18614
18615 VkCommandPool command_pool;
18616 VkCommandPoolCreateInfo pool_create_info{};
18617 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18618 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18619 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18620 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18621
18622 VkCommandBuffer command_buffer[2];
18623 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18624 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18625 command_buffer_allocate_info.commandPool = command_pool;
18626 command_buffer_allocate_info.commandBufferCount = 2;
18627 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18628 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18629
18630 {
18631 VkCommandBufferBeginInfo begin_info{};
18632 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18633 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18634
18635 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18636 nullptr, 0, nullptr, 0, nullptr);
18637
18638 VkViewport viewport{};
18639 viewport.maxDepth = 1.0f;
18640 viewport.minDepth = 0.0f;
18641 viewport.width = 512;
18642 viewport.height = 512;
18643 viewport.x = 0;
18644 viewport.y = 0;
18645 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18646 vkEndCommandBuffer(command_buffer[0]);
18647 }
18648 {
18649 VkCommandBufferBeginInfo begin_info{};
18650 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18651 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18652
18653 VkViewport viewport{};
18654 viewport.maxDepth = 1.0f;
18655 viewport.minDepth = 0.0f;
18656 viewport.width = 512;
18657 viewport.height = 512;
18658 viewport.x = 0;
18659 viewport.y = 0;
18660 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18661 vkEndCommandBuffer(command_buffer[1]);
18662 }
18663 {
18664 VkSubmitInfo submit_info{};
18665 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18666 submit_info.commandBufferCount = 1;
18667 submit_info.pCommandBuffers = &command_buffer[0];
18668 submit_info.signalSemaphoreCount = 1;
18669 submit_info.pSignalSemaphores = &semaphore;
18670 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18671 }
18672 {
18673 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18674 VkSubmitInfo submit_info{};
18675 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18676 submit_info.commandBufferCount = 1;
18677 submit_info.pCommandBuffers = &command_buffer[1];
18678 submit_info.waitSemaphoreCount = 1;
18679 submit_info.pWaitSemaphores = &semaphore;
18680 submit_info.pWaitDstStageMask = flags;
18681 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18682 }
18683
18684 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18685
18686 vkDestroyFence(m_device->device(), fence, nullptr);
18687 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18688 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18689 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18690
18691 m_errorMonitor->VerifyNotFound();
18692}
18693
18694// This is a positive test. No errors should be generated.
18695TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18696
18697 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18698 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18699 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18700
18701 m_errorMonitor->ExpectSuccess();
18702
18703 ASSERT_NO_FATAL_FAILURE(InitState());
18704 VkFence fence;
18705 VkFenceCreateInfo fence_create_info{};
18706 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18707 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18708
18709 VkCommandPool command_pool;
18710 VkCommandPoolCreateInfo pool_create_info{};
18711 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18712 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18713 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18714 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18715
18716 VkCommandBuffer command_buffer[2];
18717 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18718 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18719 command_buffer_allocate_info.commandPool = command_pool;
18720 command_buffer_allocate_info.commandBufferCount = 2;
18721 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18722 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18723
18724 {
18725 VkCommandBufferBeginInfo begin_info{};
18726 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18727 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18728
18729 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18730 nullptr, 0, nullptr, 0, nullptr);
18731
18732 VkViewport viewport{};
18733 viewport.maxDepth = 1.0f;
18734 viewport.minDepth = 0.0f;
18735 viewport.width = 512;
18736 viewport.height = 512;
18737 viewport.x = 0;
18738 viewport.y = 0;
18739 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18740 vkEndCommandBuffer(command_buffer[0]);
18741 }
18742 {
18743 VkCommandBufferBeginInfo begin_info{};
18744 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18745 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18746
18747 VkViewport viewport{};
18748 viewport.maxDepth = 1.0f;
18749 viewport.minDepth = 0.0f;
18750 viewport.width = 512;
18751 viewport.height = 512;
18752 viewport.x = 0;
18753 viewport.y = 0;
18754 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18755 vkEndCommandBuffer(command_buffer[1]);
18756 }
18757 {
18758 VkSubmitInfo submit_info{};
18759 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18760 submit_info.commandBufferCount = 1;
18761 submit_info.pCommandBuffers = &command_buffer[0];
18762 submit_info.signalSemaphoreCount = 0;
18763 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18764 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18765 }
18766 {
18767 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18768 VkSubmitInfo submit_info{};
18769 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18770 submit_info.commandBufferCount = 1;
18771 submit_info.pCommandBuffers = &command_buffer[1];
18772 submit_info.waitSemaphoreCount = 0;
18773 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18774 submit_info.pWaitDstStageMask = flags;
18775 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18776 }
18777
18778 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18779
18780 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18781 ASSERT_VK_SUCCESS(err);
18782
18783 vkDestroyFence(m_device->device(), fence, nullptr);
18784 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18785 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18786
18787 m_errorMonitor->VerifyNotFound();
18788}
18789
18790// This is a positive test. No errors should be generated.
18791TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18792
18793 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18794 "on the same queue, the second having a fence, followed "
18795 "by a WaitForFences call.");
18796
18797 m_errorMonitor->ExpectSuccess();
18798
18799 ASSERT_NO_FATAL_FAILURE(InitState());
18800 VkFence fence;
18801 VkFenceCreateInfo fence_create_info{};
18802 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18803 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18804
18805 VkCommandPool command_pool;
18806 VkCommandPoolCreateInfo pool_create_info{};
18807 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18808 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18809 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18810 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18811
18812 VkCommandBuffer command_buffer[2];
18813 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18814 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18815 command_buffer_allocate_info.commandPool = command_pool;
18816 command_buffer_allocate_info.commandBufferCount = 2;
18817 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18818 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18819
18820 {
18821 VkCommandBufferBeginInfo begin_info{};
18822 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18823 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18824
18825 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18826 nullptr, 0, nullptr, 0, nullptr);
18827
18828 VkViewport viewport{};
18829 viewport.maxDepth = 1.0f;
18830 viewport.minDepth = 0.0f;
18831 viewport.width = 512;
18832 viewport.height = 512;
18833 viewport.x = 0;
18834 viewport.y = 0;
18835 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18836 vkEndCommandBuffer(command_buffer[0]);
18837 }
18838 {
18839 VkCommandBufferBeginInfo begin_info{};
18840 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18841 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18842
18843 VkViewport viewport{};
18844 viewport.maxDepth = 1.0f;
18845 viewport.minDepth = 0.0f;
18846 viewport.width = 512;
18847 viewport.height = 512;
18848 viewport.x = 0;
18849 viewport.y = 0;
18850 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18851 vkEndCommandBuffer(command_buffer[1]);
18852 }
18853 {
18854 VkSubmitInfo submit_info{};
18855 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18856 submit_info.commandBufferCount = 1;
18857 submit_info.pCommandBuffers = &command_buffer[0];
18858 submit_info.signalSemaphoreCount = 0;
18859 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18860 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18861 }
18862 {
18863 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18864 VkSubmitInfo submit_info{};
18865 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18866 submit_info.commandBufferCount = 1;
18867 submit_info.pCommandBuffers = &command_buffer[1];
18868 submit_info.waitSemaphoreCount = 0;
18869 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18870 submit_info.pWaitDstStageMask = flags;
18871 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18872 }
18873
18874 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18875
18876 vkDestroyFence(m_device->device(), fence, nullptr);
18877 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18878 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18879
18880 m_errorMonitor->VerifyNotFound();
18881}
18882
18883// This is a positive test. No errors should be generated.
18884TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18885
18886 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18887 "QueueSubmit call followed by a WaitForFences call.");
18888 ASSERT_NO_FATAL_FAILURE(InitState());
18889
18890 m_errorMonitor->ExpectSuccess();
18891
18892 VkFence fence;
18893 VkFenceCreateInfo fence_create_info{};
18894 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18895 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18896
18897 VkSemaphore semaphore;
18898 VkSemaphoreCreateInfo semaphore_create_info{};
18899 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18900 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18901
18902 VkCommandPool command_pool;
18903 VkCommandPoolCreateInfo pool_create_info{};
18904 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18905 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18906 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18907 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18908
18909 VkCommandBuffer command_buffer[2];
18910 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18911 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18912 command_buffer_allocate_info.commandPool = command_pool;
18913 command_buffer_allocate_info.commandBufferCount = 2;
18914 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18915 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18916
18917 {
18918 VkCommandBufferBeginInfo begin_info{};
18919 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18920 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18921
18922 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18923 nullptr, 0, nullptr, 0, nullptr);
18924
18925 VkViewport viewport{};
18926 viewport.maxDepth = 1.0f;
18927 viewport.minDepth = 0.0f;
18928 viewport.width = 512;
18929 viewport.height = 512;
18930 viewport.x = 0;
18931 viewport.y = 0;
18932 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18933 vkEndCommandBuffer(command_buffer[0]);
18934 }
18935 {
18936 VkCommandBufferBeginInfo begin_info{};
18937 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18938 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18939
18940 VkViewport viewport{};
18941 viewport.maxDepth = 1.0f;
18942 viewport.minDepth = 0.0f;
18943 viewport.width = 512;
18944 viewport.height = 512;
18945 viewport.x = 0;
18946 viewport.y = 0;
18947 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18948 vkEndCommandBuffer(command_buffer[1]);
18949 }
18950 {
18951 VkSubmitInfo submit_info[2];
18952 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18953
18954 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18955 submit_info[0].pNext = NULL;
18956 submit_info[0].commandBufferCount = 1;
18957 submit_info[0].pCommandBuffers = &command_buffer[0];
18958 submit_info[0].signalSemaphoreCount = 1;
18959 submit_info[0].pSignalSemaphores = &semaphore;
18960 submit_info[0].waitSemaphoreCount = 0;
18961 submit_info[0].pWaitSemaphores = NULL;
18962 submit_info[0].pWaitDstStageMask = 0;
18963
18964 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18965 submit_info[1].pNext = NULL;
18966 submit_info[1].commandBufferCount = 1;
18967 submit_info[1].pCommandBuffers = &command_buffer[1];
18968 submit_info[1].waitSemaphoreCount = 1;
18969 submit_info[1].pWaitSemaphores = &semaphore;
18970 submit_info[1].pWaitDstStageMask = flags;
18971 submit_info[1].signalSemaphoreCount = 0;
18972 submit_info[1].pSignalSemaphores = NULL;
18973 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18974 }
18975
18976 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18977
18978 vkDestroyFence(m_device->device(), fence, nullptr);
18979 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18980 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18981 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18982
18983 m_errorMonitor->VerifyNotFound();
18984}
18985
18986TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18987 m_errorMonitor->ExpectSuccess();
18988
18989 ASSERT_NO_FATAL_FAILURE(InitState());
18990 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18991
18992 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18993 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18994
18995 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18996 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18997 m_errorMonitor->VerifyNotFound();
18998 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18999 m_errorMonitor->VerifyNotFound();
19000 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19001 m_errorMonitor->VerifyNotFound();
19002
19003 m_commandBuffer->EndCommandBuffer();
19004 m_errorMonitor->VerifyNotFound();
19005}
19006
19007TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19008 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19009 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19010 "has a valid layout, and a second subpass then uses a "
19011 "valid *READ_ONLY* layout.");
19012 m_errorMonitor->ExpectSuccess();
19013 ASSERT_NO_FATAL_FAILURE(InitState());
19014
19015 VkAttachmentReference attach[2] = {};
19016 attach[0].attachment = 0;
19017 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19018 attach[1].attachment = 0;
19019 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19020 VkSubpassDescription subpasses[2] = {};
19021 // First subpass clears DS attach on load
19022 subpasses[0].pDepthStencilAttachment = &attach[0];
19023 // 2nd subpass reads in DS as input attachment
19024 subpasses[1].inputAttachmentCount = 1;
19025 subpasses[1].pInputAttachments = &attach[1];
19026 VkAttachmentDescription attach_desc = {};
19027 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19028 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19029 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19030 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19031 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19032 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19033 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19034 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19035 VkRenderPassCreateInfo rpci = {};
19036 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19037 rpci.attachmentCount = 1;
19038 rpci.pAttachments = &attach_desc;
19039 rpci.subpassCount = 2;
19040 rpci.pSubpasses = subpasses;
19041
19042 // Now create RenderPass and verify no errors
19043 VkRenderPass rp;
19044 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19045 m_errorMonitor->VerifyNotFound();
19046
19047 vkDestroyRenderPass(m_device->device(), rp, NULL);
19048}
19049
19050TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19051 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19052 "as vertex attributes");
19053 m_errorMonitor->ExpectSuccess();
19054
19055 ASSERT_NO_FATAL_FAILURE(InitState());
19056 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19057
19058 VkVertexInputBindingDescription input_binding;
19059 memset(&input_binding, 0, sizeof(input_binding));
19060
19061 VkVertexInputAttributeDescription input_attribs[2];
19062 memset(input_attribs, 0, sizeof(input_attribs));
19063
19064 for (int i = 0; i < 2; i++) {
19065 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19066 input_attribs[i].location = i;
19067 }
19068
19069 char const *vsSource = "#version 450\n"
19070 "\n"
19071 "layout(location=0) in mat2x4 x;\n"
19072 "out gl_PerVertex {\n"
19073 " vec4 gl_Position;\n"
19074 "};\n"
19075 "void main(){\n"
19076 " gl_Position = x[0] + x[1];\n"
19077 "}\n";
19078 char const *fsSource = "#version 450\n"
19079 "\n"
19080 "layout(location=0) out vec4 color;\n"
19081 "void main(){\n"
19082 " color = vec4(1);\n"
19083 "}\n";
19084
19085 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19086 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19087
19088 VkPipelineObj pipe(m_device);
19089 pipe.AddColorAttachment();
19090 pipe.AddShader(&vs);
19091 pipe.AddShader(&fs);
19092
19093 pipe.AddVertexInputBindings(&input_binding, 1);
19094 pipe.AddVertexInputAttribs(input_attribs, 2);
19095
19096 VkDescriptorSetObj descriptorSet(m_device);
19097 descriptorSet.AppendDummy();
19098 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19099
19100 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19101
19102 /* expect success */
19103 m_errorMonitor->VerifyNotFound();
19104}
19105
19106TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19107 m_errorMonitor->ExpectSuccess();
19108
19109 ASSERT_NO_FATAL_FAILURE(InitState());
19110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19111
19112 VkVertexInputBindingDescription input_binding;
19113 memset(&input_binding, 0, sizeof(input_binding));
19114
19115 VkVertexInputAttributeDescription input_attribs[2];
19116 memset(input_attribs, 0, sizeof(input_attribs));
19117
19118 for (int i = 0; i < 2; i++) {
19119 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19120 input_attribs[i].location = i;
19121 }
19122
19123 char const *vsSource = "#version 450\n"
19124 "\n"
19125 "layout(location=0) in vec4 x[2];\n"
19126 "out gl_PerVertex {\n"
19127 " vec4 gl_Position;\n"
19128 "};\n"
19129 "void main(){\n"
19130 " gl_Position = x[0] + x[1];\n"
19131 "}\n";
19132 char const *fsSource = "#version 450\n"
19133 "\n"
19134 "layout(location=0) out vec4 color;\n"
19135 "void main(){\n"
19136 " color = vec4(1);\n"
19137 "}\n";
19138
19139 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19140 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19141
19142 VkPipelineObj pipe(m_device);
19143 pipe.AddColorAttachment();
19144 pipe.AddShader(&vs);
19145 pipe.AddShader(&fs);
19146
19147 pipe.AddVertexInputBindings(&input_binding, 1);
19148 pipe.AddVertexInputAttribs(input_attribs, 2);
19149
19150 VkDescriptorSetObj descriptorSet(m_device);
19151 descriptorSet.AppendDummy();
19152 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19153
19154 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19155
19156 m_errorMonitor->VerifyNotFound();
19157}
19158
19159TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19160 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19161 "through multiple vertex shader inputs, each consuming a different "
19162 "subset of the components.");
19163 m_errorMonitor->ExpectSuccess();
19164
19165 ASSERT_NO_FATAL_FAILURE(InitState());
19166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19167
19168 VkVertexInputBindingDescription input_binding;
19169 memset(&input_binding, 0, sizeof(input_binding));
19170
19171 VkVertexInputAttributeDescription input_attribs[3];
19172 memset(input_attribs, 0, sizeof(input_attribs));
19173
19174 for (int i = 0; i < 3; i++) {
19175 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19176 input_attribs[i].location = i;
19177 }
19178
19179 char const *vsSource = "#version 450\n"
19180 "\n"
19181 "layout(location=0) in vec4 x;\n"
19182 "layout(location=1) in vec3 y1;\n"
19183 "layout(location=1, component=3) in float y2;\n"
19184 "layout(location=2) in vec4 z;\n"
19185 "out gl_PerVertex {\n"
19186 " vec4 gl_Position;\n"
19187 "};\n"
19188 "void main(){\n"
19189 " gl_Position = x + vec4(y1, y2) + z;\n"
19190 "}\n";
19191 char const *fsSource = "#version 450\n"
19192 "\n"
19193 "layout(location=0) out vec4 color;\n"
19194 "void main(){\n"
19195 " color = vec4(1);\n"
19196 "}\n";
19197
19198 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19199 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19200
19201 VkPipelineObj pipe(m_device);
19202 pipe.AddColorAttachment();
19203 pipe.AddShader(&vs);
19204 pipe.AddShader(&fs);
19205
19206 pipe.AddVertexInputBindings(&input_binding, 1);
19207 pipe.AddVertexInputAttribs(input_attribs, 3);
19208
19209 VkDescriptorSetObj descriptorSet(m_device);
19210 descriptorSet.AppendDummy();
19211 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19212
19213 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19214
19215 m_errorMonitor->VerifyNotFound();
19216}
19217
19218TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19219 m_errorMonitor->ExpectSuccess();
19220
19221 ASSERT_NO_FATAL_FAILURE(InitState());
19222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19223
19224 char const *vsSource = "#version 450\n"
19225 "out gl_PerVertex {\n"
19226 " vec4 gl_Position;\n"
19227 "};\n"
19228 "void main(){\n"
19229 " gl_Position = vec4(0);\n"
19230 "}\n";
19231 char const *fsSource = "#version 450\n"
19232 "\n"
19233 "layout(location=0) out vec4 color;\n"
19234 "void main(){\n"
19235 " color = vec4(1);\n"
19236 "}\n";
19237
19238 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19239 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19240
19241 VkPipelineObj pipe(m_device);
19242 pipe.AddColorAttachment();
19243 pipe.AddShader(&vs);
19244 pipe.AddShader(&fs);
19245
19246 VkDescriptorSetObj descriptorSet(m_device);
19247 descriptorSet.AppendDummy();
19248 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19249
19250 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19251
19252 m_errorMonitor->VerifyNotFound();
19253}
19254
19255TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19256 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19257 "set out in 14.1.3: fundamental type must match, and producer side must "
19258 "have at least as many components");
19259 m_errorMonitor->ExpectSuccess();
19260
19261 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19262
19263 ASSERT_NO_FATAL_FAILURE(InitState());
19264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19265
19266 char const *vsSource = "#version 450\n"
19267 "out gl_PerVertex {\n"
19268 " vec4 gl_Position;\n"
19269 "};\n"
19270 "layout(location=0) out vec3 x;\n"
19271 "layout(location=1) out ivec3 y;\n"
19272 "layout(location=2) out vec3 z;\n"
19273 "void main(){\n"
19274 " gl_Position = vec4(0);\n"
19275 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19276 "}\n";
19277 char const *fsSource = "#version 450\n"
19278 "\n"
19279 "layout(location=0) out vec4 color;\n"
19280 "layout(location=0) in float x;\n"
19281 "layout(location=1) flat in int y;\n"
19282 "layout(location=2) in vec2 z;\n"
19283 "void main(){\n"
19284 " color = vec4(1 + x + y + z.x);\n"
19285 "}\n";
19286
19287 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19288 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19289
19290 VkPipelineObj pipe(m_device);
19291 pipe.AddColorAttachment();
19292 pipe.AddShader(&vs);
19293 pipe.AddShader(&fs);
19294
19295 VkDescriptorSetObj descriptorSet(m_device);
19296 descriptorSet.AppendDummy();
19297 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19298
19299 VkResult err = VK_SUCCESS;
19300 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19301 ASSERT_VK_SUCCESS(err);
19302
19303 m_errorMonitor->VerifyNotFound();
19304}
19305
19306TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19307 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19308 "passed between the TCS and TES stages");
19309 m_errorMonitor->ExpectSuccess();
19310
19311 ASSERT_NO_FATAL_FAILURE(InitState());
19312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19313
19314 if (!m_device->phy().features().tessellationShader) {
19315 printf("Device does not support tessellation shaders; skipped.\n");
19316 return;
19317 }
19318
19319 char const *vsSource = "#version 450\n"
19320 "void main(){}\n";
19321 char const *tcsSource = "#version 450\n"
19322 "layout(location=0) out int x[];\n"
19323 "layout(vertices=3) out;\n"
19324 "void main(){\n"
19325 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19326 " gl_TessLevelInner[0] = 1;\n"
19327 " x[gl_InvocationID] = gl_InvocationID;\n"
19328 "}\n";
19329 char const *tesSource = "#version 450\n"
19330 "layout(triangles, equal_spacing, cw) in;\n"
19331 "layout(location=0) in int x[];\n"
19332 "out gl_PerVertex { vec4 gl_Position; };\n"
19333 "void main(){\n"
19334 " gl_Position.xyz = gl_TessCoord;\n"
19335 " gl_Position.w = x[0] + x[1] + x[2];\n"
19336 "}\n";
19337 char const *fsSource = "#version 450\n"
19338 "layout(location=0) out vec4 color;\n"
19339 "void main(){\n"
19340 " color = vec4(1);\n"
19341 "}\n";
19342
19343 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19344 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19345 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19346 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19347
19348 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19349 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19350
19351 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19352
19353 VkPipelineObj pipe(m_device);
19354 pipe.SetInputAssembly(&iasci);
19355 pipe.SetTessellation(&tsci);
19356 pipe.AddColorAttachment();
19357 pipe.AddShader(&vs);
19358 pipe.AddShader(&tcs);
19359 pipe.AddShader(&tes);
19360 pipe.AddShader(&fs);
19361
19362 VkDescriptorSetObj descriptorSet(m_device);
19363 descriptorSet.AppendDummy();
19364 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19365
19366 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19367
19368 m_errorMonitor->VerifyNotFound();
19369}
19370
19371TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19372 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19373 "interface block passed into the geometry shader. This "
19374 "is interesting because the 'extra' array level is not "
19375 "present on the member type, but on the block instance.");
19376 m_errorMonitor->ExpectSuccess();
19377
19378 ASSERT_NO_FATAL_FAILURE(InitState());
19379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19380
19381 if (!m_device->phy().features().geometryShader) {
19382 printf("Device does not support geometry shaders; skipped.\n");
19383 return;
19384 }
19385
19386 char const *vsSource = "#version 450\n"
19387 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19388 "void main(){\n"
19389 " vs_out.x = vec4(1);\n"
19390 "}\n";
19391 char const *gsSource = "#version 450\n"
19392 "layout(triangles) in;\n"
19393 "layout(triangle_strip, max_vertices=3) out;\n"
19394 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19395 "out gl_PerVertex { vec4 gl_Position; };\n"
19396 "void main() {\n"
19397 " gl_Position = gs_in[0].x;\n"
19398 " EmitVertex();\n"
19399 "}\n";
19400 char const *fsSource = "#version 450\n"
19401 "layout(location=0) out vec4 color;\n"
19402 "void main(){\n"
19403 " color = vec4(1);\n"
19404 "}\n";
19405
19406 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19407 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19408 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19409
19410 VkPipelineObj pipe(m_device);
19411 pipe.AddColorAttachment();
19412 pipe.AddShader(&vs);
19413 pipe.AddShader(&gs);
19414 pipe.AddShader(&fs);
19415
19416 VkDescriptorSetObj descriptorSet(m_device);
19417 descriptorSet.AppendDummy();
19418 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19419
19420 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19421
19422 m_errorMonitor->VerifyNotFound();
19423}
19424
19425TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19426 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19427 "attributes. This is interesting because they consume multiple "
19428 "locations.");
19429 m_errorMonitor->ExpectSuccess();
19430
19431 ASSERT_NO_FATAL_FAILURE(InitState());
19432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19433
19434 if (!m_device->phy().features().shaderFloat64) {
19435 printf("Device does not support 64bit vertex attributes; skipped.\n");
19436 return;
19437 }
19438
19439 VkVertexInputBindingDescription input_bindings[1];
19440 memset(input_bindings, 0, sizeof(input_bindings));
19441
19442 VkVertexInputAttributeDescription input_attribs[4];
19443 memset(input_attribs, 0, sizeof(input_attribs));
19444 input_attribs[0].location = 0;
19445 input_attribs[0].offset = 0;
19446 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19447 input_attribs[1].location = 2;
19448 input_attribs[1].offset = 32;
19449 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19450 input_attribs[2].location = 4;
19451 input_attribs[2].offset = 64;
19452 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19453 input_attribs[3].location = 6;
19454 input_attribs[3].offset = 96;
19455 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19456
19457 char const *vsSource = "#version 450\n"
19458 "\n"
19459 "layout(location=0) in dmat4 x;\n"
19460 "out gl_PerVertex {\n"
19461 " vec4 gl_Position;\n"
19462 "};\n"
19463 "void main(){\n"
19464 " gl_Position = vec4(x[0][0]);\n"
19465 "}\n";
19466 char const *fsSource = "#version 450\n"
19467 "\n"
19468 "layout(location=0) out vec4 color;\n"
19469 "void main(){\n"
19470 " color = vec4(1);\n"
19471 "}\n";
19472
19473 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19474 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19475
19476 VkPipelineObj pipe(m_device);
19477 pipe.AddColorAttachment();
19478 pipe.AddShader(&vs);
19479 pipe.AddShader(&fs);
19480
19481 pipe.AddVertexInputBindings(input_bindings, 1);
19482 pipe.AddVertexInputAttribs(input_attribs, 4);
19483
19484 VkDescriptorSetObj descriptorSet(m_device);
19485 descriptorSet.AppendDummy();
19486 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19487
19488 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19489
19490 m_errorMonitor->VerifyNotFound();
19491}
19492
19493TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19494 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19495 m_errorMonitor->ExpectSuccess();
19496
19497 ASSERT_NO_FATAL_FAILURE(InitState());
19498
19499 char const *vsSource = "#version 450\n"
19500 "\n"
19501 "out gl_PerVertex {\n"
19502 " vec4 gl_Position;\n"
19503 "};\n"
19504 "void main(){\n"
19505 " gl_Position = vec4(1);\n"
19506 "}\n";
19507 char const *fsSource = "#version 450\n"
19508 "\n"
19509 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19510 "layout(location=0) out vec4 color;\n"
19511 "void main() {\n"
19512 " color = subpassLoad(x);\n"
19513 "}\n";
19514
19515 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19516 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19517
19518 VkPipelineObj pipe(m_device);
19519 pipe.AddShader(&vs);
19520 pipe.AddShader(&fs);
19521 pipe.AddColorAttachment();
19522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19523
19524 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19525 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19526 VkDescriptorSetLayout dsl;
19527 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19528 ASSERT_VK_SUCCESS(err);
19529
19530 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19531 VkPipelineLayout pl;
19532 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19533 ASSERT_VK_SUCCESS(err);
19534
19535 VkAttachmentDescription descs[2] = {
19536 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19537 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19538 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19539 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19540 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19541 };
19542 VkAttachmentReference color = {
19543 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19544 };
19545 VkAttachmentReference input = {
19546 1, VK_IMAGE_LAYOUT_GENERAL,
19547 };
19548
19549 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19550
19551 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19552 VkRenderPass rp;
19553 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19554 ASSERT_VK_SUCCESS(err);
19555
19556 // should be OK. would go wrong here if it's going to...
19557 pipe.CreateVKPipeline(pl, rp);
19558
19559 m_errorMonitor->VerifyNotFound();
19560
19561 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19562 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19563 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19564}
19565
19566TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19567 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19568 "descriptor-backed resource which is not provided, but the shader does not "
19569 "statically use it. This is interesting because it requires compute pipelines "
19570 "to have a proper descriptor use walk, which they didn't for some time.");
19571 m_errorMonitor->ExpectSuccess();
19572
19573 ASSERT_NO_FATAL_FAILURE(InitState());
19574
19575 char const *csSource = "#version 450\n"
19576 "\n"
19577 "layout(local_size_x=1) in;\n"
19578 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19579 "void main(){\n"
19580 " // x is not used.\n"
19581 "}\n";
19582
19583 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19584
19585 VkDescriptorSetObj descriptorSet(m_device);
19586 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19587
19588 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19589 nullptr,
19590 0,
19591 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19592 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19593 descriptorSet.GetPipelineLayout(),
19594 VK_NULL_HANDLE,
19595 -1 };
19596
19597 VkPipeline pipe;
19598 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19599
19600 m_errorMonitor->VerifyNotFound();
19601
19602 if (err == VK_SUCCESS) {
19603 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19604 }
19605}
19606
19607TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19608 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19609 "sampler portion of a combined image + sampler");
19610 m_errorMonitor->ExpectSuccess();
19611
19612 ASSERT_NO_FATAL_FAILURE(InitState());
19613
19614 VkDescriptorSetLayoutBinding bindings[] = {
19615 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19616 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19617 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19618 };
19619 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19620 VkDescriptorSetLayout dsl;
19621 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19622 ASSERT_VK_SUCCESS(err);
19623
19624 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19625 VkPipelineLayout pl;
19626 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19627 ASSERT_VK_SUCCESS(err);
19628
19629 char const *csSource = "#version 450\n"
19630 "\n"
19631 "layout(local_size_x=1) in;\n"
19632 "layout(set=0, binding=0) uniform sampler s;\n"
19633 "layout(set=0, binding=1) uniform texture2D t;\n"
19634 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19635 "void main() {\n"
19636 " x = texture(sampler2D(t, s), vec2(0));\n"
19637 "}\n";
19638 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19639
19640 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19641 nullptr,
19642 0,
19643 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19644 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19645 pl,
19646 VK_NULL_HANDLE,
19647 -1 };
19648
19649 VkPipeline pipe;
19650 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19651
19652 m_errorMonitor->VerifyNotFound();
19653
19654 if (err == VK_SUCCESS) {
19655 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19656 }
19657
19658 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19659 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19660}
19661
19662TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19663 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19664 "image portion of a combined image + sampler");
19665 m_errorMonitor->ExpectSuccess();
19666
19667 ASSERT_NO_FATAL_FAILURE(InitState());
19668
19669 VkDescriptorSetLayoutBinding bindings[] = {
19670 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19671 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19672 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19673 };
19674 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19675 VkDescriptorSetLayout dsl;
19676 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19677 ASSERT_VK_SUCCESS(err);
19678
19679 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19680 VkPipelineLayout pl;
19681 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19682 ASSERT_VK_SUCCESS(err);
19683
19684 char const *csSource = "#version 450\n"
19685 "\n"
19686 "layout(local_size_x=1) in;\n"
19687 "layout(set=0, binding=0) uniform texture2D t;\n"
19688 "layout(set=0, binding=1) uniform sampler s;\n"
19689 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19690 "void main() {\n"
19691 " x = texture(sampler2D(t, s), vec2(0));\n"
19692 "}\n";
19693 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19694
19695 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19696 nullptr,
19697 0,
19698 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19699 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19700 pl,
19701 VK_NULL_HANDLE,
19702 -1 };
19703
19704 VkPipeline pipe;
19705 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19706
19707 m_errorMonitor->VerifyNotFound();
19708
19709 if (err == VK_SUCCESS) {
19710 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19711 }
19712
19713 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19714 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19715}
19716
19717TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19718 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19719 "both the sampler and the image of a combined image+sampler "
19720 "but via separate variables");
19721 m_errorMonitor->ExpectSuccess();
19722
19723 ASSERT_NO_FATAL_FAILURE(InitState());
19724
19725 VkDescriptorSetLayoutBinding bindings[] = {
19726 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19727 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19728 };
19729 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19730 VkDescriptorSetLayout dsl;
19731 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19732 ASSERT_VK_SUCCESS(err);
19733
19734 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19735 VkPipelineLayout pl;
19736 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19737 ASSERT_VK_SUCCESS(err);
19738
19739 char const *csSource = "#version 450\n"
19740 "\n"
19741 "layout(local_size_x=1) in;\n"
19742 "layout(set=0, binding=0) uniform texture2D t;\n"
19743 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19744 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19745 "void main() {\n"
19746 " x = texture(sampler2D(t, s), vec2(0));\n"
19747 "}\n";
19748 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19749
19750 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19751 nullptr,
19752 0,
19753 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19754 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19755 pl,
19756 VK_NULL_HANDLE,
19757 -1 };
19758
19759 VkPipeline pipe;
19760 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19761
19762 m_errorMonitor->VerifyNotFound();
19763
19764 if (err == VK_SUCCESS) {
19765 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19766 }
19767
19768 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19769 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19770}
19771
19772TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19773 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19774
19775 ASSERT_NO_FATAL_FAILURE(InitState());
19776
19777 // Positive test to check parameter_validation and unique_objects support
19778 // for NV_dedicated_allocation
19779 uint32_t extension_count = 0;
19780 bool supports_nv_dedicated_allocation = false;
19781 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19782 ASSERT_VK_SUCCESS(err);
19783
19784 if (extension_count > 0) {
19785 std::vector<VkExtensionProperties> available_extensions(extension_count);
19786
19787 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19788 ASSERT_VK_SUCCESS(err);
19789
19790 for (const auto &extension_props : available_extensions) {
19791 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19792 supports_nv_dedicated_allocation = true;
19793 }
19794 }
19795 }
19796
19797 if (supports_nv_dedicated_allocation) {
19798 m_errorMonitor->ExpectSuccess();
19799
19800 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19801 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19802 dedicated_buffer_create_info.pNext = nullptr;
19803 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19804
19805 uint32_t queue_family_index = 0;
19806 VkBufferCreateInfo buffer_create_info = {};
19807 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19808 buffer_create_info.pNext = &dedicated_buffer_create_info;
19809 buffer_create_info.size = 1024;
19810 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19811 buffer_create_info.queueFamilyIndexCount = 1;
19812 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19813
19814 VkBuffer buffer;
19815 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19816 ASSERT_VK_SUCCESS(err);
19817
19818 VkMemoryRequirements memory_reqs;
19819 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19820
19821 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19822 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19823 dedicated_memory_info.pNext = nullptr;
19824 dedicated_memory_info.buffer = buffer;
19825 dedicated_memory_info.image = VK_NULL_HANDLE;
19826
19827 VkMemoryAllocateInfo memory_info = {};
19828 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19829 memory_info.pNext = &dedicated_memory_info;
19830 memory_info.allocationSize = memory_reqs.size;
19831
19832 bool pass;
19833 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19834 ASSERT_TRUE(pass);
19835
19836 VkDeviceMemory buffer_memory;
19837 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19838 ASSERT_VK_SUCCESS(err);
19839
19840 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19841 ASSERT_VK_SUCCESS(err);
19842
19843 vkDestroyBuffer(m_device->device(), buffer, NULL);
19844 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19845
19846 m_errorMonitor->VerifyNotFound();
19847 }
19848}
19849
19850TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19851 VkResult err;
19852
19853 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19854
19855 ASSERT_NO_FATAL_FAILURE(InitState());
19856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19857
19858 std::vector<const char *> device_extension_names;
19859 auto features = m_device->phy().features();
19860 // Artificially disable support for non-solid fill modes
19861 features.fillModeNonSolid = false;
19862 // The sacrificial device object
19863 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19864
19865 VkRenderpassObj render_pass(&test_device);
19866
19867 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19868 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19869 pipeline_layout_ci.setLayoutCount = 0;
19870 pipeline_layout_ci.pSetLayouts = NULL;
19871
19872 VkPipelineLayout pipeline_layout;
19873 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19874 ASSERT_VK_SUCCESS(err);
19875
19876 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19877 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19878 rs_ci.pNext = nullptr;
19879 rs_ci.lineWidth = 1.0f;
19880 rs_ci.rasterizerDiscardEnable = true;
19881
19882 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19883 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19884
19885 // Set polygonMode=FILL. No error is expected
19886 m_errorMonitor->ExpectSuccess();
19887 {
19888 VkPipelineObj pipe(&test_device);
19889 pipe.AddShader(&vs);
19890 pipe.AddShader(&fs);
19891 pipe.AddColorAttachment();
19892 // Set polygonMode to a good value
19893 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19894 pipe.SetRasterization(&rs_ci);
19895 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19896 }
19897 m_errorMonitor->VerifyNotFound();
19898
19899 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19900}
19901
19902TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19903 VkResult err;
19904 ASSERT_NO_FATAL_FAILURE(InitState());
19905 ASSERT_NO_FATAL_FAILURE(InitViewport());
19906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19907
19908 VkPipelineLayout pipeline_layout;
19909 VkPushConstantRange pc_range = {};
19910 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19911 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19912 pipeline_layout_ci.pushConstantRangeCount = 1;
19913 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19914
19915 //
19916 // Check for invalid push constant ranges in pipeline layouts.
19917 //
19918 struct PipelineLayoutTestCase {
19919 VkPushConstantRange const range;
19920 char const *msg;
19921 };
19922
19923 // Check for overlapping ranges
19924 const uint32_t ranges_per_test = 5;
19925 struct OverlappingRangeTestCase {
19926 VkPushConstantRange const ranges[ranges_per_test];
19927 char const *msg;
19928 };
19929
19930 // Run some positive tests to make sure overlap checking in the layer is OK
19931 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19932 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19933 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19934 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19935 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19936 "" },
19937 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19938 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19939 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19940 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19941 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19942 "" } } };
19943 for (const auto &iter : overlapping_range_tests_pos) {
19944 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19945 m_errorMonitor->ExpectSuccess();
19946 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19947 m_errorMonitor->VerifyNotFound();
19948 if (VK_SUCCESS == err) {
19949 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19950 }
19951 }
19952
19953 //
19954 // CmdPushConstants tests
19955 //
19956 const uint8_t dummy_values[100] = {};
19957
19958 BeginCommandBuffer();
19959
19960 // positive overlapping range tests with cmd
19961 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19962 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19963 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19964 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19965 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19966 } };
19967
19968 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19969 const VkPushConstantRange pc_range4[] = {
19970 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19971 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19972 };
19973
19974 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19975 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19976 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19977 ASSERT_VK_SUCCESS(err);
19978 for (const auto &iter : cmd_overlap_tests_pos) {
19979 m_errorMonitor->ExpectSuccess();
19980 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19981 iter.range.size, dummy_values);
19982 m_errorMonitor->VerifyNotFound();
19983 }
19984 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19985
19986 EndCommandBuffer();
19987}
19988
19989
19990
19991
19992
19993
19994
19995#if 0 // A few devices have issues with this test so disabling for now
19996TEST_F(VkPositiveLayerTest, LongFenceChain)
19997{
19998 m_errorMonitor->ExpectSuccess();
19999
20000 ASSERT_NO_FATAL_FAILURE(InitState());
20001 VkResult err;
20002
20003 std::vector<VkFence> fences;
20004
20005 const int chainLength = 32768;
20006
20007 for (int i = 0; i < chainLength; i++) {
20008 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20009 VkFence fence;
20010 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20011 ASSERT_VK_SUCCESS(err);
20012
20013 fences.push_back(fence);
20014
20015 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20016 0, nullptr, 0, nullptr };
20017 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20018 ASSERT_VK_SUCCESS(err);
20019
20020 }
20021
20022 // BOOM, stack overflow.
20023 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20024
20025 for (auto fence : fences)
20026 vkDestroyFence(m_device->device(), fence, nullptr);
20027
20028 m_errorMonitor->VerifyNotFound();
20029}
20030#endif
20031
20032
Cody Northrop1242dfd2016-07-13 17:24:59 -060020033#if defined(ANDROID) && defined(VALIDATION_APK)
20034static bool initialized = false;
20035static bool active = false;
20036
20037// Convert Intents to argv
20038// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020039std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020040 std::vector<std::string> args;
20041 JavaVM &vm = *app.activity->vm;
20042 JNIEnv *p_env;
20043 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20044 return args;
20045
20046 JNIEnv &env = *p_env;
20047 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020048 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020049 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020050 jmethodID get_string_extra_method =
20051 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020052 jvalue get_string_extra_args;
20053 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020054 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020055
20056 std::string args_str;
20057 if (extra_str) {
20058 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20059 args_str = extra_utf;
20060 env.ReleaseStringUTFChars(extra_str, extra_utf);
20061 env.DeleteLocalRef(extra_str);
20062 }
20063
20064 env.DeleteLocalRef(get_string_extra_args.l);
20065 env.DeleteLocalRef(intent);
20066 vm.DetachCurrentThread();
20067
20068 // split args_str
20069 std::stringstream ss(args_str);
20070 std::string arg;
20071 while (std::getline(ss, arg, ' ')) {
20072 if (!arg.empty())
20073 args.push_back(arg);
20074 }
20075
20076 return args;
20077}
20078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020079static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020081static void processCommand(struct android_app *app, int32_t cmd) {
20082 switch (cmd) {
20083 case APP_CMD_INIT_WINDOW: {
20084 if (app->window) {
20085 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020086 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020087 break;
20088 }
20089 case APP_CMD_GAINED_FOCUS: {
20090 active = true;
20091 break;
20092 }
20093 case APP_CMD_LOST_FOCUS: {
20094 active = false;
20095 break;
20096 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020097 }
20098}
20099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020100void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020101 app_dummy();
20102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020103 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020104
20105 int vulkanSupport = InitVulkan();
20106 if (vulkanSupport == 0) {
20107 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20108 return;
20109 }
20110
20111 app->onAppCmd = processCommand;
20112 app->onInputEvent = processInput;
20113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020114 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020115 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020116 struct android_poll_source *source;
20117 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020118 if (source) {
20119 source->process(app, source);
20120 }
20121
20122 if (app->destroyRequested != 0) {
20123 VkTestFramework::Finish();
20124 return;
20125 }
20126 }
20127
20128 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020129 // Use the following key to send arguments to gtest, i.e.
20130 // --es args "--gtest_filter=-VkLayerTest.foo"
20131 const char key[] = "args";
20132 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020134 std::string filter = "";
20135 if (args.size() > 0) {
20136 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20137 filter += args[0];
20138 } else {
20139 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20140 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020141
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020142 int argc = 2;
20143 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20144 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020145
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020146 // Route output to files until we can override the gtest output
20147 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20148 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020150 ::testing::InitGoogleTest(&argc, argv);
20151 VkTestFramework::InitArgs(&argc, argv);
20152 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020154 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020155
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020156 if (result != 0) {
20157 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20158 } else {
20159 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20160 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020161
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020162 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020164 fclose(stdout);
20165 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020167 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020168
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020169 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020170 }
20171 }
20172}
20173#endif
20174
Tony Barbour300a6082015-04-07 13:44:53 -060020175int main(int argc, char **argv) {
20176 int result;
20177
Cody Northrop8e54a402016-03-08 22:25:52 -070020178#ifdef ANDROID
20179 int vulkanSupport = InitVulkan();
20180 if (vulkanSupport == 0)
20181 return 1;
20182#endif
20183
Tony Barbour300a6082015-04-07 13:44:53 -060020184 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020185 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020186
20187 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20188
20189 result = RUN_ALL_TESTS();
20190
Tony Barbour6918cd52015-04-09 12:58:51 -060020191 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020192 return result;
20193}