blob: ad37d0faa46820f8b62ac9f986adf0f638ddd882 [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());
Tony Barbourf92621a2016-05-02 14:28:12 -06001943 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001944 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001945 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001946 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001947
Tony Barbourf92621a2016-05-02 14:28:12 -06001948 VkImageView dsv;
1949 VkImageViewCreateInfo dsvci = {};
1950 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1951 dsvci.image = image.handle();
1952 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1953 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1954 dsvci.subresourceRange.layerCount = 1;
1955 dsvci.subresourceRange.baseMipLevel = 0;
1956 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001958
Tony Barbourf92621a2016-05-02 14:28:12 -06001959 // Create a view with depth / stencil aspect for image with different usage
1960 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001961
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001962 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001963
1964 // Initialize buffer with TRANSFER_DST usage
1965 vk_testing::Buffer buffer;
1966 VkMemoryPropertyFlags reqs = 0;
1967 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1968 VkBufferImageCopy region = {};
1969 region.bufferRowLength = 128;
1970 region.bufferImageHeight = 128;
1971 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1972 region.imageSubresource.layerCount = 1;
1973 region.imageExtent.height = 16;
1974 region.imageExtent.width = 16;
1975 region.imageExtent.depth = 1;
1976
Tony Barbourf92621a2016-05-02 14:28:12 -06001977 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1978 // TRANSFER_DST
1979 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001980
Chris Forbesda581202016-10-06 18:25:26 +13001981 // two separate errors from this call:
1982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1984
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001985 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1986 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001987 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001988}
Tony Barbour75d79f02016-08-30 09:39:07 -06001989
Tony Barbour75d79f02016-08-30 09:39:07 -06001990
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001991#endif // MEM_TRACKER_TESTS
1992
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001993#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001994
1995TEST_F(VkLayerTest, LeakAnObject) {
1996 VkResult err;
1997
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001998 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001999
2000 // Note that we have to create a new device since destroying the
2001 // framework's device causes Teardown() to fail and just calling Teardown
2002 // will destroy the errorMonitor.
2003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002005
2006 ASSERT_NO_FATAL_FAILURE(InitState());
2007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002008 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002009 std::vector<VkDeviceQueueCreateInfo> queue_info;
2010 queue_info.reserve(queue_props.size());
2011 std::vector<std::vector<float>> queue_priorities;
2012 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2013 VkDeviceQueueCreateInfo qi = {};
2014 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2015 qi.pNext = NULL;
2016 qi.queueFamilyIndex = i;
2017 qi.queueCount = queue_props[i].queueCount;
2018 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2019 qi.pQueuePriorities = queue_priorities[i].data();
2020 queue_info.push_back(qi);
2021 }
2022
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002023 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002024
2025 // The sacrificial device object
2026 VkDevice testDevice;
2027 VkDeviceCreateInfo device_create_info = {};
2028 auto features = m_device->phy().features();
2029 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2030 device_create_info.pNext = NULL;
2031 device_create_info.queueCreateInfoCount = queue_info.size();
2032 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002033 device_create_info.enabledLayerCount = 0;
2034 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002035 device_create_info.pEnabledFeatures = &features;
2036 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2037 ASSERT_VK_SUCCESS(err);
2038
2039 VkFence fence;
2040 VkFenceCreateInfo fence_create_info = {};
2041 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2042 fence_create_info.pNext = NULL;
2043 fence_create_info.flags = 0;
2044 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2045 ASSERT_VK_SUCCESS(err);
2046
2047 // Induce failure by not calling vkDestroyFence
2048 vkDestroyDevice(testDevice, NULL);
2049 m_errorMonitor->VerifyFound();
2050}
2051
2052TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2053
2054 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2055 "attempt to delete them from another.");
2056
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002058
Cody Northropc31a84f2016-08-22 10:41:47 -06002059 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002060 VkCommandPool command_pool_one;
2061 VkCommandPool command_pool_two;
2062
2063 VkCommandPoolCreateInfo pool_create_info{};
2064 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2065 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2066 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2067
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002068 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002069
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002070 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002071
2072 VkCommandBuffer command_buffer[9];
2073 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002074 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002075 command_buffer_allocate_info.commandPool = command_pool_one;
2076 command_buffer_allocate_info.commandBufferCount = 9;
2077 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002078 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002080 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002081
2082 m_errorMonitor->VerifyFound();
2083
2084 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2085 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2086}
2087
2088TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2089 VkResult err;
2090
2091 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002092 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002093
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002095
2096 ASSERT_NO_FATAL_FAILURE(InitState());
2097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2098
2099 VkDescriptorPoolSize ds_type_count = {};
2100 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2101 ds_type_count.descriptorCount = 1;
2102
2103 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2104 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2105 ds_pool_ci.pNext = NULL;
2106 ds_pool_ci.flags = 0;
2107 ds_pool_ci.maxSets = 1;
2108 ds_pool_ci.poolSizeCount = 1;
2109 ds_pool_ci.pPoolSizes = &ds_type_count;
2110
2111 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002112 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002113 ASSERT_VK_SUCCESS(err);
2114
2115 // Create a second descriptor pool
2116 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002117 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002118 ASSERT_VK_SUCCESS(err);
2119
2120 VkDescriptorSetLayoutBinding dsl_binding = {};
2121 dsl_binding.binding = 0;
2122 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2123 dsl_binding.descriptorCount = 1;
2124 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2125 dsl_binding.pImmutableSamplers = NULL;
2126
2127 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2128 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2129 ds_layout_ci.pNext = NULL;
2130 ds_layout_ci.bindingCount = 1;
2131 ds_layout_ci.pBindings = &dsl_binding;
2132
2133 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002134 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002135 ASSERT_VK_SUCCESS(err);
2136
2137 VkDescriptorSet descriptorSet;
2138 VkDescriptorSetAllocateInfo alloc_info = {};
2139 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2140 alloc_info.descriptorSetCount = 1;
2141 alloc_info.descriptorPool = ds_pool_one;
2142 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002143 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002144 ASSERT_VK_SUCCESS(err);
2145
2146 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2147
2148 m_errorMonitor->VerifyFound();
2149
2150 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2151 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2152 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2153}
2154
2155TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002158 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002159
2160 ASSERT_NO_FATAL_FAILURE(InitState());
2161
2162 // Pass bogus handle into GetImageMemoryRequirements
2163 VkMemoryRequirements mem_reqs;
2164 uint64_t fakeImageHandle = 0xCADECADE;
2165 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2166
2167 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2168
2169 m_errorMonitor->VerifyFound();
2170}
2171
Karl Schultz6addd812016-02-02 17:17:23 -07002172TEST_F(VkLayerTest, PipelineNotBound) {
2173 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002175 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002176
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002178
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002179 ASSERT_NO_FATAL_FAILURE(InitState());
2180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002181
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002182 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002183 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2184 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002185
2186 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002187 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2188 ds_pool_ci.pNext = NULL;
2189 ds_pool_ci.maxSets = 1;
2190 ds_pool_ci.poolSizeCount = 1;
2191 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002192
2193 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002194 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002195 ASSERT_VK_SUCCESS(err);
2196
2197 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002198 dsl_binding.binding = 0;
2199 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2200 dsl_binding.descriptorCount = 1;
2201 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2202 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002203
2204 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002205 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2206 ds_layout_ci.pNext = NULL;
2207 ds_layout_ci.bindingCount = 1;
2208 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002209
2210 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002211 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002212 ASSERT_VK_SUCCESS(err);
2213
2214 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002215 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002216 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002217 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002218 alloc_info.descriptorPool = ds_pool;
2219 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002220 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002221 ASSERT_VK_SUCCESS(err);
2222
2223 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002224 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2225 pipeline_layout_ci.pNext = NULL;
2226 pipeline_layout_ci.setLayoutCount = 1;
2227 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002228
2229 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002230 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002231 ASSERT_VK_SUCCESS(err);
2232
Mark Youngad779052016-01-06 14:26:04 -07002233 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234
2235 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002236 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002237
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002238 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002239
Chia-I Wuf7458c52015-10-26 21:10:41 +08002240 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2241 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2242 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002243}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002244
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002245TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2246 VkResult err;
2247
2248 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2249 "during bind[Buffer|Image]Memory time");
2250
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002251 ASSERT_NO_FATAL_FAILURE(InitState());
2252
2253 // Create an image, allocate memory, set a bad typeIndex and then try to
2254 // bind it
2255 VkImage image;
2256 VkDeviceMemory mem;
2257 VkMemoryRequirements mem_reqs;
2258 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2259 const int32_t tex_width = 32;
2260 const int32_t tex_height = 32;
2261
2262 VkImageCreateInfo image_create_info = {};
2263 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2264 image_create_info.pNext = NULL;
2265 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2266 image_create_info.format = tex_format;
2267 image_create_info.extent.width = tex_width;
2268 image_create_info.extent.height = tex_height;
2269 image_create_info.extent.depth = 1;
2270 image_create_info.mipLevels = 1;
2271 image_create_info.arrayLayers = 1;
2272 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2273 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2274 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2275 image_create_info.flags = 0;
2276
2277 VkMemoryAllocateInfo mem_alloc = {};
2278 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2279 mem_alloc.pNext = NULL;
2280 mem_alloc.allocationSize = 0;
2281 mem_alloc.memoryTypeIndex = 0;
2282
2283 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2284 ASSERT_VK_SUCCESS(err);
2285
2286 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2287 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002288
2289 // Introduce Failure, select invalid TypeIndex
2290 VkPhysicalDeviceMemoryProperties memory_info;
2291
2292 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2293 unsigned int i;
2294 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2295 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2296 mem_alloc.memoryTypeIndex = i;
2297 break;
2298 }
2299 }
2300 if (i >= memory_info.memoryTypeCount) {
2301 printf("No invalid memory type index could be found; skipped.\n");
2302 vkDestroyImage(m_device->device(), image, NULL);
2303 return;
2304 }
2305
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002306 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 -06002307
2308 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2309 ASSERT_VK_SUCCESS(err);
2310
2311 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2312 (void)err;
2313
2314 m_errorMonitor->VerifyFound();
2315
2316 vkDestroyImage(m_device->device(), image, NULL);
2317 vkFreeMemory(m_device->device(), mem, NULL);
2318}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002319
Karl Schultz6addd812016-02-02 17:17:23 -07002320TEST_F(VkLayerTest, BindInvalidMemory) {
2321 VkResult err;
2322 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002323
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002325
Tobin Ehlisec598302015-09-15 15:02:17 -06002326 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002327
2328 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002329 VkImage image;
2330 VkDeviceMemory mem;
2331 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002332
Karl Schultz6addd812016-02-02 17:17:23 -07002333 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2334 const int32_t tex_width = 32;
2335 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002336
2337 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002338 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2339 image_create_info.pNext = NULL;
2340 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2341 image_create_info.format = tex_format;
2342 image_create_info.extent.width = tex_width;
2343 image_create_info.extent.height = tex_height;
2344 image_create_info.extent.depth = 1;
2345 image_create_info.mipLevels = 1;
2346 image_create_info.arrayLayers = 1;
2347 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2348 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2349 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2350 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002351
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002352 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002353 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2354 mem_alloc.pNext = NULL;
2355 mem_alloc.allocationSize = 0;
2356 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002357
Chia-I Wuf7458c52015-10-26 21:10:41 +08002358 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002359 ASSERT_VK_SUCCESS(err);
2360
Karl Schultz6addd812016-02-02 17:17:23 -07002361 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002362
2363 mem_alloc.allocationSize = mem_reqs.size;
2364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002365 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002366 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002367
2368 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002369 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002370 ASSERT_VK_SUCCESS(err);
2371
2372 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002373 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002374
2375 // Try to bind free memory that has been freed
2376 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2377 // This may very well return an error.
2378 (void)err;
2379
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002380 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002381
Chia-I Wuf7458c52015-10-26 21:10:41 +08002382 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002383}
2384
Karl Schultz6addd812016-02-02 17:17:23 -07002385TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2386 VkResult err;
2387 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002388
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002390
Tobin Ehlisec598302015-09-15 15:02:17 -06002391 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002392
Karl Schultz6addd812016-02-02 17:17:23 -07002393 // Create an image object, allocate memory, destroy the object and then try
2394 // to bind it
2395 VkImage image;
2396 VkDeviceMemory mem;
2397 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002398
Karl Schultz6addd812016-02-02 17:17:23 -07002399 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2400 const int32_t tex_width = 32;
2401 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002402
2403 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002404 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2405 image_create_info.pNext = NULL;
2406 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2407 image_create_info.format = tex_format;
2408 image_create_info.extent.width = tex_width;
2409 image_create_info.extent.height = tex_height;
2410 image_create_info.extent.depth = 1;
2411 image_create_info.mipLevels = 1;
2412 image_create_info.arrayLayers = 1;
2413 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2414 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2415 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2416 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002417
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002418 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002419 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2420 mem_alloc.pNext = NULL;
2421 mem_alloc.allocationSize = 0;
2422 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002423
Chia-I Wuf7458c52015-10-26 21:10:41 +08002424 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002425 ASSERT_VK_SUCCESS(err);
2426
Karl Schultz6addd812016-02-02 17:17:23 -07002427 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002428
2429 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002430 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002431 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002432
2433 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002434 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002435 ASSERT_VK_SUCCESS(err);
2436
2437 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002438 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002439 ASSERT_VK_SUCCESS(err);
2440
2441 // Now Try to bind memory to this destroyed object
2442 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2443 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002444 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002445
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002446 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002447
Chia-I Wuf7458c52015-10-26 21:10:41 +08002448 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002449}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002450
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002451#endif // OBJ_TRACKER_TESTS
2452
Tobin Ehlis0788f522015-05-26 16:11:58 -06002453#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002454
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002455TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2456 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2457
2458 ASSERT_NO_FATAL_FAILURE(InitState());
2459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2460
2461 VkVertexInputBindingDescription input_binding;
2462 memset(&input_binding, 0, sizeof(input_binding));
2463
2464 VkVertexInputAttributeDescription input_attribs;
2465 memset(&input_attribs, 0, sizeof(input_attribs));
2466
2467 // Pick a really bad format for this purpose and make sure it should fail
2468 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2469 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2470 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2471 printf("Format unsuitable for test; skipped.\n");
2472 return;
2473 }
2474
2475 input_attribs.location = 0;
2476 char const *vsSource = "#version 450\n"
2477 "\n"
2478 "out gl_PerVertex {\n"
2479 " vec4 gl_Position;\n"
2480 "};\n"
2481 "void main(){\n"
2482 " gl_Position = vec4(1);\n"
2483 "}\n";
2484 char const *fsSource = "#version 450\n"
2485 "\n"
2486 "layout(location=0) out vec4 color;\n"
2487 "void main(){\n"
2488 " color = vec4(1);\n"
2489 "}\n";
2490
2491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2492 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2493 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2494
2495 VkPipelineObj pipe(m_device);
2496 pipe.AddColorAttachment();
2497 pipe.AddShader(&vs);
2498 pipe.AddShader(&fs);
2499
2500 pipe.AddVertexInputBindings(&input_binding, 1);
2501 pipe.AddVertexInputAttribs(&input_attribs, 1);
2502
2503 VkDescriptorSetObj descriptorSet(m_device);
2504 descriptorSet.AppendDummy();
2505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2506
2507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2508
2509 m_errorMonitor->VerifyFound();
2510}
2511
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002512TEST_F(VkLayerTest, ImageSampleCounts) {
2513
2514 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2515 "validation errors.");
2516 ASSERT_NO_FATAL_FAILURE(InitState());
2517
2518 VkMemoryPropertyFlags reqs = 0;
2519 VkImageCreateInfo image_create_info = {};
2520 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2521 image_create_info.pNext = NULL;
2522 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2523 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2524 image_create_info.extent.width = 256;
2525 image_create_info.extent.height = 256;
2526 image_create_info.extent.depth = 1;
2527 image_create_info.mipLevels = 1;
2528 image_create_info.arrayLayers = 1;
2529 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2530 image_create_info.flags = 0;
2531
2532 VkImageBlit blit_region = {};
2533 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2534 blit_region.srcSubresource.baseArrayLayer = 0;
2535 blit_region.srcSubresource.layerCount = 1;
2536 blit_region.srcSubresource.mipLevel = 0;
2537 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2538 blit_region.dstSubresource.baseArrayLayer = 0;
2539 blit_region.dstSubresource.layerCount = 1;
2540 blit_region.dstSubresource.mipLevel = 0;
2541
2542 // Create two images, the source with sampleCount = 2, and attempt to blit
2543 // between them
2544 {
2545 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002546 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002547 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002549 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002550 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002551 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002553 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2555 "of VK_SAMPLE_COUNT_2_BIT but "
2556 "must be VK_SAMPLE_COUNT_1_BIT");
2557 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2558 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002559 m_errorMonitor->VerifyFound();
2560 m_commandBuffer->EndCommandBuffer();
2561 }
2562
2563 // Create two images, the dest with sampleCount = 4, and attempt to blit
2564 // between them
2565 {
2566 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002567 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002568 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002569 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002570 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002571 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002572 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002574 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2576 "of VK_SAMPLE_COUNT_4_BIT but "
2577 "must be VK_SAMPLE_COUNT_1_BIT");
2578 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2579 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002580 m_errorMonitor->VerifyFound();
2581 m_commandBuffer->EndCommandBuffer();
2582 }
2583
2584 VkBufferImageCopy copy_region = {};
2585 copy_region.bufferRowLength = 128;
2586 copy_region.bufferImageHeight = 128;
2587 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2588 copy_region.imageSubresource.layerCount = 1;
2589 copy_region.imageExtent.height = 64;
2590 copy_region.imageExtent.width = 64;
2591 copy_region.imageExtent.depth = 1;
2592
2593 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2594 // buffer to image
2595 {
2596 vk_testing::Buffer src_buffer;
2597 VkMemoryPropertyFlags reqs = 0;
2598 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2599 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002603 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2605 "of VK_SAMPLE_COUNT_8_BIT but "
2606 "must be VK_SAMPLE_COUNT_1_BIT");
2607 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2608 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002609 m_errorMonitor->VerifyFound();
2610 m_commandBuffer->EndCommandBuffer();
2611 }
2612
2613 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2614 // image to buffer
2615 {
2616 vk_testing::Buffer dst_buffer;
2617 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2618 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002619 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002620 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002622 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2624 "of VK_SAMPLE_COUNT_2_BIT but "
2625 "must be VK_SAMPLE_COUNT_1_BIT");
2626 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002627 dst_buffer.handle(), 1, &copy_region);
2628 m_errorMonitor->VerifyFound();
2629 m_commandBuffer->EndCommandBuffer();
2630 }
2631}
2632
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002633TEST_F(VkLayerTest, BlitImageFormats) {
2634
2635 // Image blit with mismatched formats
2636 const char * expected_message =
2637 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2638 " the other one must also have signed/unsigned integer format";
2639
2640 ASSERT_NO_FATAL_FAILURE(InitState());
2641
2642 VkImageObj src_image(m_device);
2643 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2644 VkImageObj dst_image(m_device);
2645 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2646 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002647 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 -06002648
2649 VkImageBlit blitRegion = {};
2650 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2651 blitRegion.srcSubresource.baseArrayLayer = 0;
2652 blitRegion.srcSubresource.layerCount = 1;
2653 blitRegion.srcSubresource.mipLevel = 0;
2654 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2655 blitRegion.dstSubresource.baseArrayLayer = 0;
2656 blitRegion.dstSubresource.layerCount = 1;
2657 blitRegion.dstSubresource.mipLevel = 0;
2658
2659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2660
2661 // Unsigned int vs not an int
2662 BeginCommandBuffer();
2663 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2664 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2665
2666 m_errorMonitor->VerifyFound();
2667
2668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2669
2670 // Unsigned int vs signed int
2671 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2672 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2673
2674 m_errorMonitor->VerifyFound();
2675
2676 EndCommandBuffer();
2677}
2678
2679
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002680TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2681 VkResult err;
2682 bool pass;
2683
2684 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2685 ASSERT_NO_FATAL_FAILURE(InitState());
2686
2687 // If w/d/h granularity is 1, test is not meaningful
2688 // TODO: When virtual device limits are available, create a set of limits for this test that
2689 // will always have a granularity of > 1 for w, h, and d
2690 auto index = m_device->graphics_queue_node_index_;
2691 auto queue_family_properties = m_device->phy().queue_properties();
2692
2693 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2694 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2695 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2696 return;
2697 }
2698
2699 // Create two images of different types and try to copy between them
2700 VkImage srcImage;
2701 VkImage dstImage;
2702 VkDeviceMemory srcMem;
2703 VkDeviceMemory destMem;
2704 VkMemoryRequirements memReqs;
2705
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002706 VkImageCreateInfo image_create_info = {};
2707 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2708 image_create_info.pNext = NULL;
2709 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2710 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2711 image_create_info.extent.width = 32;
2712 image_create_info.extent.height = 32;
2713 image_create_info.extent.depth = 1;
2714 image_create_info.mipLevels = 1;
2715 image_create_info.arrayLayers = 4;
2716 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2717 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2718 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2719 image_create_info.flags = 0;
2720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002721 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002722 ASSERT_VK_SUCCESS(err);
2723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002724 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002725 ASSERT_VK_SUCCESS(err);
2726
2727 // Allocate memory
2728 VkMemoryAllocateInfo memAlloc = {};
2729 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2730 memAlloc.pNext = NULL;
2731 memAlloc.allocationSize = 0;
2732 memAlloc.memoryTypeIndex = 0;
2733
2734 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2735 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002736 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002737 ASSERT_TRUE(pass);
2738 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2739 ASSERT_VK_SUCCESS(err);
2740
2741 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2742 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002743 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002744 ASSERT_VK_SUCCESS(err);
2745 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2746 ASSERT_VK_SUCCESS(err);
2747
2748 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2749 ASSERT_VK_SUCCESS(err);
2750 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2751 ASSERT_VK_SUCCESS(err);
2752
2753 BeginCommandBuffer();
2754 VkImageCopy copyRegion;
2755 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2756 copyRegion.srcSubresource.mipLevel = 0;
2757 copyRegion.srcSubresource.baseArrayLayer = 0;
2758 copyRegion.srcSubresource.layerCount = 1;
2759 copyRegion.srcOffset.x = 0;
2760 copyRegion.srcOffset.y = 0;
2761 copyRegion.srcOffset.z = 0;
2762 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2763 copyRegion.dstSubresource.mipLevel = 0;
2764 copyRegion.dstSubresource.baseArrayLayer = 0;
2765 copyRegion.dstSubresource.layerCount = 1;
2766 copyRegion.dstOffset.x = 0;
2767 copyRegion.dstOffset.y = 0;
2768 copyRegion.dstOffset.z = 0;
2769 copyRegion.extent.width = 1;
2770 copyRegion.extent.height = 1;
2771 copyRegion.extent.depth = 1;
2772
2773 // Introduce failure by setting srcOffset to a bad granularity value
2774 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2776 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002777 m_errorMonitor->VerifyFound();
2778
2779 // Introduce failure by setting extent to a bad granularity value
2780 copyRegion.srcOffset.y = 0;
2781 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2783 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002784 m_errorMonitor->VerifyFound();
2785
2786 // Now do some buffer/image copies
2787 vk_testing::Buffer buffer;
2788 VkMemoryPropertyFlags reqs = 0;
2789 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2790 VkBufferImageCopy region = {};
2791 region.bufferOffset = 0;
2792 region.bufferRowLength = 3;
2793 region.bufferImageHeight = 128;
2794 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2795 region.imageSubresource.layerCount = 1;
2796 region.imageExtent.height = 16;
2797 region.imageExtent.width = 16;
2798 region.imageExtent.depth = 1;
2799 region.imageOffset.x = 0;
2800 region.imageOffset.y = 0;
2801 region.imageOffset.z = 0;
2802
2803 // Introduce failure by setting bufferRowLength to a bad granularity value
2804 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2806 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2807 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002808 m_errorMonitor->VerifyFound();
2809 region.bufferRowLength = 128;
2810
2811 // Introduce failure by setting bufferOffset to a bad granularity value
2812 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2814 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2815 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002816 m_errorMonitor->VerifyFound();
2817 region.bufferOffset = 0;
2818
2819 // Introduce failure by setting bufferImageHeight to a bad granularity value
2820 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2822 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2823 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002824 m_errorMonitor->VerifyFound();
2825 region.bufferImageHeight = 128;
2826
2827 // Introduce failure by setting imageExtent to a bad granularity value
2828 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2830 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2831 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002832 m_errorMonitor->VerifyFound();
2833 region.imageExtent.width = 16;
2834
2835 // Introduce failure by setting imageOffset to a bad granularity value
2836 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2838 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2839 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002840 m_errorMonitor->VerifyFound();
2841
2842 EndCommandBuffer();
2843
2844 vkDestroyImage(m_device->device(), srcImage, NULL);
2845 vkDestroyImage(m_device->device(), dstImage, NULL);
2846 vkFreeMemory(m_device->device(), srcMem, NULL);
2847 vkFreeMemory(m_device->device(), destMem, NULL);
2848}
2849
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002850TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002851 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2852 "attempt to submit them on a queue created in a different "
2853 "queue family.");
2854
Cody Northropc31a84f2016-08-22 10:41:47 -06002855 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002856 // This test is meaningless unless we have multiple queue families
2857 auto queue_family_properties = m_device->phy().queue_properties();
2858 if (queue_family_properties.size() < 2) {
2859 return;
2860 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002862 // Get safe index of another queue family
2863 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2864 ASSERT_NO_FATAL_FAILURE(InitState());
2865 // Create a second queue using a different queue family
2866 VkQueue other_queue;
2867 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2868
2869 // Record an empty cmd buffer
2870 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2871 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2872 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2873 vkEndCommandBuffer(m_commandBuffer->handle());
2874
2875 // And submit on the wrong queue
2876 VkSubmitInfo submit_info = {};
2877 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2878 submit_info.commandBufferCount = 1;
2879 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002880 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002881
2882 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002883}
2884
Chris Forbes4c24a922016-11-16 08:59:10 +13002885TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2886 ASSERT_NO_FATAL_FAILURE(InitState());
2887
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002888 // There are no attachments, but refer to attachment 0.
2889 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002890 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002891 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2892 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002893 };
2894
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002895 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2896 nullptr,
2897 0,
2898 0,
2899 nullptr,
2900 1,
2901 subpasses,
2902 0,
2903 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002904 VkRenderPass rp;
2905
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002906 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002908 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002909 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2910 m_errorMonitor->VerifyFound();
2911}
2912
Chris Forbesa58c4522016-09-28 15:19:39 +13002913TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2914 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2915 ASSERT_NO_FATAL_FAILURE(InitState());
2916
2917 // A renderpass with two subpasses, both writing the same attachment.
2918 VkAttachmentDescription attach[] = {
2919 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2920 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2921 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2922 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2923 },
2924 };
2925 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2926 VkSubpassDescription subpasses[] = {
2927 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2928 1, &ref, nullptr, nullptr, 0, nullptr },
2929 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2930 1, &ref, nullptr, nullptr, 0, nullptr },
2931 };
2932 VkSubpassDependency dep = {
2933 0, 1,
2934 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2935 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2936 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2937 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2938 VK_DEPENDENCY_BY_REGION_BIT
2939 };
2940 VkRenderPassCreateInfo rpci = {
2941 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2942 0, 1, attach, 2, subpasses, 1, &dep
2943 };
2944 VkRenderPass rp;
2945 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2946 ASSERT_VK_SUCCESS(err);
2947
2948 VkImageObj image(m_device);
2949 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2950 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2951 VK_IMAGE_TILING_OPTIMAL, 0);
2952 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2953
2954 VkFramebufferCreateInfo fbci = {
2955 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2956 0, rp, 1, &imageView, 32, 32, 1
2957 };
2958 VkFramebuffer fb;
2959 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2960 ASSERT_VK_SUCCESS(err);
2961
2962 char const *vsSource =
2963 "#version 450\n"
2964 "void main() { gl_Position = vec4(1); }\n";
2965 char const *fsSource =
2966 "#version 450\n"
2967 "layout(location=0) out vec4 color;\n"
2968 "void main() { color = vec4(1); }\n";
2969
2970 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2971 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2972 VkPipelineObj pipe(m_device);
2973 pipe.AddColorAttachment();
2974 pipe.AddShader(&vs);
2975 pipe.AddShader(&fs);
2976 VkViewport view_port = {};
2977 m_viewports.push_back(view_port);
2978 pipe.SetViewport(m_viewports);
2979 VkRect2D rect = {};
2980 m_scissors.push_back(rect);
2981 pipe.SetScissor(m_scissors);
2982
2983 VkPipelineLayoutCreateInfo plci = {
2984 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2985 0, 0, nullptr, 0, nullptr
2986 };
2987 VkPipelineLayout pl;
2988 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2989 ASSERT_VK_SUCCESS(err);
2990 pipe.CreateVKPipeline(pl, rp);
2991
2992 BeginCommandBuffer();
2993
2994 VkRenderPassBeginInfo rpbi = {
2995 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2996 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2997 };
2998
2999 // subtest 1: bind in the wrong subpass
3000 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3001 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3003 "built for subpass 0 but used in subpass 1");
3004 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3005 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3006 m_errorMonitor->VerifyFound();
3007
3008 vkCmdEndRenderPass(m_commandBuffer->handle());
3009
3010 // subtest 2: bind in correct subpass, then transition to next subpass
3011 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3012 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3013 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3015 "built for subpass 0 but used in subpass 1");
3016 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3017 m_errorMonitor->VerifyFound();
3018
3019 vkCmdEndRenderPass(m_commandBuffer->handle());
3020
3021 EndCommandBuffer();
3022
3023 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3024 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3025 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3026}
3027
Tony Barbour4e919972016-08-09 13:27:40 -06003028TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3029 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3030 "with extent outside of framebuffer");
3031 ASSERT_NO_FATAL_FAILURE(InitState());
3032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3035 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003036
3037 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3038 m_renderPassBeginInfo.renderArea.extent.width = 257;
3039 m_renderPassBeginInfo.renderArea.extent.height = 257;
3040 BeginCommandBuffer();
3041 m_errorMonitor->VerifyFound();
3042}
3043
3044TEST_F(VkLayerTest, DisabledIndependentBlend) {
3045 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3046 "blend and then specifying different blend states for two "
3047 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003048 VkPhysicalDeviceFeatures features = {};
3049 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003050 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3053 "Invalid Pipeline CreateInfo: If independent blend feature not "
3054 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003055
Cody Northropc31a84f2016-08-22 10:41:47 -06003056 VkDescriptorSetObj descriptorSet(m_device);
3057 descriptorSet.AppendDummy();
3058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003059
Cody Northropc31a84f2016-08-22 10:41:47 -06003060 VkPipelineObj pipeline(m_device);
3061 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003062 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003063 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003064
Cody Northropc31a84f2016-08-22 10:41:47 -06003065 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3066 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3067 att_state1.blendEnable = VK_TRUE;
3068 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3069 att_state2.blendEnable = VK_FALSE;
3070 pipeline.AddColorAttachment(0, &att_state1);
3071 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003072 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003073 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003074}
3075
3076TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3077 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3078 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003079 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3082 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003083
3084 // Create a renderPass with a single color attachment
3085 VkAttachmentReference attach = {};
3086 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3087 VkSubpassDescription subpass = {};
3088 VkRenderPassCreateInfo rpci = {};
3089 rpci.subpassCount = 1;
3090 rpci.pSubpasses = &subpass;
3091 rpci.attachmentCount = 1;
3092 VkAttachmentDescription attach_desc = {};
3093 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3094 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3095 rpci.pAttachments = &attach_desc;
3096 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3097 VkRenderPass rp;
3098 subpass.pDepthStencilAttachment = &attach;
3099 subpass.pColorAttachments = NULL;
3100 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3101 m_errorMonitor->VerifyFound();
3102}
3103
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003104TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3105 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3106 "attachment reference of VK_ATTACHMENT_UNUSED");
3107
3108 ASSERT_NO_FATAL_FAILURE(InitState());
3109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3110
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003112
3113 VkAttachmentReference color_attach = {};
3114 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3115 color_attach.attachment = 0;
3116 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3117 VkSubpassDescription subpass = {};
3118 subpass.colorAttachmentCount = 1;
3119 subpass.pColorAttachments = &color_attach;
3120 subpass.preserveAttachmentCount = 1;
3121 subpass.pPreserveAttachments = &preserve_attachment;
3122
3123 VkRenderPassCreateInfo rpci = {};
3124 rpci.subpassCount = 1;
3125 rpci.pSubpasses = &subpass;
3126 rpci.attachmentCount = 1;
3127 VkAttachmentDescription attach_desc = {};
3128 attach_desc.format = VK_FORMAT_UNDEFINED;
3129 rpci.pAttachments = &attach_desc;
3130 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3131 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003132 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003133
3134 m_errorMonitor->VerifyFound();
3135
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003136 if (result == VK_SUCCESS) {
3137 vkDestroyRenderPass(m_device->device(), rp, NULL);
3138 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003139}
3140
Chris Forbesc5389742016-06-29 11:49:23 +12003141TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003142 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3143 "when the source of a subpass multisample resolve "
3144 "does not have multiple samples.");
3145
Chris Forbesc5389742016-06-29 11:49:23 +12003146 ASSERT_NO_FATAL_FAILURE(InitState());
3147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3149 "Subpass 0 requests multisample resolve from attachment 0 which has "
3150 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003151
3152 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003153 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3154 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3155 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3156 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3157 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3158 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003159 };
3160
3161 VkAttachmentReference color = {
3162 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3163 };
3164
3165 VkAttachmentReference resolve = {
3166 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3167 };
3168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003170
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003171 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003172
3173 VkRenderPass rp;
3174 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3175
3176 m_errorMonitor->VerifyFound();
3177
3178 if (err == VK_SUCCESS)
3179 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3180}
3181
3182TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003183 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3184 "when a subpass multisample resolve operation is "
3185 "requested, and the destination of that resolve has "
3186 "multiple samples.");
3187
Chris Forbesc5389742016-06-29 11:49:23 +12003188 ASSERT_NO_FATAL_FAILURE(InitState());
3189
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3191 "Subpass 0 requests multisample resolve into attachment 1, which "
3192 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003193
3194 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3196 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3197 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3198 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3199 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3200 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003201 };
3202
3203 VkAttachmentReference color = {
3204 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3205 };
3206
3207 VkAttachmentReference resolve = {
3208 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3209 };
3210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003211 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003212
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003213 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003214
3215 VkRenderPass rp;
3216 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3217
3218 m_errorMonitor->VerifyFound();
3219
3220 if (err == VK_SUCCESS)
3221 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3222}
3223
Chris Forbes3f128ef2016-06-29 14:58:53 +12003224TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003225 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3226 "when the color and depth attachments used by a subpass "
3227 "have inconsistent sample counts");
3228
Chris Forbes3f128ef2016-06-29 14:58:53 +12003229 ASSERT_NO_FATAL_FAILURE(InitState());
3230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3232 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003233
3234 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003235 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3236 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3237 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3238 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3239 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3240 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003241 };
3242
3243 VkAttachmentReference color[] = {
3244 {
3245 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3246 },
3247 {
3248 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3249 },
3250 };
3251
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003252 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003253
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003254 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003255
3256 VkRenderPass rp;
3257 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3258
3259 m_errorMonitor->VerifyFound();
3260
3261 if (err == VK_SUCCESS)
3262 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3263}
3264
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003265TEST_F(VkLayerTest, FramebufferCreateErrors) {
3266 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003267 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003268 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003269 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3270 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3271 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3272 " 6. Framebuffer attachment where dimensions don't match\n"
3273 " 7. Framebuffer attachment w/o identity swizzle\n"
3274 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003275
3276 ASSERT_NO_FATAL_FAILURE(InitState());
3277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3278
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3280 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3281 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003282
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003283 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003284 VkAttachmentReference attach = {};
3285 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3286 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003287 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003288 VkRenderPassCreateInfo rpci = {};
3289 rpci.subpassCount = 1;
3290 rpci.pSubpasses = &subpass;
3291 rpci.attachmentCount = 1;
3292 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003293 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003294 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003295 rpci.pAttachments = &attach_desc;
3296 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3297 VkRenderPass rp;
3298 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3299 ASSERT_VK_SUCCESS(err);
3300
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003301 VkImageView ivs[2];
3302 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3303 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003304 VkFramebufferCreateInfo fb_info = {};
3305 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3306 fb_info.pNext = NULL;
3307 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003308 // Set mis-matching attachmentCount
3309 fb_info.attachmentCount = 2;
3310 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003311 fb_info.width = 100;
3312 fb_info.height = 100;
3313 fb_info.layers = 1;
3314
3315 VkFramebuffer fb;
3316 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3317
3318 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003319 if (err == VK_SUCCESS) {
3320 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3321 }
3322 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003323
3324 // Create a renderPass with a depth-stencil attachment created with
3325 // IMAGE_USAGE_COLOR_ATTACHMENT
3326 // Add our color attachment to pDepthStencilAttachment
3327 subpass.pDepthStencilAttachment = &attach;
3328 subpass.pColorAttachments = NULL;
3329 VkRenderPass rp_ds;
3330 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3331 ASSERT_VK_SUCCESS(err);
3332 // Set correct attachment count, but attachment has COLOR usage bit set
3333 fb_info.attachmentCount = 1;
3334 fb_info.renderPass = rp_ds;
3335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003337 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3338
3339 m_errorMonitor->VerifyFound();
3340 if (err == VK_SUCCESS) {
3341 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3342 }
3343 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003344
3345 // Create new renderpass with alternate attachment format from fb
3346 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3347 subpass.pDepthStencilAttachment = NULL;
3348 subpass.pColorAttachments = &attach;
3349 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3350 ASSERT_VK_SUCCESS(err);
3351
3352 // Cause error due to mis-matched formats between rp & fb
3353 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3354 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3356 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003357 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3358
3359 m_errorMonitor->VerifyFound();
3360 if (err == VK_SUCCESS) {
3361 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3362 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003363 vkDestroyRenderPass(m_device->device(), rp, NULL);
3364
3365 // Create new renderpass with alternate sample count from fb
3366 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3367 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3368 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3369 ASSERT_VK_SUCCESS(err);
3370
3371 // Cause error due to mis-matched sample count between rp & fb
3372 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3374 "that do not match the "
3375 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003376 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3377
3378 m_errorMonitor->VerifyFound();
3379 if (err == VK_SUCCESS) {
3380 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3381 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003382
3383 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003384
3385 // Create a custom imageView with non-1 mip levels
3386 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 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 -06003388 ASSERT_TRUE(image.initialized());
3389
3390 VkImageView view;
3391 VkImageViewCreateInfo ivci = {};
3392 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3393 ivci.image = image.handle();
3394 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3395 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3396 ivci.subresourceRange.layerCount = 1;
3397 ivci.subresourceRange.baseMipLevel = 0;
3398 // Set level count 2 (only 1 is allowed for FB attachment)
3399 ivci.subresourceRange.levelCount = 2;
3400 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3401 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3402 ASSERT_VK_SUCCESS(err);
3403 // Re-create renderpass to have matching sample count
3404 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3405 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3406 ASSERT_VK_SUCCESS(err);
3407
3408 fb_info.renderPass = rp;
3409 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003411 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3412
3413 m_errorMonitor->VerifyFound();
3414 if (err == VK_SUCCESS) {
3415 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3416 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003417 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003418 // Update view to original color buffer and grow FB dimensions too big
3419 fb_info.pAttachments = ivs;
3420 fb_info.height = 1024;
3421 fb_info.width = 1024;
3422 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3424 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003425 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3426
3427 m_errorMonitor->VerifyFound();
3428 if (err == VK_SUCCESS) {
3429 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3430 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003431 // Create view attachment with non-identity swizzle
3432 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3433 ivci.image = image.handle();
3434 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3435 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3436 ivci.subresourceRange.layerCount = 1;
3437 ivci.subresourceRange.baseMipLevel = 0;
3438 ivci.subresourceRange.levelCount = 1;
3439 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3440 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3441 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3442 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3443 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3444 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3445 ASSERT_VK_SUCCESS(err);
3446
3447 fb_info.pAttachments = &view;
3448 fb_info.height = 100;
3449 fb_info.width = 100;
3450 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3452 "framebuffer attachments must have "
3453 "been created with the identity "
3454 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003455 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3456
3457 m_errorMonitor->VerifyFound();
3458 if (err == VK_SUCCESS) {
3459 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3460 }
3461 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003462 // Request fb that exceeds max dimensions
3463 // reset attachment to color attachment
3464 fb_info.pAttachments = ivs;
3465 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3466 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3467 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3469 "dimensions exceed physical device "
3470 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003471 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3472
3473 m_errorMonitor->VerifyFound();
3474 if (err == VK_SUCCESS) {
3475 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3476 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003477
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003478 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003479}
3480
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003481TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003482 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3483 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003484
Cody Northropc31a84f2016-08-22 10:41:47 -06003485 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003486 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3488 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003489 m_errorMonitor->VerifyFound();
3490}
3491
3492TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003493 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3494 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003495
Cody Northropc31a84f2016-08-22 10:41:47 -06003496 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003497 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3499 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003500 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003501}
3502
3503TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003504 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3505 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003506
Cody Northropc31a84f2016-08-22 10:41:47 -06003507 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003508 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003509 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 -06003510 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003511 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003512}
3513
3514TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003515 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3516 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003517
Cody Northropc31a84f2016-08-22 10:41:47 -06003518 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003519 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003520 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 -06003521 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003522 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003523}
3524
Cortd713fe82016-07-27 09:51:27 -07003525TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003526 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3527 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003528
3529 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003530 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3532 "Dynamic blend constants state not set for this command buffer");
3533 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003534 m_errorMonitor->VerifyFound();
3535}
3536
3537TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003538 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3539 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003540
3541 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003542 if (!m_device->phy().features().depthBounds) {
3543 printf("Device does not support depthBounds test; skipped.\n");
3544 return;
3545 }
3546 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3548 "Dynamic depth bounds state not set for this command buffer");
3549 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003550 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003551}
3552
3553TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003554 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3555 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003556
3557 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003558 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3560 "Dynamic stencil read mask state not set for this command buffer");
3561 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003562 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003563}
3564
3565TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3567 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003568
3569 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003570 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3572 "Dynamic stencil write mask state not set for this command buffer");
3573 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003574 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003575}
3576
3577TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003578 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3579 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003580
3581 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003582 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3584 "Dynamic stencil reference state not set for this command buffer");
3585 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003586 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003587}
3588
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003589TEST_F(VkLayerTest, IndexBufferNotBound) {
3590 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003591
3592 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3594 "Index buffer object not bound to this command buffer when Indexed ");
3595 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003596 m_errorMonitor->VerifyFound();
3597}
3598
Karl Schultz6addd812016-02-02 17:17:23 -07003599TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3601 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3602 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003603
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003604 ASSERT_NO_FATAL_FAILURE(InitState());
3605 ASSERT_NO_FATAL_FAILURE(InitViewport());
3606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3607
Karl Schultz6addd812016-02-02 17:17:23 -07003608 // We luck out b/c by default the framework creates CB w/ the
3609 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003610 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003611 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003612 EndCommandBuffer();
3613
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003614 // Bypass framework since it does the waits automatically
3615 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003616 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003617 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3618 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003619 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003620 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003621 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003622 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003623 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003624 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003625 submit_info.pSignalSemaphores = NULL;
3626
Chris Forbes40028e22016-06-13 09:59:34 +12003627 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003628 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003629 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003630
Karl Schultz6addd812016-02-02 17:17:23 -07003631 // Cause validation error by re-submitting cmd buffer that should only be
3632 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003633 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003634 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003635
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003636 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003637}
3638
Karl Schultz6addd812016-02-02 17:17:23 -07003639TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003640 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003641 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003642
3643 ASSERT_NO_FATAL_FAILURE(InitState());
3644 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003645
Karl Schultz6addd812016-02-02 17:17:23 -07003646 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3647 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003648 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003649 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003650 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003651
3652 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003653 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3654 ds_pool_ci.pNext = NULL;
3655 ds_pool_ci.flags = 0;
3656 ds_pool_ci.maxSets = 1;
3657 ds_pool_ci.poolSizeCount = 1;
3658 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003659
3660 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003661 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003662 ASSERT_VK_SUCCESS(err);
3663
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003664 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3665 dsl_binding_samp.binding = 0;
3666 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3667 dsl_binding_samp.descriptorCount = 1;
3668 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3669 dsl_binding_samp.pImmutableSamplers = NULL;
3670
3671 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3672 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3673 ds_layout_ci.pNext = NULL;
3674 ds_layout_ci.bindingCount = 1;
3675 ds_layout_ci.pBindings = &dsl_binding_samp;
3676
3677 VkDescriptorSetLayout ds_layout_samp;
3678 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3679 ASSERT_VK_SUCCESS(err);
3680
3681 // Try to allocate 2 sets when pool only has 1 set
3682 VkDescriptorSet descriptor_sets[2];
3683 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3684 VkDescriptorSetAllocateInfo alloc_info = {};
3685 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3686 alloc_info.descriptorSetCount = 2;
3687 alloc_info.descriptorPool = ds_pool;
3688 alloc_info.pSetLayouts = set_layouts;
3689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3690 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3691 m_errorMonitor->VerifyFound();
3692
3693 alloc_info.descriptorSetCount = 1;
3694 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003695 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003696 dsl_binding.binding = 0;
3697 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3698 dsl_binding.descriptorCount = 1;
3699 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3700 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003701
Karl Schultz6addd812016-02-02 17:17:23 -07003702 ds_layout_ci.bindingCount = 1;
3703 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003704
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003705 VkDescriptorSetLayout ds_layout_ub;
3706 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003707 ASSERT_VK_SUCCESS(err);
3708
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003709 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003710 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003711 alloc_info.pSetLayouts = &ds_layout_ub;
3712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3713 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003714
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003715 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003716
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003717 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003718 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003719}
3720
Karl Schultz6addd812016-02-02 17:17:23 -07003721TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3722 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3725 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3726 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003727
Tobin Ehlise735c692015-10-08 13:13:50 -06003728 ASSERT_NO_FATAL_FAILURE(InitState());
3729 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003730
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003731 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003732 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3733 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003734
3735 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003736 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3737 ds_pool_ci.pNext = NULL;
3738 ds_pool_ci.maxSets = 1;
3739 ds_pool_ci.poolSizeCount = 1;
3740 ds_pool_ci.flags = 0;
3741 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3742 // app can only call vkResetDescriptorPool on this pool.;
3743 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003744
3745 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003746 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003747 ASSERT_VK_SUCCESS(err);
3748
3749 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003750 dsl_binding.binding = 0;
3751 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3752 dsl_binding.descriptorCount = 1;
3753 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3754 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003755
3756 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003757 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3758 ds_layout_ci.pNext = NULL;
3759 ds_layout_ci.bindingCount = 1;
3760 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003761
3762 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003763 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003764 ASSERT_VK_SUCCESS(err);
3765
3766 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003767 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003768 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003769 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003770 alloc_info.descriptorPool = ds_pool;
3771 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003772 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003773 ASSERT_VK_SUCCESS(err);
3774
3775 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003776 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003777
Chia-I Wuf7458c52015-10-26 21:10:41 +08003778 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3779 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003780}
3781
Karl Schultz6addd812016-02-02 17:17:23 -07003782TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003783 // Attempt to clear Descriptor Pool with bad object.
3784 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003785
3786 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003788 uint64_t fake_pool_handle = 0xbaad6001;
3789 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3790 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003791 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003792}
3793
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003794TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003795 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3796 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003797 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003798 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003799
3800 uint64_t fake_set_handle = 0xbaad6001;
3801 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003802 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003804
3805 ASSERT_NO_FATAL_FAILURE(InitState());
3806
3807 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3808 layout_bindings[0].binding = 0;
3809 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3810 layout_bindings[0].descriptorCount = 1;
3811 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3812 layout_bindings[0].pImmutableSamplers = NULL;
3813
3814 VkDescriptorSetLayout descriptor_set_layout;
3815 VkDescriptorSetLayoutCreateInfo dslci = {};
3816 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3817 dslci.pNext = NULL;
3818 dslci.bindingCount = 1;
3819 dslci.pBindings = layout_bindings;
3820 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003821 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003822
3823 VkPipelineLayout pipeline_layout;
3824 VkPipelineLayoutCreateInfo plci = {};
3825 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3826 plci.pNext = NULL;
3827 plci.setLayoutCount = 1;
3828 plci.pSetLayouts = &descriptor_set_layout;
3829 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003830 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003831
3832 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003833 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3834 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003835 m_errorMonitor->VerifyFound();
3836 EndCommandBuffer();
3837 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3838 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003839}
3840
Karl Schultz6addd812016-02-02 17:17:23 -07003841TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003842 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3843 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003844 uint64_t fake_layout_handle = 0xbaad6001;
3845 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003847 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003848 VkPipelineLayout pipeline_layout;
3849 VkPipelineLayoutCreateInfo plci = {};
3850 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3851 plci.pNext = NULL;
3852 plci.setLayoutCount = 1;
3853 plci.pSetLayouts = &bad_layout;
3854 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3855
3856 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003857}
3858
Mark Muellerd4914412016-06-13 17:52:06 -06003859TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3860 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3861 "1) A uniform buffer update must have a valid buffer index."
3862 "2) When using an array of descriptors in a single WriteDescriptor,"
3863 " the descriptor types and stageflags must all be the same."
3864 "3) Immutable Sampler state must match across descriptors");
3865
3866 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003867 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3868 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3869 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3870 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3871 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003872
Mark Muellerd4914412016-06-13 17:52:06 -06003873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3874
3875 ASSERT_NO_FATAL_FAILURE(InitState());
3876 VkDescriptorPoolSize ds_type_count[4] = {};
3877 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3878 ds_type_count[0].descriptorCount = 1;
3879 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3880 ds_type_count[1].descriptorCount = 1;
3881 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3882 ds_type_count[2].descriptorCount = 1;
3883 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3884 ds_type_count[3].descriptorCount = 1;
3885
3886 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3887 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3888 ds_pool_ci.maxSets = 1;
3889 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3890 ds_pool_ci.pPoolSizes = ds_type_count;
3891
3892 VkDescriptorPool ds_pool;
3893 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3894 ASSERT_VK_SUCCESS(err);
3895
Mark Muellerb9896722016-06-16 09:54:29 -06003896 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003897 layout_binding[0].binding = 0;
3898 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3899 layout_binding[0].descriptorCount = 1;
3900 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3901 layout_binding[0].pImmutableSamplers = NULL;
3902
3903 layout_binding[1].binding = 1;
3904 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3905 layout_binding[1].descriptorCount = 1;
3906 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3907 layout_binding[1].pImmutableSamplers = NULL;
3908
3909 VkSamplerCreateInfo sampler_ci = {};
3910 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3911 sampler_ci.pNext = NULL;
3912 sampler_ci.magFilter = VK_FILTER_NEAREST;
3913 sampler_ci.minFilter = VK_FILTER_NEAREST;
3914 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3915 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3916 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3917 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3918 sampler_ci.mipLodBias = 1.0;
3919 sampler_ci.anisotropyEnable = VK_FALSE;
3920 sampler_ci.maxAnisotropy = 1;
3921 sampler_ci.compareEnable = VK_FALSE;
3922 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3923 sampler_ci.minLod = 1.0;
3924 sampler_ci.maxLod = 1.0;
3925 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3926 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3927 VkSampler sampler;
3928
3929 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3930 ASSERT_VK_SUCCESS(err);
3931
3932 layout_binding[2].binding = 2;
3933 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3934 layout_binding[2].descriptorCount = 1;
3935 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3936 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3937
Mark Muellerd4914412016-06-13 17:52:06 -06003938 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3939 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3940 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3941 ds_layout_ci.pBindings = layout_binding;
3942 VkDescriptorSetLayout ds_layout;
3943 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3944 ASSERT_VK_SUCCESS(err);
3945
3946 VkDescriptorSetAllocateInfo alloc_info = {};
3947 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3948 alloc_info.descriptorSetCount = 1;
3949 alloc_info.descriptorPool = ds_pool;
3950 alloc_info.pSetLayouts = &ds_layout;
3951 VkDescriptorSet descriptorSet;
3952 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3953 ASSERT_VK_SUCCESS(err);
3954
3955 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3956 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3957 pipeline_layout_ci.pNext = NULL;
3958 pipeline_layout_ci.setLayoutCount = 1;
3959 pipeline_layout_ci.pSetLayouts = &ds_layout;
3960
3961 VkPipelineLayout pipeline_layout;
3962 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3963 ASSERT_VK_SUCCESS(err);
3964
Mark Mueller5c838ce2016-06-16 09:54:29 -06003965 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003966 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3967 descriptor_write.dstSet = descriptorSet;
3968 descriptor_write.dstBinding = 0;
3969 descriptor_write.descriptorCount = 1;
3970 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3971
Mark Mueller5c838ce2016-06-16 09:54:29 -06003972 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003973 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3974 m_errorMonitor->VerifyFound();
3975
3976 // Create a buffer to update the descriptor with
3977 uint32_t qfi = 0;
3978 VkBufferCreateInfo buffCI = {};
3979 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3980 buffCI.size = 1024;
3981 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3982 buffCI.queueFamilyIndexCount = 1;
3983 buffCI.pQueueFamilyIndices = &qfi;
3984
3985 VkBuffer dyub;
3986 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3987 ASSERT_VK_SUCCESS(err);
3988 VkDescriptorBufferInfo buffInfo = {};
3989 buffInfo.buffer = dyub;
3990 buffInfo.offset = 0;
3991 buffInfo.range = 1024;
3992
3993 descriptor_write.pBufferInfo = &buffInfo;
3994 descriptor_write.descriptorCount = 2;
3995
Mark Mueller5c838ce2016-06-16 09:54:29 -06003996 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3998 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3999 m_errorMonitor->VerifyFound();
4000
Mark Mueller5c838ce2016-06-16 09:54:29 -06004001 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4002 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004003 descriptor_write.dstBinding = 1;
4004 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004005
Mark Mueller5c838ce2016-06-16 09:54:29 -06004006 // Make pImageInfo index non-null to avoid complaints of it missing
4007 VkDescriptorImageInfo imageInfo = {};
4008 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4009 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4011 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4012 m_errorMonitor->VerifyFound();
4013
Mark Muellerd4914412016-06-13 17:52:06 -06004014 vkDestroyBuffer(m_device->device(), dyub, NULL);
4015 vkDestroySampler(m_device->device(), sampler, NULL);
4016 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4017 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4018 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4019}
4020
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004021TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4022 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4023 "due to a buffer dependency being destroyed.");
4024 ASSERT_NO_FATAL_FAILURE(InitState());
4025
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004026 VkBuffer buffer;
4027 VkDeviceMemory mem;
4028 VkMemoryRequirements mem_reqs;
4029
4030 VkBufferCreateInfo buf_info = {};
4031 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004032 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004033 buf_info.size = 256;
4034 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4035 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4036 ASSERT_VK_SUCCESS(err);
4037
4038 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4039
4040 VkMemoryAllocateInfo alloc_info = {};
4041 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4042 alloc_info.allocationSize = 256;
4043 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004044 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 -06004045 if (!pass) {
4046 vkDestroyBuffer(m_device->device(), buffer, NULL);
4047 return;
4048 }
4049 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4050 ASSERT_VK_SUCCESS(err);
4051
4052 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4053 ASSERT_VK_SUCCESS(err);
4054
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004055 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004056 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004057 m_commandBuffer->EndCommandBuffer();
4058
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004060 // Destroy buffer dependency prior to submit to cause ERROR
4061 vkDestroyBuffer(m_device->device(), buffer, NULL);
4062
4063 VkSubmitInfo submit_info = {};
4064 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4065 submit_info.commandBufferCount = 1;
4066 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4067 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4068
4069 m_errorMonitor->VerifyFound();
4070 vkFreeMemory(m_device->handle(), mem, NULL);
4071}
4072
Tobin Ehlisea413442016-09-28 10:23:59 -06004073TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4074 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4075
4076 ASSERT_NO_FATAL_FAILURE(InitState());
4077 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4078
4079 VkDescriptorPoolSize ds_type_count;
4080 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4081 ds_type_count.descriptorCount = 1;
4082
4083 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4084 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4085 ds_pool_ci.maxSets = 1;
4086 ds_pool_ci.poolSizeCount = 1;
4087 ds_pool_ci.pPoolSizes = &ds_type_count;
4088
4089 VkDescriptorPool ds_pool;
4090 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4091 ASSERT_VK_SUCCESS(err);
4092
4093 VkDescriptorSetLayoutBinding layout_binding;
4094 layout_binding.binding = 0;
4095 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4096 layout_binding.descriptorCount = 1;
4097 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4098 layout_binding.pImmutableSamplers = NULL;
4099
4100 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4101 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4102 ds_layout_ci.bindingCount = 1;
4103 ds_layout_ci.pBindings = &layout_binding;
4104 VkDescriptorSetLayout ds_layout;
4105 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4106 ASSERT_VK_SUCCESS(err);
4107
4108 VkDescriptorSetAllocateInfo alloc_info = {};
4109 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4110 alloc_info.descriptorSetCount = 1;
4111 alloc_info.descriptorPool = ds_pool;
4112 alloc_info.pSetLayouts = &ds_layout;
4113 VkDescriptorSet descriptor_set;
4114 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4115 ASSERT_VK_SUCCESS(err);
4116
4117 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4118 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4119 pipeline_layout_ci.pNext = NULL;
4120 pipeline_layout_ci.setLayoutCount = 1;
4121 pipeline_layout_ci.pSetLayouts = &ds_layout;
4122
4123 VkPipelineLayout pipeline_layout;
4124 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4125 ASSERT_VK_SUCCESS(err);
4126
4127 VkBuffer buffer;
4128 uint32_t queue_family_index = 0;
4129 VkBufferCreateInfo buffer_create_info = {};
4130 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4131 buffer_create_info.size = 1024;
4132 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4133 buffer_create_info.queueFamilyIndexCount = 1;
4134 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4135
4136 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4137 ASSERT_VK_SUCCESS(err);
4138
4139 VkMemoryRequirements memory_reqs;
4140 VkDeviceMemory buffer_memory;
4141
4142 VkMemoryAllocateInfo memory_info = {};
4143 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4144 memory_info.allocationSize = 0;
4145 memory_info.memoryTypeIndex = 0;
4146
4147 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4148 memory_info.allocationSize = memory_reqs.size;
4149 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4150 ASSERT_TRUE(pass);
4151
4152 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4153 ASSERT_VK_SUCCESS(err);
4154 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4155 ASSERT_VK_SUCCESS(err);
4156
4157 VkBufferView view;
4158 VkBufferViewCreateInfo bvci = {};
4159 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4160 bvci.buffer = buffer;
4161 bvci.format = VK_FORMAT_R8_UNORM;
4162 bvci.range = VK_WHOLE_SIZE;
4163
4164 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4165 ASSERT_VK_SUCCESS(err);
4166
4167 VkWriteDescriptorSet descriptor_write = {};
4168 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4169 descriptor_write.dstSet = descriptor_set;
4170 descriptor_write.dstBinding = 0;
4171 descriptor_write.descriptorCount = 1;
4172 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4173 descriptor_write.pTexelBufferView = &view;
4174
4175 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4176
4177 char const *vsSource = "#version 450\n"
4178 "\n"
4179 "out gl_PerVertex { \n"
4180 " vec4 gl_Position;\n"
4181 "};\n"
4182 "void main(){\n"
4183 " gl_Position = vec4(1);\n"
4184 "}\n";
4185 char const *fsSource = "#version 450\n"
4186 "\n"
4187 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4188 "layout(location=0) out vec4 x;\n"
4189 "void main(){\n"
4190 " x = imageLoad(s, 0);\n"
4191 "}\n";
4192 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4193 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4194 VkPipelineObj pipe(m_device);
4195 pipe.AddShader(&vs);
4196 pipe.AddShader(&fs);
4197 pipe.AddColorAttachment();
4198 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4199
4200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4202
4203 BeginCommandBuffer();
4204 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4205 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4206 VkRect2D scissor = {{0, 0}, {16, 16}};
4207 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4208 // Bind pipeline to cmd buffer
4209 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4210 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4211 &descriptor_set, 0, nullptr);
4212 Draw(1, 0, 0, 0);
4213 EndCommandBuffer();
4214
4215 // Delete BufferView in order to invalidate cmd buffer
4216 vkDestroyBufferView(m_device->device(), view, NULL);
4217 // Now attempt submit of cmd buffer
4218 VkSubmitInfo submit_info = {};
4219 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4220 submit_info.commandBufferCount = 1;
4221 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4222 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4223 m_errorMonitor->VerifyFound();
4224
4225 // Clean-up
4226 vkDestroyBuffer(m_device->device(), buffer, NULL);
4227 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4228 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4229 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4230 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4231}
4232
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004233TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4234 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4235 "due to an image dependency being destroyed.");
4236 ASSERT_NO_FATAL_FAILURE(InitState());
4237
4238 VkImage image;
4239 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4240 VkImageCreateInfo image_create_info = {};
4241 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4242 image_create_info.pNext = NULL;
4243 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4244 image_create_info.format = tex_format;
4245 image_create_info.extent.width = 32;
4246 image_create_info.extent.height = 32;
4247 image_create_info.extent.depth = 1;
4248 image_create_info.mipLevels = 1;
4249 image_create_info.arrayLayers = 1;
4250 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4251 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004252 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004253 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004254 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004255 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004256 // Have to bind memory to image before recording cmd in cmd buffer using it
4257 VkMemoryRequirements mem_reqs;
4258 VkDeviceMemory image_mem;
4259 bool pass;
4260 VkMemoryAllocateInfo mem_alloc = {};
4261 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4262 mem_alloc.pNext = NULL;
4263 mem_alloc.memoryTypeIndex = 0;
4264 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4265 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004266 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004267 ASSERT_TRUE(pass);
4268 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4269 ASSERT_VK_SUCCESS(err);
4270 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4271 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004272
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004273 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004274 VkClearColorValue ccv;
4275 ccv.float32[0] = 1.0f;
4276 ccv.float32[1] = 1.0f;
4277 ccv.float32[2] = 1.0f;
4278 ccv.float32[3] = 1.0f;
4279 VkImageSubresourceRange isr = {};
4280 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004281 isr.baseArrayLayer = 0;
4282 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004283 isr.layerCount = 1;
4284 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004285 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004286 m_commandBuffer->EndCommandBuffer();
4287
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004289 // Destroy image dependency prior to submit to cause ERROR
4290 vkDestroyImage(m_device->device(), image, NULL);
4291
4292 VkSubmitInfo submit_info = {};
4293 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4294 submit_info.commandBufferCount = 1;
4295 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4296 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4297
4298 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004299 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004300}
4301
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004302TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4303 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4304 "due to a framebuffer image dependency being destroyed.");
4305 VkFormatProperties format_properties;
4306 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004307 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4308 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004309 return;
4310 }
4311
4312 ASSERT_NO_FATAL_FAILURE(InitState());
4313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4314
4315 VkImageCreateInfo image_ci = {};
4316 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4317 image_ci.pNext = NULL;
4318 image_ci.imageType = VK_IMAGE_TYPE_2D;
4319 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4320 image_ci.extent.width = 32;
4321 image_ci.extent.height = 32;
4322 image_ci.extent.depth = 1;
4323 image_ci.mipLevels = 1;
4324 image_ci.arrayLayers = 1;
4325 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4326 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004327 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004328 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4329 image_ci.flags = 0;
4330 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004331 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004332
4333 VkMemoryRequirements memory_reqs;
4334 VkDeviceMemory image_memory;
4335 bool pass;
4336 VkMemoryAllocateInfo memory_info = {};
4337 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4338 memory_info.pNext = NULL;
4339 memory_info.allocationSize = 0;
4340 memory_info.memoryTypeIndex = 0;
4341 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4342 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004343 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004344 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004345 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004346 ASSERT_VK_SUCCESS(err);
4347 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4348 ASSERT_VK_SUCCESS(err);
4349
4350 VkImageViewCreateInfo ivci = {
4351 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4352 nullptr,
4353 0,
4354 image,
4355 VK_IMAGE_VIEW_TYPE_2D,
4356 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004357 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004358 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4359 };
4360 VkImageView view;
4361 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4362 ASSERT_VK_SUCCESS(err);
4363
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004364 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004365 VkFramebuffer fb;
4366 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4367 ASSERT_VK_SUCCESS(err);
4368
4369 // Just use default renderpass with our framebuffer
4370 m_renderPassBeginInfo.framebuffer = fb;
4371 // Create Null cmd buffer for submit
4372 BeginCommandBuffer();
4373 EndCommandBuffer();
4374 // Destroy image attached to framebuffer to invalidate cmd buffer
4375 vkDestroyImage(m_device->device(), image, NULL);
4376 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004378 QueueCommandBuffer(false);
4379 m_errorMonitor->VerifyFound();
4380
4381 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4382 vkDestroyImageView(m_device->device(), view, nullptr);
4383 vkFreeMemory(m_device->device(), image_memory, nullptr);
4384}
4385
Tobin Ehlisb329f992016-10-12 13:20:29 -06004386TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4387 TEST_DESCRIPTION("Delete in-use framebuffer.");
4388 VkFormatProperties format_properties;
4389 VkResult err = VK_SUCCESS;
4390 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4391
4392 ASSERT_NO_FATAL_FAILURE(InitState());
4393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4394
4395 VkImageObj image(m_device);
4396 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4397 ASSERT_TRUE(image.initialized());
4398 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4399
4400 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4401 VkFramebuffer fb;
4402 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4403 ASSERT_VK_SUCCESS(err);
4404
4405 // Just use default renderpass with our framebuffer
4406 m_renderPassBeginInfo.framebuffer = fb;
4407 // Create Null cmd buffer for submit
4408 BeginCommandBuffer();
4409 EndCommandBuffer();
4410 // Submit cmd buffer to put it in-flight
4411 VkSubmitInfo submit_info = {};
4412 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4413 submit_info.commandBufferCount = 1;
4414 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4415 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4416 // Destroy framebuffer while in-flight
4417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4418 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4419 m_errorMonitor->VerifyFound();
4420 // Wait for queue to complete so we can safely destroy everything
4421 vkQueueWaitIdle(m_device->m_queue);
4422 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4423}
4424
Tobin Ehlis88becd72016-09-21 14:33:41 -06004425TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4426 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4427 VkFormatProperties format_properties;
4428 VkResult err = VK_SUCCESS;
4429 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004430
4431 ASSERT_NO_FATAL_FAILURE(InitState());
4432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4433
4434 VkImageCreateInfo image_ci = {};
4435 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4436 image_ci.pNext = NULL;
4437 image_ci.imageType = VK_IMAGE_TYPE_2D;
4438 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4439 image_ci.extent.width = 256;
4440 image_ci.extent.height = 256;
4441 image_ci.extent.depth = 1;
4442 image_ci.mipLevels = 1;
4443 image_ci.arrayLayers = 1;
4444 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4445 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004446 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004447 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4448 image_ci.flags = 0;
4449 VkImage image;
4450 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4451
4452 VkMemoryRequirements memory_reqs;
4453 VkDeviceMemory image_memory;
4454 bool pass;
4455 VkMemoryAllocateInfo memory_info = {};
4456 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4457 memory_info.pNext = NULL;
4458 memory_info.allocationSize = 0;
4459 memory_info.memoryTypeIndex = 0;
4460 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4461 memory_info.allocationSize = memory_reqs.size;
4462 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4463 ASSERT_TRUE(pass);
4464 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4465 ASSERT_VK_SUCCESS(err);
4466 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4467 ASSERT_VK_SUCCESS(err);
4468
4469 VkImageViewCreateInfo ivci = {
4470 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4471 nullptr,
4472 0,
4473 image,
4474 VK_IMAGE_VIEW_TYPE_2D,
4475 VK_FORMAT_B8G8R8A8_UNORM,
4476 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4477 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4478 };
4479 VkImageView view;
4480 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4481 ASSERT_VK_SUCCESS(err);
4482
4483 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4484 VkFramebuffer fb;
4485 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4486 ASSERT_VK_SUCCESS(err);
4487
4488 // Just use default renderpass with our framebuffer
4489 m_renderPassBeginInfo.framebuffer = fb;
4490 // Create Null cmd buffer for submit
4491 BeginCommandBuffer();
4492 EndCommandBuffer();
4493 // Submit cmd buffer to put it (and attached imageView) in-flight
4494 VkSubmitInfo submit_info = {};
4495 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4496 submit_info.commandBufferCount = 1;
4497 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4498 // Submit cmd buffer to put framebuffer and children in-flight
4499 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4500 // Destroy image attached to framebuffer while in-flight
4501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4502 vkDestroyImage(m_device->device(), image, NULL);
4503 m_errorMonitor->VerifyFound();
4504 // Wait for queue to complete so we can safely destroy image and other objects
4505 vkQueueWaitIdle(m_device->m_queue);
4506 vkDestroyImage(m_device->device(), image, NULL);
4507 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4508 vkDestroyImageView(m_device->device(), view, nullptr);
4509 vkFreeMemory(m_device->device(), image_memory, nullptr);
4510}
4511
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004512TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4513 TEST_DESCRIPTION("Delete in-use renderPass.");
4514
4515 ASSERT_NO_FATAL_FAILURE(InitState());
4516 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4517
4518 // Create simple renderpass
4519 VkAttachmentReference attach = {};
4520 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4521 VkSubpassDescription subpass = {};
4522 subpass.pColorAttachments = &attach;
4523 VkRenderPassCreateInfo rpci = {};
4524 rpci.subpassCount = 1;
4525 rpci.pSubpasses = &subpass;
4526 rpci.attachmentCount = 1;
4527 VkAttachmentDescription attach_desc = {};
4528 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4529 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4530 rpci.pAttachments = &attach_desc;
4531 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4532 VkRenderPass rp;
4533 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4534 ASSERT_VK_SUCCESS(err);
4535
4536 // Create a pipeline that uses the given renderpass
4537 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4538 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4539
4540 VkPipelineLayout pipeline_layout;
4541 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4542 ASSERT_VK_SUCCESS(err);
4543
4544 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4545 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4546 vp_state_ci.viewportCount = 1;
4547 VkViewport vp = {}; // Just need dummy vp to point to
4548 vp_state_ci.pViewports = &vp;
4549 vp_state_ci.scissorCount = 1;
4550 VkRect2D scissors = {}; // Dummy scissors to point to
4551 vp_state_ci.pScissors = &scissors;
4552
4553 VkPipelineShaderStageCreateInfo shaderStages[2];
4554 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4555
4556 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4557 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4558 // but add it to be able to run on more devices
4559 shaderStages[0] = vs.GetStageCreateInfo();
4560 shaderStages[1] = fs.GetStageCreateInfo();
4561
4562 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4563 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4564
4565 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4566 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4567 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4568
4569 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4570 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4571 rs_ci.rasterizerDiscardEnable = true;
4572 rs_ci.lineWidth = 1.0f;
4573
4574 VkPipelineColorBlendAttachmentState att = {};
4575 att.blendEnable = VK_FALSE;
4576 att.colorWriteMask = 0xf;
4577
4578 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4579 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4580 cb_ci.attachmentCount = 1;
4581 cb_ci.pAttachments = &att;
4582
4583 VkGraphicsPipelineCreateInfo gp_ci = {};
4584 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4585 gp_ci.stageCount = 2;
4586 gp_ci.pStages = shaderStages;
4587 gp_ci.pVertexInputState = &vi_ci;
4588 gp_ci.pInputAssemblyState = &ia_ci;
4589 gp_ci.pViewportState = &vp_state_ci;
4590 gp_ci.pRasterizationState = &rs_ci;
4591 gp_ci.pColorBlendState = &cb_ci;
4592 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4593 gp_ci.layout = pipeline_layout;
4594 gp_ci.renderPass = rp;
4595
4596 VkPipelineCacheCreateInfo pc_ci = {};
4597 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4598
4599 VkPipeline pipeline;
4600 VkPipelineCache pipe_cache;
4601 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4602 ASSERT_VK_SUCCESS(err);
4603
4604 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4605 ASSERT_VK_SUCCESS(err);
4606 // Bind pipeline to cmd buffer, will also bind renderpass
4607 m_commandBuffer->BeginCommandBuffer();
4608 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4609 m_commandBuffer->EndCommandBuffer();
4610
4611 VkSubmitInfo submit_info = {};
4612 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4613 submit_info.commandBufferCount = 1;
4614 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4615 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4616
4617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4618 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4619 m_errorMonitor->VerifyFound();
4620
4621 // Wait for queue to complete so we can safely destroy everything
4622 vkQueueWaitIdle(m_device->m_queue);
4623 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4624 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4625 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4626 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4627}
4628
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004629TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004630 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004631 ASSERT_NO_FATAL_FAILURE(InitState());
4632
4633 VkImage image;
4634 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4635 VkImageCreateInfo image_create_info = {};
4636 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4637 image_create_info.pNext = NULL;
4638 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4639 image_create_info.format = tex_format;
4640 image_create_info.extent.width = 32;
4641 image_create_info.extent.height = 32;
4642 image_create_info.extent.depth = 1;
4643 image_create_info.mipLevels = 1;
4644 image_create_info.arrayLayers = 1;
4645 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4646 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004647 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004648 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004649 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004650 ASSERT_VK_SUCCESS(err);
4651 // Have to bind memory to image before recording cmd in cmd buffer using it
4652 VkMemoryRequirements mem_reqs;
4653 VkDeviceMemory image_mem;
4654 bool pass;
4655 VkMemoryAllocateInfo mem_alloc = {};
4656 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4657 mem_alloc.pNext = NULL;
4658 mem_alloc.memoryTypeIndex = 0;
4659 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4660 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004661 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004662 ASSERT_TRUE(pass);
4663 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4664 ASSERT_VK_SUCCESS(err);
4665
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004666 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004668 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004669
4670 m_commandBuffer->BeginCommandBuffer();
4671 VkClearColorValue ccv;
4672 ccv.float32[0] = 1.0f;
4673 ccv.float32[1] = 1.0f;
4674 ccv.float32[2] = 1.0f;
4675 ccv.float32[3] = 1.0f;
4676 VkImageSubresourceRange isr = {};
4677 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4678 isr.baseArrayLayer = 0;
4679 isr.baseMipLevel = 0;
4680 isr.layerCount = 1;
4681 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004682 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004683 m_commandBuffer->EndCommandBuffer();
4684
4685 m_errorMonitor->VerifyFound();
4686 vkDestroyImage(m_device->device(), image, NULL);
4687 vkFreeMemory(m_device->device(), image_mem, nullptr);
4688}
4689
4690TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004691 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004692 ASSERT_NO_FATAL_FAILURE(InitState());
4693
4694 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004695 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 -06004696 VK_IMAGE_TILING_OPTIMAL, 0);
4697 ASSERT_TRUE(image.initialized());
4698
4699 VkBuffer buffer;
4700 VkDeviceMemory mem;
4701 VkMemoryRequirements mem_reqs;
4702
4703 VkBufferCreateInfo buf_info = {};
4704 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004705 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004706 buf_info.size = 256;
4707 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4708 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4709 ASSERT_VK_SUCCESS(err);
4710
4711 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4712
4713 VkMemoryAllocateInfo alloc_info = {};
4714 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4715 alloc_info.allocationSize = 256;
4716 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004717 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 -06004718 if (!pass) {
4719 vkDestroyBuffer(m_device->device(), buffer, NULL);
4720 return;
4721 }
4722 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4723 ASSERT_VK_SUCCESS(err);
4724
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004725 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004727 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004728 VkBufferImageCopy region = {};
4729 region.bufferRowLength = 128;
4730 region.bufferImageHeight = 128;
4731 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4732
4733 region.imageSubresource.layerCount = 1;
4734 region.imageExtent.height = 4;
4735 region.imageExtent.width = 4;
4736 region.imageExtent.depth = 1;
4737 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004738 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4739 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004740 m_commandBuffer->EndCommandBuffer();
4741
4742 m_errorMonitor->VerifyFound();
4743
4744 vkDestroyBuffer(m_device->device(), buffer, NULL);
4745 vkFreeMemory(m_device->handle(), mem, NULL);
4746}
4747
Tobin Ehlis85940f52016-07-07 16:57:21 -06004748TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4749 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4750 "due to an event dependency being destroyed.");
4751 ASSERT_NO_FATAL_FAILURE(InitState());
4752
4753 VkEvent event;
4754 VkEventCreateInfo evci = {};
4755 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4756 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4757 ASSERT_VK_SUCCESS(result);
4758
4759 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004760 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004761 m_commandBuffer->EndCommandBuffer();
4762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004764 // Destroy event dependency prior to submit to cause ERROR
4765 vkDestroyEvent(m_device->device(), event, NULL);
4766
4767 VkSubmitInfo submit_info = {};
4768 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4769 submit_info.commandBufferCount = 1;
4770 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4771 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4772
4773 m_errorMonitor->VerifyFound();
4774}
4775
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004776TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4777 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4778 "due to a query pool dependency being destroyed.");
4779 ASSERT_NO_FATAL_FAILURE(InitState());
4780
4781 VkQueryPool query_pool;
4782 VkQueryPoolCreateInfo qpci{};
4783 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4784 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4785 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004786 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004787 ASSERT_VK_SUCCESS(result);
4788
4789 m_commandBuffer->BeginCommandBuffer();
4790 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4791 m_commandBuffer->EndCommandBuffer();
4792
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004794 // Destroy query pool dependency prior to submit to cause ERROR
4795 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4796
4797 VkSubmitInfo submit_info = {};
4798 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4799 submit_info.commandBufferCount = 1;
4800 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4801 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4802
4803 m_errorMonitor->VerifyFound();
4804}
4805
Tobin Ehlis24130d92016-07-08 15:50:53 -06004806TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4807 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4808 "due to a pipeline dependency being destroyed.");
4809 ASSERT_NO_FATAL_FAILURE(InitState());
4810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4811
4812 VkResult err;
4813
4814 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4815 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4816
4817 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004818 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004819 ASSERT_VK_SUCCESS(err);
4820
4821 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4822 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4823 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004824 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004825 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004826 vp_state_ci.scissorCount = 1;
4827 VkRect2D scissors = {}; // Dummy scissors to point to
4828 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004829
4830 VkPipelineShaderStageCreateInfo shaderStages[2];
4831 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4832
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004833 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4834 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4835 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004836 shaderStages[0] = vs.GetStageCreateInfo();
4837 shaderStages[1] = fs.GetStageCreateInfo();
4838
4839 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4840 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4841
4842 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4843 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4844 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4845
4846 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4847 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004848 rs_ci.rasterizerDiscardEnable = true;
4849 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004850
4851 VkPipelineColorBlendAttachmentState att = {};
4852 att.blendEnable = VK_FALSE;
4853 att.colorWriteMask = 0xf;
4854
4855 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4856 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4857 cb_ci.attachmentCount = 1;
4858 cb_ci.pAttachments = &att;
4859
4860 VkGraphicsPipelineCreateInfo gp_ci = {};
4861 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4862 gp_ci.stageCount = 2;
4863 gp_ci.pStages = shaderStages;
4864 gp_ci.pVertexInputState = &vi_ci;
4865 gp_ci.pInputAssemblyState = &ia_ci;
4866 gp_ci.pViewportState = &vp_state_ci;
4867 gp_ci.pRasterizationState = &rs_ci;
4868 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004869 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4870 gp_ci.layout = pipeline_layout;
4871 gp_ci.renderPass = renderPass();
4872
4873 VkPipelineCacheCreateInfo pc_ci = {};
4874 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4875
4876 VkPipeline pipeline;
4877 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004878 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004879 ASSERT_VK_SUCCESS(err);
4880
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004881 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004882 ASSERT_VK_SUCCESS(err);
4883
4884 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004885 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004886 m_commandBuffer->EndCommandBuffer();
4887 // Now destroy pipeline in order to cause error when submitting
4888 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004891
4892 VkSubmitInfo submit_info = {};
4893 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4894 submit_info.commandBufferCount = 1;
4895 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4896 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4897
4898 m_errorMonitor->VerifyFound();
4899 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4900 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4901}
4902
Tobin Ehlis31289162016-08-17 14:57:58 -06004903TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4904 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4905 "due to a bound descriptor set with a buffer dependency "
4906 "being destroyed.");
4907 ASSERT_NO_FATAL_FAILURE(InitState());
4908 ASSERT_NO_FATAL_FAILURE(InitViewport());
4909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4910
4911 VkDescriptorPoolSize ds_type_count = {};
4912 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4913 ds_type_count.descriptorCount = 1;
4914
4915 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4916 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4917 ds_pool_ci.pNext = NULL;
4918 ds_pool_ci.maxSets = 1;
4919 ds_pool_ci.poolSizeCount = 1;
4920 ds_pool_ci.pPoolSizes = &ds_type_count;
4921
4922 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004923 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004924 ASSERT_VK_SUCCESS(err);
4925
4926 VkDescriptorSetLayoutBinding dsl_binding = {};
4927 dsl_binding.binding = 0;
4928 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4929 dsl_binding.descriptorCount = 1;
4930 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4931 dsl_binding.pImmutableSamplers = NULL;
4932
4933 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4934 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4935 ds_layout_ci.pNext = NULL;
4936 ds_layout_ci.bindingCount = 1;
4937 ds_layout_ci.pBindings = &dsl_binding;
4938 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004939 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004940 ASSERT_VK_SUCCESS(err);
4941
4942 VkDescriptorSet descriptorSet;
4943 VkDescriptorSetAllocateInfo alloc_info = {};
4944 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4945 alloc_info.descriptorSetCount = 1;
4946 alloc_info.descriptorPool = ds_pool;
4947 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004948 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004949 ASSERT_VK_SUCCESS(err);
4950
4951 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4952 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4953 pipeline_layout_ci.pNext = NULL;
4954 pipeline_layout_ci.setLayoutCount = 1;
4955 pipeline_layout_ci.pSetLayouts = &ds_layout;
4956
4957 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004958 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004959 ASSERT_VK_SUCCESS(err);
4960
4961 // Create a buffer to update the descriptor with
4962 uint32_t qfi = 0;
4963 VkBufferCreateInfo buffCI = {};
4964 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4965 buffCI.size = 1024;
4966 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4967 buffCI.queueFamilyIndexCount = 1;
4968 buffCI.pQueueFamilyIndices = &qfi;
4969
4970 VkBuffer buffer;
4971 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4972 ASSERT_VK_SUCCESS(err);
4973 // Allocate memory and bind to buffer so we can make it to the appropriate
4974 // error
4975 VkMemoryAllocateInfo mem_alloc = {};
4976 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4977 mem_alloc.pNext = NULL;
4978 mem_alloc.allocationSize = 1024;
4979 mem_alloc.memoryTypeIndex = 0;
4980
4981 VkMemoryRequirements memReqs;
4982 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004983 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004984 if (!pass) {
4985 vkDestroyBuffer(m_device->device(), buffer, NULL);
4986 return;
4987 }
4988
4989 VkDeviceMemory mem;
4990 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4991 ASSERT_VK_SUCCESS(err);
4992 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4993 ASSERT_VK_SUCCESS(err);
4994 // Correctly update descriptor to avoid "NOT_UPDATED" error
4995 VkDescriptorBufferInfo buffInfo = {};
4996 buffInfo.buffer = buffer;
4997 buffInfo.offset = 0;
4998 buffInfo.range = 1024;
4999
5000 VkWriteDescriptorSet descriptor_write;
5001 memset(&descriptor_write, 0, sizeof(descriptor_write));
5002 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5003 descriptor_write.dstSet = descriptorSet;
5004 descriptor_write.dstBinding = 0;
5005 descriptor_write.descriptorCount = 1;
5006 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5007 descriptor_write.pBufferInfo = &buffInfo;
5008
5009 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5010
5011 // Create PSO to be used for draw-time errors below
5012 char const *vsSource = "#version 450\n"
5013 "\n"
5014 "out gl_PerVertex { \n"
5015 " vec4 gl_Position;\n"
5016 "};\n"
5017 "void main(){\n"
5018 " gl_Position = vec4(1);\n"
5019 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005020 char const *fsSource = "#version 450\n"
5021 "\n"
5022 "layout(location=0) out vec4 x;\n"
5023 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5024 "void main(){\n"
5025 " x = vec4(bar.y);\n"
5026 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005027 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5028 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5029 VkPipelineObj pipe(m_device);
5030 pipe.AddShader(&vs);
5031 pipe.AddShader(&fs);
5032 pipe.AddColorAttachment();
5033 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5034
5035 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005036 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5037 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5038 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005039 Draw(1, 0, 0, 0);
5040 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005042 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5043 vkDestroyBuffer(m_device->device(), buffer, NULL);
5044 // Attempt to submit cmd buffer
5045 VkSubmitInfo submit_info = {};
5046 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5047 submit_info.commandBufferCount = 1;
5048 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5049 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5050 m_errorMonitor->VerifyFound();
5051 // Cleanup
5052 vkFreeMemory(m_device->device(), mem, NULL);
5053
5054 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5055 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5056 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5057}
5058
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005059TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5060 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5061 "due to a bound descriptor sets with a combined image "
5062 "sampler having their image, sampler, and descriptor set "
5063 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005064 "submit associated cmd buffers. Attempt to destroy a "
5065 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005066 ASSERT_NO_FATAL_FAILURE(InitState());
5067 ASSERT_NO_FATAL_FAILURE(InitViewport());
5068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5069
5070 VkDescriptorPoolSize ds_type_count = {};
5071 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5072 ds_type_count.descriptorCount = 1;
5073
5074 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5075 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5076 ds_pool_ci.pNext = NULL;
5077 ds_pool_ci.maxSets = 1;
5078 ds_pool_ci.poolSizeCount = 1;
5079 ds_pool_ci.pPoolSizes = &ds_type_count;
5080
5081 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005082 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005083 ASSERT_VK_SUCCESS(err);
5084
5085 VkDescriptorSetLayoutBinding dsl_binding = {};
5086 dsl_binding.binding = 0;
5087 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5088 dsl_binding.descriptorCount = 1;
5089 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5090 dsl_binding.pImmutableSamplers = NULL;
5091
5092 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5093 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5094 ds_layout_ci.pNext = NULL;
5095 ds_layout_ci.bindingCount = 1;
5096 ds_layout_ci.pBindings = &dsl_binding;
5097 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005098 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005099 ASSERT_VK_SUCCESS(err);
5100
5101 VkDescriptorSet descriptorSet;
5102 VkDescriptorSetAllocateInfo alloc_info = {};
5103 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5104 alloc_info.descriptorSetCount = 1;
5105 alloc_info.descriptorPool = ds_pool;
5106 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005107 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005108 ASSERT_VK_SUCCESS(err);
5109
5110 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5111 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5112 pipeline_layout_ci.pNext = NULL;
5113 pipeline_layout_ci.setLayoutCount = 1;
5114 pipeline_layout_ci.pSetLayouts = &ds_layout;
5115
5116 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005117 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005118 ASSERT_VK_SUCCESS(err);
5119
5120 // Create images to update the descriptor with
5121 VkImage image;
5122 VkImage image2;
5123 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5124 const int32_t tex_width = 32;
5125 const int32_t tex_height = 32;
5126 VkImageCreateInfo image_create_info = {};
5127 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5128 image_create_info.pNext = NULL;
5129 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5130 image_create_info.format = tex_format;
5131 image_create_info.extent.width = tex_width;
5132 image_create_info.extent.height = tex_height;
5133 image_create_info.extent.depth = 1;
5134 image_create_info.mipLevels = 1;
5135 image_create_info.arrayLayers = 1;
5136 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5137 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5138 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5139 image_create_info.flags = 0;
5140 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5141 ASSERT_VK_SUCCESS(err);
5142 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5143 ASSERT_VK_SUCCESS(err);
5144
5145 VkMemoryRequirements memory_reqs;
5146 VkDeviceMemory image_memory;
5147 bool pass;
5148 VkMemoryAllocateInfo memory_info = {};
5149 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5150 memory_info.pNext = NULL;
5151 memory_info.allocationSize = 0;
5152 memory_info.memoryTypeIndex = 0;
5153 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5154 // Allocate enough memory for both images
5155 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005156 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005157 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005158 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005159 ASSERT_VK_SUCCESS(err);
5160 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5161 ASSERT_VK_SUCCESS(err);
5162 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005163 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005164 ASSERT_VK_SUCCESS(err);
5165
5166 VkImageViewCreateInfo image_view_create_info = {};
5167 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5168 image_view_create_info.image = image;
5169 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5170 image_view_create_info.format = tex_format;
5171 image_view_create_info.subresourceRange.layerCount = 1;
5172 image_view_create_info.subresourceRange.baseMipLevel = 0;
5173 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005174 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005175
5176 VkImageView view;
5177 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005178 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005179 ASSERT_VK_SUCCESS(err);
5180 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005181 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005182 ASSERT_VK_SUCCESS(err);
5183 // Create Samplers
5184 VkSamplerCreateInfo sampler_ci = {};
5185 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5186 sampler_ci.pNext = NULL;
5187 sampler_ci.magFilter = VK_FILTER_NEAREST;
5188 sampler_ci.minFilter = VK_FILTER_NEAREST;
5189 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5190 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5191 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5192 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5193 sampler_ci.mipLodBias = 1.0;
5194 sampler_ci.anisotropyEnable = VK_FALSE;
5195 sampler_ci.maxAnisotropy = 1;
5196 sampler_ci.compareEnable = VK_FALSE;
5197 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5198 sampler_ci.minLod = 1.0;
5199 sampler_ci.maxLod = 1.0;
5200 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5201 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5202 VkSampler sampler;
5203 VkSampler sampler2;
5204 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5205 ASSERT_VK_SUCCESS(err);
5206 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5207 ASSERT_VK_SUCCESS(err);
5208 // Update descriptor with image and sampler
5209 VkDescriptorImageInfo img_info = {};
5210 img_info.sampler = sampler;
5211 img_info.imageView = view;
5212 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5213
5214 VkWriteDescriptorSet descriptor_write;
5215 memset(&descriptor_write, 0, sizeof(descriptor_write));
5216 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5217 descriptor_write.dstSet = descriptorSet;
5218 descriptor_write.dstBinding = 0;
5219 descriptor_write.descriptorCount = 1;
5220 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5221 descriptor_write.pImageInfo = &img_info;
5222
5223 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5224
5225 // Create PSO to be used for draw-time errors below
5226 char const *vsSource = "#version 450\n"
5227 "\n"
5228 "out gl_PerVertex { \n"
5229 " vec4 gl_Position;\n"
5230 "};\n"
5231 "void main(){\n"
5232 " gl_Position = vec4(1);\n"
5233 "}\n";
5234 char const *fsSource = "#version 450\n"
5235 "\n"
5236 "layout(set=0, binding=0) uniform sampler2D s;\n"
5237 "layout(location=0) out vec4 x;\n"
5238 "void main(){\n"
5239 " x = texture(s, vec2(1));\n"
5240 "}\n";
5241 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5242 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5243 VkPipelineObj pipe(m_device);
5244 pipe.AddShader(&vs);
5245 pipe.AddShader(&fs);
5246 pipe.AddColorAttachment();
5247 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5248
5249 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005251 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005252 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5253 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5254 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005255 Draw(1, 0, 0, 0);
5256 EndCommandBuffer();
5257 // Destroy sampler invalidates the cmd buffer, causing error on submit
5258 vkDestroySampler(m_device->device(), sampler, NULL);
5259 // Attempt to submit cmd buffer
5260 VkSubmitInfo submit_info = {};
5261 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5262 submit_info.commandBufferCount = 1;
5263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5264 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5265 m_errorMonitor->VerifyFound();
5266 // Now re-update descriptor with valid sampler and delete image
5267 img_info.sampler = sampler2;
5268 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005270 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005271 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5272 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5273 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005274 Draw(1, 0, 0, 0);
5275 EndCommandBuffer();
5276 // Destroy image invalidates the cmd buffer, causing error on submit
5277 vkDestroyImage(m_device->device(), image, NULL);
5278 // Attempt to submit cmd buffer
5279 submit_info = {};
5280 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5281 submit_info.commandBufferCount = 1;
5282 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5283 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5284 m_errorMonitor->VerifyFound();
5285 // Now update descriptor to be valid, but then free descriptor
5286 img_info.imageView = view2;
5287 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005289 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005290 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5291 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5292 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005293 Draw(1, 0, 0, 0);
5294 EndCommandBuffer();
5295 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005297 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005298 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005299 // Attempt to submit cmd buffer
5300 submit_info = {};
5301 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5302 submit_info.commandBufferCount = 1;
5303 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5304 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5305 m_errorMonitor->VerifyFound();
5306 // Cleanup
5307 vkFreeMemory(m_device->device(), image_memory, NULL);
5308 vkDestroySampler(m_device->device(), sampler2, NULL);
5309 vkDestroyImage(m_device->device(), image2, NULL);
5310 vkDestroyImageView(m_device->device(), view, NULL);
5311 vkDestroyImageView(m_device->device(), view2, NULL);
5312 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5313 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5314 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5315}
5316
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005317TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5318 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5319 ASSERT_NO_FATAL_FAILURE(InitState());
5320 ASSERT_NO_FATAL_FAILURE(InitViewport());
5321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5322
5323 VkDescriptorPoolSize ds_type_count = {};
5324 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5325 ds_type_count.descriptorCount = 1;
5326
5327 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5328 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5329 ds_pool_ci.pNext = NULL;
5330 ds_pool_ci.maxSets = 1;
5331 ds_pool_ci.poolSizeCount = 1;
5332 ds_pool_ci.pPoolSizes = &ds_type_count;
5333
5334 VkDescriptorPool ds_pool;
5335 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5336 ASSERT_VK_SUCCESS(err);
5337
5338 VkDescriptorSetLayoutBinding dsl_binding = {};
5339 dsl_binding.binding = 0;
5340 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5341 dsl_binding.descriptorCount = 1;
5342 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5343 dsl_binding.pImmutableSamplers = NULL;
5344
5345 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5346 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5347 ds_layout_ci.pNext = NULL;
5348 ds_layout_ci.bindingCount = 1;
5349 ds_layout_ci.pBindings = &dsl_binding;
5350 VkDescriptorSetLayout ds_layout;
5351 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5352 ASSERT_VK_SUCCESS(err);
5353
5354 VkDescriptorSet descriptor_set;
5355 VkDescriptorSetAllocateInfo alloc_info = {};
5356 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5357 alloc_info.descriptorSetCount = 1;
5358 alloc_info.descriptorPool = ds_pool;
5359 alloc_info.pSetLayouts = &ds_layout;
5360 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5361 ASSERT_VK_SUCCESS(err);
5362
5363 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5364 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5365 pipeline_layout_ci.pNext = NULL;
5366 pipeline_layout_ci.setLayoutCount = 1;
5367 pipeline_layout_ci.pSetLayouts = &ds_layout;
5368
5369 VkPipelineLayout pipeline_layout;
5370 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5371 ASSERT_VK_SUCCESS(err);
5372
5373 // Create image to update the descriptor with
5374 VkImageObj image(m_device);
5375 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5376 ASSERT_TRUE(image.initialized());
5377
5378 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5379 // Create Sampler
5380 VkSamplerCreateInfo sampler_ci = {};
5381 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5382 sampler_ci.pNext = NULL;
5383 sampler_ci.magFilter = VK_FILTER_NEAREST;
5384 sampler_ci.minFilter = VK_FILTER_NEAREST;
5385 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5386 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5387 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5388 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5389 sampler_ci.mipLodBias = 1.0;
5390 sampler_ci.anisotropyEnable = VK_FALSE;
5391 sampler_ci.maxAnisotropy = 1;
5392 sampler_ci.compareEnable = VK_FALSE;
5393 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5394 sampler_ci.minLod = 1.0;
5395 sampler_ci.maxLod = 1.0;
5396 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5397 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5398 VkSampler sampler;
5399 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5400 ASSERT_VK_SUCCESS(err);
5401 // Update descriptor with image and sampler
5402 VkDescriptorImageInfo img_info = {};
5403 img_info.sampler = sampler;
5404 img_info.imageView = view;
5405 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5406
5407 VkWriteDescriptorSet descriptor_write;
5408 memset(&descriptor_write, 0, sizeof(descriptor_write));
5409 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5410 descriptor_write.dstSet = descriptor_set;
5411 descriptor_write.dstBinding = 0;
5412 descriptor_write.descriptorCount = 1;
5413 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5414 descriptor_write.pImageInfo = &img_info;
5415
5416 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5417
5418 // Create PSO to be used for draw-time errors below
5419 char const *vsSource = "#version 450\n"
5420 "\n"
5421 "out gl_PerVertex { \n"
5422 " vec4 gl_Position;\n"
5423 "};\n"
5424 "void main(){\n"
5425 " gl_Position = vec4(1);\n"
5426 "}\n";
5427 char const *fsSource = "#version 450\n"
5428 "\n"
5429 "layout(set=0, binding=0) uniform sampler2D s;\n"
5430 "layout(location=0) out vec4 x;\n"
5431 "void main(){\n"
5432 " x = texture(s, vec2(1));\n"
5433 "}\n";
5434 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5435 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5436 VkPipelineObj pipe(m_device);
5437 pipe.AddShader(&vs);
5438 pipe.AddShader(&fs);
5439 pipe.AddColorAttachment();
5440 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5441
5442 BeginCommandBuffer();
5443 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5444 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5445 &descriptor_set, 0, NULL);
5446 Draw(1, 0, 0, 0);
5447 EndCommandBuffer();
5448 // Submit cmd buffer to put pool in-flight
5449 VkSubmitInfo submit_info = {};
5450 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5451 submit_info.commandBufferCount = 1;
5452 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5453 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5454 // Destroy pool while in-flight, causing error
5455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5456 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5457 m_errorMonitor->VerifyFound();
5458 vkQueueWaitIdle(m_device->m_queue);
5459 // Cleanup
5460 vkDestroySampler(m_device->device(), sampler, NULL);
5461 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5462 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5463 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5464}
5465
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005466TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5467 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5468 ASSERT_NO_FATAL_FAILURE(InitState());
5469 ASSERT_NO_FATAL_FAILURE(InitViewport());
5470 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5471
5472 VkDescriptorPoolSize ds_type_count = {};
5473 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5474 ds_type_count.descriptorCount = 1;
5475
5476 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5477 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5478 ds_pool_ci.pNext = NULL;
5479 ds_pool_ci.maxSets = 1;
5480 ds_pool_ci.poolSizeCount = 1;
5481 ds_pool_ci.pPoolSizes = &ds_type_count;
5482
5483 VkDescriptorPool ds_pool;
5484 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5485 ASSERT_VK_SUCCESS(err);
5486
5487 VkDescriptorSetLayoutBinding dsl_binding = {};
5488 dsl_binding.binding = 0;
5489 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5490 dsl_binding.descriptorCount = 1;
5491 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5492 dsl_binding.pImmutableSamplers = NULL;
5493
5494 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5495 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5496 ds_layout_ci.pNext = NULL;
5497 ds_layout_ci.bindingCount = 1;
5498 ds_layout_ci.pBindings = &dsl_binding;
5499 VkDescriptorSetLayout ds_layout;
5500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5501 ASSERT_VK_SUCCESS(err);
5502
5503 VkDescriptorSet descriptorSet;
5504 VkDescriptorSetAllocateInfo alloc_info = {};
5505 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5506 alloc_info.descriptorSetCount = 1;
5507 alloc_info.descriptorPool = ds_pool;
5508 alloc_info.pSetLayouts = &ds_layout;
5509 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5510 ASSERT_VK_SUCCESS(err);
5511
5512 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5513 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5514 pipeline_layout_ci.pNext = NULL;
5515 pipeline_layout_ci.setLayoutCount = 1;
5516 pipeline_layout_ci.pSetLayouts = &ds_layout;
5517
5518 VkPipelineLayout pipeline_layout;
5519 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5520 ASSERT_VK_SUCCESS(err);
5521
5522 // Create images to update the descriptor with
5523 VkImage image;
5524 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5525 const int32_t tex_width = 32;
5526 const int32_t tex_height = 32;
5527 VkImageCreateInfo image_create_info = {};
5528 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5529 image_create_info.pNext = NULL;
5530 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5531 image_create_info.format = tex_format;
5532 image_create_info.extent.width = tex_width;
5533 image_create_info.extent.height = tex_height;
5534 image_create_info.extent.depth = 1;
5535 image_create_info.mipLevels = 1;
5536 image_create_info.arrayLayers = 1;
5537 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5538 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5539 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5540 image_create_info.flags = 0;
5541 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5542 ASSERT_VK_SUCCESS(err);
5543 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5544 VkMemoryRequirements memory_reqs;
5545 VkDeviceMemory image_memory;
5546 bool pass;
5547 VkMemoryAllocateInfo memory_info = {};
5548 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5549 memory_info.pNext = NULL;
5550 memory_info.allocationSize = 0;
5551 memory_info.memoryTypeIndex = 0;
5552 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5553 // Allocate enough memory for image
5554 memory_info.allocationSize = memory_reqs.size;
5555 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5556 ASSERT_TRUE(pass);
5557 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5558 ASSERT_VK_SUCCESS(err);
5559 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5560 ASSERT_VK_SUCCESS(err);
5561
5562 VkImageViewCreateInfo image_view_create_info = {};
5563 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5564 image_view_create_info.image = image;
5565 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5566 image_view_create_info.format = tex_format;
5567 image_view_create_info.subresourceRange.layerCount = 1;
5568 image_view_create_info.subresourceRange.baseMipLevel = 0;
5569 image_view_create_info.subresourceRange.levelCount = 1;
5570 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5571
5572 VkImageView view;
5573 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5574 ASSERT_VK_SUCCESS(err);
5575 // Create Samplers
5576 VkSamplerCreateInfo sampler_ci = {};
5577 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5578 sampler_ci.pNext = NULL;
5579 sampler_ci.magFilter = VK_FILTER_NEAREST;
5580 sampler_ci.minFilter = VK_FILTER_NEAREST;
5581 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5582 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5583 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5584 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5585 sampler_ci.mipLodBias = 1.0;
5586 sampler_ci.anisotropyEnable = VK_FALSE;
5587 sampler_ci.maxAnisotropy = 1;
5588 sampler_ci.compareEnable = VK_FALSE;
5589 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5590 sampler_ci.minLod = 1.0;
5591 sampler_ci.maxLod = 1.0;
5592 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5593 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5594 VkSampler sampler;
5595 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5596 ASSERT_VK_SUCCESS(err);
5597 // Update descriptor with image and sampler
5598 VkDescriptorImageInfo img_info = {};
5599 img_info.sampler = sampler;
5600 img_info.imageView = view;
5601 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5602
5603 VkWriteDescriptorSet descriptor_write;
5604 memset(&descriptor_write, 0, sizeof(descriptor_write));
5605 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5606 descriptor_write.dstSet = descriptorSet;
5607 descriptor_write.dstBinding = 0;
5608 descriptor_write.descriptorCount = 1;
5609 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5610 descriptor_write.pImageInfo = &img_info;
5611 // Break memory binding and attempt update
5612 vkFreeMemory(m_device->device(), image_memory, nullptr);
5613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005614 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5616 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5617 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5618 m_errorMonitor->VerifyFound();
5619 // Cleanup
5620 vkDestroyImage(m_device->device(), image, NULL);
5621 vkDestroySampler(m_device->device(), sampler, NULL);
5622 vkDestroyImageView(m_device->device(), view, NULL);
5623 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5624 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5625 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5626}
5627
Karl Schultz6addd812016-02-02 17:17:23 -07005628TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005629 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5630 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005631 // Create a valid cmd buffer
5632 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005633 uint64_t fake_pipeline_handle = 0xbaad6001;
5634 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005635 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5637
5638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005639 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005640 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005641 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005642
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005643 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005644 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 -06005645 Draw(1, 0, 0, 0);
5646 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005647
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005648 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005649 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 +12005650 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005651 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5652 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005653}
5654
Karl Schultz6addd812016-02-02 17:17:23 -07005655TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005656 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005657 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005658
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005660
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005661 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005662 ASSERT_NO_FATAL_FAILURE(InitViewport());
5663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005664 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005665 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5666 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005667
5668 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005669 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5670 ds_pool_ci.pNext = NULL;
5671 ds_pool_ci.maxSets = 1;
5672 ds_pool_ci.poolSizeCount = 1;
5673 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005674
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005675 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005676 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005677 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005678
Tony Barboureb254902015-07-15 12:50:33 -06005679 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005680 dsl_binding.binding = 0;
5681 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5682 dsl_binding.descriptorCount = 1;
5683 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5684 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005685
Tony Barboureb254902015-07-15 12:50:33 -06005686 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005687 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5688 ds_layout_ci.pNext = NULL;
5689 ds_layout_ci.bindingCount = 1;
5690 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005691 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005692 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005693 ASSERT_VK_SUCCESS(err);
5694
5695 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005696 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005697 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005698 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005699 alloc_info.descriptorPool = ds_pool;
5700 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005701 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005702 ASSERT_VK_SUCCESS(err);
5703
Tony Barboureb254902015-07-15 12:50:33 -06005704 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005705 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5706 pipeline_layout_ci.pNext = NULL;
5707 pipeline_layout_ci.setLayoutCount = 1;
5708 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005709
5710 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005711 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005712 ASSERT_VK_SUCCESS(err);
5713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005714 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005715 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005716 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005717 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005718
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005719 VkPipelineObj pipe(m_device);
5720 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005721 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005722 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005723 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005724
5725 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005726 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5727 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5728 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005729
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005730 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005731
Chia-I Wuf7458c52015-10-26 21:10:41 +08005732 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5733 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5734 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005735}
5736
Karl Schultz6addd812016-02-02 17:17:23 -07005737TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005738 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005739 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5742 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005743
5744 ASSERT_NO_FATAL_FAILURE(InitState());
5745 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005746 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5747 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005748
5749 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005750 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5751 ds_pool_ci.pNext = NULL;
5752 ds_pool_ci.maxSets = 1;
5753 ds_pool_ci.poolSizeCount = 1;
5754 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005755
5756 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005757 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005758 ASSERT_VK_SUCCESS(err);
5759
5760 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005761 dsl_binding.binding = 0;
5762 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5763 dsl_binding.descriptorCount = 1;
5764 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5765 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005766
5767 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005768 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5769 ds_layout_ci.pNext = NULL;
5770 ds_layout_ci.bindingCount = 1;
5771 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005772 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005773 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005774 ASSERT_VK_SUCCESS(err);
5775
5776 VkDescriptorSet descriptorSet;
5777 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005778 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005779 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005780 alloc_info.descriptorPool = ds_pool;
5781 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005782 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005783 ASSERT_VK_SUCCESS(err);
5784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005785 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005786 VkWriteDescriptorSet descriptor_write;
5787 memset(&descriptor_write, 0, sizeof(descriptor_write));
5788 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5789 descriptor_write.dstSet = descriptorSet;
5790 descriptor_write.dstBinding = 0;
5791 descriptor_write.descriptorCount = 1;
5792 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5793 descriptor_write.pTexelBufferView = &view;
5794
5795 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5796
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005797 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005798
5799 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5800 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5801}
5802
Mark Youngd339ba32016-05-30 13:28:35 -06005803TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005804 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 -06005805
5806 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005808 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005809
5810 ASSERT_NO_FATAL_FAILURE(InitState());
5811
5812 // Create a buffer with no bound memory and then attempt to create
5813 // a buffer view.
5814 VkBufferCreateInfo buff_ci = {};
5815 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005816 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005817 buff_ci.size = 256;
5818 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5819 VkBuffer buffer;
5820 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5821 ASSERT_VK_SUCCESS(err);
5822
5823 VkBufferViewCreateInfo buff_view_ci = {};
5824 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5825 buff_view_ci.buffer = buffer;
5826 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5827 buff_view_ci.range = VK_WHOLE_SIZE;
5828 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005829 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005830
5831 m_errorMonitor->VerifyFound();
5832 vkDestroyBuffer(m_device->device(), buffer, NULL);
5833 // If last error is success, it still created the view, so delete it.
5834 if (err == VK_SUCCESS) {
5835 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5836 }
5837}
5838
Karl Schultz6addd812016-02-02 17:17:23 -07005839TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5840 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5841 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005842 // 1. No dynamicOffset supplied
5843 // 2. Too many dynamicOffsets supplied
5844 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005845 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5847 "0 dynamicOffsets are left in "
5848 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005849
5850 ASSERT_NO_FATAL_FAILURE(InitState());
5851 ASSERT_NO_FATAL_FAILURE(InitViewport());
5852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5853
5854 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005855 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5856 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005857
5858 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005859 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5860 ds_pool_ci.pNext = NULL;
5861 ds_pool_ci.maxSets = 1;
5862 ds_pool_ci.poolSizeCount = 1;
5863 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005864
5865 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005866 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005867 ASSERT_VK_SUCCESS(err);
5868
5869 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005870 dsl_binding.binding = 0;
5871 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5872 dsl_binding.descriptorCount = 1;
5873 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5874 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005875
5876 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005877 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5878 ds_layout_ci.pNext = NULL;
5879 ds_layout_ci.bindingCount = 1;
5880 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005881 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005882 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005883 ASSERT_VK_SUCCESS(err);
5884
5885 VkDescriptorSet descriptorSet;
5886 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005887 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005888 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005889 alloc_info.descriptorPool = ds_pool;
5890 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005891 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005892 ASSERT_VK_SUCCESS(err);
5893
5894 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005895 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5896 pipeline_layout_ci.pNext = NULL;
5897 pipeline_layout_ci.setLayoutCount = 1;
5898 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005899
5900 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005901 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005902 ASSERT_VK_SUCCESS(err);
5903
5904 // Create a buffer to update the descriptor with
5905 uint32_t qfi = 0;
5906 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005907 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5908 buffCI.size = 1024;
5909 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5910 buffCI.queueFamilyIndexCount = 1;
5911 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005912
5913 VkBuffer dyub;
5914 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5915 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005916 // Allocate memory and bind to buffer so we can make it to the appropriate
5917 // error
5918 VkMemoryAllocateInfo mem_alloc = {};
5919 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5920 mem_alloc.pNext = NULL;
5921 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005922 mem_alloc.memoryTypeIndex = 0;
5923
5924 VkMemoryRequirements memReqs;
5925 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005926 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005927 if (!pass) {
5928 vkDestroyBuffer(m_device->device(), dyub, NULL);
5929 return;
5930 }
5931
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005932 VkDeviceMemory mem;
5933 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5934 ASSERT_VK_SUCCESS(err);
5935 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5936 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005937 // Correctly update descriptor to avoid "NOT_UPDATED" error
5938 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005939 buffInfo.buffer = dyub;
5940 buffInfo.offset = 0;
5941 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005942
5943 VkWriteDescriptorSet descriptor_write;
5944 memset(&descriptor_write, 0, sizeof(descriptor_write));
5945 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5946 descriptor_write.dstSet = descriptorSet;
5947 descriptor_write.dstBinding = 0;
5948 descriptor_write.descriptorCount = 1;
5949 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5950 descriptor_write.pBufferInfo = &buffInfo;
5951
5952 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5953
5954 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005955 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5956 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005957 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005958 uint32_t pDynOff[2] = {512, 756};
5959 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5961 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5962 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5963 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005964 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005965 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5967 "offset 0 and range 1024 that "
5968 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005969 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005970 char const *vsSource = "#version 450\n"
5971 "\n"
5972 "out gl_PerVertex { \n"
5973 " vec4 gl_Position;\n"
5974 "};\n"
5975 "void main(){\n"
5976 " gl_Position = vec4(1);\n"
5977 "}\n";
5978 char const *fsSource = "#version 450\n"
5979 "\n"
5980 "layout(location=0) out vec4 x;\n"
5981 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5982 "void main(){\n"
5983 " x = vec4(bar.y);\n"
5984 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005985 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5986 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5987 VkPipelineObj pipe(m_device);
5988 pipe.AddShader(&vs);
5989 pipe.AddShader(&fs);
5990 pipe.AddColorAttachment();
5991 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5992
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005993 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005994 // This update should succeed, but offset size of 512 will overstep buffer
5995 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005996 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5997 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005998 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005999 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006000
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006001 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006002 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006003
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006004 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006005 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006006 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6007}
6008
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006009TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6010 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6011 "that doesn't have memory bound");
6012 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006014 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6016 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006017
6018 ASSERT_NO_FATAL_FAILURE(InitState());
6019 ASSERT_NO_FATAL_FAILURE(InitViewport());
6020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6021
6022 VkDescriptorPoolSize ds_type_count = {};
6023 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6024 ds_type_count.descriptorCount = 1;
6025
6026 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6027 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6028 ds_pool_ci.pNext = NULL;
6029 ds_pool_ci.maxSets = 1;
6030 ds_pool_ci.poolSizeCount = 1;
6031 ds_pool_ci.pPoolSizes = &ds_type_count;
6032
6033 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006034 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006035 ASSERT_VK_SUCCESS(err);
6036
6037 VkDescriptorSetLayoutBinding dsl_binding = {};
6038 dsl_binding.binding = 0;
6039 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6040 dsl_binding.descriptorCount = 1;
6041 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6042 dsl_binding.pImmutableSamplers = NULL;
6043
6044 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6045 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6046 ds_layout_ci.pNext = NULL;
6047 ds_layout_ci.bindingCount = 1;
6048 ds_layout_ci.pBindings = &dsl_binding;
6049 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006050 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006051 ASSERT_VK_SUCCESS(err);
6052
6053 VkDescriptorSet descriptorSet;
6054 VkDescriptorSetAllocateInfo alloc_info = {};
6055 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6056 alloc_info.descriptorSetCount = 1;
6057 alloc_info.descriptorPool = ds_pool;
6058 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006059 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006060 ASSERT_VK_SUCCESS(err);
6061
6062 // Create a buffer to update the descriptor with
6063 uint32_t qfi = 0;
6064 VkBufferCreateInfo buffCI = {};
6065 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6066 buffCI.size = 1024;
6067 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6068 buffCI.queueFamilyIndexCount = 1;
6069 buffCI.pQueueFamilyIndices = &qfi;
6070
6071 VkBuffer dyub;
6072 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6073 ASSERT_VK_SUCCESS(err);
6074
6075 // Attempt to update descriptor without binding memory to it
6076 VkDescriptorBufferInfo buffInfo = {};
6077 buffInfo.buffer = dyub;
6078 buffInfo.offset = 0;
6079 buffInfo.range = 1024;
6080
6081 VkWriteDescriptorSet descriptor_write;
6082 memset(&descriptor_write, 0, sizeof(descriptor_write));
6083 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6084 descriptor_write.dstSet = descriptorSet;
6085 descriptor_write.dstBinding = 0;
6086 descriptor_write.descriptorCount = 1;
6087 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6088 descriptor_write.pBufferInfo = &buffInfo;
6089
6090 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6091 m_errorMonitor->VerifyFound();
6092
6093 vkDestroyBuffer(m_device->device(), dyub, NULL);
6094 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6095 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6096}
6097
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006098TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006099 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006100 ASSERT_NO_FATAL_FAILURE(InitState());
6101 ASSERT_NO_FATAL_FAILURE(InitViewport());
6102 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6103
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006104 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006105 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006106 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6107 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6108 pipeline_layout_ci.pushConstantRangeCount = 1;
6109 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6110
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006111 //
6112 // Check for invalid push constant ranges in pipeline layouts.
6113 //
6114 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006115 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006116 char const *msg;
6117 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006118
Karl Schultzc81037d2016-05-12 08:11:23 -06006119 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6120 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6121 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6122 "vkCreatePipelineLayout() call has push constants index 0 with "
6123 "size 0."},
6124 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6125 "vkCreatePipelineLayout() call has push constants index 0 with "
6126 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006127 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006128 "vkCreatePipelineLayout() call has push constants index 0 with "
6129 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006130 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006131 "vkCreatePipelineLayout() call has push constants index 0 with "
6132 "size 0."},
6133 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6134 "vkCreatePipelineLayout() call has push constants index 0 with "
6135 "offset 1. Offset must"},
6136 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6137 "vkCreatePipelineLayout() call has push constants index 0 "
6138 "with offset "},
6139 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6140 "vkCreatePipelineLayout() call has push constants "
6141 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006142 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006143 "vkCreatePipelineLayout() call has push constants index 0 "
6144 "with offset "},
6145 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6146 "vkCreatePipelineLayout() call has push "
6147 "constants index 0 with offset "},
6148 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6149 "vkCreatePipelineLayout() call has push "
6150 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006151 }};
6152
6153 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006154 for (const auto &iter : range_tests) {
6155 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6157 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006158 m_errorMonitor->VerifyFound();
6159 if (VK_SUCCESS == err) {
6160 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6161 }
6162 }
6163
6164 // Check for invalid stage flag
6165 pc_range.offset = 0;
6166 pc_range.size = 16;
6167 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006168 m_errorMonitor->SetDesiredFailureMsg(
6169 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6170 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006171 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006172 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006173 if (VK_SUCCESS == err) {
6174 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6175 }
6176
6177 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006178 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006179 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006180 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006181 char const *msg;
6182 };
6183
Karl Schultzc81037d2016-05-12 08:11:23 -06006184 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006185 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6186 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6187 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6188 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6189 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006190 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006191 {
6192 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6193 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6194 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6195 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6196 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006197 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006198 },
6199 {
6200 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6201 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6202 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6203 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6204 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006205 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006206 },
6207 {
6208 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6209 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6210 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6211 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6212 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006213 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006214 },
6215 {
6216 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6217 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6218 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6219 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6220 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006221 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006222 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006223
Karl Schultzc81037d2016-05-12 08:11:23 -06006224 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006225 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006226 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006229 m_errorMonitor->VerifyFound();
6230 if (VK_SUCCESS == err) {
6231 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6232 }
6233 }
6234
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006235 //
6236 // CmdPushConstants tests
6237 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006238 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006239
6240 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006241 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6242 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006243 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6244 "vkCmdPushConstants() call has push constants with size 1. Size "
6245 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006246 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006247 "vkCmdPushConstants() call has push constants with size 1. Size "
6248 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006249 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006250 "vkCmdPushConstants() call has push constants with offset 1. "
6251 "Offset must be a multiple of 4."},
6252 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6253 "vkCmdPushConstants() call has push constants with offset 1. "
6254 "Offset must be a multiple of 4."},
6255 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6256 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6257 "0x1 not within flag-matching ranges in pipeline layout"},
6258 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6259 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6260 "0x1 not within flag-matching ranges in pipeline layout"},
6261 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6262 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6263 "0x1 not within flag-matching ranges in pipeline layout"},
6264 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6265 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6266 "0x1 not within flag-matching ranges in pipeline layout"},
6267 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6268 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6269 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006270 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006271 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6272 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006273 }};
6274
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006275 BeginCommandBuffer();
6276
6277 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006278 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006279 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006280 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006281 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006282 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006283 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006284 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006285 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6287 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006288 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006289 m_errorMonitor->VerifyFound();
6290 }
6291
6292 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006294 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006295 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006296 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006297
Karl Schultzc81037d2016-05-12 08:11:23 -06006298 // overlapping range tests with cmd
6299 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6300 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6301 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6302 "0x1 not within flag-matching ranges in pipeline layout"},
6303 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6304 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6305 "0x1 not within flag-matching ranges in pipeline layout"},
6306 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6307 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6308 "0x1 not within flag-matching ranges in pipeline layout"},
6309 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006310 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006311 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006312 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6313 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006314 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006315 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006316 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006317 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006318 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006319 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6321 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006322 iter.range.size, dummy_values);
6323 m_errorMonitor->VerifyFound();
6324 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006325 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6326
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006327 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006328}
6329
Karl Schultz6addd812016-02-02 17:17:23 -07006330TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006331 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006332 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006333
6334 ASSERT_NO_FATAL_FAILURE(InitState());
6335 ASSERT_NO_FATAL_FAILURE(InitViewport());
6336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6337
Mike Stroyanb8a61002016-06-20 16:00:28 -06006338 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6339 VkImageTiling tiling;
6340 VkFormatProperties format_properties;
6341 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006342 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006343 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006344 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006345 tiling = VK_IMAGE_TILING_OPTIMAL;
6346 } else {
6347 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6348 "skipped.\n");
6349 return;
6350 }
6351
Tobin Ehlis559c6382015-11-05 09:52:49 -07006352 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6353 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006354 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6355 ds_type_count[0].descriptorCount = 10;
6356 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6357 ds_type_count[1].descriptorCount = 2;
6358 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6359 ds_type_count[2].descriptorCount = 2;
6360 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6361 ds_type_count[3].descriptorCount = 5;
6362 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6363 // type
6364 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6365 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6366 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006367
6368 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006369 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6370 ds_pool_ci.pNext = NULL;
6371 ds_pool_ci.maxSets = 5;
6372 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6373 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006374
6375 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006376 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006377 ASSERT_VK_SUCCESS(err);
6378
6379 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6380 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006381 dsl_binding[0].binding = 0;
6382 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6383 dsl_binding[0].descriptorCount = 5;
6384 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6385 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006386
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006387 // Create layout identical to set0 layout but w/ different stageFlags
6388 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006389 dsl_fs_stage_only.binding = 0;
6390 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6391 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006392 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6393 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006394 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006395 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006396 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6397 ds_layout_ci.pNext = NULL;
6398 ds_layout_ci.bindingCount = 1;
6399 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006400 static const uint32_t NUM_LAYOUTS = 4;
6401 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006402 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006403 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6404 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006405 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006406 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006407 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006409 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006410 dsl_binding[0].binding = 0;
6411 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006412 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006413 dsl_binding[1].binding = 1;
6414 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6415 dsl_binding[1].descriptorCount = 2;
6416 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6417 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006418 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006419 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006420 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006421 ASSERT_VK_SUCCESS(err);
6422 dsl_binding[0].binding = 0;
6423 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006424 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006425 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006426 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006427 ASSERT_VK_SUCCESS(err);
6428 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006429 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006430 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006431 ASSERT_VK_SUCCESS(err);
6432
6433 static const uint32_t NUM_SETS = 4;
6434 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6435 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006436 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006437 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006438 alloc_info.descriptorPool = ds_pool;
6439 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006440 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006441 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006442 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006443 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006444 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006445 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006446 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006447
6448 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006449 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6450 pipeline_layout_ci.pNext = NULL;
6451 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6452 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006453
6454 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006455 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006456 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006457 // Create pipelineLayout with only one setLayout
6458 pipeline_layout_ci.setLayoutCount = 1;
6459 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006460 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006461 ASSERT_VK_SUCCESS(err);
6462 // Create pipelineLayout with 2 descriptor setLayout at index 0
6463 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6464 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006465 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006466 ASSERT_VK_SUCCESS(err);
6467 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6468 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6469 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006470 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006471 ASSERT_VK_SUCCESS(err);
6472 // Create pipelineLayout with UB type, but stageFlags for FS only
6473 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6474 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006475 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006476 ASSERT_VK_SUCCESS(err);
6477 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6478 VkDescriptorSetLayout pl_bad_s0[2] = {};
6479 pl_bad_s0[0] = ds_layout_fs_only;
6480 pl_bad_s0[1] = ds_layout[1];
6481 pipeline_layout_ci.setLayoutCount = 2;
6482 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6483 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006484 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006485 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006486
6487 // Create a buffer to update the descriptor with
6488 uint32_t qfi = 0;
6489 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006490 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6491 buffCI.size = 1024;
6492 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6493 buffCI.queueFamilyIndexCount = 1;
6494 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006495
6496 VkBuffer dyub;
6497 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6498 ASSERT_VK_SUCCESS(err);
6499 // Correctly update descriptor to avoid "NOT_UPDATED" error
6500 static const uint32_t NUM_BUFFS = 5;
6501 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006502 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006503 buffInfo[i].buffer = dyub;
6504 buffInfo[i].offset = 0;
6505 buffInfo[i].range = 1024;
6506 }
Karl Schultz6addd812016-02-02 17:17:23 -07006507 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006508 const int32_t tex_width = 32;
6509 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006510 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006511 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6512 image_create_info.pNext = NULL;
6513 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6514 image_create_info.format = tex_format;
6515 image_create_info.extent.width = tex_width;
6516 image_create_info.extent.height = tex_height;
6517 image_create_info.extent.depth = 1;
6518 image_create_info.mipLevels = 1;
6519 image_create_info.arrayLayers = 1;
6520 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006521 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006522 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006523 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006524 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6525 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006526
Karl Schultz6addd812016-02-02 17:17:23 -07006527 VkMemoryRequirements memReqs;
6528 VkDeviceMemory imageMem;
6529 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006530 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006531 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6532 memAlloc.pNext = NULL;
6533 memAlloc.allocationSize = 0;
6534 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006535 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6536 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006537 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006538 ASSERT_TRUE(pass);
6539 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6540 ASSERT_VK_SUCCESS(err);
6541 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6542 ASSERT_VK_SUCCESS(err);
6543
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006544 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006545 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6546 image_view_create_info.image = image;
6547 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6548 image_view_create_info.format = tex_format;
6549 image_view_create_info.subresourceRange.layerCount = 1;
6550 image_view_create_info.subresourceRange.baseMipLevel = 0;
6551 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006552 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006553
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006554 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006555 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006556 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006557 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006558 imageInfo[0].imageView = view;
6559 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6560 imageInfo[1].imageView = view;
6561 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006562 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006563 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006564 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006565 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006566
6567 static const uint32_t NUM_SET_UPDATES = 3;
6568 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6569 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6570 descriptor_write[0].dstSet = descriptorSet[0];
6571 descriptor_write[0].dstBinding = 0;
6572 descriptor_write[0].descriptorCount = 5;
6573 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6574 descriptor_write[0].pBufferInfo = buffInfo;
6575 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6576 descriptor_write[1].dstSet = descriptorSet[1];
6577 descriptor_write[1].dstBinding = 0;
6578 descriptor_write[1].descriptorCount = 2;
6579 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6580 descriptor_write[1].pImageInfo = imageInfo;
6581 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6582 descriptor_write[2].dstSet = descriptorSet[1];
6583 descriptor_write[2].dstBinding = 1;
6584 descriptor_write[2].descriptorCount = 2;
6585 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006586 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006587
6588 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006589
Tobin Ehlis88452832015-12-03 09:40:56 -07006590 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006591 char const *vsSource = "#version 450\n"
6592 "\n"
6593 "out gl_PerVertex {\n"
6594 " vec4 gl_Position;\n"
6595 "};\n"
6596 "void main(){\n"
6597 " gl_Position = vec4(1);\n"
6598 "}\n";
6599 char const *fsSource = "#version 450\n"
6600 "\n"
6601 "layout(location=0) out vec4 x;\n"
6602 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6603 "void main(){\n"
6604 " x = vec4(bar.y);\n"
6605 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006606 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6607 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006608 VkPipelineObj pipe(m_device);
6609 pipe.AddShader(&vs);
6610 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006611 pipe.AddColorAttachment();
6612 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006613
6614 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006615
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006616 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006617 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6618 // of PSO
6619 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6620 // cmd_pipeline.c
6621 // due to the fact that cmd_alloc_dset_data() has not been called in
6622 // cmd_bind_graphics_pipeline()
6623 // TODO : Want to cause various binding incompatibility issues here to test
6624 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006625 // First cause various verify_layout_compatibility() fails
6626 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006627 // verify_set_layout_compatibility fail cases:
6628 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6630 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6631 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006632 m_errorMonitor->VerifyFound();
6633
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006634 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6636 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6637 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006638 m_errorMonitor->VerifyFound();
6639
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006640 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006641 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6642 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6644 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6645 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006646 m_errorMonitor->VerifyFound();
6647
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006648 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6649 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6651 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6652 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006653 m_errorMonitor->VerifyFound();
6654
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006655 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6656 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6658 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6659 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6660 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006661 m_errorMonitor->VerifyFound();
6662
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006663 // Cause INFO messages due to disturbing previously bound Sets
6664 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006665 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6666 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006667 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6669 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6670 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006671 m_errorMonitor->VerifyFound();
6672
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006673 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6674 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006675 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6677 "any subsequent sets were disturbed ");
6678 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6679 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006680 m_errorMonitor->VerifyFound();
6681
Tobin Ehlis10fad692016-07-07 12:00:36 -06006682 // Now that we're done actively using the pipelineLayout that gfx pipeline
6683 // was created with, we should be able to delete it. Do that now to verify
6684 // that validation obeys pipelineLayout lifetime
6685 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6686
Tobin Ehlis88452832015-12-03 09:40:56 -07006687 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006688 // 1. Error due to not binding required set (we actually use same code as
6689 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006690 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6691 &descriptorSet[0], 0, NULL);
6692 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6693 &descriptorSet[1], 0, NULL);
6694 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 -07006695 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006696 m_errorMonitor->VerifyFound();
6697
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006698 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006699 // 2. Error due to bound set not being compatible with PSO's
6700 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006701 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6702 &descriptorSet[0], 0, NULL);
6703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006704 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006705 m_errorMonitor->VerifyFound();
6706
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006707 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006708 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006709 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6710 }
6711 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006712 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006713 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6714 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006715 vkFreeMemory(m_device->device(), imageMem, NULL);
6716 vkDestroyImage(m_device->device(), image, NULL);
6717 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006718}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006719
Karl Schultz6addd812016-02-02 17:17:23 -07006720TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006721
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6723 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006724
6725 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006726 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006727 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006728 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006729
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006730 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006731}
6732
Karl Schultz6addd812016-02-02 17:17:23 -07006733TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6734 VkResult err;
6735 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006736
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006738
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006739 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006740
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006741 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006742 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006743 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006744 cmd.commandPool = m_commandPool;
6745 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006746 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006747
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006748 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006749 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006750
6751 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006752 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006753 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006754 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006755 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006756 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 -07006757 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006758
6759 // The error should be caught by validation of the BeginCommandBuffer call
6760 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6761
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006762 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006763 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006764}
6765
Karl Schultz6addd812016-02-02 17:17:23 -07006766TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006767 // Cause error due to Begin while recording CB
6768 // Then cause 2 errors for attempting to reset CB w/o having
6769 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6770 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006772
6773 ASSERT_NO_FATAL_FAILURE(InitState());
6774
6775 // Calls AllocateCommandBuffers
6776 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6777
Karl Schultz6addd812016-02-02 17:17:23 -07006778 // Force the failure by setting the Renderpass and Framebuffer fields with
6779 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006780 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006781 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006782 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6783 cmd_buf_info.pNext = NULL;
6784 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006785 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006786
6787 // Begin CB to transition to recording state
6788 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6789 // Can't re-begin. This should trigger error
6790 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006791 m_errorMonitor->VerifyFound();
6792
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006794 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6795 // Reset attempt will trigger error due to incorrect CommandPool state
6796 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006797 m_errorMonitor->VerifyFound();
6798
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006800 // Transition CB to RECORDED state
6801 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6802 // Now attempting to Begin will implicitly reset, which triggers error
6803 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006804 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006805}
6806
Karl Schultz6addd812016-02-02 17:17:23 -07006807TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006808 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006809 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006810
Mike Weiblencce7ec72016-10-17 19:33:05 -06006811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006812
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006813 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006815
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006816 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006817 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6818 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006819
6820 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006821 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6822 ds_pool_ci.pNext = NULL;
6823 ds_pool_ci.maxSets = 1;
6824 ds_pool_ci.poolSizeCount = 1;
6825 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006826
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006827 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006828 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006829 ASSERT_VK_SUCCESS(err);
6830
Tony Barboureb254902015-07-15 12:50:33 -06006831 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006832 dsl_binding.binding = 0;
6833 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6834 dsl_binding.descriptorCount = 1;
6835 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6836 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006837
Tony Barboureb254902015-07-15 12:50:33 -06006838 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006839 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6840 ds_layout_ci.pNext = NULL;
6841 ds_layout_ci.bindingCount = 1;
6842 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006843
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006844 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006845 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006846 ASSERT_VK_SUCCESS(err);
6847
6848 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006849 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006850 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006851 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006852 alloc_info.descriptorPool = ds_pool;
6853 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006854 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006855 ASSERT_VK_SUCCESS(err);
6856
Tony Barboureb254902015-07-15 12:50:33 -06006857 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006858 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6859 pipeline_layout_ci.setLayoutCount = 1;
6860 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006861
6862 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006863 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006864 ASSERT_VK_SUCCESS(err);
6865
Tobin Ehlise68360f2015-10-01 11:15:13 -06006866 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006867 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006868
6869 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006870 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6871 vp_state_ci.scissorCount = 1;
6872 vp_state_ci.pScissors = &sc;
6873 vp_state_ci.viewportCount = 1;
6874 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006875
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006876 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6877 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6878 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6879 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6880 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6881 rs_state_ci.depthClampEnable = VK_FALSE;
6882 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6883 rs_state_ci.depthBiasEnable = VK_FALSE;
6884
Tony Barboureb254902015-07-15 12:50:33 -06006885 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006886 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6887 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006888 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006889 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6890 gp_ci.layout = pipeline_layout;
6891 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006892
6893 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006894 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6895 pc_ci.initialDataSize = 0;
6896 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006897
6898 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006899 VkPipelineCache pipelineCache;
6900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006901 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006902 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006903 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006904
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006905 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006906
Chia-I Wuf7458c52015-10-26 21:10:41 +08006907 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6908 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6909 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6910 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006911}
Tobin Ehlis912df022015-09-17 08:46:18 -06006912/*// TODO : This test should be good, but needs Tess support in compiler to run
6913TEST_F(VkLayerTest, InvalidPatchControlPoints)
6914{
6915 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006916 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006917
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006919 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6920primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006921
Tobin Ehlis912df022015-09-17 08:46:18 -06006922 ASSERT_NO_FATAL_FAILURE(InitState());
6923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006924
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006925 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006926 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006927 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006928
6929 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6930 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6931 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006932 ds_pool_ci.poolSizeCount = 1;
6933 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006934
6935 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006936 err = vkCreateDescriptorPool(m_device->device(),
6937VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006938 ASSERT_VK_SUCCESS(err);
6939
6940 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006941 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006942 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006943 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006944 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6945 dsl_binding.pImmutableSamplers = NULL;
6946
6947 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006948 ds_layout_ci.sType =
6949VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006950 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006951 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006952 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006953
6954 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006955 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6956&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006957 ASSERT_VK_SUCCESS(err);
6958
6959 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006960 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6961VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006962 ASSERT_VK_SUCCESS(err);
6963
6964 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006965 pipeline_layout_ci.sType =
6966VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006967 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006968 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006969 pipeline_layout_ci.pSetLayouts = &ds_layout;
6970
6971 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006972 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6973&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006974 ASSERT_VK_SUCCESS(err);
6975
6976 VkPipelineShaderStageCreateInfo shaderStages[3];
6977 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6978
Karl Schultz6addd812016-02-02 17:17:23 -07006979 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6980this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006981 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006982 VkShaderObj
6983tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6984this);
6985 VkShaderObj
6986te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6987this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006988
Karl Schultz6addd812016-02-02 17:17:23 -07006989 shaderStages[0].sType =
6990VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006991 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006992 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006993 shaderStages[1].sType =
6994VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006995 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006996 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006997 shaderStages[2].sType =
6998VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006999 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007000 shaderStages[2].shader = te.handle();
7001
7002 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007003 iaCI.sType =
7004VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007005 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007006
7007 VkPipelineTessellationStateCreateInfo tsCI = {};
7008 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7009 tsCI.patchControlPoints = 0; // This will cause an error
7010
7011 VkGraphicsPipelineCreateInfo gp_ci = {};
7012 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7013 gp_ci.pNext = NULL;
7014 gp_ci.stageCount = 3;
7015 gp_ci.pStages = shaderStages;
7016 gp_ci.pVertexInputState = NULL;
7017 gp_ci.pInputAssemblyState = &iaCI;
7018 gp_ci.pTessellationState = &tsCI;
7019 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007020 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007021 gp_ci.pMultisampleState = NULL;
7022 gp_ci.pDepthStencilState = NULL;
7023 gp_ci.pColorBlendState = NULL;
7024 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7025 gp_ci.layout = pipeline_layout;
7026 gp_ci.renderPass = renderPass();
7027
7028 VkPipelineCacheCreateInfo pc_ci = {};
7029 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7030 pc_ci.pNext = NULL;
7031 pc_ci.initialSize = 0;
7032 pc_ci.initialData = 0;
7033 pc_ci.maxSize = 0;
7034
7035 VkPipeline pipeline;
7036 VkPipelineCache pipelineCache;
7037
Karl Schultz6addd812016-02-02 17:17:23 -07007038 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7039&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007040 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007041 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7042&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007043
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007044 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007045
Chia-I Wuf7458c52015-10-26 21:10:41 +08007046 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7047 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7048 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7049 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007050}
7051*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007052// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007053TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007054 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007055
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7057 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007058
Tobin Ehlise68360f2015-10-01 11:15:13 -06007059 ASSERT_NO_FATAL_FAILURE(InitState());
7060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007061
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007062 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007063 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7064 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007065
7066 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007067 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7068 ds_pool_ci.maxSets = 1;
7069 ds_pool_ci.poolSizeCount = 1;
7070 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007071
7072 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007073 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007074 ASSERT_VK_SUCCESS(err);
7075
7076 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007077 dsl_binding.binding = 0;
7078 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7079 dsl_binding.descriptorCount = 1;
7080 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007081
7082 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007083 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7084 ds_layout_ci.bindingCount = 1;
7085 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007086
7087 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007088 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007089 ASSERT_VK_SUCCESS(err);
7090
7091 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007092 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007093 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007094 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007095 alloc_info.descriptorPool = ds_pool;
7096 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007097 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007098 ASSERT_VK_SUCCESS(err);
7099
7100 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007101 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7102 pipeline_layout_ci.setLayoutCount = 1;
7103 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007104
7105 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007106 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007107 ASSERT_VK_SUCCESS(err);
7108
7109 VkViewport vp = {}; // Just need dummy vp to point to
7110
7111 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007112 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7113 vp_state_ci.scissorCount = 0;
7114 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7115 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007116
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007117 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7118 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7119 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7120 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7121 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7122 rs_state_ci.depthClampEnable = VK_FALSE;
7123 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7124 rs_state_ci.depthBiasEnable = VK_FALSE;
7125
Cody Northropeb3a6c12015-10-05 14:44:45 -06007126 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007127 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007129 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7130 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7131 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007132 shaderStages[0] = vs.GetStageCreateInfo();
7133 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134
7135 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007136 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7137 gp_ci.stageCount = 2;
7138 gp_ci.pStages = shaderStages;
7139 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007140 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007141 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7142 gp_ci.layout = pipeline_layout;
7143 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007144
7145 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007146 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007147
7148 VkPipeline pipeline;
7149 VkPipelineCache pipelineCache;
7150
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007151 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007152 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007153 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007154
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007155 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007156
Chia-I Wuf7458c52015-10-26 21:10:41 +08007157 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7158 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7159 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7160 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161}
Karl Schultz6addd812016-02-02 17:17:23 -07007162// Don't set viewport state in PSO. This is an error b/c we always need this
7163// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007164// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007165TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007166 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007167 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007170
Tobin Ehlise68360f2015-10-01 11:15:13 -06007171 ASSERT_NO_FATAL_FAILURE(InitState());
7172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007173
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007174 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007175 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7176 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007177
7178 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007179 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7180 ds_pool_ci.maxSets = 1;
7181 ds_pool_ci.poolSizeCount = 1;
7182 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007183
7184 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007185 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007186 ASSERT_VK_SUCCESS(err);
7187
7188 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007189 dsl_binding.binding = 0;
7190 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7191 dsl_binding.descriptorCount = 1;
7192 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007193
7194 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007195 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7196 ds_layout_ci.bindingCount = 1;
7197 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007198
7199 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007200 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007201 ASSERT_VK_SUCCESS(err);
7202
7203 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007204 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007205 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007206 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007207 alloc_info.descriptorPool = ds_pool;
7208 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007209 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007210 ASSERT_VK_SUCCESS(err);
7211
7212 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007213 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7214 pipeline_layout_ci.setLayoutCount = 1;
7215 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007216
7217 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007218 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007219 ASSERT_VK_SUCCESS(err);
7220
7221 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7222 // Set scissor as dynamic to avoid second error
7223 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007224 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7225 dyn_state_ci.dynamicStateCount = 1;
7226 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007227
Cody Northropeb3a6c12015-10-05 14:44:45 -06007228 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007229 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007231 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7232 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7233 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007234 shaderStages[0] = vs.GetStageCreateInfo();
7235 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007236
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007237 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7238 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7239 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7240 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7241 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7242 rs_state_ci.depthClampEnable = VK_FALSE;
7243 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7244 rs_state_ci.depthBiasEnable = VK_FALSE;
7245
Tobin Ehlise68360f2015-10-01 11:15:13 -06007246 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007247 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7248 gp_ci.stageCount = 2;
7249 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007250 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007251 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7252 // should cause validation error
7253 gp_ci.pDynamicState = &dyn_state_ci;
7254 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7255 gp_ci.layout = pipeline_layout;
7256 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007257
7258 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007259 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007260
7261 VkPipeline pipeline;
7262 VkPipelineCache pipelineCache;
7263
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007264 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007265 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007266 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007267
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007268 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007269
Chia-I Wuf7458c52015-10-26 21:10:41 +08007270 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7271 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7272 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7273 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007274}
7275// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007276// Then run second test where dynamic scissor count doesn't match PSO scissor
7277// count
7278TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7279 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007280
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7282 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007283
Tobin Ehlise68360f2015-10-01 11:15:13 -06007284 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007285
7286 if (!m_device->phy().features().multiViewport) {
7287 printf("Device does not support multiple viewports/scissors; skipped.\n");
7288 return;
7289 }
7290
Tobin Ehlise68360f2015-10-01 11:15:13 -06007291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007292
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007293 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007294 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7295 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007296
7297 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007298 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7299 ds_pool_ci.maxSets = 1;
7300 ds_pool_ci.poolSizeCount = 1;
7301 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007302
7303 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007304 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007305 ASSERT_VK_SUCCESS(err);
7306
7307 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007308 dsl_binding.binding = 0;
7309 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7310 dsl_binding.descriptorCount = 1;
7311 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007312
7313 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007314 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7315 ds_layout_ci.bindingCount = 1;
7316 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007317
7318 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007319 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007320 ASSERT_VK_SUCCESS(err);
7321
7322 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007323 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007324 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007325 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007326 alloc_info.descriptorPool = ds_pool;
7327 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007328 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007329 ASSERT_VK_SUCCESS(err);
7330
7331 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007332 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7333 pipeline_layout_ci.setLayoutCount = 1;
7334 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007335
7336 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007337 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007338 ASSERT_VK_SUCCESS(err);
7339
7340 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007341 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7342 vp_state_ci.viewportCount = 1;
7343 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7344 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007345 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007346
7347 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7348 // Set scissor as dynamic to avoid that error
7349 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007350 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7351 dyn_state_ci.dynamicStateCount = 1;
7352 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007353
Cody Northropeb3a6c12015-10-05 14:44:45 -06007354 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007355 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007356
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007357 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7358 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7359 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007360 shaderStages[0] = vs.GetStageCreateInfo();
7361 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007362
Cody Northropf6622dc2015-10-06 10:33:21 -06007363 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7364 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7365 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007366 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007367 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007368 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007369 vi_ci.pVertexAttributeDescriptions = nullptr;
7370
7371 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7372 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7373 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7374
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007375 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007376 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007377 rs_ci.pNext = nullptr;
7378
Mark Youngc89c6312016-03-31 16:03:20 -06007379 VkPipelineColorBlendAttachmentState att = {};
7380 att.blendEnable = VK_FALSE;
7381 att.colorWriteMask = 0xf;
7382
Cody Northropf6622dc2015-10-06 10:33:21 -06007383 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7384 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7385 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007386 cb_ci.attachmentCount = 1;
7387 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007388
Tobin Ehlise68360f2015-10-01 11:15:13 -06007389 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007390 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7391 gp_ci.stageCount = 2;
7392 gp_ci.pStages = shaderStages;
7393 gp_ci.pVertexInputState = &vi_ci;
7394 gp_ci.pInputAssemblyState = &ia_ci;
7395 gp_ci.pViewportState = &vp_state_ci;
7396 gp_ci.pRasterizationState = &rs_ci;
7397 gp_ci.pColorBlendState = &cb_ci;
7398 gp_ci.pDynamicState = &dyn_state_ci;
7399 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7400 gp_ci.layout = pipeline_layout;
7401 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007402
7403 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007404 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007405
7406 VkPipeline pipeline;
7407 VkPipelineCache pipelineCache;
7408
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007409 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007410 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007411 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007412
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007413 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007414
Tobin Ehlisd332f282015-10-02 11:00:56 -06007415 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007416 // First need to successfully create the PSO from above by setting
7417 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007418 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 -07007419
7420 VkViewport vp = {}; // Just need dummy vp to point to
7421 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007422 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007423 ASSERT_VK_SUCCESS(err);
7424 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007425 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007426 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007427 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007428 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007429 Draw(1, 0, 0, 0);
7430
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007431 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007432
7433 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7434 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7435 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7436 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007437 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007438}
7439// Create PSO w/o non-zero scissorCount but no scissor data
7440// Then run second test where dynamic viewportCount doesn't match PSO
7441// viewportCount
7442TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7443 VkResult err;
7444
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007445 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 -07007446
7447 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007448
7449 if (!m_device->phy().features().multiViewport) {
7450 printf("Device does not support multiple viewports/scissors; skipped.\n");
7451 return;
7452 }
7453
Karl Schultz6addd812016-02-02 17:17:23 -07007454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7455
7456 VkDescriptorPoolSize ds_type_count = {};
7457 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7458 ds_type_count.descriptorCount = 1;
7459
7460 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7461 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7462 ds_pool_ci.maxSets = 1;
7463 ds_pool_ci.poolSizeCount = 1;
7464 ds_pool_ci.pPoolSizes = &ds_type_count;
7465
7466 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007467 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007468 ASSERT_VK_SUCCESS(err);
7469
7470 VkDescriptorSetLayoutBinding dsl_binding = {};
7471 dsl_binding.binding = 0;
7472 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7473 dsl_binding.descriptorCount = 1;
7474 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7475
7476 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7477 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7478 ds_layout_ci.bindingCount = 1;
7479 ds_layout_ci.pBindings = &dsl_binding;
7480
7481 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007482 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007483 ASSERT_VK_SUCCESS(err);
7484
7485 VkDescriptorSet descriptorSet;
7486 VkDescriptorSetAllocateInfo alloc_info = {};
7487 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7488 alloc_info.descriptorSetCount = 1;
7489 alloc_info.descriptorPool = ds_pool;
7490 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007491 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007492 ASSERT_VK_SUCCESS(err);
7493
7494 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7495 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7496 pipeline_layout_ci.setLayoutCount = 1;
7497 pipeline_layout_ci.pSetLayouts = &ds_layout;
7498
7499 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007500 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007501 ASSERT_VK_SUCCESS(err);
7502
7503 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7504 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7505 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007506 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007507 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007508 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007509
7510 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7511 // Set scissor as dynamic to avoid that error
7512 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7513 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7514 dyn_state_ci.dynamicStateCount = 1;
7515 dyn_state_ci.pDynamicStates = &vp_state;
7516
7517 VkPipelineShaderStageCreateInfo shaderStages[2];
7518 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7519
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007520 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7521 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7522 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007523 shaderStages[0] = vs.GetStageCreateInfo();
7524 shaderStages[1] = fs.GetStageCreateInfo();
7525
7526 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7527 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7528 vi_ci.pNext = nullptr;
7529 vi_ci.vertexBindingDescriptionCount = 0;
7530 vi_ci.pVertexBindingDescriptions = nullptr;
7531 vi_ci.vertexAttributeDescriptionCount = 0;
7532 vi_ci.pVertexAttributeDescriptions = nullptr;
7533
7534 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7535 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7536 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7537
7538 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7539 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7540 rs_ci.pNext = nullptr;
7541
Mark Youngc89c6312016-03-31 16:03:20 -06007542 VkPipelineColorBlendAttachmentState att = {};
7543 att.blendEnable = VK_FALSE;
7544 att.colorWriteMask = 0xf;
7545
Karl Schultz6addd812016-02-02 17:17:23 -07007546 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7547 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7548 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007549 cb_ci.attachmentCount = 1;
7550 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007551
7552 VkGraphicsPipelineCreateInfo gp_ci = {};
7553 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7554 gp_ci.stageCount = 2;
7555 gp_ci.pStages = shaderStages;
7556 gp_ci.pVertexInputState = &vi_ci;
7557 gp_ci.pInputAssemblyState = &ia_ci;
7558 gp_ci.pViewportState = &vp_state_ci;
7559 gp_ci.pRasterizationState = &rs_ci;
7560 gp_ci.pColorBlendState = &cb_ci;
7561 gp_ci.pDynamicState = &dyn_state_ci;
7562 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7563 gp_ci.layout = pipeline_layout;
7564 gp_ci.renderPass = renderPass();
7565
7566 VkPipelineCacheCreateInfo pc_ci = {};
7567 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7568
7569 VkPipeline pipeline;
7570 VkPipelineCache pipelineCache;
7571
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007572 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007573 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007574 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007575
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007576 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007577
7578 // Now hit second fail case where we set scissor w/ different count than PSO
7579 // First need to successfully create the PSO from above by setting
7580 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007581 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 -06007582
Tobin Ehlisd332f282015-10-02 11:00:56 -06007583 VkRect2D sc = {}; // Just need dummy vp to point to
7584 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007585 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007586 ASSERT_VK_SUCCESS(err);
7587 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007588 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007589 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007590 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007591 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007592 Draw(1, 0, 0, 0);
7593
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007594 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007595
Chia-I Wuf7458c52015-10-26 21:10:41 +08007596 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7597 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7598 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7599 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007600 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007601}
7602
Mark Young7394fdd2016-03-31 14:56:43 -06007603TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7604 VkResult err;
7605
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007607
7608 ASSERT_NO_FATAL_FAILURE(InitState());
7609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7610
7611 VkDescriptorPoolSize ds_type_count = {};
7612 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7613 ds_type_count.descriptorCount = 1;
7614
7615 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7616 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7617 ds_pool_ci.maxSets = 1;
7618 ds_pool_ci.poolSizeCount = 1;
7619 ds_pool_ci.pPoolSizes = &ds_type_count;
7620
7621 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007622 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007623 ASSERT_VK_SUCCESS(err);
7624
7625 VkDescriptorSetLayoutBinding dsl_binding = {};
7626 dsl_binding.binding = 0;
7627 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7628 dsl_binding.descriptorCount = 1;
7629 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7630
7631 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7632 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7633 ds_layout_ci.bindingCount = 1;
7634 ds_layout_ci.pBindings = &dsl_binding;
7635
7636 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007637 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007638 ASSERT_VK_SUCCESS(err);
7639
7640 VkDescriptorSet descriptorSet;
7641 VkDescriptorSetAllocateInfo alloc_info = {};
7642 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7643 alloc_info.descriptorSetCount = 1;
7644 alloc_info.descriptorPool = ds_pool;
7645 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007646 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007647 ASSERT_VK_SUCCESS(err);
7648
7649 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7650 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7651 pipeline_layout_ci.setLayoutCount = 1;
7652 pipeline_layout_ci.pSetLayouts = &ds_layout;
7653
7654 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007655 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007656 ASSERT_VK_SUCCESS(err);
7657
7658 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7659 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7660 vp_state_ci.scissorCount = 1;
7661 vp_state_ci.pScissors = NULL;
7662 vp_state_ci.viewportCount = 1;
7663 vp_state_ci.pViewports = NULL;
7664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007665 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007666 // Set scissor as dynamic to avoid that error
7667 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7668 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7669 dyn_state_ci.dynamicStateCount = 2;
7670 dyn_state_ci.pDynamicStates = dynamic_states;
7671
7672 VkPipelineShaderStageCreateInfo shaderStages[2];
7673 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7674
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007675 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7676 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007677 this); // TODO - We shouldn't need a fragment shader
7678 // but add it to be able to run on more devices
7679 shaderStages[0] = vs.GetStageCreateInfo();
7680 shaderStages[1] = fs.GetStageCreateInfo();
7681
7682 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7683 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7684 vi_ci.pNext = nullptr;
7685 vi_ci.vertexBindingDescriptionCount = 0;
7686 vi_ci.pVertexBindingDescriptions = nullptr;
7687 vi_ci.vertexAttributeDescriptionCount = 0;
7688 vi_ci.pVertexAttributeDescriptions = nullptr;
7689
7690 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7691 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7692 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7693
7694 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7695 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7696 rs_ci.pNext = nullptr;
7697
Mark Young47107952016-05-02 15:59:55 -06007698 // Check too low (line width of -1.0f).
7699 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007700
7701 VkPipelineColorBlendAttachmentState att = {};
7702 att.blendEnable = VK_FALSE;
7703 att.colorWriteMask = 0xf;
7704
7705 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7706 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7707 cb_ci.pNext = nullptr;
7708 cb_ci.attachmentCount = 1;
7709 cb_ci.pAttachments = &att;
7710
7711 VkGraphicsPipelineCreateInfo gp_ci = {};
7712 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7713 gp_ci.stageCount = 2;
7714 gp_ci.pStages = shaderStages;
7715 gp_ci.pVertexInputState = &vi_ci;
7716 gp_ci.pInputAssemblyState = &ia_ci;
7717 gp_ci.pViewportState = &vp_state_ci;
7718 gp_ci.pRasterizationState = &rs_ci;
7719 gp_ci.pColorBlendState = &cb_ci;
7720 gp_ci.pDynamicState = &dyn_state_ci;
7721 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7722 gp_ci.layout = pipeline_layout;
7723 gp_ci.renderPass = renderPass();
7724
7725 VkPipelineCacheCreateInfo pc_ci = {};
7726 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7727
7728 VkPipeline pipeline;
7729 VkPipelineCache pipelineCache;
7730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007731 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007732 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007733 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007734
7735 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007736 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007737
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007739
7740 // Check too high (line width of 65536.0f).
7741 rs_ci.lineWidth = 65536.0f;
7742
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007743 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007744 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007745 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007746
7747 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007748 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007749
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007751
7752 dyn_state_ci.dynamicStateCount = 3;
7753
7754 rs_ci.lineWidth = 1.0f;
7755
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007756 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007757 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007758 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007759 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007760 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007761
7762 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007763 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007764 m_errorMonitor->VerifyFound();
7765
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007767
7768 // Check too high with dynamic setting.
7769 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7770 m_errorMonitor->VerifyFound();
7771 EndCommandBuffer();
7772
7773 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7774 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7775 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7776 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007777 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007778}
7779
Karl Schultz6addd812016-02-02 17:17:23 -07007780TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007781 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7783 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007784
7785 ASSERT_NO_FATAL_FAILURE(InitState());
7786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007787
Tony Barbourfe3351b2015-07-28 10:17:20 -06007788 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007789 // Don't care about RenderPass handle b/c error should be flagged before
7790 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007791 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007792
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007793 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007794}
7795
Karl Schultz6addd812016-02-02 17:17:23 -07007796TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007797 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7799 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007800
7801 ASSERT_NO_FATAL_FAILURE(InitState());
7802 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007803
Tony Barbourfe3351b2015-07-28 10:17:20 -06007804 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007805 // Just create a dummy Renderpass that's non-NULL so we can get to the
7806 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007807 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007808
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007809 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007810}
7811
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007812TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7813 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7814 "the number of renderPass attachments that use loadOp"
7815 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7816
7817 ASSERT_NO_FATAL_FAILURE(InitState());
7818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7819
7820 // Create a renderPass with a single attachment that uses loadOp CLEAR
7821 VkAttachmentReference attach = {};
7822 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7823 VkSubpassDescription subpass = {};
7824 subpass.inputAttachmentCount = 1;
7825 subpass.pInputAttachments = &attach;
7826 VkRenderPassCreateInfo rpci = {};
7827 rpci.subpassCount = 1;
7828 rpci.pSubpasses = &subpass;
7829 rpci.attachmentCount = 1;
7830 VkAttachmentDescription attach_desc = {};
7831 attach_desc.format = VK_FORMAT_UNDEFINED;
7832 // Set loadOp to CLEAR
7833 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7834 rpci.pAttachments = &attach_desc;
7835 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7836 VkRenderPass rp;
7837 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7838
7839 VkCommandBufferInheritanceInfo hinfo = {};
7840 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7841 hinfo.renderPass = VK_NULL_HANDLE;
7842 hinfo.subpass = 0;
7843 hinfo.framebuffer = VK_NULL_HANDLE;
7844 hinfo.occlusionQueryEnable = VK_FALSE;
7845 hinfo.queryFlags = 0;
7846 hinfo.pipelineStatistics = 0;
7847 VkCommandBufferBeginInfo info = {};
7848 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7849 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7850 info.pInheritanceInfo = &hinfo;
7851
7852 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7853 VkRenderPassBeginInfo rp_begin = {};
7854 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7855 rp_begin.pNext = NULL;
7856 rp_begin.renderPass = renderPass();
7857 rp_begin.framebuffer = framebuffer();
7858 rp_begin.clearValueCount = 0; // Should be 1
7859
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7861 "there must be at least 1 entries in "
7862 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007863
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007864 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007865
7866 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007867
7868 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007869}
7870
Cody Northrop3bb4d962016-05-09 16:15:57 -06007871TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7872
7873 TEST_DESCRIPTION("End a command buffer with an active render pass");
7874
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7876 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007877
7878 ASSERT_NO_FATAL_FAILURE(InitState());
7879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7880
7881 // The framework's BeginCommandBuffer calls CreateRenderPass
7882 BeginCommandBuffer();
7883
7884 // Call directly into vkEndCommandBuffer instead of the
7885 // the framework's EndCommandBuffer, which inserts a
7886 // vkEndRenderPass
7887 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7888
7889 m_errorMonitor->VerifyFound();
7890
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007891 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7892 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007893}
7894
Karl Schultz6addd812016-02-02 17:17:23 -07007895TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007896 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7898 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007899
7900 ASSERT_NO_FATAL_FAILURE(InitState());
7901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007902
7903 // Renderpass is started here
7904 BeginCommandBuffer();
7905
7906 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007907 vk_testing::Buffer dstBuffer;
7908 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007909
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007910 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007911
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007912 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007913}
7914
Karl Schultz6addd812016-02-02 17:17:23 -07007915TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007916 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7918 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007919
7920 ASSERT_NO_FATAL_FAILURE(InitState());
7921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007922
7923 // Renderpass is started here
7924 BeginCommandBuffer();
7925
7926 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007927 vk_testing::Buffer dstBuffer;
7928 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007929
Karl Schultz6addd812016-02-02 17:17:23 -07007930 VkDeviceSize dstOffset = 0;
7931 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007932 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007935
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007936 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007937}
7938
Karl Schultz6addd812016-02-02 17:17:23 -07007939TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007940 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7942 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007943
7944 ASSERT_NO_FATAL_FAILURE(InitState());
7945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007946
7947 // Renderpass is started here
7948 BeginCommandBuffer();
7949
Michael Lentine0a369f62016-02-03 16:51:46 -06007950 VkClearColorValue clear_color;
7951 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007952 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7953 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7954 const int32_t tex_width = 32;
7955 const int32_t tex_height = 32;
7956 VkImageCreateInfo image_create_info = {};
7957 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7958 image_create_info.pNext = NULL;
7959 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7960 image_create_info.format = tex_format;
7961 image_create_info.extent.width = tex_width;
7962 image_create_info.extent.height = tex_height;
7963 image_create_info.extent.depth = 1;
7964 image_create_info.mipLevels = 1;
7965 image_create_info.arrayLayers = 1;
7966 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7967 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7968 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007969
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007970 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007971 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007972
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007973 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007974
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007975 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007976
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007977 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007978}
7979
Karl Schultz6addd812016-02-02 17:17:23 -07007980TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007981 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7983 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007984
7985 ASSERT_NO_FATAL_FAILURE(InitState());
7986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007987
7988 // Renderpass is started here
7989 BeginCommandBuffer();
7990
7991 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007992 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007993 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7994 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7995 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7996 image_create_info.extent.width = 64;
7997 image_create_info.extent.height = 64;
7998 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7999 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008000
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008001 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008002 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008004 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008005
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008006 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8007 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008008
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008009 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008010}
8011
Karl Schultz6addd812016-02-02 17:17:23 -07008012TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008013 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008014 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008015
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8017 "must be issued inside an active "
8018 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008019
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008020 ASSERT_NO_FATAL_FAILURE(InitState());
8021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008022
8023 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008024 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008025 ASSERT_VK_SUCCESS(err);
8026
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008027 VkClearAttachment color_attachment;
8028 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8029 color_attachment.clearValue.color.float32[0] = 0;
8030 color_attachment.clearValue.color.float32[1] = 0;
8031 color_attachment.clearValue.color.float32[2] = 0;
8032 color_attachment.clearValue.color.float32[3] = 0;
8033 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008034 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008035 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008036
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008037 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008038}
8039
Chris Forbes3b97e932016-09-07 11:29:24 +12008040TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8041 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8042 "called too many times in a renderpass instance");
8043
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8045 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008046
8047 ASSERT_NO_FATAL_FAILURE(InitState());
8048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8049
8050 BeginCommandBuffer();
8051
8052 // error here.
8053 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8054 m_errorMonitor->VerifyFound();
8055
8056 EndCommandBuffer();
8057}
8058
Chris Forbes6d624702016-09-07 13:57:05 +12008059TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8060 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8061 "called before the final subpass has been reached");
8062
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8064 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008065
8066 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008067 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8068 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008069
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008070 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008071
8072 VkRenderPass rp;
8073 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8074 ASSERT_VK_SUCCESS(err);
8075
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008076 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008077
8078 VkFramebuffer fb;
8079 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8080 ASSERT_VK_SUCCESS(err);
8081
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008082 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008083
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008084 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 +12008085
8086 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8087
8088 // Error here.
8089 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8090 m_errorMonitor->VerifyFound();
8091
8092 // Clean up.
8093 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8094 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8095}
8096
Karl Schultz9e66a292016-04-21 15:57:51 -06008097TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8098 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8100 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008101
8102 ASSERT_NO_FATAL_FAILURE(InitState());
8103 BeginCommandBuffer();
8104
8105 VkBufferMemoryBarrier buf_barrier = {};
8106 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8107 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8108 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8109 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8110 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8111 buf_barrier.buffer = VK_NULL_HANDLE;
8112 buf_barrier.offset = 0;
8113 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008114 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8115 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008116
8117 m_errorMonitor->VerifyFound();
8118}
8119
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008120TEST_F(VkLayerTest, InvalidBarriers) {
8121 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008124
8125 ASSERT_NO_FATAL_FAILURE(InitState());
8126 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8127
8128 VkMemoryBarrier mem_barrier = {};
8129 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8130 mem_barrier.pNext = NULL;
8131 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8132 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8133 BeginCommandBuffer();
8134 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008135 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008136 &mem_barrier, 0, nullptr, 0, nullptr);
8137 m_errorMonitor->VerifyFound();
8138
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008140 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008141 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 -06008142 ASSERT_TRUE(image.initialized());
8143 VkImageMemoryBarrier img_barrier = {};
8144 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8145 img_barrier.pNext = NULL;
8146 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8147 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8148 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8149 // New layout can't be UNDEFINED
8150 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8151 img_barrier.image = image.handle();
8152 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8153 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8154 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8155 img_barrier.subresourceRange.baseArrayLayer = 0;
8156 img_barrier.subresourceRange.baseMipLevel = 0;
8157 img_barrier.subresourceRange.layerCount = 1;
8158 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008159 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8160 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008161 m_errorMonitor->VerifyFound();
8162 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8163
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8165 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008166 // baseArrayLayer + layerCount must be <= image's arrayLayers
8167 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008168 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8169 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008170 m_errorMonitor->VerifyFound();
8171 img_barrier.subresourceRange.baseArrayLayer = 0;
8172
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008174 // baseMipLevel + levelCount must be <= image's mipLevels
8175 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8177 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008178 m_errorMonitor->VerifyFound();
8179 img_barrier.subresourceRange.baseMipLevel = 0;
8180
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008181 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 -06008182 vk_testing::Buffer buffer;
8183 buffer.init(*m_device, 256);
8184 VkBufferMemoryBarrier buf_barrier = {};
8185 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8186 buf_barrier.pNext = NULL;
8187 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8188 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8189 buf_barrier.buffer = buffer.handle();
8190 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8191 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8192 buf_barrier.offset = 0;
8193 buf_barrier.size = VK_WHOLE_SIZE;
8194 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008195 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8196 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008197 m_errorMonitor->VerifyFound();
8198 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8199
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008201 buf_barrier.offset = 257;
8202 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008203 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8204 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008205 m_errorMonitor->VerifyFound();
8206 buf_barrier.offset = 0;
8207
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008209 buf_barrier.size = 257;
8210 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008211 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8212 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008213 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008214
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008215 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008216 m_errorMonitor->SetDesiredFailureMsg(
8217 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8218 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8219 m_errorMonitor->SetDesiredFailureMsg(
8220 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8221 "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 -06008222 VkDepthStencilObj ds_image(m_device);
8223 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8224 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008225 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8226 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008227 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008228 // Use of COLOR aspect on DS image is error
8229 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008230 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8231 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008232 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008233 // Now test depth-only
8234 VkFormatProperties format_props;
8235
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008236 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8237 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8239 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8241 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008242 VkDepthStencilObj d_image(m_device);
8243 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8244 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008245 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008246 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008247 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008248 // Use of COLOR aspect on depth image is error
8249 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008250 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8251 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008252 m_errorMonitor->VerifyFound();
8253 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008254 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8255 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008256 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8258 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008259 VkDepthStencilObj s_image(m_device);
8260 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8261 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008262 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008263 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008264 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008265 // Use of COLOR aspect on depth image is error
8266 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008267 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8268 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008269 m_errorMonitor->VerifyFound();
8270 }
8271 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8273 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8275 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008276 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008277 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 -06008278 ASSERT_TRUE(c_image.initialized());
8279 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8280 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8281 img_barrier.image = c_image.handle();
8282 // Set aspect to depth (non-color)
8283 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008284 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8285 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008286 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008287}
8288
Tony Barbour18ba25c2016-09-29 13:42:40 -06008289TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8290 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8291
8292 m_errorMonitor->SetDesiredFailureMsg(
8293 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8294 "must have required access bit");
8295 ASSERT_NO_FATAL_FAILURE(InitState());
8296 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008297 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 -06008298 ASSERT_TRUE(image.initialized());
8299
8300 VkImageMemoryBarrier barrier = {};
8301 VkImageSubresourceRange range;
8302 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8303 barrier.srcAccessMask = 0;
8304 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8305 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8306 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8307 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8308 barrier.image = image.handle();
8309 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8310 range.baseMipLevel = 0;
8311 range.levelCount = 1;
8312 range.baseArrayLayer = 0;
8313 range.layerCount = 1;
8314 barrier.subresourceRange = range;
8315 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8316 cmdbuf.BeginCommandBuffer();
8317 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8318 &barrier);
8319 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8320 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8321 barrier.srcAccessMask = 0;
8322 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8323 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8324 &barrier);
8325
8326 m_errorMonitor->VerifyFound();
8327}
8328
Karl Schultz6addd812016-02-02 17:17:23 -07008329TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008330 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008331 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008332
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008334
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008335 ASSERT_NO_FATAL_FAILURE(InitState());
8336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008337 uint32_t qfi = 0;
8338 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008339 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8340 buffCI.size = 1024;
8341 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8342 buffCI.queueFamilyIndexCount = 1;
8343 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008344
8345 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008346 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008347 ASSERT_VK_SUCCESS(err);
8348
8349 BeginCommandBuffer();
8350 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008351 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8352 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008353 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008354 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008355
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008356 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008357
Chia-I Wuf7458c52015-10-26 21:10:41 +08008358 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008359}
8360
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008361TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8362 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8364 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8365 "of the indices specified when the device was created, via the "
8366 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008367
8368 ASSERT_NO_FATAL_FAILURE(InitState());
8369 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8370 VkBufferCreateInfo buffCI = {};
8371 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8372 buffCI.size = 1024;
8373 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8374 buffCI.queueFamilyIndexCount = 1;
8375 // Introduce failure by specifying invalid queue_family_index
8376 uint32_t qfi = 777;
8377 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008378 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008379
8380 VkBuffer ib;
8381 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8382
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008383 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008384 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008385}
8386
Karl Schultz6addd812016-02-02 17:17:23 -07008387TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008388TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008389 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008390
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008391 ASSERT_NO_FATAL_FAILURE(InitState());
8392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008393
Chris Forbesf29a84f2016-10-06 18:39:28 +13008394 // An empty primary command buffer
8395 VkCommandBufferObj cb(m_device, m_commandPool);
8396 cb.BeginCommandBuffer();
8397 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008398
Chris Forbesf29a84f2016-10-06 18:39:28 +13008399 m_commandBuffer->BeginCommandBuffer();
8400 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8401 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008402
Chris Forbesf29a84f2016-10-06 18:39:28 +13008403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8404 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008405 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008406}
8407
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008408TEST_F(VkLayerTest, DSUsageBitsErrors) {
8409 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8410 "that do not have correct usage bits sets.");
8411 VkResult err;
8412
8413 ASSERT_NO_FATAL_FAILURE(InitState());
8414 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8415 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8416 ds_type_count[i].type = VkDescriptorType(i);
8417 ds_type_count[i].descriptorCount = 1;
8418 }
8419 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8420 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8421 ds_pool_ci.pNext = NULL;
8422 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8423 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8424 ds_pool_ci.pPoolSizes = ds_type_count;
8425
8426 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008427 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008428 ASSERT_VK_SUCCESS(err);
8429
8430 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008431 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008432 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8433 dsl_binding[i].binding = 0;
8434 dsl_binding[i].descriptorType = VkDescriptorType(i);
8435 dsl_binding[i].descriptorCount = 1;
8436 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8437 dsl_binding[i].pImmutableSamplers = NULL;
8438 }
8439
8440 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8441 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8442 ds_layout_ci.pNext = NULL;
8443 ds_layout_ci.bindingCount = 1;
8444 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8445 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8446 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008447 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008448 ASSERT_VK_SUCCESS(err);
8449 }
8450 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8451 VkDescriptorSetAllocateInfo alloc_info = {};
8452 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8453 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8454 alloc_info.descriptorPool = ds_pool;
8455 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008456 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008457 ASSERT_VK_SUCCESS(err);
8458
8459 // Create a buffer & bufferView to be used for invalid updates
8460 VkBufferCreateInfo buff_ci = {};
8461 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8462 // This usage is not valid for any descriptor type
8463 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8464 buff_ci.size = 256;
8465 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8466 VkBuffer buffer;
8467 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8468 ASSERT_VK_SUCCESS(err);
8469
8470 VkBufferViewCreateInfo buff_view_ci = {};
8471 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8472 buff_view_ci.buffer = buffer;
8473 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8474 buff_view_ci.range = VK_WHOLE_SIZE;
8475 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008476 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008477 ASSERT_VK_SUCCESS(err);
8478
8479 // Create an image to be used for invalid updates
8480 VkImageCreateInfo image_ci = {};
8481 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8482 image_ci.imageType = VK_IMAGE_TYPE_2D;
8483 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8484 image_ci.extent.width = 64;
8485 image_ci.extent.height = 64;
8486 image_ci.extent.depth = 1;
8487 image_ci.mipLevels = 1;
8488 image_ci.arrayLayers = 1;
8489 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8490 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8491 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8492 // This usage is not valid for any descriptor type
8493 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8494 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8495 VkImage image;
8496 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8497 ASSERT_VK_SUCCESS(err);
8498 // Bind memory to image
8499 VkMemoryRequirements mem_reqs;
8500 VkDeviceMemory image_mem;
8501 bool pass;
8502 VkMemoryAllocateInfo mem_alloc = {};
8503 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8504 mem_alloc.pNext = NULL;
8505 mem_alloc.allocationSize = 0;
8506 mem_alloc.memoryTypeIndex = 0;
8507 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8508 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008509 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008510 ASSERT_TRUE(pass);
8511 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8512 ASSERT_VK_SUCCESS(err);
8513 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8514 ASSERT_VK_SUCCESS(err);
8515 // Now create view for image
8516 VkImageViewCreateInfo image_view_ci = {};
8517 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8518 image_view_ci.image = image;
8519 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8520 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8521 image_view_ci.subresourceRange.layerCount = 1;
8522 image_view_ci.subresourceRange.baseArrayLayer = 0;
8523 image_view_ci.subresourceRange.levelCount = 1;
8524 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8525 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008526 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008527 ASSERT_VK_SUCCESS(err);
8528
8529 VkDescriptorBufferInfo buff_info = {};
8530 buff_info.buffer = buffer;
8531 VkDescriptorImageInfo img_info = {};
8532 img_info.imageView = image_view;
8533 VkWriteDescriptorSet descriptor_write = {};
8534 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8535 descriptor_write.dstBinding = 0;
8536 descriptor_write.descriptorCount = 1;
8537 descriptor_write.pTexelBufferView = &buff_view;
8538 descriptor_write.pBufferInfo = &buff_info;
8539 descriptor_write.pImageInfo = &img_info;
8540
8541 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008542 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8543 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8544 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8545 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8546 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8547 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8548 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8549 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8550 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8551 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8552 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008553 // Start loop at 1 as SAMPLER desc type has no usage bit error
8554 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8555 descriptor_write.descriptorType = VkDescriptorType(i);
8556 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008558
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008559 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008560
8561 m_errorMonitor->VerifyFound();
8562 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8563 }
8564 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8565 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008566 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008567 vkDestroyImageView(m_device->device(), image_view, NULL);
8568 vkDestroyBuffer(m_device->device(), buffer, NULL);
8569 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008570 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008571 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8572}
8573
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008574TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008575 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8576 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8577 "1. offset value greater than buffer size\n"
8578 "2. range value of 0\n"
8579 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008580 VkResult err;
8581
8582 ASSERT_NO_FATAL_FAILURE(InitState());
8583 VkDescriptorPoolSize ds_type_count = {};
8584 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8585 ds_type_count.descriptorCount = 1;
8586
8587 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8588 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8589 ds_pool_ci.pNext = NULL;
8590 ds_pool_ci.maxSets = 1;
8591 ds_pool_ci.poolSizeCount = 1;
8592 ds_pool_ci.pPoolSizes = &ds_type_count;
8593
8594 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008595 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008596 ASSERT_VK_SUCCESS(err);
8597
8598 // Create layout with single uniform buffer descriptor
8599 VkDescriptorSetLayoutBinding dsl_binding = {};
8600 dsl_binding.binding = 0;
8601 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8602 dsl_binding.descriptorCount = 1;
8603 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8604 dsl_binding.pImmutableSamplers = NULL;
8605
8606 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8607 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8608 ds_layout_ci.pNext = NULL;
8609 ds_layout_ci.bindingCount = 1;
8610 ds_layout_ci.pBindings = &dsl_binding;
8611 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008612 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008613 ASSERT_VK_SUCCESS(err);
8614
8615 VkDescriptorSet descriptor_set = {};
8616 VkDescriptorSetAllocateInfo alloc_info = {};
8617 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8618 alloc_info.descriptorSetCount = 1;
8619 alloc_info.descriptorPool = ds_pool;
8620 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008621 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008622 ASSERT_VK_SUCCESS(err);
8623
8624 // Create a buffer to be used for invalid updates
8625 VkBufferCreateInfo buff_ci = {};
8626 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8627 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8628 buff_ci.size = 256;
8629 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8630 VkBuffer buffer;
8631 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8632 ASSERT_VK_SUCCESS(err);
8633 // Have to bind memory to buffer before descriptor update
8634 VkMemoryAllocateInfo mem_alloc = {};
8635 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8636 mem_alloc.pNext = NULL;
8637 mem_alloc.allocationSize = 256;
8638 mem_alloc.memoryTypeIndex = 0;
8639
8640 VkMemoryRequirements mem_reqs;
8641 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008642 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008643 if (!pass) {
8644 vkDestroyBuffer(m_device->device(), buffer, NULL);
8645 return;
8646 }
8647
8648 VkDeviceMemory mem;
8649 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8650 ASSERT_VK_SUCCESS(err);
8651 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8652 ASSERT_VK_SUCCESS(err);
8653
8654 VkDescriptorBufferInfo buff_info = {};
8655 buff_info.buffer = buffer;
8656 // First make offset 1 larger than buffer size
8657 buff_info.offset = 257;
8658 buff_info.range = VK_WHOLE_SIZE;
8659 VkWriteDescriptorSet descriptor_write = {};
8660 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8661 descriptor_write.dstBinding = 0;
8662 descriptor_write.descriptorCount = 1;
8663 descriptor_write.pTexelBufferView = nullptr;
8664 descriptor_write.pBufferInfo = &buff_info;
8665 descriptor_write.pImageInfo = nullptr;
8666
8667 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8668 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008670
8671 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8672
8673 m_errorMonitor->VerifyFound();
8674 // Now cause error due to range of 0
8675 buff_info.offset = 0;
8676 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8678 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008679
8680 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8681
8682 m_errorMonitor->VerifyFound();
8683 // Now cause error due to range exceeding buffer size - offset
8684 buff_info.offset = 128;
8685 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008686 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 -06008687
8688 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8689
8690 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008691 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008692 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8693 vkDestroyBuffer(m_device->device(), buffer, NULL);
8694 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8695 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8696}
8697
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008698TEST_F(VkLayerTest, DSAspectBitsErrors) {
8699 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8700 // are set, but could expand this test to hit more cases.
8701 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8702 "that do not have correct aspect bits sets.");
8703 VkResult err;
8704
8705 ASSERT_NO_FATAL_FAILURE(InitState());
8706 VkDescriptorPoolSize ds_type_count = {};
8707 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8708 ds_type_count.descriptorCount = 1;
8709
8710 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8711 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8712 ds_pool_ci.pNext = NULL;
8713 ds_pool_ci.maxSets = 5;
8714 ds_pool_ci.poolSizeCount = 1;
8715 ds_pool_ci.pPoolSizes = &ds_type_count;
8716
8717 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008718 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008719 ASSERT_VK_SUCCESS(err);
8720
8721 VkDescriptorSetLayoutBinding dsl_binding = {};
8722 dsl_binding.binding = 0;
8723 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8724 dsl_binding.descriptorCount = 1;
8725 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8726 dsl_binding.pImmutableSamplers = NULL;
8727
8728 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8729 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8730 ds_layout_ci.pNext = NULL;
8731 ds_layout_ci.bindingCount = 1;
8732 ds_layout_ci.pBindings = &dsl_binding;
8733 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008734 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008735 ASSERT_VK_SUCCESS(err);
8736
8737 VkDescriptorSet descriptor_set = {};
8738 VkDescriptorSetAllocateInfo alloc_info = {};
8739 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8740 alloc_info.descriptorSetCount = 1;
8741 alloc_info.descriptorPool = ds_pool;
8742 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008743 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008744 ASSERT_VK_SUCCESS(err);
8745
8746 // Create an image to be used for invalid updates
8747 VkImageCreateInfo image_ci = {};
8748 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8749 image_ci.imageType = VK_IMAGE_TYPE_2D;
8750 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8751 image_ci.extent.width = 64;
8752 image_ci.extent.height = 64;
8753 image_ci.extent.depth = 1;
8754 image_ci.mipLevels = 1;
8755 image_ci.arrayLayers = 1;
8756 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8757 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8758 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8759 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8760 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8761 VkImage image;
8762 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8763 ASSERT_VK_SUCCESS(err);
8764 // Bind memory to image
8765 VkMemoryRequirements mem_reqs;
8766 VkDeviceMemory image_mem;
8767 bool pass;
8768 VkMemoryAllocateInfo mem_alloc = {};
8769 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8770 mem_alloc.pNext = NULL;
8771 mem_alloc.allocationSize = 0;
8772 mem_alloc.memoryTypeIndex = 0;
8773 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8774 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008775 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008776 ASSERT_TRUE(pass);
8777 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8778 ASSERT_VK_SUCCESS(err);
8779 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8780 ASSERT_VK_SUCCESS(err);
8781 // Now create view for image
8782 VkImageViewCreateInfo image_view_ci = {};
8783 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8784 image_view_ci.image = image;
8785 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8786 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8787 image_view_ci.subresourceRange.layerCount = 1;
8788 image_view_ci.subresourceRange.baseArrayLayer = 0;
8789 image_view_ci.subresourceRange.levelCount = 1;
8790 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008791 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008792
8793 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008794 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008795 ASSERT_VK_SUCCESS(err);
8796
8797 VkDescriptorImageInfo img_info = {};
8798 img_info.imageView = image_view;
8799 VkWriteDescriptorSet descriptor_write = {};
8800 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8801 descriptor_write.dstBinding = 0;
8802 descriptor_write.descriptorCount = 1;
8803 descriptor_write.pTexelBufferView = NULL;
8804 descriptor_write.pBufferInfo = NULL;
8805 descriptor_write.pImageInfo = &img_info;
8806 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8807 descriptor_write.dstSet = descriptor_set;
8808 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8809 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008811
8812 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8813
8814 m_errorMonitor->VerifyFound();
8815 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8816 vkDestroyImage(m_device->device(), image, NULL);
8817 vkFreeMemory(m_device->device(), image_mem, NULL);
8818 vkDestroyImageView(m_device->device(), image_view, NULL);
8819 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8820 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8821}
8822
Karl Schultz6addd812016-02-02 17:17:23 -07008823TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008824 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008825 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008826
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8828 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8829 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008830
Tobin Ehlis3b780662015-05-28 12:11:26 -06008831 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008832 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008833 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008834 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8835 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008836
8837 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008838 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8839 ds_pool_ci.pNext = NULL;
8840 ds_pool_ci.maxSets = 1;
8841 ds_pool_ci.poolSizeCount = 1;
8842 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008843
Tobin Ehlis3b780662015-05-28 12:11:26 -06008844 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008845 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008846 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008847 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008848 dsl_binding.binding = 0;
8849 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8850 dsl_binding.descriptorCount = 1;
8851 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8852 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008853
Tony Barboureb254902015-07-15 12:50:33 -06008854 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008855 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8856 ds_layout_ci.pNext = NULL;
8857 ds_layout_ci.bindingCount = 1;
8858 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008859
Tobin Ehlis3b780662015-05-28 12:11:26 -06008860 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008862 ASSERT_VK_SUCCESS(err);
8863
8864 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008865 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008867 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008868 alloc_info.descriptorPool = ds_pool;
8869 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008871 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008872
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008873 VkSamplerCreateInfo sampler_ci = {};
8874 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8875 sampler_ci.pNext = NULL;
8876 sampler_ci.magFilter = VK_FILTER_NEAREST;
8877 sampler_ci.minFilter = VK_FILTER_NEAREST;
8878 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8879 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8880 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8881 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8882 sampler_ci.mipLodBias = 1.0;
8883 sampler_ci.anisotropyEnable = VK_FALSE;
8884 sampler_ci.maxAnisotropy = 1;
8885 sampler_ci.compareEnable = VK_FALSE;
8886 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8887 sampler_ci.minLod = 1.0;
8888 sampler_ci.maxLod = 1.0;
8889 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8890 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8891 VkSampler sampler;
8892 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8893 ASSERT_VK_SUCCESS(err);
8894
8895 VkDescriptorImageInfo info = {};
8896 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008897
8898 VkWriteDescriptorSet descriptor_write;
8899 memset(&descriptor_write, 0, sizeof(descriptor_write));
8900 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008901 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008902 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008903 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008904 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008905 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008906
8907 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8908
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008909 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008910
Chia-I Wuf7458c52015-10-26 21:10:41 +08008911 vkDestroySampler(m_device->device(), sampler, NULL);
8912 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8913 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008914}
8915
Karl Schultz6addd812016-02-02 17:17:23 -07008916TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008917 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008918 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008919
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8921 " binding #0 with 1 total descriptors but update of 1 descriptors "
8922 "starting at binding offset of 0 combined with update array element "
8923 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008924
Tobin Ehlis3b780662015-05-28 12:11:26 -06008925 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008926 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008927 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008928 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8929 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008930
8931 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008932 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8933 ds_pool_ci.pNext = NULL;
8934 ds_pool_ci.maxSets = 1;
8935 ds_pool_ci.poolSizeCount = 1;
8936 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008937
Tobin Ehlis3b780662015-05-28 12:11:26 -06008938 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008939 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008940 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008941
Tony Barboureb254902015-07-15 12:50:33 -06008942 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008943 dsl_binding.binding = 0;
8944 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8945 dsl_binding.descriptorCount = 1;
8946 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8947 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008948
8949 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008950 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8951 ds_layout_ci.pNext = NULL;
8952 ds_layout_ci.bindingCount = 1;
8953 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008954
Tobin Ehlis3b780662015-05-28 12:11:26 -06008955 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008956 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008957 ASSERT_VK_SUCCESS(err);
8958
8959 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008960 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008961 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008962 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008963 alloc_info.descriptorPool = ds_pool;
8964 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008965 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008966 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008967
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008968 // Correctly update descriptor to avoid "NOT_UPDATED" error
8969 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008970 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008971 buff_info.offset = 0;
8972 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008973
8974 VkWriteDescriptorSet descriptor_write;
8975 memset(&descriptor_write, 0, sizeof(descriptor_write));
8976 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008977 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008978 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008979 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008980 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8981 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008982
8983 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8984
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008985 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008986
Chia-I Wuf7458c52015-10-26 21:10:41 +08008987 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8988 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008989}
8990
Karl Schultz6addd812016-02-02 17:17:23 -07008991TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008992 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07008993 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008994
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008996
Tobin Ehlis3b780662015-05-28 12:11:26 -06008997 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008998 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008999 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009000 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9001 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009002
9003 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009004 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9005 ds_pool_ci.pNext = NULL;
9006 ds_pool_ci.maxSets = 1;
9007 ds_pool_ci.poolSizeCount = 1;
9008 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009009
Tobin Ehlis3b780662015-05-28 12:11:26 -06009010 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009011 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009012 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009013
Tony Barboureb254902015-07-15 12:50:33 -06009014 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009015 dsl_binding.binding = 0;
9016 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9017 dsl_binding.descriptorCount = 1;
9018 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9019 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009020
9021 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009022 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9023 ds_layout_ci.pNext = NULL;
9024 ds_layout_ci.bindingCount = 1;
9025 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009026 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009027 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009028 ASSERT_VK_SUCCESS(err);
9029
9030 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009031 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009032 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009033 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009034 alloc_info.descriptorPool = ds_pool;
9035 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009036 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009037 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009038
Tony Barboureb254902015-07-15 12:50:33 -06009039 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009040 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9041 sampler_ci.pNext = NULL;
9042 sampler_ci.magFilter = VK_FILTER_NEAREST;
9043 sampler_ci.minFilter = VK_FILTER_NEAREST;
9044 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9045 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9046 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9047 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9048 sampler_ci.mipLodBias = 1.0;
9049 sampler_ci.anisotropyEnable = VK_FALSE;
9050 sampler_ci.maxAnisotropy = 1;
9051 sampler_ci.compareEnable = VK_FALSE;
9052 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9053 sampler_ci.minLod = 1.0;
9054 sampler_ci.maxLod = 1.0;
9055 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9056 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009057
Tobin Ehlis3b780662015-05-28 12:11:26 -06009058 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009059 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009060 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009061
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009062 VkDescriptorImageInfo info = {};
9063 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009064
9065 VkWriteDescriptorSet descriptor_write;
9066 memset(&descriptor_write, 0, sizeof(descriptor_write));
9067 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009068 descriptor_write.dstSet = descriptorSet;
9069 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009070 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009071 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009072 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009073 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009074
9075 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9076
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009077 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009078
Chia-I Wuf7458c52015-10-26 21:10:41 +08009079 vkDestroySampler(m_device->device(), sampler, NULL);
9080 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9081 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009082}
9083
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009084TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9085 // Create layout w/ empty binding and attempt to update it
9086 VkResult err;
9087
9088 ASSERT_NO_FATAL_FAILURE(InitState());
9089
9090 VkDescriptorPoolSize ds_type_count = {};
9091 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9092 ds_type_count.descriptorCount = 1;
9093
9094 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9095 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9096 ds_pool_ci.pNext = NULL;
9097 ds_pool_ci.maxSets = 1;
9098 ds_pool_ci.poolSizeCount = 1;
9099 ds_pool_ci.pPoolSizes = &ds_type_count;
9100
9101 VkDescriptorPool ds_pool;
9102 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9103 ASSERT_VK_SUCCESS(err);
9104
9105 VkDescriptorSetLayoutBinding dsl_binding = {};
9106 dsl_binding.binding = 0;
9107 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9108 dsl_binding.descriptorCount = 0;
9109 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9110 dsl_binding.pImmutableSamplers = NULL;
9111
9112 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9113 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9114 ds_layout_ci.pNext = NULL;
9115 ds_layout_ci.bindingCount = 1;
9116 ds_layout_ci.pBindings = &dsl_binding;
9117 VkDescriptorSetLayout ds_layout;
9118 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9119 ASSERT_VK_SUCCESS(err);
9120
9121 VkDescriptorSet descriptor_set;
9122 VkDescriptorSetAllocateInfo alloc_info = {};
9123 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9124 alloc_info.descriptorSetCount = 1;
9125 alloc_info.descriptorPool = ds_pool;
9126 alloc_info.pSetLayouts = &ds_layout;
9127 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9128 ASSERT_VK_SUCCESS(err);
9129
9130 VkSamplerCreateInfo sampler_ci = {};
9131 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9132 sampler_ci.magFilter = VK_FILTER_NEAREST;
9133 sampler_ci.minFilter = VK_FILTER_NEAREST;
9134 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9135 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9136 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9137 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9138 sampler_ci.mipLodBias = 1.0;
9139 sampler_ci.maxAnisotropy = 1;
9140 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9141 sampler_ci.minLod = 1.0;
9142 sampler_ci.maxLod = 1.0;
9143 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9144
9145 VkSampler sampler;
9146 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9147 ASSERT_VK_SUCCESS(err);
9148
9149 VkDescriptorImageInfo info = {};
9150 info.sampler = sampler;
9151
9152 VkWriteDescriptorSet descriptor_write;
9153 memset(&descriptor_write, 0, sizeof(descriptor_write));
9154 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9155 descriptor_write.dstSet = descriptor_set;
9156 descriptor_write.dstBinding = 0;
9157 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9158 // This is the wrong type, but empty binding error will be flagged first
9159 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9160 descriptor_write.pImageInfo = &info;
9161
9162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9163 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9164 m_errorMonitor->VerifyFound();
9165
9166 vkDestroySampler(m_device->device(), sampler, NULL);
9167 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9168 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9169}
9170
Karl Schultz6addd812016-02-02 17:17:23 -07009171TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9172 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9173 // types
9174 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009176 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 -06009177
Tobin Ehlis3b780662015-05-28 12:11:26 -06009178 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009179
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009180 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009181 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9182 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009183
9184 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009185 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9186 ds_pool_ci.pNext = NULL;
9187 ds_pool_ci.maxSets = 1;
9188 ds_pool_ci.poolSizeCount = 1;
9189 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009190
Tobin Ehlis3b780662015-05-28 12:11:26 -06009191 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009192 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009193 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009194 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009195 dsl_binding.binding = 0;
9196 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9197 dsl_binding.descriptorCount = 1;
9198 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9199 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009200
Tony Barboureb254902015-07-15 12:50:33 -06009201 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009202 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9203 ds_layout_ci.pNext = NULL;
9204 ds_layout_ci.bindingCount = 1;
9205 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009206
Tobin Ehlis3b780662015-05-28 12:11:26 -06009207 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009208 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009209 ASSERT_VK_SUCCESS(err);
9210
9211 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009212 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009213 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009214 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009215 alloc_info.descriptorPool = ds_pool;
9216 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009217 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009218 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009219
Tony Barboureb254902015-07-15 12:50:33 -06009220 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009221 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9222 sampler_ci.pNext = NULL;
9223 sampler_ci.magFilter = VK_FILTER_NEAREST;
9224 sampler_ci.minFilter = VK_FILTER_NEAREST;
9225 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9226 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9227 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9228 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9229 sampler_ci.mipLodBias = 1.0;
9230 sampler_ci.anisotropyEnable = VK_FALSE;
9231 sampler_ci.maxAnisotropy = 1;
9232 sampler_ci.compareEnable = VK_FALSE;
9233 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9234 sampler_ci.minLod = 1.0;
9235 sampler_ci.maxLod = 1.0;
9236 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9237 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009238 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009239 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009240 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009241
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009242 VkDescriptorImageInfo info = {};
9243 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009244
9245 VkWriteDescriptorSet descriptor_write;
9246 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009247 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009248 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009249 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009250 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009251 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009252 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009253
9254 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9255
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009256 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009257
Chia-I Wuf7458c52015-10-26 21:10:41 +08009258 vkDestroySampler(m_device->device(), sampler, NULL);
9259 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9260 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009261}
9262
Karl Schultz6addd812016-02-02 17:17:23 -07009263TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009264 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009265 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009266
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9268 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009269
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009270 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009271 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9272 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009273 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009274 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9275 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009276
9277 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009278 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9279 ds_pool_ci.pNext = NULL;
9280 ds_pool_ci.maxSets = 1;
9281 ds_pool_ci.poolSizeCount = 1;
9282 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009283
9284 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009285 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009286 ASSERT_VK_SUCCESS(err);
9287
9288 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009289 dsl_binding.binding = 0;
9290 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9291 dsl_binding.descriptorCount = 1;
9292 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9293 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009294
9295 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009296 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9297 ds_layout_ci.pNext = NULL;
9298 ds_layout_ci.bindingCount = 1;
9299 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009300 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009301 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009302 ASSERT_VK_SUCCESS(err);
9303
9304 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009305 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009306 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009307 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009308 alloc_info.descriptorPool = ds_pool;
9309 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009310 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009311 ASSERT_VK_SUCCESS(err);
9312
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009313 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009314
9315 VkDescriptorImageInfo descriptor_info;
9316 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9317 descriptor_info.sampler = sampler;
9318
9319 VkWriteDescriptorSet descriptor_write;
9320 memset(&descriptor_write, 0, sizeof(descriptor_write));
9321 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009322 descriptor_write.dstSet = descriptorSet;
9323 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009324 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009325 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9326 descriptor_write.pImageInfo = &descriptor_info;
9327
9328 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9329
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009330 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009331
Chia-I Wuf7458c52015-10-26 21:10:41 +08009332 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9333 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009334}
9335
Karl Schultz6addd812016-02-02 17:17:23 -07009336TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9337 // Create a single combined Image/Sampler descriptor and send it an invalid
9338 // imageView
9339 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009340
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9342 "image sampler descriptor failed due "
9343 "to: Invalid VkImageView:");
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 ";
10260 const char *double_destroy_message = "Cannot free buffer 0x";
10261 const char *invalid_offset_message = "vkBindBufferMemory(): "
10262 "memoryOffset is 0x";
10263 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10264 "storage memoryOffset "
10265 "is 0x";
10266 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10267 "texel memoryOffset "
10268 "is 0x";
10269 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10270 "uniform memoryOffset "
10271 "is 0x";
10272 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
10273 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -060010274 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010275
10276 ASSERT_NO_FATAL_FAILURE(InitState());
10277 ASSERT_NO_FATAL_FAILURE(InitViewport());
10278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10279
10280 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010281 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010282 pipe_ms_state_ci.pNext = NULL;
10283 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10284 pipe_ms_state_ci.sampleShadingEnable = 0;
10285 pipe_ms_state_ci.minSampleShading = 1.0;
10286 pipe_ms_state_ci.pSampleMask = nullptr;
10287
10288 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10289 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10290 VkPipelineLayout pipeline_layout;
10291
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010292 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010293 ASSERT_VK_SUCCESS(err);
10294
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010295 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10296 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010297 VkPipelineObj pipe(m_device);
10298 pipe.AddShader(&vs);
10299 pipe.AddShader(&fs);
10300 pipe.AddColorAttachment();
10301 pipe.SetMSAA(&pipe_ms_state_ci);
10302 pipe.SetViewport(m_viewports);
10303 pipe.SetScissor(m_scissors);
10304 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10305
10306 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010307 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010308
10309 {
10310 // Create and bind a vertex buffer in a reduced scope, which will cause
10311 // it to be deleted upon leaving this scope
10312 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010314 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10315 draw_verticies.AddVertexInputToPipe(pipe);
10316 }
10317
10318 Draw(1, 0, 0, 0);
10319
10320 EndCommandBuffer();
10321
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010323 QueueCommandBuffer(false);
10324 m_errorMonitor->VerifyFound();
10325
10326 {
10327 // Create and bind a vertex buffer in a reduced scope, and delete it
10328 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010329 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010331 buffer_test.TestDoubleDestroy();
10332 }
10333 m_errorMonitor->VerifyFound();
10334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010335 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010336 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10338 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10339 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010340 m_errorMonitor->VerifyFound();
10341 }
10342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010343 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10344 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010345 // Create and bind a memory buffer with an invalid offset again,
10346 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10348 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10349 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010350 m_errorMonitor->VerifyFound();
10351 }
10352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010353 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010354 // Create and bind a memory buffer with an invalid offset again, but
10355 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10357 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10358 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010359 m_errorMonitor->VerifyFound();
10360 }
10361
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010362 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010363 // Create and bind a memory buffer with an invalid offset again, but
10364 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10366 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10367 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010368 m_errorMonitor->VerifyFound();
10369 }
10370
10371 {
10372 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10374 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10375 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010376 m_errorMonitor->VerifyFound();
10377 }
10378
10379 {
10380 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10382 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10383 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010384 }
10385 m_errorMonitor->VerifyFound();
10386
10387 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10388}
10389
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010390// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10391TEST_F(VkLayerTest, InvalidImageLayout) {
10392 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010393 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10394 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010395 // 3 in ValidateCmdBufImageLayouts
10396 // * -1 Attempt to submit cmd buf w/ deleted image
10397 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10398 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10400 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010401
10402 ASSERT_NO_FATAL_FAILURE(InitState());
10403 // Create src & dst images to use for copy operations
10404 VkImage src_image;
10405 VkImage dst_image;
10406
10407 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10408 const int32_t tex_width = 32;
10409 const int32_t tex_height = 32;
10410
10411 VkImageCreateInfo image_create_info = {};
10412 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10413 image_create_info.pNext = NULL;
10414 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10415 image_create_info.format = tex_format;
10416 image_create_info.extent.width = tex_width;
10417 image_create_info.extent.height = tex_height;
10418 image_create_info.extent.depth = 1;
10419 image_create_info.mipLevels = 1;
10420 image_create_info.arrayLayers = 4;
10421 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10422 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10423 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10424 image_create_info.flags = 0;
10425
10426 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10427 ASSERT_VK_SUCCESS(err);
10428 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10429 ASSERT_VK_SUCCESS(err);
10430
10431 BeginCommandBuffer();
10432 VkImageCopy copyRegion;
10433 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10434 copyRegion.srcSubresource.mipLevel = 0;
10435 copyRegion.srcSubresource.baseArrayLayer = 0;
10436 copyRegion.srcSubresource.layerCount = 1;
10437 copyRegion.srcOffset.x = 0;
10438 copyRegion.srcOffset.y = 0;
10439 copyRegion.srcOffset.z = 0;
10440 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10441 copyRegion.dstSubresource.mipLevel = 0;
10442 copyRegion.dstSubresource.baseArrayLayer = 0;
10443 copyRegion.dstSubresource.layerCount = 1;
10444 copyRegion.dstOffset.x = 0;
10445 copyRegion.dstOffset.y = 0;
10446 copyRegion.dstOffset.z = 0;
10447 copyRegion.extent.width = 1;
10448 copyRegion.extent.height = 1;
10449 copyRegion.extent.depth = 1;
10450 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10451 m_errorMonitor->VerifyFound();
10452 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10454 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10455 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010456 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10457 m_errorMonitor->VerifyFound();
10458 // Final src error is due to bad layout type
10459 m_errorMonitor->SetDesiredFailureMsg(
10460 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10461 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10462 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10463 m_errorMonitor->VerifyFound();
10464 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10466 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010467 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10468 m_errorMonitor->VerifyFound();
10469 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10471 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10472 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010473 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10474 m_errorMonitor->VerifyFound();
10475 m_errorMonitor->SetDesiredFailureMsg(
10476 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10477 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10478 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10479 m_errorMonitor->VerifyFound();
10480 // Now cause error due to bad image layout transition in PipelineBarrier
10481 VkImageMemoryBarrier image_barrier[1] = {};
10482 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10483 image_barrier[0].image = src_image;
10484 image_barrier[0].subresourceRange.layerCount = 2;
10485 image_barrier[0].subresourceRange.levelCount = 2;
10486 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10488 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10489 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10490 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10491 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010492 m_errorMonitor->VerifyFound();
10493
10494 // Finally some layout errors at RenderPass create time
10495 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10496 VkAttachmentReference attach = {};
10497 // perf warning for GENERAL layout w/ non-DS input attachment
10498 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10499 VkSubpassDescription subpass = {};
10500 subpass.inputAttachmentCount = 1;
10501 subpass.pInputAttachments = &attach;
10502 VkRenderPassCreateInfo rpci = {};
10503 rpci.subpassCount = 1;
10504 rpci.pSubpasses = &subpass;
10505 rpci.attachmentCount = 1;
10506 VkAttachmentDescription attach_desc = {};
10507 attach_desc.format = VK_FORMAT_UNDEFINED;
10508 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010509 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010510 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10512 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010513 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10514 m_errorMonitor->VerifyFound();
10515 // error w/ non-general layout
10516 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10517
10518 m_errorMonitor->SetDesiredFailureMsg(
10519 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10520 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10521 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10522 m_errorMonitor->VerifyFound();
10523 subpass.inputAttachmentCount = 0;
10524 subpass.colorAttachmentCount = 1;
10525 subpass.pColorAttachments = &attach;
10526 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10527 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10529 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010530 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10531 m_errorMonitor->VerifyFound();
10532 // error w/ non-color opt or GENERAL layout for color attachment
10533 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10534 m_errorMonitor->SetDesiredFailureMsg(
10535 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10536 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10537 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10538 m_errorMonitor->VerifyFound();
10539 subpass.colorAttachmentCount = 0;
10540 subpass.pDepthStencilAttachment = &attach;
10541 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10542 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10544 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010545 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10546 m_errorMonitor->VerifyFound();
10547 // error w/ non-ds opt or GENERAL layout for color attachment
10548 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10550 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10551 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010552 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10553 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010554 // For this error we need a valid renderpass so create default one
10555 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10556 attach.attachment = 0;
10557 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10558 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10559 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10560 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10561 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10562 // Can't do a CLEAR load on READ_ONLY initialLayout
10563 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10564 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10565 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10567 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10568 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010569 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10570 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010571
10572 vkDestroyImage(m_device->device(), src_image, NULL);
10573 vkDestroyImage(m_device->device(), dst_image, NULL);
10574}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010575
Tobin Ehlise0936662016-10-11 08:10:51 -060010576TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10577 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10578 VkResult err;
10579
10580 ASSERT_NO_FATAL_FAILURE(InitState());
10581
10582 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10583 VkImageTiling tiling;
10584 VkFormatProperties format_properties;
10585 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10586 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10587 tiling = VK_IMAGE_TILING_LINEAR;
10588 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10589 tiling = VK_IMAGE_TILING_OPTIMAL;
10590 } else {
10591 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10592 "skipped.\n");
10593 return;
10594 }
10595
10596 VkDescriptorPoolSize ds_type = {};
10597 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10598 ds_type.descriptorCount = 1;
10599
10600 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10601 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10602 ds_pool_ci.maxSets = 1;
10603 ds_pool_ci.poolSizeCount = 1;
10604 ds_pool_ci.pPoolSizes = &ds_type;
10605 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10606
10607 VkDescriptorPool ds_pool;
10608 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10609 ASSERT_VK_SUCCESS(err);
10610
10611 VkDescriptorSetLayoutBinding dsl_binding = {};
10612 dsl_binding.binding = 0;
10613 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10614 dsl_binding.descriptorCount = 1;
10615 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10616 dsl_binding.pImmutableSamplers = NULL;
10617
10618 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10619 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10620 ds_layout_ci.pNext = NULL;
10621 ds_layout_ci.bindingCount = 1;
10622 ds_layout_ci.pBindings = &dsl_binding;
10623
10624 VkDescriptorSetLayout ds_layout;
10625 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10626 ASSERT_VK_SUCCESS(err);
10627
10628 VkDescriptorSetAllocateInfo alloc_info = {};
10629 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10630 alloc_info.descriptorSetCount = 1;
10631 alloc_info.descriptorPool = ds_pool;
10632 alloc_info.pSetLayouts = &ds_layout;
10633 VkDescriptorSet descriptor_set;
10634 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10635 ASSERT_VK_SUCCESS(err);
10636
10637 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10638 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10639 pipeline_layout_ci.pNext = NULL;
10640 pipeline_layout_ci.setLayoutCount = 1;
10641 pipeline_layout_ci.pSetLayouts = &ds_layout;
10642 VkPipelineLayout pipeline_layout;
10643 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10644 ASSERT_VK_SUCCESS(err);
10645
10646 VkImageObj image(m_device);
10647 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10648 ASSERT_TRUE(image.initialized());
10649 VkImageView view = image.targetView(tex_format);
10650
10651 VkDescriptorImageInfo image_info = {};
10652 image_info.imageView = view;
10653 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10654
10655 VkWriteDescriptorSet descriptor_write = {};
10656 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10657 descriptor_write.dstSet = descriptor_set;
10658 descriptor_write.dstBinding = 0;
10659 descriptor_write.descriptorCount = 1;
10660 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10661 descriptor_write.pImageInfo = &image_info;
10662
10663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10664 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10665 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10666 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10667 m_errorMonitor->VerifyFound();
10668
10669 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10670 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10671 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10672 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10673}
10674
Mark Mueller93b938f2016-08-18 10:27:40 -060010675TEST_F(VkLayerTest, SimultaneousUse) {
10676 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10677 "in primary and secondary command buffers.");
10678
10679 ASSERT_NO_FATAL_FAILURE(InitState());
10680 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10681
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010682 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010683 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10684 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010685
10686 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010687 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010688 command_buffer_allocate_info.commandPool = m_commandPool;
10689 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10690 command_buffer_allocate_info.commandBufferCount = 1;
10691
10692 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010693 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010694 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10695 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010696 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010697 command_buffer_inheritance_info.renderPass = m_renderPass;
10698 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10699 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010700 command_buffer_begin_info.flags =
10701 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010702 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10703
10704 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010705 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10706 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010707 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010708 vkEndCommandBuffer(secondary_command_buffer);
10709
Mark Mueller93b938f2016-08-18 10:27:40 -060010710 VkSubmitInfo submit_info = {};
10711 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10712 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010713 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010714 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010715
Mark Mueller4042b652016-09-05 22:52:21 -060010716 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010717 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10719 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010720 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010721 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10722 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010723
10724 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010725 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10726
Mark Mueller4042b652016-09-05 22:52:21 -060010727 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010728 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010729 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10732 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010733 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010734 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10735 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010736}
10737
Mark Mueller917f6bc2016-08-30 10:57:19 -060010738TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10739 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10740 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010741 "Delete objects that are inuse. Call VkQueueSubmit "
10742 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010743
10744 ASSERT_NO_FATAL_FAILURE(InitState());
10745 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10746
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010747 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10748 const char *cannot_delete_event_message = "Cannot delete event 0x";
10749 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10750 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010751
10752 BeginCommandBuffer();
10753
10754 VkEvent event;
10755 VkEventCreateInfo event_create_info = {};
10756 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10757 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010758 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010759
Mark Muellerc8d441e2016-08-23 17:36:00 -060010760 EndCommandBuffer();
10761 vkDestroyEvent(m_device->device(), event, nullptr);
10762
10763 VkSubmitInfo submit_info = {};
10764 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10765 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010766 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010768 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10769 m_errorMonitor->VerifyFound();
10770
10771 m_errorMonitor->SetDesiredFailureMsg(0, "");
10772 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10773
10774 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10775
Mark Mueller917f6bc2016-08-30 10:57:19 -060010776 VkSemaphoreCreateInfo semaphore_create_info = {};
10777 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10778 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010779 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010780 VkFenceCreateInfo fence_create_info = {};
10781 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10782 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010783 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010784
10785 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010786 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010787 descriptor_pool_type_count.descriptorCount = 1;
10788
10789 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10790 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10791 descriptor_pool_create_info.maxSets = 1;
10792 descriptor_pool_create_info.poolSizeCount = 1;
10793 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010794 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010795
10796 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010797 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010798
10799 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010800 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010801 descriptorset_layout_binding.descriptorCount = 1;
10802 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10803
10804 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010805 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010806 descriptorset_layout_create_info.bindingCount = 1;
10807 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10808
10809 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010810 ASSERT_VK_SUCCESS(
10811 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010812
10813 VkDescriptorSet descriptorset;
10814 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010815 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010816 descriptorset_allocate_info.descriptorSetCount = 1;
10817 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10818 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010819 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010820
Mark Mueller4042b652016-09-05 22:52:21 -060010821 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10822
10823 VkDescriptorBufferInfo buffer_info = {};
10824 buffer_info.buffer = buffer_test.GetBuffer();
10825 buffer_info.offset = 0;
10826 buffer_info.range = 1024;
10827
10828 VkWriteDescriptorSet write_descriptor_set = {};
10829 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10830 write_descriptor_set.dstSet = descriptorset;
10831 write_descriptor_set.descriptorCount = 1;
10832 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10833 write_descriptor_set.pBufferInfo = &buffer_info;
10834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010835 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010837 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10838 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010839
10840 VkPipelineObj pipe(m_device);
10841 pipe.AddColorAttachment();
10842 pipe.AddShader(&vs);
10843 pipe.AddShader(&fs);
10844
10845 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010846 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010847 pipeline_layout_create_info.setLayoutCount = 1;
10848 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10849
10850 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010851 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010852
10853 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10854
Mark Muellerc8d441e2016-08-23 17:36:00 -060010855 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010856 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010857
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010858 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10859 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10860 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010861
Mark Muellerc8d441e2016-08-23 17:36:00 -060010862 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010863
Mark Mueller917f6bc2016-08-30 10:57:19 -060010864 submit_info.signalSemaphoreCount = 1;
10865 submit_info.pSignalSemaphores = &semaphore;
10866 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010867
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010869 vkDestroyEvent(m_device->device(), event, nullptr);
10870 m_errorMonitor->VerifyFound();
10871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010873 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10874 m_errorMonitor->VerifyFound();
10875
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010877 vkDestroyFence(m_device->device(), fence, nullptr);
10878 m_errorMonitor->VerifyFound();
10879
Tobin Ehlis122207b2016-09-01 08:50:06 -070010880 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010881 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10882 vkDestroyFence(m_device->device(), fence, nullptr);
10883 vkDestroyEvent(m_device->device(), event, nullptr);
10884 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010885 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010886 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10887}
10888
Tobin Ehlis2adda372016-09-01 08:51:06 -070010889TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10890 TEST_DESCRIPTION("Delete in-use query pool.");
10891
10892 ASSERT_NO_FATAL_FAILURE(InitState());
10893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10894
10895 VkQueryPool query_pool;
10896 VkQueryPoolCreateInfo query_pool_ci{};
10897 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10898 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10899 query_pool_ci.queryCount = 1;
10900 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10901 BeginCommandBuffer();
10902 // Reset query pool to create binding with cmd buffer
10903 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10904
10905 EndCommandBuffer();
10906
10907 VkSubmitInfo submit_info = {};
10908 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10909 submit_info.commandBufferCount = 1;
10910 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10911 // Submit cmd buffer and then destroy query pool while in-flight
10912 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10913
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010915 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10916 m_errorMonitor->VerifyFound();
10917
10918 vkQueueWaitIdle(m_device->m_queue);
10919 // Now that cmd buffer done we can safely destroy query_pool
10920 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10921}
10922
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010923TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10924 TEST_DESCRIPTION("Delete in-use pipeline.");
10925
10926 ASSERT_NO_FATAL_FAILURE(InitState());
10927 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10928
10929 // Empty pipeline layout used for binding PSO
10930 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10931 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10932 pipeline_layout_ci.setLayoutCount = 0;
10933 pipeline_layout_ci.pSetLayouts = NULL;
10934
10935 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010936 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010937 ASSERT_VK_SUCCESS(err);
10938
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010940 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010941 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10942 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010943 // Store pipeline handle so we can actually delete it before test finishes
10944 VkPipeline delete_this_pipeline;
10945 { // Scope pipeline so it will be auto-deleted
10946 VkPipelineObj pipe(m_device);
10947 pipe.AddShader(&vs);
10948 pipe.AddShader(&fs);
10949 pipe.AddColorAttachment();
10950 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10951 delete_this_pipeline = pipe.handle();
10952
10953 BeginCommandBuffer();
10954 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010955 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010956
10957 EndCommandBuffer();
10958
10959 VkSubmitInfo submit_info = {};
10960 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10961 submit_info.commandBufferCount = 1;
10962 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10963 // Submit cmd buffer and then pipeline destroyed while in-flight
10964 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10965 } // Pipeline deletion triggered here
10966 m_errorMonitor->VerifyFound();
10967 // Make sure queue finished and then actually delete pipeline
10968 vkQueueWaitIdle(m_device->m_queue);
10969 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10970 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10971}
10972
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010973TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10974 TEST_DESCRIPTION("Delete in-use imageView.");
10975
10976 ASSERT_NO_FATAL_FAILURE(InitState());
10977 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10978
10979 VkDescriptorPoolSize ds_type_count;
10980 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10981 ds_type_count.descriptorCount = 1;
10982
10983 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10984 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10985 ds_pool_ci.maxSets = 1;
10986 ds_pool_ci.poolSizeCount = 1;
10987 ds_pool_ci.pPoolSizes = &ds_type_count;
10988
10989 VkDescriptorPool ds_pool;
10990 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10991 ASSERT_VK_SUCCESS(err);
10992
10993 VkSamplerCreateInfo sampler_ci = {};
10994 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10995 sampler_ci.pNext = NULL;
10996 sampler_ci.magFilter = VK_FILTER_NEAREST;
10997 sampler_ci.minFilter = VK_FILTER_NEAREST;
10998 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10999 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11000 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11001 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11002 sampler_ci.mipLodBias = 1.0;
11003 sampler_ci.anisotropyEnable = VK_FALSE;
11004 sampler_ci.maxAnisotropy = 1;
11005 sampler_ci.compareEnable = VK_FALSE;
11006 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11007 sampler_ci.minLod = 1.0;
11008 sampler_ci.maxLod = 1.0;
11009 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11010 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11011 VkSampler sampler;
11012
11013 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11014 ASSERT_VK_SUCCESS(err);
11015
11016 VkDescriptorSetLayoutBinding layout_binding;
11017 layout_binding.binding = 0;
11018 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11019 layout_binding.descriptorCount = 1;
11020 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11021 layout_binding.pImmutableSamplers = NULL;
11022
11023 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11024 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11025 ds_layout_ci.bindingCount = 1;
11026 ds_layout_ci.pBindings = &layout_binding;
11027 VkDescriptorSetLayout ds_layout;
11028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11029 ASSERT_VK_SUCCESS(err);
11030
11031 VkDescriptorSetAllocateInfo alloc_info = {};
11032 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11033 alloc_info.descriptorSetCount = 1;
11034 alloc_info.descriptorPool = ds_pool;
11035 alloc_info.pSetLayouts = &ds_layout;
11036 VkDescriptorSet descriptor_set;
11037 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11038 ASSERT_VK_SUCCESS(err);
11039
11040 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11041 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11042 pipeline_layout_ci.pNext = NULL;
11043 pipeline_layout_ci.setLayoutCount = 1;
11044 pipeline_layout_ci.pSetLayouts = &ds_layout;
11045
11046 VkPipelineLayout pipeline_layout;
11047 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11048 ASSERT_VK_SUCCESS(err);
11049
11050 VkImageObj image(m_device);
11051 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11052 ASSERT_TRUE(image.initialized());
11053
11054 VkImageView view;
11055 VkImageViewCreateInfo ivci = {};
11056 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11057 ivci.image = image.handle();
11058 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11059 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11060 ivci.subresourceRange.layerCount = 1;
11061 ivci.subresourceRange.baseMipLevel = 0;
11062 ivci.subresourceRange.levelCount = 1;
11063 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11064
11065 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11066 ASSERT_VK_SUCCESS(err);
11067
11068 VkDescriptorImageInfo image_info{};
11069 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11070 image_info.imageView = view;
11071 image_info.sampler = sampler;
11072
11073 VkWriteDescriptorSet descriptor_write = {};
11074 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11075 descriptor_write.dstSet = descriptor_set;
11076 descriptor_write.dstBinding = 0;
11077 descriptor_write.descriptorCount = 1;
11078 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11079 descriptor_write.pImageInfo = &image_info;
11080
11081 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11082
11083 // Create PSO to use the sampler
11084 char const *vsSource = "#version 450\n"
11085 "\n"
11086 "out gl_PerVertex { \n"
11087 " vec4 gl_Position;\n"
11088 "};\n"
11089 "void main(){\n"
11090 " gl_Position = vec4(1);\n"
11091 "}\n";
11092 char const *fsSource = "#version 450\n"
11093 "\n"
11094 "layout(set=0, binding=0) uniform sampler2D s;\n"
11095 "layout(location=0) out vec4 x;\n"
11096 "void main(){\n"
11097 " x = texture(s, vec2(1));\n"
11098 "}\n";
11099 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11100 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11101 VkPipelineObj pipe(m_device);
11102 pipe.AddShader(&vs);
11103 pipe.AddShader(&fs);
11104 pipe.AddColorAttachment();
11105 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11106
11107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11108
11109 BeginCommandBuffer();
11110 // Bind pipeline to cmd buffer
11111 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11112 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11113 &descriptor_set, 0, nullptr);
11114 Draw(1, 0, 0, 0);
11115 EndCommandBuffer();
11116 // Submit cmd buffer then destroy sampler
11117 VkSubmitInfo submit_info = {};
11118 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11119 submit_info.commandBufferCount = 1;
11120 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11121 // Submit cmd buffer and then destroy imageView while in-flight
11122 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11123
11124 vkDestroyImageView(m_device->device(), view, nullptr);
11125 m_errorMonitor->VerifyFound();
11126 vkQueueWaitIdle(m_device->m_queue);
11127 // Now we can actually destroy imageView
11128 vkDestroyImageView(m_device->device(), view, NULL);
11129 vkDestroySampler(m_device->device(), sampler, nullptr);
11130 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11131 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11132 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11133}
11134
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011135TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11136 TEST_DESCRIPTION("Delete in-use bufferView.");
11137
11138 ASSERT_NO_FATAL_FAILURE(InitState());
11139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11140
11141 VkDescriptorPoolSize ds_type_count;
11142 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11143 ds_type_count.descriptorCount = 1;
11144
11145 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11146 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11147 ds_pool_ci.maxSets = 1;
11148 ds_pool_ci.poolSizeCount = 1;
11149 ds_pool_ci.pPoolSizes = &ds_type_count;
11150
11151 VkDescriptorPool ds_pool;
11152 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11153 ASSERT_VK_SUCCESS(err);
11154
11155 VkDescriptorSetLayoutBinding layout_binding;
11156 layout_binding.binding = 0;
11157 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11158 layout_binding.descriptorCount = 1;
11159 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11160 layout_binding.pImmutableSamplers = NULL;
11161
11162 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11163 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11164 ds_layout_ci.bindingCount = 1;
11165 ds_layout_ci.pBindings = &layout_binding;
11166 VkDescriptorSetLayout ds_layout;
11167 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11168 ASSERT_VK_SUCCESS(err);
11169
11170 VkDescriptorSetAllocateInfo alloc_info = {};
11171 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11172 alloc_info.descriptorSetCount = 1;
11173 alloc_info.descriptorPool = ds_pool;
11174 alloc_info.pSetLayouts = &ds_layout;
11175 VkDescriptorSet descriptor_set;
11176 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11177 ASSERT_VK_SUCCESS(err);
11178
11179 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11180 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11181 pipeline_layout_ci.pNext = NULL;
11182 pipeline_layout_ci.setLayoutCount = 1;
11183 pipeline_layout_ci.pSetLayouts = &ds_layout;
11184
11185 VkPipelineLayout pipeline_layout;
11186 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11187 ASSERT_VK_SUCCESS(err);
11188
11189 VkBuffer buffer;
11190 uint32_t queue_family_index = 0;
11191 VkBufferCreateInfo buffer_create_info = {};
11192 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11193 buffer_create_info.size = 1024;
11194 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11195 buffer_create_info.queueFamilyIndexCount = 1;
11196 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11197
11198 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11199 ASSERT_VK_SUCCESS(err);
11200
11201 VkMemoryRequirements memory_reqs;
11202 VkDeviceMemory buffer_memory;
11203
11204 VkMemoryAllocateInfo memory_info = {};
11205 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11206 memory_info.allocationSize = 0;
11207 memory_info.memoryTypeIndex = 0;
11208
11209 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11210 memory_info.allocationSize = memory_reqs.size;
11211 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11212 ASSERT_TRUE(pass);
11213
11214 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11215 ASSERT_VK_SUCCESS(err);
11216 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11217 ASSERT_VK_SUCCESS(err);
11218
11219 VkBufferView view;
11220 VkBufferViewCreateInfo bvci = {};
11221 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11222 bvci.buffer = buffer;
11223 bvci.format = VK_FORMAT_R8_UNORM;
11224 bvci.range = VK_WHOLE_SIZE;
11225
11226 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11227 ASSERT_VK_SUCCESS(err);
11228
11229 VkWriteDescriptorSet descriptor_write = {};
11230 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11231 descriptor_write.dstSet = descriptor_set;
11232 descriptor_write.dstBinding = 0;
11233 descriptor_write.descriptorCount = 1;
11234 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11235 descriptor_write.pTexelBufferView = &view;
11236
11237 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11238
11239 char const *vsSource = "#version 450\n"
11240 "\n"
11241 "out gl_PerVertex { \n"
11242 " vec4 gl_Position;\n"
11243 "};\n"
11244 "void main(){\n"
11245 " gl_Position = vec4(1);\n"
11246 "}\n";
11247 char const *fsSource = "#version 450\n"
11248 "\n"
11249 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11250 "layout(location=0) out vec4 x;\n"
11251 "void main(){\n"
11252 " x = imageLoad(s, 0);\n"
11253 "}\n";
11254 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11255 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11256 VkPipelineObj pipe(m_device);
11257 pipe.AddShader(&vs);
11258 pipe.AddShader(&fs);
11259 pipe.AddColorAttachment();
11260 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11261
11262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11263
11264 BeginCommandBuffer();
11265 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11266 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11267 VkRect2D scissor = {{0, 0}, {16, 16}};
11268 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11269 // Bind pipeline to cmd buffer
11270 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11271 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11272 &descriptor_set, 0, nullptr);
11273 Draw(1, 0, 0, 0);
11274 EndCommandBuffer();
11275
11276 VkSubmitInfo submit_info = {};
11277 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11278 submit_info.commandBufferCount = 1;
11279 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11280 // Submit cmd buffer and then destroy bufferView while in-flight
11281 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11282
11283 vkDestroyBufferView(m_device->device(), view, nullptr);
11284 m_errorMonitor->VerifyFound();
11285 vkQueueWaitIdle(m_device->m_queue);
11286 // Now we can actually destroy bufferView
11287 vkDestroyBufferView(m_device->device(), view, NULL);
11288 vkDestroyBuffer(m_device->device(), buffer, NULL);
11289 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11290 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11291 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11293}
11294
Tobin Ehlis209532e2016-09-07 13:52:18 -060011295TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11296 TEST_DESCRIPTION("Delete in-use sampler.");
11297
11298 ASSERT_NO_FATAL_FAILURE(InitState());
11299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11300
11301 VkDescriptorPoolSize ds_type_count;
11302 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11303 ds_type_count.descriptorCount = 1;
11304
11305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11307 ds_pool_ci.maxSets = 1;
11308 ds_pool_ci.poolSizeCount = 1;
11309 ds_pool_ci.pPoolSizes = &ds_type_count;
11310
11311 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011312 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011313 ASSERT_VK_SUCCESS(err);
11314
11315 VkSamplerCreateInfo sampler_ci = {};
11316 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11317 sampler_ci.pNext = NULL;
11318 sampler_ci.magFilter = VK_FILTER_NEAREST;
11319 sampler_ci.minFilter = VK_FILTER_NEAREST;
11320 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11321 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11322 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11323 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11324 sampler_ci.mipLodBias = 1.0;
11325 sampler_ci.anisotropyEnable = VK_FALSE;
11326 sampler_ci.maxAnisotropy = 1;
11327 sampler_ci.compareEnable = VK_FALSE;
11328 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11329 sampler_ci.minLod = 1.0;
11330 sampler_ci.maxLod = 1.0;
11331 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11332 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11333 VkSampler sampler;
11334
11335 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11336 ASSERT_VK_SUCCESS(err);
11337
11338 VkDescriptorSetLayoutBinding layout_binding;
11339 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011340 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011341 layout_binding.descriptorCount = 1;
11342 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11343 layout_binding.pImmutableSamplers = NULL;
11344
11345 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11346 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11347 ds_layout_ci.bindingCount = 1;
11348 ds_layout_ci.pBindings = &layout_binding;
11349 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011350 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011351 ASSERT_VK_SUCCESS(err);
11352
11353 VkDescriptorSetAllocateInfo alloc_info = {};
11354 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11355 alloc_info.descriptorSetCount = 1;
11356 alloc_info.descriptorPool = ds_pool;
11357 alloc_info.pSetLayouts = &ds_layout;
11358 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011359 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011360 ASSERT_VK_SUCCESS(err);
11361
11362 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11363 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11364 pipeline_layout_ci.pNext = NULL;
11365 pipeline_layout_ci.setLayoutCount = 1;
11366 pipeline_layout_ci.pSetLayouts = &ds_layout;
11367
11368 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011369 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011370 ASSERT_VK_SUCCESS(err);
11371
11372 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011373 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 -060011374 ASSERT_TRUE(image.initialized());
11375
11376 VkImageView view;
11377 VkImageViewCreateInfo ivci = {};
11378 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11379 ivci.image = image.handle();
11380 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11381 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11382 ivci.subresourceRange.layerCount = 1;
11383 ivci.subresourceRange.baseMipLevel = 0;
11384 ivci.subresourceRange.levelCount = 1;
11385 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11386
11387 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11388 ASSERT_VK_SUCCESS(err);
11389
11390 VkDescriptorImageInfo image_info{};
11391 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11392 image_info.imageView = view;
11393 image_info.sampler = sampler;
11394
11395 VkWriteDescriptorSet descriptor_write = {};
11396 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11397 descriptor_write.dstSet = descriptor_set;
11398 descriptor_write.dstBinding = 0;
11399 descriptor_write.descriptorCount = 1;
11400 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11401 descriptor_write.pImageInfo = &image_info;
11402
11403 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11404
11405 // Create PSO to use the sampler
11406 char const *vsSource = "#version 450\n"
11407 "\n"
11408 "out gl_PerVertex { \n"
11409 " vec4 gl_Position;\n"
11410 "};\n"
11411 "void main(){\n"
11412 " gl_Position = vec4(1);\n"
11413 "}\n";
11414 char const *fsSource = "#version 450\n"
11415 "\n"
11416 "layout(set=0, binding=0) uniform sampler2D s;\n"
11417 "layout(location=0) out vec4 x;\n"
11418 "void main(){\n"
11419 " x = texture(s, vec2(1));\n"
11420 "}\n";
11421 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11422 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11423 VkPipelineObj pipe(m_device);
11424 pipe.AddShader(&vs);
11425 pipe.AddShader(&fs);
11426 pipe.AddColorAttachment();
11427 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11428
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011430
11431 BeginCommandBuffer();
11432 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011433 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11434 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11435 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011436 Draw(1, 0, 0, 0);
11437 EndCommandBuffer();
11438 // Submit cmd buffer then destroy sampler
11439 VkSubmitInfo submit_info = {};
11440 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11441 submit_info.commandBufferCount = 1;
11442 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11443 // Submit cmd buffer and then destroy sampler while in-flight
11444 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11445
11446 vkDestroySampler(m_device->device(), sampler, nullptr);
11447 m_errorMonitor->VerifyFound();
11448 vkQueueWaitIdle(m_device->m_queue);
11449 // Now we can actually destroy sampler
11450 vkDestroySampler(m_device->device(), sampler, nullptr);
11451 vkDestroyImageView(m_device->device(), view, NULL);
11452 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11453 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11454 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11455}
11456
Mark Mueller1cd9f412016-08-25 13:23:52 -060011457TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011458 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011459 "signaled but not waited on by the queue. Wait on a "
11460 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011461
11462 ASSERT_NO_FATAL_FAILURE(InitState());
11463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11464
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011465 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11466 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11467 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011468
11469 BeginCommandBuffer();
11470 EndCommandBuffer();
11471
11472 VkSemaphoreCreateInfo semaphore_create_info = {};
11473 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11474 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011475 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011476 VkSubmitInfo submit_info = {};
11477 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11478 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011479 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011480 submit_info.signalSemaphoreCount = 1;
11481 submit_info.pSignalSemaphores = &semaphore;
11482 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11483 m_errorMonitor->SetDesiredFailureMsg(0, "");
11484 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11485 BeginCommandBuffer();
11486 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011488 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11489 m_errorMonitor->VerifyFound();
11490
Mark Mueller1cd9f412016-08-25 13:23:52 -060011491 VkFenceCreateInfo fence_create_info = {};
11492 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11493 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011494 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011497 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11498 m_errorMonitor->VerifyFound();
11499
Mark Mueller4042b652016-09-05 22:52:21 -060011500 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011501 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011502 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11503}
11504
Tobin Ehlis4af23302016-07-19 10:50:30 -060011505TEST_F(VkLayerTest, FramebufferIncompatible) {
11506 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11507 "that does not match the framebuffer for the active "
11508 "renderpass.");
11509 ASSERT_NO_FATAL_FAILURE(InitState());
11510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11511
11512 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011513 VkAttachmentDescription attachment = {0,
11514 VK_FORMAT_B8G8R8A8_UNORM,
11515 VK_SAMPLE_COUNT_1_BIT,
11516 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11517 VK_ATTACHMENT_STORE_OP_STORE,
11518 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11519 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11520 VK_IMAGE_LAYOUT_UNDEFINED,
11521 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011522
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011523 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011524
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011525 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011527 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011528
11529 VkRenderPass rp;
11530 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11531 ASSERT_VK_SUCCESS(err);
11532
11533 // A compatible framebuffer.
11534 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011535 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 -060011536 ASSERT_TRUE(image.initialized());
11537
11538 VkImageViewCreateInfo ivci = {
11539 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11540 nullptr,
11541 0,
11542 image.handle(),
11543 VK_IMAGE_VIEW_TYPE_2D,
11544 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011545 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11546 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011547 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11548 };
11549 VkImageView view;
11550 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11551 ASSERT_VK_SUCCESS(err);
11552
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011553 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011554 VkFramebuffer fb;
11555 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11556 ASSERT_VK_SUCCESS(err);
11557
11558 VkCommandBufferAllocateInfo cbai = {};
11559 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11560 cbai.commandPool = m_commandPool;
11561 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11562 cbai.commandBufferCount = 1;
11563
11564 VkCommandBuffer sec_cb;
11565 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11566 ASSERT_VK_SUCCESS(err);
11567 VkCommandBufferBeginInfo cbbi = {};
11568 VkCommandBufferInheritanceInfo cbii = {};
11569 cbii.renderPass = renderPass();
11570 cbii.framebuffer = fb;
11571 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11572 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011573 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 -060011574 cbbi.pInheritanceInfo = &cbii;
11575 vkBeginCommandBuffer(sec_cb, &cbbi);
11576 vkEndCommandBuffer(sec_cb);
11577
Chris Forbes3400bc52016-09-13 18:10:34 +120011578 VkCommandBufferBeginInfo cbbi2 = {
11579 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11580 0, nullptr
11581 };
11582 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11583 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011584
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011586 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011587 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11588 m_errorMonitor->VerifyFound();
11589 // Cleanup
11590 vkDestroyImageView(m_device->device(), view, NULL);
11591 vkDestroyRenderPass(m_device->device(), rp, NULL);
11592 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11593}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011594
11595TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11596 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11597 "invalid value. If logicOp is not available, attempt to "
11598 "use it and verify that we see the correct error.");
11599 ASSERT_NO_FATAL_FAILURE(InitState());
11600 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11601
11602 auto features = m_device->phy().features();
11603 // Set the expected error depending on whether or not logicOp available
11604 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11606 "enabled, logicOpEnable must be "
11607 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011608 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011610 }
11611 // Create a pipeline using logicOp
11612 VkResult err;
11613
11614 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11615 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11616
11617 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011618 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011619 ASSERT_VK_SUCCESS(err);
11620
11621 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11622 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11623 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011624 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011625 vp_state_ci.pViewports = &vp;
11626 vp_state_ci.scissorCount = 1;
11627 VkRect2D scissors = {}; // Dummy scissors to point to
11628 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011629
11630 VkPipelineShaderStageCreateInfo shaderStages[2];
11631 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11632
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011633 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11634 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011635 shaderStages[0] = vs.GetStageCreateInfo();
11636 shaderStages[1] = fs.GetStageCreateInfo();
11637
11638 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11639 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11640
11641 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11642 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11643 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11644
11645 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11646 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011647 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011648
11649 VkPipelineColorBlendAttachmentState att = {};
11650 att.blendEnable = VK_FALSE;
11651 att.colorWriteMask = 0xf;
11652
11653 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11654 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11655 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11656 cb_ci.logicOpEnable = VK_TRUE;
11657 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11658 cb_ci.attachmentCount = 1;
11659 cb_ci.pAttachments = &att;
11660
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011661 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11662 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11663 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11664
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011665 VkGraphicsPipelineCreateInfo gp_ci = {};
11666 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11667 gp_ci.stageCount = 2;
11668 gp_ci.pStages = shaderStages;
11669 gp_ci.pVertexInputState = &vi_ci;
11670 gp_ci.pInputAssemblyState = &ia_ci;
11671 gp_ci.pViewportState = &vp_state_ci;
11672 gp_ci.pRasterizationState = &rs_ci;
11673 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011674 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011675 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11676 gp_ci.layout = pipeline_layout;
11677 gp_ci.renderPass = renderPass();
11678
11679 VkPipelineCacheCreateInfo pc_ci = {};
11680 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11681
11682 VkPipeline pipeline;
11683 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011684 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011685 ASSERT_VK_SUCCESS(err);
11686
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011687 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011688 m_errorMonitor->VerifyFound();
11689 if (VK_SUCCESS == err) {
11690 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11691 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011692 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11693 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11694}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011695#endif // DRAW_STATE_TESTS
11696
Tobin Ehlis0788f522015-05-26 16:11:58 -060011697#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011698#if GTEST_IS_THREADSAFE
11699struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011700 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011701 VkEvent event;
11702 bool bailout;
11703};
11704
Karl Schultz6addd812016-02-02 17:17:23 -070011705extern "C" void *AddToCommandBuffer(void *arg) {
11706 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011707
Mike Stroyana6d14942016-07-13 15:10:05 -060011708 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011709 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011710 if (data->bailout) {
11711 break;
11712 }
11713 }
11714 return NULL;
11715}
11716
Karl Schultz6addd812016-02-02 17:17:23 -070011717TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011718 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011719
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011721
Mike Stroyanaccf7692015-05-12 16:00:45 -060011722 ASSERT_NO_FATAL_FAILURE(InitState());
11723 ASSERT_NO_FATAL_FAILURE(InitViewport());
11724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11725
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011726 // Calls AllocateCommandBuffers
11727 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011728
11729 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011730 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011731
11732 VkEventCreateInfo event_info;
11733 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011734 VkResult err;
11735
11736 memset(&event_info, 0, sizeof(event_info));
11737 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11738
Chia-I Wuf7458c52015-10-26 21:10:41 +080011739 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011740 ASSERT_VK_SUCCESS(err);
11741
Mike Stroyanaccf7692015-05-12 16:00:45 -060011742 err = vkResetEvent(device(), event);
11743 ASSERT_VK_SUCCESS(err);
11744
11745 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011746 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011747 data.event = event;
11748 data.bailout = false;
11749 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011750
11751 // First do some correct operations using multiple threads.
11752 // Add many entries to command buffer from another thread.
11753 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11754 // Make non-conflicting calls from this thread at the same time.
11755 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011756 uint32_t count;
11757 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011758 }
11759 test_platform_thread_join(thread, NULL);
11760
11761 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011762 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011763 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011764 // Add many entries to command buffer from this thread at the same time.
11765 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011766
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011767 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011768 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011769
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011770 m_errorMonitor->SetBailout(NULL);
11771
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011772 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011773
Chia-I Wuf7458c52015-10-26 21:10:41 +080011774 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011775}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011776#endif // GTEST_IS_THREADSAFE
11777#endif // THREADING_TESTS
11778
Chris Forbes9f7ff632015-05-25 11:13:08 +120011779#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011780TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011781 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11782 "with an impossible code size");
11783
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011785
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011786 ASSERT_NO_FATAL_FAILURE(InitState());
11787 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11788
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011789 VkShaderModule module;
11790 VkShaderModuleCreateInfo moduleCreateInfo;
11791 struct icd_spv_header spv;
11792
11793 spv.magic = ICD_SPV_MAGIC;
11794 spv.version = ICD_SPV_VERSION;
11795 spv.gen_magic = 0;
11796
11797 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11798 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011799 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011800 moduleCreateInfo.codeSize = 4;
11801 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011802 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011803
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011804 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011805}
11806
Karl Schultz6addd812016-02-02 17:17:23 -070011807TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011808 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11809 "with a bad magic number");
11810
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011812
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011813 ASSERT_NO_FATAL_FAILURE(InitState());
11814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11815
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011816 VkShaderModule module;
11817 VkShaderModuleCreateInfo moduleCreateInfo;
11818 struct icd_spv_header spv;
11819
11820 spv.magic = ~ICD_SPV_MAGIC;
11821 spv.version = ICD_SPV_VERSION;
11822 spv.gen_magic = 0;
11823
11824 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11825 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011826 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011827 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11828 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011829 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011830
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011831 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011832}
11833
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011834#if 0
11835// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011836TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011838 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011839
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011840 ASSERT_NO_FATAL_FAILURE(InitState());
11841 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11842
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011843 VkShaderModule module;
11844 VkShaderModuleCreateInfo moduleCreateInfo;
11845 struct icd_spv_header spv;
11846
11847 spv.magic = ICD_SPV_MAGIC;
11848 spv.version = ~ICD_SPV_VERSION;
11849 spv.gen_magic = 0;
11850
11851 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11852 moduleCreateInfo.pNext = NULL;
11853
Karl Schultz6addd812016-02-02 17:17:23 -070011854 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011855 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11856 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011857 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011858
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011859 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011860}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011861#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011862
Karl Schultz6addd812016-02-02 17:17:23 -070011863TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011864 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11865 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011867
Chris Forbes9f7ff632015-05-25 11:13:08 +120011868 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011869 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011870
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011871 char const *vsSource = "#version 450\n"
11872 "\n"
11873 "layout(location=0) out float x;\n"
11874 "out gl_PerVertex {\n"
11875 " vec4 gl_Position;\n"
11876 "};\n"
11877 "void main(){\n"
11878 " gl_Position = vec4(1);\n"
11879 " x = 0;\n"
11880 "}\n";
11881 char const *fsSource = "#version 450\n"
11882 "\n"
11883 "layout(location=0) out vec4 color;\n"
11884 "void main(){\n"
11885 " color = vec4(1);\n"
11886 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011887
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011888 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11889 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011890
11891 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011892 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011893 pipe.AddShader(&vs);
11894 pipe.AddShader(&fs);
11895
Chris Forbes9f7ff632015-05-25 11:13:08 +120011896 VkDescriptorSetObj descriptorSet(m_device);
11897 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011898 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011899
Tony Barbour5781e8f2015-08-04 16:23:11 -060011900 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011901
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011902 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011903}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011904
Mark Mueller098c9cb2016-09-08 09:01:57 -060011905TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11906 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11907
11908 ASSERT_NO_FATAL_FAILURE(InitState());
11909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11910
11911 const char *bad_specialization_message =
11912 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11913
11914 char const *vsSource =
11915 "#version 450\n"
11916 "\n"
11917 "out gl_PerVertex {\n"
11918 " vec4 gl_Position;\n"
11919 "};\n"
11920 "void main(){\n"
11921 " gl_Position = vec4(1);\n"
11922 "}\n";
11923
11924 char const *fsSource =
11925 "#version 450\n"
11926 "\n"
11927 "layout (constant_id = 0) const float r = 0.0f;\n"
11928 "layout(location = 0) out vec4 uFragColor;\n"
11929 "void main(){\n"
11930 " uFragColor = vec4(r,1,0,1);\n"
11931 "}\n";
11932
11933 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11934 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11935
11936 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11937 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11938
11939 VkPipelineLayout pipeline_layout;
11940 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11941
11942 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11943 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11944 vp_state_create_info.viewportCount = 1;
11945 VkViewport viewport = {};
11946 vp_state_create_info.pViewports = &viewport;
11947 vp_state_create_info.scissorCount = 1;
11948 VkRect2D scissors = {};
11949 vp_state_create_info.pScissors = &scissors;
11950
11951 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11952
11953 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11954 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11955 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11956 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11957
11958 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11959 vs.GetStageCreateInfo(),
11960 fs.GetStageCreateInfo()
11961 };
11962
11963 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11964 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11965
11966 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11967 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11968 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11969
11970 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11971 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11972 rasterization_state_create_info.pNext = nullptr;
11973 rasterization_state_create_info.lineWidth = 1.0f;
11974 rasterization_state_create_info.rasterizerDiscardEnable = true;
11975
11976 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11977 color_blend_attachment_state.blendEnable = VK_FALSE;
11978 color_blend_attachment_state.colorWriteMask = 0xf;
11979
11980 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11981 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11982 color_blend_state_create_info.attachmentCount = 1;
11983 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11984
11985 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11986 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11987 graphicspipe_create_info.stageCount = 2;
11988 graphicspipe_create_info.pStages = shader_stage_create_info;
11989 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11990 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11991 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11992 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11993 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11994 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11995 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11996 graphicspipe_create_info.layout = pipeline_layout;
11997 graphicspipe_create_info.renderPass = renderPass();
11998
11999 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12000 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12001
12002 VkPipelineCache pipelineCache;
12003 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12004
12005 // This structure maps constant ids to data locations.
12006 const VkSpecializationMapEntry entry =
12007 // id, offset, size
12008 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12009
12010 uint32_t data = 1;
12011
12012 // Set up the info describing spec map and data
12013 const VkSpecializationInfo specialization_info = {
12014 1,
12015 &entry,
12016 1 * sizeof(float),
12017 &data,
12018 };
12019 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12020
12021 VkPipeline pipeline;
12022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12023 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12024 m_errorMonitor->VerifyFound();
12025
12026 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12027 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12028}
12029
12030TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12031 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12032
12033 ASSERT_NO_FATAL_FAILURE(InitState());
12034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12035
12036 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12037
12038 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12039 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12040 descriptor_pool_type_count[0].descriptorCount = 1;
12041 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12042 descriptor_pool_type_count[1].descriptorCount = 1;
12043
12044 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12045 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12046 descriptor_pool_create_info.maxSets = 1;
12047 descriptor_pool_create_info.poolSizeCount = 2;
12048 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12049 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12050
12051 VkDescriptorPool descriptorset_pool;
12052 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12053
12054 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12055 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12056 descriptorset_layout_binding.descriptorCount = 1;
12057 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12058
12059 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12060 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12061 descriptorset_layout_create_info.bindingCount = 1;
12062 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12063
12064 VkDescriptorSetLayout descriptorset_layout;
12065 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12066
12067 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12068 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12069 descriptorset_allocate_info.descriptorSetCount = 1;
12070 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12071 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12072 VkDescriptorSet descriptorset;
12073 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12074
12075 // Challenge core_validation with a non uniform buffer type.
12076 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12077
Mark Mueller098c9cb2016-09-08 09:01:57 -060012078 char const *vsSource =
12079 "#version 450\n"
12080 "\n"
12081 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12082 " mat4 mvp;\n"
12083 "} ubuf;\n"
12084 "out gl_PerVertex {\n"
12085 " vec4 gl_Position;\n"
12086 "};\n"
12087 "void main(){\n"
12088 " gl_Position = ubuf.mvp * vec4(1);\n"
12089 "}\n";
12090
12091 char const *fsSource =
12092 "#version 450\n"
12093 "\n"
12094 "layout(location = 0) out vec4 uFragColor;\n"
12095 "void main(){\n"
12096 " uFragColor = vec4(0,1,0,1);\n"
12097 "}\n";
12098
12099 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12100 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12101
12102 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12103 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12104 pipeline_layout_create_info.setLayoutCount = 1;
12105 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12106
12107 VkPipelineLayout pipeline_layout;
12108 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12109
12110 VkPipelineObj pipe(m_device);
12111 pipe.AddColorAttachment();
12112 pipe.AddShader(&vs);
12113 pipe.AddShader(&fs);
12114
12115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12116 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12117 m_errorMonitor->VerifyFound();
12118
12119 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12120 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12121 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12122}
12123
12124TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12125 TEST_DESCRIPTION(
12126 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12127
12128 ASSERT_NO_FATAL_FAILURE(InitState());
12129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12130
12131 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12132
12133 VkDescriptorPoolSize descriptor_pool_type_count = {};
12134 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12135 descriptor_pool_type_count.descriptorCount = 1;
12136
12137 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12138 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12139 descriptor_pool_create_info.maxSets = 1;
12140 descriptor_pool_create_info.poolSizeCount = 1;
12141 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12142 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12143
12144 VkDescriptorPool descriptorset_pool;
12145 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12146
12147 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12148 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12149 descriptorset_layout_binding.descriptorCount = 1;
12150 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12151 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12152
12153 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12154 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12155 descriptorset_layout_create_info.bindingCount = 1;
12156 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12157
12158 VkDescriptorSetLayout descriptorset_layout;
12159 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12160 nullptr, &descriptorset_layout));
12161
12162 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12163 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12164 descriptorset_allocate_info.descriptorSetCount = 1;
12165 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12166 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12167 VkDescriptorSet descriptorset;
12168 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12169
12170 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12171
Mark Mueller098c9cb2016-09-08 09:01:57 -060012172 char const *vsSource =
12173 "#version 450\n"
12174 "\n"
12175 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12176 " mat4 mvp;\n"
12177 "} ubuf;\n"
12178 "out gl_PerVertex {\n"
12179 " vec4 gl_Position;\n"
12180 "};\n"
12181 "void main(){\n"
12182 " gl_Position = ubuf.mvp * vec4(1);\n"
12183 "}\n";
12184
12185 char const *fsSource =
12186 "#version 450\n"
12187 "\n"
12188 "layout(location = 0) out vec4 uFragColor;\n"
12189 "void main(){\n"
12190 " uFragColor = vec4(0,1,0,1);\n"
12191 "}\n";
12192
12193 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12194 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12195
12196 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12197 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12198 pipeline_layout_create_info.setLayoutCount = 1;
12199 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12200
12201 VkPipelineLayout pipeline_layout;
12202 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12203
12204 VkPipelineObj pipe(m_device);
12205 pipe.AddColorAttachment();
12206 pipe.AddShader(&vs);
12207 pipe.AddShader(&fs);
12208
12209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12210 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12211 m_errorMonitor->VerifyFound();
12212
12213 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12214 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12215 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12216}
12217
12218TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12219 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12220 "accessible from the current shader stage.");
12221
12222 ASSERT_NO_FATAL_FAILURE(InitState());
12223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12224
12225 const char *push_constant_not_accessible_message =
12226 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12227
12228 char const *vsSource =
12229 "#version 450\n"
12230 "\n"
12231 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12232 "out gl_PerVertex {\n"
12233 " vec4 gl_Position;\n"
12234 "};\n"
12235 "void main(){\n"
12236 " gl_Position = vec4(consts.x);\n"
12237 "}\n";
12238
12239 char const *fsSource =
12240 "#version 450\n"
12241 "\n"
12242 "layout(location = 0) out vec4 uFragColor;\n"
12243 "void main(){\n"
12244 " uFragColor = vec4(0,1,0,1);\n"
12245 "}\n";
12246
12247 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12248 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12249
12250 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12251 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12252
12253 // Set up a push constant range
12254 VkPushConstantRange push_constant_ranges = {};
12255 // Set to the wrong stage to challenge core_validation
12256 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12257 push_constant_ranges.size = 4;
12258
12259 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12260 pipeline_layout_create_info.pushConstantRangeCount = 1;
12261
12262 VkPipelineLayout pipeline_layout;
12263 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12264
12265 VkPipelineObj pipe(m_device);
12266 pipe.AddColorAttachment();
12267 pipe.AddShader(&vs);
12268 pipe.AddShader(&fs);
12269
12270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12271 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12272 m_errorMonitor->VerifyFound();
12273
12274 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12275}
12276
12277TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12278 TEST_DESCRIPTION(
12279 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12280
12281 ASSERT_NO_FATAL_FAILURE(InitState());
12282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12283
12284 const char *feature_not_enabled_message =
12285 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12286
12287 // Some awkward steps are required to test with custom device features.
12288 std::vector<const char *> device_extension_names;
12289 auto features = m_device->phy().features();
12290 // Disable support for 64 bit floats
12291 features.shaderFloat64 = false;
12292 // The sacrificial device object
12293 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12294
12295 char const *vsSource = "#version 450\n"
12296 "\n"
12297 "out gl_PerVertex {\n"
12298 " vec4 gl_Position;\n"
12299 "};\n"
12300 "void main(){\n"
12301 " gl_Position = vec4(1);\n"
12302 "}\n";
12303 char const *fsSource = "#version 450\n"
12304 "\n"
12305 "layout(location=0) out vec4 color;\n"
12306 "void main(){\n"
12307 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12308 " color = vec4(green);\n"
12309 "}\n";
12310
12311 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12312 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12313
12314 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012315
12316 VkPipelineObj pipe(&test_device);
12317 pipe.AddColorAttachment();
12318 pipe.AddShader(&vs);
12319 pipe.AddShader(&fs);
12320
12321 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12322 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12323 VkPipelineLayout pipeline_layout;
12324 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12325
12326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12327 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12328 m_errorMonitor->VerifyFound();
12329
12330 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12331}
12332
12333TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12334 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12335
12336 ASSERT_NO_FATAL_FAILURE(InitState());
12337 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12338
12339 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12340
12341 char const *vsSource = "#version 450\n"
12342 "\n"
12343 "out gl_PerVertex {\n"
12344 " vec4 gl_Position;\n"
12345 "};\n"
12346 "layout(xfb_buffer = 1) out;"
12347 "void main(){\n"
12348 " gl_Position = vec4(1);\n"
12349 "}\n";
12350 char const *fsSource = "#version 450\n"
12351 "\n"
12352 "layout(location=0) out vec4 color;\n"
12353 "void main(){\n"
12354 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12355 " color = vec4(green);\n"
12356 "}\n";
12357
12358 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12359 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12360
12361 VkPipelineObj pipe(m_device);
12362 pipe.AddColorAttachment();
12363 pipe.AddShader(&vs);
12364 pipe.AddShader(&fs);
12365
12366 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12367 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12368 VkPipelineLayout pipeline_layout;
12369 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12370
12371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12372 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12373 m_errorMonitor->VerifyFound();
12374
12375 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12376}
12377
Karl Schultz6addd812016-02-02 17:17:23 -070012378TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012379 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12380 "which is not present in the outputs of the previous stage");
12381
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012383
Chris Forbes59cb88d2015-05-25 11:13:13 +120012384 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012385 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012386
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012387 char const *vsSource = "#version 450\n"
12388 "\n"
12389 "out gl_PerVertex {\n"
12390 " vec4 gl_Position;\n"
12391 "};\n"
12392 "void main(){\n"
12393 " gl_Position = vec4(1);\n"
12394 "}\n";
12395 char const *fsSource = "#version 450\n"
12396 "\n"
12397 "layout(location=0) in float x;\n"
12398 "layout(location=0) out vec4 color;\n"
12399 "void main(){\n"
12400 " color = vec4(x);\n"
12401 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012402
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012403 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12404 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012405
12406 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012407 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012408 pipe.AddShader(&vs);
12409 pipe.AddShader(&fs);
12410
Chris Forbes59cb88d2015-05-25 11:13:13 +120012411 VkDescriptorSetObj descriptorSet(m_device);
12412 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012413 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012414
Tony Barbour5781e8f2015-08-04 16:23:11 -060012415 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012416
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012417 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012418}
12419
Karl Schultz6addd812016-02-02 17:17:23 -070012420TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012421 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12422 "within an interace block, which is not present in the outputs "
12423 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012425
12426 ASSERT_NO_FATAL_FAILURE(InitState());
12427 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12428
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012429 char const *vsSource = "#version 450\n"
12430 "\n"
12431 "out gl_PerVertex {\n"
12432 " vec4 gl_Position;\n"
12433 "};\n"
12434 "void main(){\n"
12435 " gl_Position = vec4(1);\n"
12436 "}\n";
12437 char const *fsSource = "#version 450\n"
12438 "\n"
12439 "in block { layout(location=0) float x; } ins;\n"
12440 "layout(location=0) out vec4 color;\n"
12441 "void main(){\n"
12442 " color = vec4(ins.x);\n"
12443 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012444
12445 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12446 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12447
12448 VkPipelineObj pipe(m_device);
12449 pipe.AddColorAttachment();
12450 pipe.AddShader(&vs);
12451 pipe.AddShader(&fs);
12452
12453 VkDescriptorSetObj descriptorSet(m_device);
12454 descriptorSet.AppendDummy();
12455 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12456
12457 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12458
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012459 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012460}
12461
Karl Schultz6addd812016-02-02 17:17:23 -070012462TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012463 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012464 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12466 "output arr[2] of float32' vs 'ptr to "
12467 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012468
12469 ASSERT_NO_FATAL_FAILURE(InitState());
12470 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12471
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012472 char const *vsSource = "#version 450\n"
12473 "\n"
12474 "layout(location=0) out float x[2];\n"
12475 "out gl_PerVertex {\n"
12476 " vec4 gl_Position;\n"
12477 "};\n"
12478 "void main(){\n"
12479 " x[0] = 0; x[1] = 0;\n"
12480 " gl_Position = vec4(1);\n"
12481 "}\n";
12482 char const *fsSource = "#version 450\n"
12483 "\n"
12484 "layout(location=0) in float x[3];\n"
12485 "layout(location=0) out vec4 color;\n"
12486 "void main(){\n"
12487 " color = vec4(x[0] + x[1] + x[2]);\n"
12488 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012489
12490 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12491 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12492
12493 VkPipelineObj pipe(m_device);
12494 pipe.AddColorAttachment();
12495 pipe.AddShader(&vs);
12496 pipe.AddShader(&fs);
12497
12498 VkDescriptorSetObj descriptorSet(m_device);
12499 descriptorSet.AppendDummy();
12500 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12501
12502 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12503
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012504 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012505}
12506
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012507
Karl Schultz6addd812016-02-02 17:17:23 -070012508TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012509 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012510 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012512
Chris Forbesb56af562015-05-25 11:13:17 +120012513 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012515
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012516 char const *vsSource = "#version 450\n"
12517 "\n"
12518 "layout(location=0) out int x;\n"
12519 "out gl_PerVertex {\n"
12520 " vec4 gl_Position;\n"
12521 "};\n"
12522 "void main(){\n"
12523 " x = 0;\n"
12524 " gl_Position = vec4(1);\n"
12525 "}\n";
12526 char const *fsSource = "#version 450\n"
12527 "\n"
12528 "layout(location=0) in float x;\n" /* VS writes int */
12529 "layout(location=0) out vec4 color;\n"
12530 "void main(){\n"
12531 " color = vec4(x);\n"
12532 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012533
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012534 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12535 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012536
12537 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012538 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012539 pipe.AddShader(&vs);
12540 pipe.AddShader(&fs);
12541
Chris Forbesb56af562015-05-25 11:13:17 +120012542 VkDescriptorSetObj descriptorSet(m_device);
12543 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012544 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012545
Tony Barbour5781e8f2015-08-04 16:23:11 -060012546 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012547
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012548 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012549}
12550
Karl Schultz6addd812016-02-02 17:17:23 -070012551TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012552 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012553 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012554 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012556
12557 ASSERT_NO_FATAL_FAILURE(InitState());
12558 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012560 char const *vsSource = "#version 450\n"
12561 "\n"
12562 "out block { layout(location=0) int x; } outs;\n"
12563 "out gl_PerVertex {\n"
12564 " vec4 gl_Position;\n"
12565 "};\n"
12566 "void main(){\n"
12567 " outs.x = 0;\n"
12568 " gl_Position = vec4(1);\n"
12569 "}\n";
12570 char const *fsSource = "#version 450\n"
12571 "\n"
12572 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12573 "layout(location=0) out vec4 color;\n"
12574 "void main(){\n"
12575 " color = vec4(ins.x);\n"
12576 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012577
12578 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12579 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12580
12581 VkPipelineObj pipe(m_device);
12582 pipe.AddColorAttachment();
12583 pipe.AddShader(&vs);
12584 pipe.AddShader(&fs);
12585
12586 VkDescriptorSetObj descriptorSet(m_device);
12587 descriptorSet.AppendDummy();
12588 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12589
12590 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12591
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012592 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012593}
12594
12595TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012596 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012597 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012598 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012599 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 +130012600
12601 ASSERT_NO_FATAL_FAILURE(InitState());
12602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012604 char const *vsSource = "#version 450\n"
12605 "\n"
12606 "out block { layout(location=1) float x; } outs;\n"
12607 "out gl_PerVertex {\n"
12608 " vec4 gl_Position;\n"
12609 "};\n"
12610 "void main(){\n"
12611 " outs.x = 0;\n"
12612 " gl_Position = vec4(1);\n"
12613 "}\n";
12614 char const *fsSource = "#version 450\n"
12615 "\n"
12616 "in block { layout(location=0) float x; } ins;\n"
12617 "layout(location=0) out vec4 color;\n"
12618 "void main(){\n"
12619 " color = vec4(ins.x);\n"
12620 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012621
12622 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12623 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12624
12625 VkPipelineObj pipe(m_device);
12626 pipe.AddColorAttachment();
12627 pipe.AddShader(&vs);
12628 pipe.AddShader(&fs);
12629
12630 VkDescriptorSetObj descriptorSet(m_device);
12631 descriptorSet.AppendDummy();
12632 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12633
12634 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12635
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012636 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012637}
12638
12639TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012640 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012641 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012642 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012643 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 +130012644
12645 ASSERT_NO_FATAL_FAILURE(InitState());
12646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12647
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012648 char const *vsSource = "#version 450\n"
12649 "\n"
12650 "out block { layout(location=0, component=0) float x; } outs;\n"
12651 "out gl_PerVertex {\n"
12652 " vec4 gl_Position;\n"
12653 "};\n"
12654 "void main(){\n"
12655 " outs.x = 0;\n"
12656 " gl_Position = vec4(1);\n"
12657 "}\n";
12658 char const *fsSource = "#version 450\n"
12659 "\n"
12660 "in block { layout(location=0, component=1) float x; } ins;\n"
12661 "layout(location=0) out vec4 color;\n"
12662 "void main(){\n"
12663 " color = vec4(ins.x);\n"
12664 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012665
12666 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12667 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12668
12669 VkPipelineObj pipe(m_device);
12670 pipe.AddColorAttachment();
12671 pipe.AddShader(&vs);
12672 pipe.AddShader(&fs);
12673
12674 VkDescriptorSetObj descriptorSet(m_device);
12675 descriptorSet.AppendDummy();
12676 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12677
12678 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12679
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012680 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012681}
12682
Karl Schultz6addd812016-02-02 17:17:23 -070012683TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012684 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12685 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012687
Chris Forbesde136e02015-05-25 11:13:28 +120012688 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012689 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012690
12691 VkVertexInputBindingDescription input_binding;
12692 memset(&input_binding, 0, sizeof(input_binding));
12693
12694 VkVertexInputAttributeDescription input_attrib;
12695 memset(&input_attrib, 0, sizeof(input_attrib));
12696 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12697
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012698 char const *vsSource = "#version 450\n"
12699 "\n"
12700 "out gl_PerVertex {\n"
12701 " vec4 gl_Position;\n"
12702 "};\n"
12703 "void main(){\n"
12704 " gl_Position = vec4(1);\n"
12705 "}\n";
12706 char const *fsSource = "#version 450\n"
12707 "\n"
12708 "layout(location=0) out vec4 color;\n"
12709 "void main(){\n"
12710 " color = vec4(1);\n"
12711 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012712
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012713 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12714 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012715
12716 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012717 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012718 pipe.AddShader(&vs);
12719 pipe.AddShader(&fs);
12720
12721 pipe.AddVertexInputBindings(&input_binding, 1);
12722 pipe.AddVertexInputAttribs(&input_attrib, 1);
12723
Chris Forbesde136e02015-05-25 11:13:28 +120012724 VkDescriptorSetObj descriptorSet(m_device);
12725 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012726 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012727
Tony Barbour5781e8f2015-08-04 16:23:11 -060012728 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012729
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012730 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012731}
12732
Karl Schultz6addd812016-02-02 17:17:23 -070012733TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012734 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12735 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012737
12738 ASSERT_NO_FATAL_FAILURE(InitState());
12739 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12740
12741 VkVertexInputBindingDescription input_binding;
12742 memset(&input_binding, 0, sizeof(input_binding));
12743
12744 VkVertexInputAttributeDescription input_attrib;
12745 memset(&input_attrib, 0, sizeof(input_attrib));
12746 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12747
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012748 char const *vsSource = "#version 450\n"
12749 "\n"
12750 "layout(location=1) in float x;\n"
12751 "out gl_PerVertex {\n"
12752 " vec4 gl_Position;\n"
12753 "};\n"
12754 "void main(){\n"
12755 " gl_Position = vec4(x);\n"
12756 "}\n";
12757 char const *fsSource = "#version 450\n"
12758 "\n"
12759 "layout(location=0) out vec4 color;\n"
12760 "void main(){\n"
12761 " color = vec4(1);\n"
12762 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012763
12764 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12765 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12766
12767 VkPipelineObj pipe(m_device);
12768 pipe.AddColorAttachment();
12769 pipe.AddShader(&vs);
12770 pipe.AddShader(&fs);
12771
12772 pipe.AddVertexInputBindings(&input_binding, 1);
12773 pipe.AddVertexInputAttribs(&input_attrib, 1);
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 Forbes7d83cd52016-01-15 11:32:03 +130012782}
12783
Karl Schultz6addd812016-02-02 17:17:23 -070012784TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012785 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012786 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012787 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 -060012788
Chris Forbes62e8e502015-05-25 11:13:29 +120012789 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012791
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012792 char const *vsSource = "#version 450\n"
12793 "\n"
12794 "layout(location=0) in vec4 x;\n" /* not provided */
12795 "out gl_PerVertex {\n"
12796 " vec4 gl_Position;\n"
12797 "};\n"
12798 "void main(){\n"
12799 " gl_Position = x;\n"
12800 "}\n";
12801 char const *fsSource = "#version 450\n"
12802 "\n"
12803 "layout(location=0) out vec4 color;\n"
12804 "void main(){\n"
12805 " color = vec4(1);\n"
12806 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012807
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012808 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12809 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012810
12811 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012812 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012813 pipe.AddShader(&vs);
12814 pipe.AddShader(&fs);
12815
Chris Forbes62e8e502015-05-25 11:13:29 +120012816 VkDescriptorSetObj descriptorSet(m_device);
12817 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012818 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012819
Tony Barbour5781e8f2015-08-04 16:23:11 -060012820 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012821
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012822 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012823}
12824
Karl Schultz6addd812016-02-02 17:17:23 -070012825TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012826 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12827 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012828 "vertex shader input that consumes it");
12829 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 -060012830
Chris Forbesc97d98e2015-05-25 11:13:31 +120012831 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012832 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012833
12834 VkVertexInputBindingDescription input_binding;
12835 memset(&input_binding, 0, sizeof(input_binding));
12836
12837 VkVertexInputAttributeDescription input_attrib;
12838 memset(&input_attrib, 0, sizeof(input_attrib));
12839 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12840
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012841 char const *vsSource = "#version 450\n"
12842 "\n"
12843 "layout(location=0) in int x;\n" /* attrib provided float */
12844 "out gl_PerVertex {\n"
12845 " vec4 gl_Position;\n"
12846 "};\n"
12847 "void main(){\n"
12848 " gl_Position = vec4(x);\n"
12849 "}\n";
12850 char const *fsSource = "#version 450\n"
12851 "\n"
12852 "layout(location=0) out vec4 color;\n"
12853 "void main(){\n"
12854 " color = vec4(1);\n"
12855 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012856
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012857 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12858 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012859
12860 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012861 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012862 pipe.AddShader(&vs);
12863 pipe.AddShader(&fs);
12864
12865 pipe.AddVertexInputBindings(&input_binding, 1);
12866 pipe.AddVertexInputAttribs(&input_attrib, 1);
12867
Chris Forbesc97d98e2015-05-25 11:13:31 +120012868 VkDescriptorSetObj descriptorSet(m_device);
12869 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012870 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012871
Tony Barbour5781e8f2015-08-04 16:23:11 -060012872 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012873
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012874 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012875}
12876
Chris Forbesc68b43c2016-04-06 11:18:47 +120012877TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012878 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12879 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12881 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012882
12883 ASSERT_NO_FATAL_FAILURE(InitState());
12884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012886 char const *vsSource = "#version 450\n"
12887 "\n"
12888 "out gl_PerVertex {\n"
12889 " vec4 gl_Position;\n"
12890 "};\n"
12891 "void main(){\n"
12892 " gl_Position = vec4(1);\n"
12893 "}\n";
12894 char const *fsSource = "#version 450\n"
12895 "\n"
12896 "layout(location=0) out vec4 color;\n"
12897 "void main(){\n"
12898 " color = vec4(1);\n"
12899 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012900
12901 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12902 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12903
12904 VkPipelineObj pipe(m_device);
12905 pipe.AddColorAttachment();
12906 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012907 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012908 pipe.AddShader(&fs);
12909
12910 VkDescriptorSetObj descriptorSet(m_device);
12911 descriptorSet.AppendDummy();
12912 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12913
12914 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12915
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012916 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012917}
12918
Chris Forbes82ff92a2016-09-09 10:50:24 +120012919TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12921 "No entrypoint found named `foo`");
12922
12923 ASSERT_NO_FATAL_FAILURE(InitState());
12924 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12925
12926 char const *vsSource = "#version 450\n"
12927 "out gl_PerVertex {\n"
12928 " vec4 gl_Position;\n"
12929 "};\n"
12930 "void main(){\n"
12931 " gl_Position = vec4(0);\n"
12932 "}\n";
12933 char const *fsSource = "#version 450\n"
12934 "\n"
12935 "layout(location=0) out vec4 color;\n"
12936 "void main(){\n"
12937 " color = vec4(1);\n"
12938 "}\n";
12939
12940 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12941 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12942
12943 VkPipelineObj pipe(m_device);
12944 pipe.AddColorAttachment();
12945 pipe.AddShader(&vs);
12946 pipe.AddShader(&fs);
12947
12948 VkDescriptorSetObj descriptorSet(m_device);
12949 descriptorSet.AppendDummy();
12950 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12951
12952 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12953
12954 m_errorMonitor->VerifyFound();
12955}
12956
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012957TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12958 m_errorMonitor->SetDesiredFailureMsg(
12959 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12960 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12961 "uses a depth/stencil attachment");
12962
12963 ASSERT_NO_FATAL_FAILURE(InitState());
12964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12965
12966 char const *vsSource = "#version 450\n"
12967 "void main(){ gl_Position = vec4(0); }\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";
12974
12975 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12976 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12977
12978 VkPipelineObj pipe(m_device);
12979 pipe.AddColorAttachment();
12980 pipe.AddShader(&vs);
12981 pipe.AddShader(&fs);
12982
12983 VkDescriptorSetObj descriptorSet(m_device);
12984 descriptorSet.AppendDummy();
12985 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12986
12987 VkAttachmentDescription attachments[] = {
12988 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12989 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12990 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12991 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12992 },
12993 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12994 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12995 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12996 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12997 },
12998 };
12999 VkAttachmentReference refs[] = {
13000 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13001 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13002 };
13003 VkSubpassDescription subpass = {
13004 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13005 1, &refs[0], nullptr, &refs[1],
13006 0, nullptr
13007 };
13008 VkRenderPassCreateInfo rpci = {
13009 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13010 0, 2, attachments, 1, &subpass, 0, nullptr
13011 };
13012 VkRenderPass rp;
13013 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13014 ASSERT_VK_SUCCESS(err);
13015
13016 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13017
13018 m_errorMonitor->VerifyFound();
13019
13020 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13021}
13022
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013023TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013024 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13025 "the TCS without the patch decoration, but consumed in the TES "
13026 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13028 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013029
13030 ASSERT_NO_FATAL_FAILURE(InitState());
13031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13032
Chris Forbesc1e852d2016-04-04 19:26:42 +120013033 if (!m_device->phy().features().tessellationShader) {
13034 printf("Device does not support tessellation shaders; skipped.\n");
13035 return;
13036 }
13037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013038 char const *vsSource = "#version 450\n"
13039 "void main(){}\n";
13040 char const *tcsSource = "#version 450\n"
13041 "layout(location=0) out int x[];\n"
13042 "layout(vertices=3) out;\n"
13043 "void main(){\n"
13044 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13045 " gl_TessLevelInner[0] = 1;\n"
13046 " x[gl_InvocationID] = gl_InvocationID;\n"
13047 "}\n";
13048 char const *tesSource = "#version 450\n"
13049 "layout(triangles, equal_spacing, cw) in;\n"
13050 "layout(location=0) patch in int x;\n"
13051 "out gl_PerVertex { vec4 gl_Position; };\n"
13052 "void main(){\n"
13053 " gl_Position.xyz = gl_TessCoord;\n"
13054 " gl_Position.w = x;\n"
13055 "}\n";
13056 char const *fsSource = "#version 450\n"
13057 "layout(location=0) out vec4 color;\n"
13058 "void main(){\n"
13059 " color = vec4(1);\n"
13060 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013061
13062 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13063 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13064 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13065 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013067 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13068 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013070 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013071
13072 VkPipelineObj pipe(m_device);
13073 pipe.SetInputAssembly(&iasci);
13074 pipe.SetTessellation(&tsci);
13075 pipe.AddColorAttachment();
13076 pipe.AddShader(&vs);
13077 pipe.AddShader(&tcs);
13078 pipe.AddShader(&tes);
13079 pipe.AddShader(&fs);
13080
13081 VkDescriptorSetObj descriptorSet(m_device);
13082 descriptorSet.AppendDummy();
13083 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13084
13085 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13086
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013087 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013088}
13089
Karl Schultz6addd812016-02-02 17:17:23 -070013090TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013091 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13092 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13094 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013095
Chris Forbes280ba2c2015-06-12 11:16:41 +120013096 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013098
13099 /* Two binding descriptions for binding 0 */
13100 VkVertexInputBindingDescription input_bindings[2];
13101 memset(input_bindings, 0, sizeof(input_bindings));
13102
13103 VkVertexInputAttributeDescription input_attrib;
13104 memset(&input_attrib, 0, sizeof(input_attrib));
13105 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13106
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013107 char const *vsSource = "#version 450\n"
13108 "\n"
13109 "layout(location=0) in float x;\n" /* attrib provided float */
13110 "out gl_PerVertex {\n"
13111 " vec4 gl_Position;\n"
13112 "};\n"
13113 "void main(){\n"
13114 " gl_Position = vec4(x);\n"
13115 "}\n";
13116 char const *fsSource = "#version 450\n"
13117 "\n"
13118 "layout(location=0) out vec4 color;\n"
13119 "void main(){\n"
13120 " color = vec4(1);\n"
13121 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013122
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013123 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13124 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013125
13126 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013127 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013128 pipe.AddShader(&vs);
13129 pipe.AddShader(&fs);
13130
13131 pipe.AddVertexInputBindings(input_bindings, 2);
13132 pipe.AddVertexInputAttribs(&input_attrib, 1);
13133
Chris Forbes280ba2c2015-06-12 11:16:41 +120013134 VkDescriptorSetObj descriptorSet(m_device);
13135 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013136 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013137
Tony Barbour5781e8f2015-08-04 16:23:11 -060013138 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013139
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013140 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013141}
Chris Forbes8f68b562015-05-25 11:13:32 +120013142
Karl Schultz6addd812016-02-02 17:17:23 -070013143TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013144 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013145 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013147
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013148 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013150 char const *vsSource = "#version 450\n"
13151 "\n"
13152 "out gl_PerVertex {\n"
13153 " vec4 gl_Position;\n"
13154 "};\n"
13155 "void main(){\n"
13156 " gl_Position = vec4(1);\n"
13157 "}\n";
13158 char const *fsSource = "#version 450\n"
13159 "\n"
13160 "void main(){\n"
13161 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013162
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013163 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13164 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013165
13166 VkPipelineObj pipe(m_device);
13167 pipe.AddShader(&vs);
13168 pipe.AddShader(&fs);
13169
Chia-I Wu08accc62015-07-07 11:50:03 +080013170 /* set up CB 0, not written */
13171 pipe.AddColorAttachment();
13172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013173
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013174 VkDescriptorSetObj descriptorSet(m_device);
13175 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013176 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013177
Tony Barbour5781e8f2015-08-04 16:23:11 -060013178 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013179
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013180 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013181}
13182
Karl Schultz6addd812016-02-02 17:17:23 -070013183TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013184 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013185 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013187 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013188
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013189 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013191 char const *vsSource = "#version 450\n"
13192 "\n"
13193 "out gl_PerVertex {\n"
13194 " vec4 gl_Position;\n"
13195 "};\n"
13196 "void main(){\n"
13197 " gl_Position = vec4(1);\n"
13198 "}\n";
13199 char const *fsSource = "#version 450\n"
13200 "\n"
13201 "layout(location=0) out vec4 x;\n"
13202 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13203 "void main(){\n"
13204 " x = vec4(1);\n"
13205 " y = vec4(1);\n"
13206 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013207
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013208 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13209 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013210
13211 VkPipelineObj pipe(m_device);
13212 pipe.AddShader(&vs);
13213 pipe.AddShader(&fs);
13214
Chia-I Wu08accc62015-07-07 11:50:03 +080013215 /* set up CB 0, not written */
13216 pipe.AddColorAttachment();
13217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013218 /* FS writes CB 1, but we don't configure it */
13219
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013220 VkDescriptorSetObj descriptorSet(m_device);
13221 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013222 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013223
Tony Barbour5781e8f2015-08-04 16:23:11 -060013224 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013225
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013226 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013227}
13228
Karl Schultz6addd812016-02-02 17:17:23 -070013229TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013230 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013231 "type of an fragment shader output variable, and the format of the corresponding attachment");
13232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013233
Chris Forbesa36d69e2015-05-25 11:13:44 +120013234 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013236 char const *vsSource = "#version 450\n"
13237 "\n"
13238 "out gl_PerVertex {\n"
13239 " vec4 gl_Position;\n"
13240 "};\n"
13241 "void main(){\n"
13242 " gl_Position = vec4(1);\n"
13243 "}\n";
13244 char const *fsSource = "#version 450\n"
13245 "\n"
13246 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13247 "void main(){\n"
13248 " x = ivec4(1);\n"
13249 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013250
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013251 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13252 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013253
13254 VkPipelineObj pipe(m_device);
13255 pipe.AddShader(&vs);
13256 pipe.AddShader(&fs);
13257
Chia-I Wu08accc62015-07-07 11:50:03 +080013258 /* set up CB 0; type is UNORM by default */
13259 pipe.AddColorAttachment();
13260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013261
Chris Forbesa36d69e2015-05-25 11:13:44 +120013262 VkDescriptorSetObj descriptorSet(m_device);
13263 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013264 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013265
Tony Barbour5781e8f2015-08-04 16:23:11 -060013266 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013267
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013268 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013269}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013270
Karl Schultz6addd812016-02-02 17:17:23 -070013271TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013272 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13273 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013275
Chris Forbes556c76c2015-08-14 12:04:59 +120013276 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013278 char const *vsSource = "#version 450\n"
13279 "\n"
13280 "out gl_PerVertex {\n"
13281 " vec4 gl_Position;\n"
13282 "};\n"
13283 "void main(){\n"
13284 " gl_Position = vec4(1);\n"
13285 "}\n";
13286 char const *fsSource = "#version 450\n"
13287 "\n"
13288 "layout(location=0) out vec4 x;\n"
13289 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13290 "void main(){\n"
13291 " x = vec4(bar.y);\n"
13292 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013293
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013294 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13295 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013296
Chris Forbes556c76c2015-08-14 12:04:59 +120013297 VkPipelineObj pipe(m_device);
13298 pipe.AddShader(&vs);
13299 pipe.AddShader(&fs);
13300
13301 /* set up CB 0; type is UNORM by default */
13302 pipe.AddColorAttachment();
13303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13304
13305 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013306 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013307
13308 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13309
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013310 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013311}
13312
Chris Forbes5c59e902016-02-26 16:56:09 +130013313TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013314 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13315 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013317
13318 ASSERT_NO_FATAL_FAILURE(InitState());
13319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013320 char const *vsSource = "#version 450\n"
13321 "\n"
13322 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13323 "out gl_PerVertex {\n"
13324 " vec4 gl_Position;\n"
13325 "};\n"
13326 "void main(){\n"
13327 " gl_Position = vec4(consts.x);\n"
13328 "}\n";
13329 char const *fsSource = "#version 450\n"
13330 "\n"
13331 "layout(location=0) out vec4 x;\n"
13332 "void main(){\n"
13333 " x = vec4(1);\n"
13334 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013335
13336 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13337 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13338
13339 VkPipelineObj pipe(m_device);
13340 pipe.AddShader(&vs);
13341 pipe.AddShader(&fs);
13342
13343 /* set up CB 0; type is UNORM by default */
13344 pipe.AddColorAttachment();
13345 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13346
13347 VkDescriptorSetObj descriptorSet(m_device);
13348 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13349
13350 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13351
13352 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013353 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013354}
13355
Chris Forbes3fb17902016-08-22 14:57:55 +120013356TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13357 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13358 "which is not included in the subpass description");
13359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13360 "consumes input attachment index 0 but not provided in subpass");
13361
13362 ASSERT_NO_FATAL_FAILURE(InitState());
13363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013364 char const *vsSource = "#version 450\n"
13365 "\n"
13366 "out gl_PerVertex {\n"
13367 " vec4 gl_Position;\n"
13368 "};\n"
13369 "void main(){\n"
13370 " gl_Position = vec4(1);\n"
13371 "}\n";
13372 char const *fsSource = "#version 450\n"
13373 "\n"
13374 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13375 "layout(location=0) out vec4 color;\n"
13376 "void main() {\n"
13377 " color = subpassLoad(x);\n"
13378 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013379
13380 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13381 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13382
13383 VkPipelineObj pipe(m_device);
13384 pipe.AddShader(&vs);
13385 pipe.AddShader(&fs);
13386 pipe.AddColorAttachment();
13387 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013389 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13390 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013391 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013392 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013393 ASSERT_VK_SUCCESS(err);
13394
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013395 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013396 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013397 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013398 ASSERT_VK_SUCCESS(err);
13399
13400 // error here.
13401 pipe.CreateVKPipeline(pl, renderPass());
13402
13403 m_errorMonitor->VerifyFound();
13404
13405 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13406 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13407}
13408
Chris Forbes5a9a0472016-08-22 16:02:09 +120013409TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13410 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13411 "with a format having a different fundamental type");
13412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13413 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13414
13415 ASSERT_NO_FATAL_FAILURE(InitState());
13416
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013417 char const *vsSource = "#version 450\n"
13418 "\n"
13419 "out gl_PerVertex {\n"
13420 " vec4 gl_Position;\n"
13421 "};\n"
13422 "void main(){\n"
13423 " gl_Position = vec4(1);\n"
13424 "}\n";
13425 char const *fsSource = "#version 450\n"
13426 "\n"
13427 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13428 "layout(location=0) out vec4 color;\n"
13429 "void main() {\n"
13430 " color = subpassLoad(x);\n"
13431 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013432
13433 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13434 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13435
13436 VkPipelineObj pipe(m_device);
13437 pipe.AddShader(&vs);
13438 pipe.AddShader(&fs);
13439 pipe.AddColorAttachment();
13440 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13441
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013442 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13443 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013444 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013445 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013446 ASSERT_VK_SUCCESS(err);
13447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013448 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013449 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013450 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013451 ASSERT_VK_SUCCESS(err);
13452
13453 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013454 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13455 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13456 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13457 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13458 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 +120013459 };
13460 VkAttachmentReference color = {
13461 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13462 };
13463 VkAttachmentReference input = {
13464 1, VK_IMAGE_LAYOUT_GENERAL,
13465 };
13466
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013467 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013468
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013469 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013470 VkRenderPass rp;
13471 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13472 ASSERT_VK_SUCCESS(err);
13473
13474 // error here.
13475 pipe.CreateVKPipeline(pl, rp);
13476
13477 m_errorMonitor->VerifyFound();
13478
13479 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13480 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13481 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13482}
13483
Chris Forbes541f7b02016-08-22 15:30:27 +120013484TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13485 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13486 "which is not included in the subpass description -- array case");
13487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13488 "consumes input attachment index 1 but not provided in subpass");
13489
13490 ASSERT_NO_FATAL_FAILURE(InitState());
13491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013492 char const *vsSource = "#version 450\n"
13493 "\n"
13494 "out gl_PerVertex {\n"
13495 " vec4 gl_Position;\n"
13496 "};\n"
13497 "void main(){\n"
13498 " gl_Position = vec4(1);\n"
13499 "}\n";
13500 char const *fsSource = "#version 450\n"
13501 "\n"
13502 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13503 "layout(location=0) out vec4 color;\n"
13504 "void main() {\n"
13505 " color = subpassLoad(xs[1]);\n"
13506 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013507
13508 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13509 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13510
13511 VkPipelineObj pipe(m_device);
13512 pipe.AddShader(&vs);
13513 pipe.AddShader(&fs);
13514 pipe.AddColorAttachment();
13515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013517 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13518 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013519 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013520 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013521 ASSERT_VK_SUCCESS(err);
13522
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013523 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013524 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013525 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013526 ASSERT_VK_SUCCESS(err);
13527
13528 // error here.
13529 pipe.CreateVKPipeline(pl, renderPass());
13530
13531 m_errorMonitor->VerifyFound();
13532
13533 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13534 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13535}
13536
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013537TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013538 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13539 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013541
13542 ASSERT_NO_FATAL_FAILURE(InitState());
13543
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013544 char const *csSource = "#version 450\n"
13545 "\n"
13546 "layout(local_size_x=1) in;\n"
13547 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13548 "void main(){\n"
13549 " x = vec4(1);\n"
13550 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013551
13552 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13553
13554 VkDescriptorSetObj descriptorSet(m_device);
13555 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13556
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013557 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13558 nullptr,
13559 0,
13560 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13561 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13562 descriptorSet.GetPipelineLayout(),
13563 VK_NULL_HANDLE,
13564 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013565
13566 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013567 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013568
13569 m_errorMonitor->VerifyFound();
13570
13571 if (err == VK_SUCCESS) {
13572 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13573 }
13574}
13575
Chris Forbes22a9b092016-07-19 14:34:05 +120013576TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013577 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13578 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13580 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013581
13582 ASSERT_NO_FATAL_FAILURE(InitState());
13583
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013584 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13585 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013586 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013587 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013588 ASSERT_VK_SUCCESS(err);
13589
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013590 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013591 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013592 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013593 ASSERT_VK_SUCCESS(err);
13594
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013595 char const *csSource = "#version 450\n"
13596 "\n"
13597 "layout(local_size_x=1) in;\n"
13598 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13599 "void main() {\n"
13600 " x.x = 1.0f;\n"
13601 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013602 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013604 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13605 nullptr,
13606 0,
13607 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13608 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13609 pl,
13610 VK_NULL_HANDLE,
13611 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013612
13613 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013614 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013615
13616 m_errorMonitor->VerifyFound();
13617
13618 if (err == VK_SUCCESS) {
13619 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13620 }
13621
13622 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13623 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13624}
13625
Chris Forbes50020592016-07-27 13:52:41 +120013626TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13627 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13628 "does not match the dimensionality declared in the shader");
13629
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013630 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 +120013631
13632 ASSERT_NO_FATAL_FAILURE(InitState());
13633 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13634
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013635 char const *vsSource = "#version 450\n"
13636 "\n"
13637 "out gl_PerVertex { vec4 gl_Position; };\n"
13638 "void main() { gl_Position = vec4(0); }\n";
13639 char const *fsSource = "#version 450\n"
13640 "\n"
13641 "layout(set=0, binding=0) uniform sampler3D s;\n"
13642 "layout(location=0) out vec4 color;\n"
13643 "void main() {\n"
13644 " color = texture(s, vec3(0));\n"
13645 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013646 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13647 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13648
13649 VkPipelineObj pipe(m_device);
13650 pipe.AddShader(&vs);
13651 pipe.AddShader(&fs);
13652 pipe.AddColorAttachment();
13653
13654 VkTextureObj texture(m_device, nullptr);
13655 VkSamplerObj sampler(m_device);
13656
13657 VkDescriptorSetObj descriptorSet(m_device);
13658 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13659 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13660
13661 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13662 ASSERT_VK_SUCCESS(err);
13663
13664 BeginCommandBuffer();
13665
13666 m_commandBuffer->BindPipeline(pipe);
13667 m_commandBuffer->BindDescriptorSet(descriptorSet);
13668
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013669 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013670 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013671 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013672 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13673
13674 // error produced here.
13675 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13676
13677 m_errorMonitor->VerifyFound();
13678
13679 EndCommandBuffer();
13680}
13681
Chris Forbes5533bfc2016-07-27 14:12:34 +120013682TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13683 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13684 "are consumed via singlesample images types in the shader, or vice versa.");
13685
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013687
13688 ASSERT_NO_FATAL_FAILURE(InitState());
13689 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13690
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013691 char const *vsSource = "#version 450\n"
13692 "\n"
13693 "out gl_PerVertex { vec4 gl_Position; };\n"
13694 "void main() { gl_Position = vec4(0); }\n";
13695 char const *fsSource = "#version 450\n"
13696 "\n"
13697 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13698 "layout(location=0) out vec4 color;\n"
13699 "void main() {\n"
13700 " color = texelFetch(s, ivec2(0), 0);\n"
13701 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013702 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13703 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13704
13705 VkPipelineObj pipe(m_device);
13706 pipe.AddShader(&vs);
13707 pipe.AddShader(&fs);
13708 pipe.AddColorAttachment();
13709
13710 VkTextureObj texture(m_device, nullptr);
13711 VkSamplerObj sampler(m_device);
13712
13713 VkDescriptorSetObj descriptorSet(m_device);
13714 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13715 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13716
13717 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13718 ASSERT_VK_SUCCESS(err);
13719
13720 BeginCommandBuffer();
13721
13722 m_commandBuffer->BindPipeline(pipe);
13723 m_commandBuffer->BindDescriptorSet(descriptorSet);
13724
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013725 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013726 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013727 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013728 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13729
13730 // error produced here.
13731 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13732
13733 m_errorMonitor->VerifyFound();
13734
13735 EndCommandBuffer();
13736}
13737
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013738#endif // SHADER_CHECKER_TESTS
13739
13740#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013741TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013743
13744 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013745
13746 // Create an image
13747 VkImage image;
13748
Karl Schultz6addd812016-02-02 17:17:23 -070013749 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13750 const int32_t tex_width = 32;
13751 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013752
13753 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013754 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13755 image_create_info.pNext = NULL;
13756 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13757 image_create_info.format = tex_format;
13758 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013759 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013760 image_create_info.extent.depth = 1;
13761 image_create_info.mipLevels = 1;
13762 image_create_info.arrayLayers = 1;
13763 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13764 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13765 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13766 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013767
13768 // Introduce error by sending down a bogus width extent
13769 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013770 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013771
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013772 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013773}
13774
Mark Youngc48c4c12016-04-11 14:26:49 -060013775TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13777 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013778
13779 ASSERT_NO_FATAL_FAILURE(InitState());
13780
13781 // Create an image
13782 VkImage image;
13783
13784 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13785 const int32_t tex_width = 32;
13786 const int32_t tex_height = 32;
13787
13788 VkImageCreateInfo image_create_info = {};
13789 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13790 image_create_info.pNext = NULL;
13791 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13792 image_create_info.format = tex_format;
13793 image_create_info.extent.width = tex_width;
13794 image_create_info.extent.height = tex_height;
13795 image_create_info.extent.depth = 1;
13796 image_create_info.mipLevels = 1;
13797 image_create_info.arrayLayers = 1;
13798 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13799 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13800 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13801 image_create_info.flags = 0;
13802
13803 // Introduce error by sending down a bogus width extent
13804 image_create_info.extent.width = 0;
13805 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13806
13807 m_errorMonitor->VerifyFound();
13808}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013809#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013810
Tobin Ehliscde08892015-09-22 10:11:37 -060013811#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013812
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013813TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13814 TEST_DESCRIPTION("Create a render pass with an attachment description "
13815 "format set to VK_FORMAT_UNDEFINED");
13816
13817 ASSERT_NO_FATAL_FAILURE(InitState());
13818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13819
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013821
13822 VkAttachmentReference color_attach = {};
13823 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13824 color_attach.attachment = 0;
13825 VkSubpassDescription subpass = {};
13826 subpass.colorAttachmentCount = 1;
13827 subpass.pColorAttachments = &color_attach;
13828
13829 VkRenderPassCreateInfo rpci = {};
13830 rpci.subpassCount = 1;
13831 rpci.pSubpasses = &subpass;
13832 rpci.attachmentCount = 1;
13833 VkAttachmentDescription attach_desc = {};
13834 attach_desc.format = VK_FORMAT_UNDEFINED;
13835 rpci.pAttachments = &attach_desc;
13836 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13837 VkRenderPass rp;
13838 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13839
13840 m_errorMonitor->VerifyFound();
13841
13842 if (result == VK_SUCCESS) {
13843 vkDestroyRenderPass(m_device->device(), rp, NULL);
13844 }
13845}
13846
Karl Schultz6addd812016-02-02 17:17:23 -070013847TEST_F(VkLayerTest, InvalidImageView) {
13848 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013849
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013851
Tobin Ehliscde08892015-09-22 10:11:37 -060013852 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013853
Mike Stroyana3082432015-09-25 13:39:21 -060013854 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013855 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013856
Karl Schultz6addd812016-02-02 17:17:23 -070013857 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13858 const int32_t tex_width = 32;
13859 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013860
13861 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013862 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13863 image_create_info.pNext = NULL;
13864 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13865 image_create_info.format = tex_format;
13866 image_create_info.extent.width = tex_width;
13867 image_create_info.extent.height = tex_height;
13868 image_create_info.extent.depth = 1;
13869 image_create_info.mipLevels = 1;
13870 image_create_info.arrayLayers = 1;
13871 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13872 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13873 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13874 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013875
Chia-I Wuf7458c52015-10-26 21:10:41 +080013876 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013877 ASSERT_VK_SUCCESS(err);
13878
13879 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130013880 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070013881 image_view_create_info.image = image;
13882 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13883 image_view_create_info.format = tex_format;
13884 image_view_create_info.subresourceRange.layerCount = 1;
13885 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13886 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013887 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013888
13889 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013890 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013891
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013892 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013893 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013894}
Mike Stroyana3082432015-09-25 13:39:21 -060013895
Mark Youngd339ba32016-05-30 13:28:35 -060013896TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13897 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013899 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013900
13901 ASSERT_NO_FATAL_FAILURE(InitState());
13902
13903 // Create an image and try to create a view with no memory backing the image
13904 VkImage image;
13905
13906 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13907 const int32_t tex_width = 32;
13908 const int32_t tex_height = 32;
13909
13910 VkImageCreateInfo image_create_info = {};
13911 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13912 image_create_info.pNext = NULL;
13913 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13914 image_create_info.format = tex_format;
13915 image_create_info.extent.width = tex_width;
13916 image_create_info.extent.height = tex_height;
13917 image_create_info.extent.depth = 1;
13918 image_create_info.mipLevels = 1;
13919 image_create_info.arrayLayers = 1;
13920 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13921 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13922 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13923 image_create_info.flags = 0;
13924
13925 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13926 ASSERT_VK_SUCCESS(err);
13927
13928 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130013929 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060013930 image_view_create_info.image = image;
13931 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13932 image_view_create_info.format = tex_format;
13933 image_view_create_info.subresourceRange.layerCount = 1;
13934 image_view_create_info.subresourceRange.baseMipLevel = 0;
13935 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013936 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013937
13938 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013939 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013940
13941 m_errorMonitor->VerifyFound();
13942 vkDestroyImage(m_device->device(), image, NULL);
13943 // If last error is success, it still created the view, so delete it.
13944 if (err == VK_SUCCESS) {
13945 vkDestroyImageView(m_device->device(), view, NULL);
13946 }
Mark Youngd339ba32016-05-30 13:28:35 -060013947}
13948
Karl Schultz6addd812016-02-02 17:17:23 -070013949TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013950 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013952 "formats must have ONLY the "
13953 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13955 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013956
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013957 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013958
Karl Schultz6addd812016-02-02 17:17:23 -070013959 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013960 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013961 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013962 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013963
13964 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013965 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013966 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013967 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13968 image_view_create_info.format = tex_format;
13969 image_view_create_info.subresourceRange.baseMipLevel = 0;
13970 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013971 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013972 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013973 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013974
13975 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013976 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013977
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013978 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013979}
13980
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013981TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013982 VkResult err;
13983 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13986 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013987
Mike Stroyana3082432015-09-25 13:39:21 -060013988 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013989
13990 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013991 VkImage srcImage;
13992 VkImage dstImage;
13993 VkDeviceMemory srcMem;
13994 VkDeviceMemory destMem;
13995 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013996
13997 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013998 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13999 image_create_info.pNext = NULL;
14000 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14001 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14002 image_create_info.extent.width = 32;
14003 image_create_info.extent.height = 32;
14004 image_create_info.extent.depth = 1;
14005 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014006 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014007 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14008 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14009 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14010 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014012 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014013 ASSERT_VK_SUCCESS(err);
14014
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014015 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014016 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014017 ASSERT_VK_SUCCESS(err);
14018
14019 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014020 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014021 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14022 memAlloc.pNext = NULL;
14023 memAlloc.allocationSize = 0;
14024 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014025
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014026 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014027 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014028 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014029 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014030 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014031 ASSERT_VK_SUCCESS(err);
14032
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014033 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014034 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014035 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014036 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014037 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014038 ASSERT_VK_SUCCESS(err);
14039
14040 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14041 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014042 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014043 ASSERT_VK_SUCCESS(err);
14044
14045 BeginCommandBuffer();
14046 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014047 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014048 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014049 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014050 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014051 copyRegion.srcOffset.x = 0;
14052 copyRegion.srcOffset.y = 0;
14053 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014054 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014055 copyRegion.dstSubresource.mipLevel = 0;
14056 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014057 // Introduce failure by forcing the dst layerCount to differ from src
14058 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014059 copyRegion.dstOffset.x = 0;
14060 copyRegion.dstOffset.y = 0;
14061 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014062 copyRegion.extent.width = 1;
14063 copyRegion.extent.height = 1;
14064 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014065 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014066 EndCommandBuffer();
14067
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014068 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014069
Chia-I Wuf7458c52015-10-26 21:10:41 +080014070 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014071 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014072 vkFreeMemory(m_device->device(), srcMem, NULL);
14073 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014074}
14075
Tony Barbourd6673642016-05-05 14:46:39 -060014076TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14077
14078 TEST_DESCRIPTION("Creating images with unsuported formats ");
14079
14080 ASSERT_NO_FATAL_FAILURE(InitState());
14081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14082 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014083 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 -060014084 VK_IMAGE_TILING_OPTIMAL, 0);
14085 ASSERT_TRUE(image.initialized());
14086
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014087 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014088 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014089 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014090 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14091 image_create_info.format = VK_FORMAT_UNDEFINED;
14092 image_create_info.extent.width = 32;
14093 image_create_info.extent.height = 32;
14094 image_create_info.extent.depth = 1;
14095 image_create_info.mipLevels = 1;
14096 image_create_info.arrayLayers = 1;
14097 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14098 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14099 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014100
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14102 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014103
14104 VkImage localImage;
14105 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14106 m_errorMonitor->VerifyFound();
14107
Tony Barbourd6673642016-05-05 14:46:39 -060014108 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014109 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014110 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14111 VkFormat format = static_cast<VkFormat>(f);
14112 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014113 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014114 unsupported = format;
14115 break;
14116 }
14117 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014118
Tony Barbourd6673642016-05-05 14:46:39 -060014119 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014120 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014122
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014123 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014124 m_errorMonitor->VerifyFound();
14125 }
14126}
14127
14128TEST_F(VkLayerTest, ImageLayerViewTests) {
14129 VkResult ret;
14130 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14131
14132 ASSERT_NO_FATAL_FAILURE(InitState());
14133
14134 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014135 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 -060014136 VK_IMAGE_TILING_OPTIMAL, 0);
14137 ASSERT_TRUE(image.initialized());
14138
14139 VkImageView imgView;
14140 VkImageViewCreateInfo imgViewInfo = {};
14141 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14142 imgViewInfo.image = image.handle();
14143 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14144 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14145 imgViewInfo.subresourceRange.layerCount = 1;
14146 imgViewInfo.subresourceRange.baseMipLevel = 0;
14147 imgViewInfo.subresourceRange.levelCount = 1;
14148 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014151 // View can't have baseMipLevel >= image's mipLevels - Expect
14152 // VIEW_CREATE_ERROR
14153 imgViewInfo.subresourceRange.baseMipLevel = 1;
14154 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14155 m_errorMonitor->VerifyFound();
14156 imgViewInfo.subresourceRange.baseMipLevel = 0;
14157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014159 // View can't have baseArrayLayer >= image's arraySize - Expect
14160 // VIEW_CREATE_ERROR
14161 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14162 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14163 m_errorMonitor->VerifyFound();
14164 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14165
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14167 "pCreateInfo->subresourceRange."
14168 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014169 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14170 imgViewInfo.subresourceRange.levelCount = 0;
14171 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14172 m_errorMonitor->VerifyFound();
14173 imgViewInfo.subresourceRange.levelCount = 1;
14174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14176 "pCreateInfo->subresourceRange."
14177 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014178 m_errorMonitor->SetDesiredFailureMsg(
14179 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14180 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014181 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14182 imgViewInfo.subresourceRange.layerCount = 0;
14183 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14184 m_errorMonitor->VerifyFound();
14185 imgViewInfo.subresourceRange.layerCount = 1;
14186
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14189 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14190 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014191 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14192 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14193 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14194 m_errorMonitor->VerifyFound();
14195 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14198 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14199 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014200 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14201 // VIEW_CREATE_ERROR
14202 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14203 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14204 m_errorMonitor->VerifyFound();
14205 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14208 "differing formats but they must be "
14209 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014210 // TODO: Update framework to easily passing mutable flag into ImageObj init
14211 // For now just allowing image for this one test to not have memory bound
14212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14213 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014214 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14215 // VIEW_CREATE_ERROR
14216 VkImageCreateInfo mutImgInfo = image.create_info();
14217 VkImage mutImage;
14218 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014219 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014220 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14221 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14222 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14223 ASSERT_VK_SUCCESS(ret);
14224 imgViewInfo.image = mutImage;
14225 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14226 m_errorMonitor->VerifyFound();
14227 imgViewInfo.image = image.handle();
14228 vkDestroyImage(m_device->handle(), mutImage, NULL);
14229}
14230
14231TEST_F(VkLayerTest, MiscImageLayerTests) {
14232
14233 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14234
14235 ASSERT_NO_FATAL_FAILURE(InitState());
14236
14237 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014238 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 -060014239 VK_IMAGE_TILING_OPTIMAL, 0);
14240 ASSERT_TRUE(image.initialized());
14241
Tony Barbourd6673642016-05-05 14:46:39 -060014242 vk_testing::Buffer buffer;
14243 VkMemoryPropertyFlags reqs = 0;
14244 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14245 VkBufferImageCopy region = {};
14246 region.bufferRowLength = 128;
14247 region.bufferImageHeight = 128;
14248 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14249 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014250 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014251 region.imageExtent.height = 4;
14252 region.imageExtent.width = 4;
14253 region.imageExtent.depth = 1;
14254 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014255
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014256 // Image must have offset.z of 0 and extent.depth of 1
14257 // Introduce failure by setting imageExtent.depth to 0
14258 region.imageExtent.depth = 0;
14259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14260 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14261 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14262 m_errorMonitor->VerifyFound();
14263
14264 region.imageExtent.depth = 1;
14265
14266 // Image must have offset.z of 0 and extent.depth of 1
14267 // Introduce failure by setting imageOffset.z to 4
14268 region.imageOffset.z = 4;
14269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14270 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14271 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14272 m_errorMonitor->VerifyFound();
14273
14274 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014275 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14276 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14277 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014279 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14280 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014281 m_errorMonitor->VerifyFound();
14282
14283 // BufferOffset must be a multiple of 4
14284 // Introduce failure by setting bufferOffset to a value not divisible by 4
14285 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014287 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14288 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014289 m_errorMonitor->VerifyFound();
14290
14291 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14292 region.bufferOffset = 0;
14293 region.imageExtent.height = 128;
14294 region.imageExtent.width = 128;
14295 // Introduce failure by setting bufferRowLength > 0 but less than width
14296 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014298 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14299 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014300 m_errorMonitor->VerifyFound();
14301
14302 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14303 region.bufferRowLength = 128;
14304 // Introduce failure by setting bufferRowHeight > 0 but less than height
14305 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014307 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14308 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014309 m_errorMonitor->VerifyFound();
14310
14311 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14313 "If the format of srcImage is a depth, stencil, depth stencil or "
14314 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014315 // Expect INVALID_FILTER
14316 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014317 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 -060014318 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014319 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 -060014320 VkImageBlit blitRegion = {};
14321 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14322 blitRegion.srcSubresource.baseArrayLayer = 0;
14323 blitRegion.srcSubresource.layerCount = 1;
14324 blitRegion.srcSubresource.mipLevel = 0;
14325 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14326 blitRegion.dstSubresource.baseArrayLayer = 0;
14327 blitRegion.dstSubresource.layerCount = 1;
14328 blitRegion.dstSubresource.mipLevel = 0;
14329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014330 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14331 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014332 m_errorMonitor->VerifyFound();
14333
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014334 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14336 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14337 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014338 m_errorMonitor->VerifyFound();
14339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014341 VkImageMemoryBarrier img_barrier;
14342 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14343 img_barrier.pNext = NULL;
14344 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14345 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14346 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14347 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14348 img_barrier.image = image.handle();
14349 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14350 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14351 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14352 img_barrier.subresourceRange.baseArrayLayer = 0;
14353 img_barrier.subresourceRange.baseMipLevel = 0;
14354 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14355 img_barrier.subresourceRange.layerCount = 0;
14356 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014357 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14358 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014359 m_errorMonitor->VerifyFound();
14360 img_barrier.subresourceRange.layerCount = 1;
14361}
14362
14363TEST_F(VkLayerTest, ImageFormatLimits) {
14364
14365 TEST_DESCRIPTION("Exceed the limits of image format ");
14366
Cody Northropc31a84f2016-08-22 10:41:47 -060014367 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014369 VkImageCreateInfo image_create_info = {};
14370 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14371 image_create_info.pNext = NULL;
14372 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14373 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14374 image_create_info.extent.width = 32;
14375 image_create_info.extent.height = 32;
14376 image_create_info.extent.depth = 1;
14377 image_create_info.mipLevels = 1;
14378 image_create_info.arrayLayers = 1;
14379 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14380 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14381 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14382 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14383 image_create_info.flags = 0;
14384
14385 VkImage nullImg;
14386 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014387 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14388 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014389 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14390 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14391 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14392 m_errorMonitor->VerifyFound();
14393 image_create_info.extent.depth = 1;
14394
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014396 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14397 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14398 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14399 m_errorMonitor->VerifyFound();
14400 image_create_info.mipLevels = 1;
14401
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014403 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14404 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14405 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14406 m_errorMonitor->VerifyFound();
14407 image_create_info.arrayLayers = 1;
14408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014410 int samples = imgFmtProps.sampleCounts >> 1;
14411 image_create_info.samples = (VkSampleCountFlagBits)samples;
14412 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14413 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14414 m_errorMonitor->VerifyFound();
14415 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14416
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14418 "VK_IMAGE_LAYOUT_UNDEFINED or "
14419 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014420 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14421 // Expect INVALID_LAYOUT
14422 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14423 m_errorMonitor->VerifyFound();
14424 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14425}
14426
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014427TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14428
14429 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014431
14432 ASSERT_NO_FATAL_FAILURE(InitState());
14433
14434 VkImageObj src_image(m_device);
14435 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14436 VkImageObj dst_image(m_device);
14437 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14438
14439 BeginCommandBuffer();
14440 VkImageCopy copy_region;
14441 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14442 copy_region.srcSubresource.mipLevel = 0;
14443 copy_region.srcSubresource.baseArrayLayer = 0;
14444 copy_region.srcSubresource.layerCount = 0;
14445 copy_region.srcOffset.x = 0;
14446 copy_region.srcOffset.y = 0;
14447 copy_region.srcOffset.z = 0;
14448 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14449 copy_region.dstSubresource.mipLevel = 0;
14450 copy_region.dstSubresource.baseArrayLayer = 0;
14451 copy_region.dstSubresource.layerCount = 0;
14452 copy_region.dstOffset.x = 0;
14453 copy_region.dstOffset.y = 0;
14454 copy_region.dstOffset.z = 0;
14455 copy_region.extent.width = 64;
14456 copy_region.extent.height = 64;
14457 copy_region.extent.depth = 1;
14458 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14459 &copy_region);
14460 EndCommandBuffer();
14461
14462 m_errorMonitor->VerifyFound();
14463}
14464
14465TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14466
14467 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014469
14470 ASSERT_NO_FATAL_FAILURE(InitState());
14471
14472 VkImageObj src_image(m_device);
14473 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14474 VkImageObj dst_image(m_device);
14475 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14476
14477 BeginCommandBuffer();
14478 VkImageCopy copy_region;
14479 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14480 copy_region.srcSubresource.mipLevel = 0;
14481 copy_region.srcSubresource.baseArrayLayer = 0;
14482 copy_region.srcSubresource.layerCount = 0;
14483 copy_region.srcOffset.x = 0;
14484 copy_region.srcOffset.y = 0;
14485 copy_region.srcOffset.z = 0;
14486 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14487 copy_region.dstSubresource.mipLevel = 0;
14488 copy_region.dstSubresource.baseArrayLayer = 0;
14489 copy_region.dstSubresource.layerCount = 0;
14490 copy_region.dstOffset.x = 0;
14491 copy_region.dstOffset.y = 0;
14492 copy_region.dstOffset.z = 0;
14493 copy_region.extent.width = 64;
14494 copy_region.extent.height = 64;
14495 copy_region.extent.depth = 1;
14496 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14497 &copy_region);
14498 EndCommandBuffer();
14499
14500 m_errorMonitor->VerifyFound();
14501}
14502
Karl Schultz6addd812016-02-02 17:17:23 -070014503TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014504 VkResult err;
14505 bool pass;
14506
14507 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14509 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014510
14511 ASSERT_NO_FATAL_FAILURE(InitState());
14512
14513 // Create two images of different types and try to copy between them
14514 VkImage srcImage;
14515 VkImage dstImage;
14516 VkDeviceMemory srcMem;
14517 VkDeviceMemory destMem;
14518 VkMemoryRequirements memReqs;
14519
14520 VkImageCreateInfo image_create_info = {};
14521 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14522 image_create_info.pNext = NULL;
14523 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14524 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14525 image_create_info.extent.width = 32;
14526 image_create_info.extent.height = 32;
14527 image_create_info.extent.depth = 1;
14528 image_create_info.mipLevels = 1;
14529 image_create_info.arrayLayers = 1;
14530 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14531 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14532 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14533 image_create_info.flags = 0;
14534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014535 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014536 ASSERT_VK_SUCCESS(err);
14537
14538 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14539 // Introduce failure by creating second image with a different-sized format.
14540 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14541
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014542 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014543 ASSERT_VK_SUCCESS(err);
14544
14545 // Allocate memory
14546 VkMemoryAllocateInfo memAlloc = {};
14547 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14548 memAlloc.pNext = NULL;
14549 memAlloc.allocationSize = 0;
14550 memAlloc.memoryTypeIndex = 0;
14551
14552 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14553 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014554 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014555 ASSERT_TRUE(pass);
14556 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14557 ASSERT_VK_SUCCESS(err);
14558
14559 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14560 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014561 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014562 ASSERT_TRUE(pass);
14563 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14564 ASSERT_VK_SUCCESS(err);
14565
14566 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14567 ASSERT_VK_SUCCESS(err);
14568 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14569 ASSERT_VK_SUCCESS(err);
14570
14571 BeginCommandBuffer();
14572 VkImageCopy copyRegion;
14573 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14574 copyRegion.srcSubresource.mipLevel = 0;
14575 copyRegion.srcSubresource.baseArrayLayer = 0;
14576 copyRegion.srcSubresource.layerCount = 0;
14577 copyRegion.srcOffset.x = 0;
14578 copyRegion.srcOffset.y = 0;
14579 copyRegion.srcOffset.z = 0;
14580 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14581 copyRegion.dstSubresource.mipLevel = 0;
14582 copyRegion.dstSubresource.baseArrayLayer = 0;
14583 copyRegion.dstSubresource.layerCount = 0;
14584 copyRegion.dstOffset.x = 0;
14585 copyRegion.dstOffset.y = 0;
14586 copyRegion.dstOffset.z = 0;
14587 copyRegion.extent.width = 1;
14588 copyRegion.extent.height = 1;
14589 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014590 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014591 EndCommandBuffer();
14592
14593 m_errorMonitor->VerifyFound();
14594
14595 vkDestroyImage(m_device->device(), srcImage, NULL);
14596 vkDestroyImage(m_device->device(), dstImage, NULL);
14597 vkFreeMemory(m_device->device(), srcMem, NULL);
14598 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014599}
14600
Karl Schultz6addd812016-02-02 17:17:23 -070014601TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14602 VkResult err;
14603 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014604
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014605 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14607 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014608
Mike Stroyana3082432015-09-25 13:39:21 -060014609 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014610
14611 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014612 VkImage srcImage;
14613 VkImage dstImage;
14614 VkDeviceMemory srcMem;
14615 VkDeviceMemory destMem;
14616 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014617
14618 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014619 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14620 image_create_info.pNext = NULL;
14621 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14622 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14623 image_create_info.extent.width = 32;
14624 image_create_info.extent.height = 32;
14625 image_create_info.extent.depth = 1;
14626 image_create_info.mipLevels = 1;
14627 image_create_info.arrayLayers = 1;
14628 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14629 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14630 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14631 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014632
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014633 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014634 ASSERT_VK_SUCCESS(err);
14635
Karl Schultzbdb75952016-04-19 11:36:49 -060014636 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14637
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014638 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014639 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014640 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014641 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014642
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014643 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014644 ASSERT_VK_SUCCESS(err);
14645
14646 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014647 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014648 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14649 memAlloc.pNext = NULL;
14650 memAlloc.allocationSize = 0;
14651 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014652
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014653 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014654 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014655 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014656 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014657 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014658 ASSERT_VK_SUCCESS(err);
14659
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014660 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014661 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014662 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014663 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014664 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014665 ASSERT_VK_SUCCESS(err);
14666
14667 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14668 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014669 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014670 ASSERT_VK_SUCCESS(err);
14671
14672 BeginCommandBuffer();
14673 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014674 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014675 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014676 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014677 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014678 copyRegion.srcOffset.x = 0;
14679 copyRegion.srcOffset.y = 0;
14680 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014681 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014682 copyRegion.dstSubresource.mipLevel = 0;
14683 copyRegion.dstSubresource.baseArrayLayer = 0;
14684 copyRegion.dstSubresource.layerCount = 0;
14685 copyRegion.dstOffset.x = 0;
14686 copyRegion.dstOffset.y = 0;
14687 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014688 copyRegion.extent.width = 1;
14689 copyRegion.extent.height = 1;
14690 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014691 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014692 EndCommandBuffer();
14693
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014694 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014695
Chia-I Wuf7458c52015-10-26 21:10:41 +080014696 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014697 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014698 vkFreeMemory(m_device->device(), srcMem, NULL);
14699 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014700}
14701
Karl Schultz6addd812016-02-02 17:17:23 -070014702TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14703 VkResult err;
14704 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014705
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14707 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014708
Mike Stroyana3082432015-09-25 13:39:21 -060014709 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014710
14711 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014712 VkImage srcImage;
14713 VkImage dstImage;
14714 VkDeviceMemory srcMem;
14715 VkDeviceMemory destMem;
14716 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014717
14718 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014719 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14720 image_create_info.pNext = NULL;
14721 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14722 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14723 image_create_info.extent.width = 32;
14724 image_create_info.extent.height = 1;
14725 image_create_info.extent.depth = 1;
14726 image_create_info.mipLevels = 1;
14727 image_create_info.arrayLayers = 1;
14728 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14729 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14730 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14731 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014732
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014733 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014734 ASSERT_VK_SUCCESS(err);
14735
Karl Schultz6addd812016-02-02 17:17:23 -070014736 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014738 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014739 ASSERT_VK_SUCCESS(err);
14740
14741 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014742 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014743 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14744 memAlloc.pNext = NULL;
14745 memAlloc.allocationSize = 0;
14746 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014747
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014748 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014749 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014750 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014751 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014752 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014753 ASSERT_VK_SUCCESS(err);
14754
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014755 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014756 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014757 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014758 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014759 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014760 ASSERT_VK_SUCCESS(err);
14761
14762 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14763 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014764 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014765 ASSERT_VK_SUCCESS(err);
14766
14767 BeginCommandBuffer();
14768 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014769 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14770 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014771 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014772 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014773 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014774 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014775 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014776 resolveRegion.srcOffset.x = 0;
14777 resolveRegion.srcOffset.y = 0;
14778 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014779 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014780 resolveRegion.dstSubresource.mipLevel = 0;
14781 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014782 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014783 resolveRegion.dstOffset.x = 0;
14784 resolveRegion.dstOffset.y = 0;
14785 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014786 resolveRegion.extent.width = 1;
14787 resolveRegion.extent.height = 1;
14788 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014789 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014790 EndCommandBuffer();
14791
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014792 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014793
Chia-I Wuf7458c52015-10-26 21:10:41 +080014794 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014795 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014796 vkFreeMemory(m_device->device(), srcMem, NULL);
14797 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014798}
14799
Karl Schultz6addd812016-02-02 17:17:23 -070014800TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14801 VkResult err;
14802 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014803
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14805 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014806
Mike Stroyana3082432015-09-25 13:39:21 -060014807 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014808
Chris Forbesa7530692016-05-08 12:35:39 +120014809 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014810 VkImage srcImage;
14811 VkImage dstImage;
14812 VkDeviceMemory srcMem;
14813 VkDeviceMemory destMem;
14814 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014815
14816 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014817 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14818 image_create_info.pNext = NULL;
14819 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14820 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14821 image_create_info.extent.width = 32;
14822 image_create_info.extent.height = 1;
14823 image_create_info.extent.depth = 1;
14824 image_create_info.mipLevels = 1;
14825 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014826 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014827 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14828 // Note: Some implementations expect color attachment usage for any
14829 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014830 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014831 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014832
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014833 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014834 ASSERT_VK_SUCCESS(err);
14835
Karl Schultz6addd812016-02-02 17:17:23 -070014836 // Note: Some implementations expect color attachment usage for any
14837 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014838 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014839
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014840 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014841 ASSERT_VK_SUCCESS(err);
14842
14843 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014844 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014845 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14846 memAlloc.pNext = NULL;
14847 memAlloc.allocationSize = 0;
14848 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014849
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014850 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014851 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014852 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014853 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014854 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014855 ASSERT_VK_SUCCESS(err);
14856
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014857 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014858 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014859 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014860 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014861 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014862 ASSERT_VK_SUCCESS(err);
14863
14864 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14865 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014866 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014867 ASSERT_VK_SUCCESS(err);
14868
14869 BeginCommandBuffer();
14870 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014871 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14872 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014873 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014874 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014875 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014876 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014877 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014878 resolveRegion.srcOffset.x = 0;
14879 resolveRegion.srcOffset.y = 0;
14880 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014881 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014882 resolveRegion.dstSubresource.mipLevel = 0;
14883 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014884 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014885 resolveRegion.dstOffset.x = 0;
14886 resolveRegion.dstOffset.y = 0;
14887 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014888 resolveRegion.extent.width = 1;
14889 resolveRegion.extent.height = 1;
14890 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014891 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014892 EndCommandBuffer();
14893
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014894 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014895
Chia-I Wuf7458c52015-10-26 21:10:41 +080014896 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014897 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014898 vkFreeMemory(m_device->device(), srcMem, NULL);
14899 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014900}
14901
Karl Schultz6addd812016-02-02 17:17:23 -070014902TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14903 VkResult err;
14904 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014905
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14907 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014908
Mike Stroyana3082432015-09-25 13:39:21 -060014909 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014910
14911 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014912 VkImage srcImage;
14913 VkImage dstImage;
14914 VkDeviceMemory srcMem;
14915 VkDeviceMemory destMem;
14916 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014917
14918 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014919 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14920 image_create_info.pNext = NULL;
14921 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14922 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14923 image_create_info.extent.width = 32;
14924 image_create_info.extent.height = 1;
14925 image_create_info.extent.depth = 1;
14926 image_create_info.mipLevels = 1;
14927 image_create_info.arrayLayers = 1;
14928 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14929 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14930 // Note: Some implementations expect color attachment usage for any
14931 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014932 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014933 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014935 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014936 ASSERT_VK_SUCCESS(err);
14937
Karl Schultz6addd812016-02-02 17:17:23 -070014938 // Set format to something other than source image
14939 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14940 // Note: Some implementations expect color attachment usage for any
14941 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014942 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014943 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014944
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014945 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014946 ASSERT_VK_SUCCESS(err);
14947
14948 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014949 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014950 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14951 memAlloc.pNext = NULL;
14952 memAlloc.allocationSize = 0;
14953 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014954
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014955 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014956 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014957 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014958 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014959 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014960 ASSERT_VK_SUCCESS(err);
14961
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014962 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014963 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014964 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014965 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014966 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014967 ASSERT_VK_SUCCESS(err);
14968
14969 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14970 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014971 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014972 ASSERT_VK_SUCCESS(err);
14973
14974 BeginCommandBuffer();
14975 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014976 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14977 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014978 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014979 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014980 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014981 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014982 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014983 resolveRegion.srcOffset.x = 0;
14984 resolveRegion.srcOffset.y = 0;
14985 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014986 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014987 resolveRegion.dstSubresource.mipLevel = 0;
14988 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014989 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014990 resolveRegion.dstOffset.x = 0;
14991 resolveRegion.dstOffset.y = 0;
14992 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014993 resolveRegion.extent.width = 1;
14994 resolveRegion.extent.height = 1;
14995 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014996 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014997 EndCommandBuffer();
14998
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014999 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015000
Chia-I Wuf7458c52015-10-26 21:10:41 +080015001 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015002 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015003 vkFreeMemory(m_device->device(), srcMem, NULL);
15004 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015005}
15006
Karl Schultz6addd812016-02-02 17:17:23 -070015007TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15008 VkResult err;
15009 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15012 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015013
Mike Stroyana3082432015-09-25 13:39:21 -060015014 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015015
15016 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015017 VkImage srcImage;
15018 VkImage dstImage;
15019 VkDeviceMemory srcMem;
15020 VkDeviceMemory destMem;
15021 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015022
15023 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015024 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15025 image_create_info.pNext = NULL;
15026 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15027 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15028 image_create_info.extent.width = 32;
15029 image_create_info.extent.height = 1;
15030 image_create_info.extent.depth = 1;
15031 image_create_info.mipLevels = 1;
15032 image_create_info.arrayLayers = 1;
15033 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15034 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15035 // Note: Some implementations expect color attachment usage for any
15036 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015037 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015038 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015040 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015041 ASSERT_VK_SUCCESS(err);
15042
Karl Schultz6addd812016-02-02 17:17:23 -070015043 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15044 // Note: Some implementations expect color attachment usage for any
15045 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015046 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015047 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015048
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015049 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015050 ASSERT_VK_SUCCESS(err);
15051
15052 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015053 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015054 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15055 memAlloc.pNext = NULL;
15056 memAlloc.allocationSize = 0;
15057 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015058
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015059 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015060 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015061 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015062 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015063 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015064 ASSERT_VK_SUCCESS(err);
15065
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015066 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015067 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015068 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015069 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015070 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015071 ASSERT_VK_SUCCESS(err);
15072
15073 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15074 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015075 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015076 ASSERT_VK_SUCCESS(err);
15077
15078 BeginCommandBuffer();
15079 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015080 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15081 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015082 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015083 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015084 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015085 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015086 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015087 resolveRegion.srcOffset.x = 0;
15088 resolveRegion.srcOffset.y = 0;
15089 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015090 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015091 resolveRegion.dstSubresource.mipLevel = 0;
15092 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015093 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015094 resolveRegion.dstOffset.x = 0;
15095 resolveRegion.dstOffset.y = 0;
15096 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015097 resolveRegion.extent.width = 1;
15098 resolveRegion.extent.height = 1;
15099 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015100 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015101 EndCommandBuffer();
15102
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015103 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015104
Chia-I Wuf7458c52015-10-26 21:10:41 +080015105 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015106 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015107 vkFreeMemory(m_device->device(), srcMem, NULL);
15108 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015109}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015110
Karl Schultz6addd812016-02-02 17:17:23 -070015111TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015112 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015113 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15114 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015115 // The image format check comes 2nd in validation so we trigger it first,
15116 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015117 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15120 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015121
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015122 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015123
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015124 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015125 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15126 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015127
15128 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015129 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15130 ds_pool_ci.pNext = NULL;
15131 ds_pool_ci.maxSets = 1;
15132 ds_pool_ci.poolSizeCount = 1;
15133 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015134
15135 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015136 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015137 ASSERT_VK_SUCCESS(err);
15138
15139 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015140 dsl_binding.binding = 0;
15141 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15142 dsl_binding.descriptorCount = 1;
15143 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15144 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015145
15146 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015147 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15148 ds_layout_ci.pNext = NULL;
15149 ds_layout_ci.bindingCount = 1;
15150 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015151 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015152 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015153 ASSERT_VK_SUCCESS(err);
15154
15155 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015156 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015157 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015158 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015159 alloc_info.descriptorPool = ds_pool;
15160 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015161 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015162 ASSERT_VK_SUCCESS(err);
15163
Karl Schultz6addd812016-02-02 17:17:23 -070015164 VkImage image_bad;
15165 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015166 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015167 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015168 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015169 const int32_t tex_width = 32;
15170 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015171
15172 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015173 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15174 image_create_info.pNext = NULL;
15175 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15176 image_create_info.format = tex_format_bad;
15177 image_create_info.extent.width = tex_width;
15178 image_create_info.extent.height = tex_height;
15179 image_create_info.extent.depth = 1;
15180 image_create_info.mipLevels = 1;
15181 image_create_info.arrayLayers = 1;
15182 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15183 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015184 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015185 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015186
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015187 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015188 ASSERT_VK_SUCCESS(err);
15189 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015190 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15191 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015192 ASSERT_VK_SUCCESS(err);
15193
15194 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015195 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015196 image_view_create_info.image = image_bad;
15197 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15198 image_view_create_info.format = tex_format_bad;
15199 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15200 image_view_create_info.subresourceRange.baseMipLevel = 0;
15201 image_view_create_info.subresourceRange.layerCount = 1;
15202 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015203 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015204
15205 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015206 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015207
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015208 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015209
Chia-I Wuf7458c52015-10-26 21:10:41 +080015210 vkDestroyImage(m_device->device(), image_bad, NULL);
15211 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015212 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15213 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015214}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015215
15216TEST_F(VkLayerTest, ClearImageErrors) {
15217 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15218 "ClearDepthStencilImage with a color image.");
15219
15220 ASSERT_NO_FATAL_FAILURE(InitState());
15221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15222
15223 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15224 BeginCommandBuffer();
15225 m_commandBuffer->EndRenderPass();
15226
15227 // Color image
15228 VkClearColorValue clear_color;
15229 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15230 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15231 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15232 const int32_t img_width = 32;
15233 const int32_t img_height = 32;
15234 VkImageCreateInfo image_create_info = {};
15235 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15236 image_create_info.pNext = NULL;
15237 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15238 image_create_info.format = color_format;
15239 image_create_info.extent.width = img_width;
15240 image_create_info.extent.height = img_height;
15241 image_create_info.extent.depth = 1;
15242 image_create_info.mipLevels = 1;
15243 image_create_info.arrayLayers = 1;
15244 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15245 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15246 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15247
15248 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015249 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015250
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015251 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015252
15253 // Depth/Stencil image
15254 VkClearDepthStencilValue clear_value = {0};
15255 reqs = 0; // don't need HOST_VISIBLE DS image
15256 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15257 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15258 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15259 ds_image_create_info.extent.width = 64;
15260 ds_image_create_info.extent.height = 64;
15261 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15262 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15263
15264 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015265 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015267 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 -060015268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015271 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015272 &color_range);
15273
15274 m_errorMonitor->VerifyFound();
15275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15277 "image created without "
15278 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015279
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015280 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015281 &color_range);
15282
15283 m_errorMonitor->VerifyFound();
15284
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015285 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15287 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015288
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015289 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15290 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015291
15292 m_errorMonitor->VerifyFound();
15293}
Tobin Ehliscde08892015-09-22 10:11:37 -060015294#endif // IMAGE_TESTS
15295
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015296
15297// WSI Enabled Tests
15298//
Chris Forbes09368e42016-10-13 11:59:22 +130015299#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015300TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15301
15302#if defined(VK_USE_PLATFORM_XCB_KHR)
15303 VkSurfaceKHR surface = VK_NULL_HANDLE;
15304
15305 VkResult err;
15306 bool pass;
15307 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15308 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15309 // uint32_t swapchain_image_count = 0;
15310 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15311 // uint32_t image_index = 0;
15312 // VkPresentInfoKHR present_info = {};
15313
15314 ASSERT_NO_FATAL_FAILURE(InitState());
15315
15316 // Use the create function from one of the VK_KHR_*_surface extension in
15317 // order to create a surface, testing all known errors in the process,
15318 // before successfully creating a surface:
15319 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15321 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15322 pass = (err != VK_SUCCESS);
15323 ASSERT_TRUE(pass);
15324 m_errorMonitor->VerifyFound();
15325
15326 // Next, try to create a surface with the wrong
15327 // VkXcbSurfaceCreateInfoKHR::sType:
15328 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15329 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15331 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15332 pass = (err != VK_SUCCESS);
15333 ASSERT_TRUE(pass);
15334 m_errorMonitor->VerifyFound();
15335
15336 // Create a native window, and then correctly create a surface:
15337 xcb_connection_t *connection;
15338 xcb_screen_t *screen;
15339 xcb_window_t xcb_window;
15340 xcb_intern_atom_reply_t *atom_wm_delete_window;
15341
15342 const xcb_setup_t *setup;
15343 xcb_screen_iterator_t iter;
15344 int scr;
15345 uint32_t value_mask, value_list[32];
15346 int width = 1;
15347 int height = 1;
15348
15349 connection = xcb_connect(NULL, &scr);
15350 ASSERT_TRUE(connection != NULL);
15351 setup = xcb_get_setup(connection);
15352 iter = xcb_setup_roots_iterator(setup);
15353 while (scr-- > 0)
15354 xcb_screen_next(&iter);
15355 screen = iter.data;
15356
15357 xcb_window = xcb_generate_id(connection);
15358
15359 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15360 value_list[0] = screen->black_pixel;
15361 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15362
15363 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15364 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15365
15366 /* Magic code that will send notification when window is destroyed */
15367 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15368 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15369
15370 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15371 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15372 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15373 free(reply);
15374
15375 xcb_map_window(connection, xcb_window);
15376
15377 // Force the x/y coordinates to 100,100 results are identical in consecutive
15378 // runs
15379 const uint32_t coords[] = { 100, 100 };
15380 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15381
15382 // Finally, try to correctly create a surface:
15383 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15384 xcb_create_info.pNext = NULL;
15385 xcb_create_info.flags = 0;
15386 xcb_create_info.connection = connection;
15387 xcb_create_info.window = xcb_window;
15388 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15389 pass = (err == VK_SUCCESS);
15390 ASSERT_TRUE(pass);
15391
15392 // Check if surface supports presentation:
15393
15394 // 1st, do so without having queried the queue families:
15395 VkBool32 supported = false;
15396 // TODO: Get the following error to come out:
15397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15398 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15399 "function");
15400 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15401 pass = (err != VK_SUCCESS);
15402 // ASSERT_TRUE(pass);
15403 // m_errorMonitor->VerifyFound();
15404
15405 // Next, query a queue family index that's too large:
15406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15407 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15408 pass = (err != VK_SUCCESS);
15409 ASSERT_TRUE(pass);
15410 m_errorMonitor->VerifyFound();
15411
15412 // Finally, do so correctly:
15413 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15414 // SUPPORTED
15415 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15416 pass = (err == VK_SUCCESS);
15417 ASSERT_TRUE(pass);
15418
15419 // Before proceeding, try to create a swapchain without having called
15420 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15421 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15422 swapchain_create_info.pNext = NULL;
15423 swapchain_create_info.flags = 0;
15424 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15425 swapchain_create_info.surface = surface;
15426 swapchain_create_info.imageArrayLayers = 1;
15427 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15428 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15430 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15431 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15432 pass = (err != VK_SUCCESS);
15433 ASSERT_TRUE(pass);
15434 m_errorMonitor->VerifyFound();
15435
15436 // Get the surface capabilities:
15437 VkSurfaceCapabilitiesKHR surface_capabilities;
15438
15439 // Do so correctly (only error logged by this entrypoint is if the
15440 // extension isn't enabled):
15441 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15442 pass = (err == VK_SUCCESS);
15443 ASSERT_TRUE(pass);
15444
15445 // Get the surface formats:
15446 uint32_t surface_format_count;
15447
15448 // First, try without a pointer to surface_format_count:
15449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15450 "specified as NULL");
15451 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15452 pass = (err == VK_SUCCESS);
15453 ASSERT_TRUE(pass);
15454 m_errorMonitor->VerifyFound();
15455
15456 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15457 // correctly done a 1st try (to get the count):
15458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15459 surface_format_count = 0;
15460 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15461 pass = (err == VK_SUCCESS);
15462 ASSERT_TRUE(pass);
15463 m_errorMonitor->VerifyFound();
15464
15465 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15466 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15467 pass = (err == VK_SUCCESS);
15468 ASSERT_TRUE(pass);
15469
15470 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15471 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15472
15473 // Next, do a 2nd try with surface_format_count being set too high:
15474 surface_format_count += 5;
15475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15476 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15477 pass = (err == VK_SUCCESS);
15478 ASSERT_TRUE(pass);
15479 m_errorMonitor->VerifyFound();
15480
15481 // Finally, do a correct 1st and 2nd try:
15482 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15483 pass = (err == VK_SUCCESS);
15484 ASSERT_TRUE(pass);
15485 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15486 pass = (err == VK_SUCCESS);
15487 ASSERT_TRUE(pass);
15488
15489 // Get the surface present modes:
15490 uint32_t surface_present_mode_count;
15491
15492 // First, try without a pointer to surface_format_count:
15493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15494 "specified as NULL");
15495
15496 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15497 pass = (err == VK_SUCCESS);
15498 ASSERT_TRUE(pass);
15499 m_errorMonitor->VerifyFound();
15500
15501 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15502 // correctly done a 1st try (to get the count):
15503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15504 surface_present_mode_count = 0;
15505 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15506 (VkPresentModeKHR *)&surface_present_mode_count);
15507 pass = (err == VK_SUCCESS);
15508 ASSERT_TRUE(pass);
15509 m_errorMonitor->VerifyFound();
15510
15511 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15512 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15513 pass = (err == VK_SUCCESS);
15514 ASSERT_TRUE(pass);
15515
15516 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15517 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15518
15519 // Next, do a 2nd try with surface_format_count being set too high:
15520 surface_present_mode_count += 5;
15521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15522 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15523 pass = (err == VK_SUCCESS);
15524 ASSERT_TRUE(pass);
15525 m_errorMonitor->VerifyFound();
15526
15527 // Finally, do a correct 1st and 2nd try:
15528 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15529 pass = (err == VK_SUCCESS);
15530 ASSERT_TRUE(pass);
15531 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15532 pass = (err == VK_SUCCESS);
15533 ASSERT_TRUE(pass);
15534
15535 // Create a swapchain:
15536
15537 // First, try without a pointer to swapchain_create_info:
15538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15539 "specified as NULL");
15540
15541 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15542 pass = (err != VK_SUCCESS);
15543 ASSERT_TRUE(pass);
15544 m_errorMonitor->VerifyFound();
15545
15546 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15547 // sType:
15548 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15550
15551 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15552 pass = (err != VK_SUCCESS);
15553 ASSERT_TRUE(pass);
15554 m_errorMonitor->VerifyFound();
15555
15556 // Next, call with a NULL swapchain pointer:
15557 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15558 swapchain_create_info.pNext = NULL;
15559 swapchain_create_info.flags = 0;
15560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15561 "specified as NULL");
15562
15563 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15564 pass = (err != VK_SUCCESS);
15565 ASSERT_TRUE(pass);
15566 m_errorMonitor->VerifyFound();
15567
15568 // TODO: Enhance swapchain layer so that
15569 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15570
15571 // Next, call with a queue family index that's too large:
15572 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15573 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15574 swapchain_create_info.queueFamilyIndexCount = 2;
15575 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15577 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15578 pass = (err != VK_SUCCESS);
15579 ASSERT_TRUE(pass);
15580 m_errorMonitor->VerifyFound();
15581
15582 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15583 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15584 swapchain_create_info.queueFamilyIndexCount = 1;
15585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15586 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15587 "pCreateInfo->pQueueFamilyIndices).");
15588 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15589 pass = (err != VK_SUCCESS);
15590 ASSERT_TRUE(pass);
15591 m_errorMonitor->VerifyFound();
15592
15593 // Next, call with an invalid imageSharingMode:
15594 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15595 swapchain_create_info.queueFamilyIndexCount = 1;
15596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15597 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
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 // Fix for the future:
15603 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15604 // SUPPORTED
15605 swapchain_create_info.queueFamilyIndexCount = 0;
15606 queueFamilyIndex[0] = 0;
15607 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15608
15609 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15610 // Get the images from a swapchain:
15611 // Acquire an image from a swapchain:
15612 // Present an image to a swapchain:
15613 // Destroy the swapchain:
15614
15615 // TODOs:
15616 //
15617 // - Try destroying the device without first destroying the swapchain
15618 //
15619 // - Try destroying the device without first destroying the surface
15620 //
15621 // - Try destroying the surface without first destroying the swapchain
15622
15623 // Destroy the surface:
15624 vkDestroySurfaceKHR(instance(), surface, NULL);
15625
15626 // Tear down the window:
15627 xcb_destroy_window(connection, xcb_window);
15628 xcb_disconnect(connection);
15629
15630#else // VK_USE_PLATFORM_XCB_KHR
15631 return;
15632#endif // VK_USE_PLATFORM_XCB_KHR
15633}
Chris Forbes09368e42016-10-13 11:59:22 +130015634#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015635
15636//
15637// POSITIVE VALIDATION TESTS
15638//
15639// These tests do not expect to encounter ANY validation errors pass only if this is true
15640
Tobin Ehlise0006882016-11-03 10:14:28 -060015641TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15642 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15643 "by a transition in the primary.");
15644 VkResult err;
15645 m_errorMonitor->ExpectSuccess();
15646 ASSERT_NO_FATAL_FAILURE(InitState());
15647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15648 // Allocate a secondary and primary cmd buffer
15649 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15650 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15651 command_buffer_allocate_info.commandPool = m_commandPool;
15652 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15653 command_buffer_allocate_info.commandBufferCount = 1;
15654
15655 VkCommandBuffer secondary_command_buffer;
15656 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15657 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15658 VkCommandBuffer primary_command_buffer;
15659 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15660 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15661 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15662 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15663 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15664 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15665 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15666
15667 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15668 ASSERT_VK_SUCCESS(err);
15669 VkImageObj image(m_device);
15670 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15671 ASSERT_TRUE(image.initialized());
15672 VkImageMemoryBarrier img_barrier = {};
15673 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15674 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15675 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15676 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15677 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15678 img_barrier.image = image.handle();
15679 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15680 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15681 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15682 img_barrier.subresourceRange.baseArrayLayer = 0;
15683 img_barrier.subresourceRange.baseMipLevel = 0;
15684 img_barrier.subresourceRange.layerCount = 1;
15685 img_barrier.subresourceRange.levelCount = 1;
15686 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15687 0, nullptr, 1, &img_barrier);
15688 err = vkEndCommandBuffer(secondary_command_buffer);
15689 ASSERT_VK_SUCCESS(err);
15690
15691 // Now update primary cmd buffer to execute secondary and transitions image
15692 command_buffer_begin_info.pInheritanceInfo = nullptr;
15693 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15694 ASSERT_VK_SUCCESS(err);
15695 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15696 VkImageMemoryBarrier img_barrier2 = {};
15697 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15698 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15699 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15700 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15701 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15702 img_barrier2.image = image.handle();
15703 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15704 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15705 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15706 img_barrier2.subresourceRange.baseArrayLayer = 0;
15707 img_barrier2.subresourceRange.baseMipLevel = 0;
15708 img_barrier2.subresourceRange.layerCount = 1;
15709 img_barrier2.subresourceRange.levelCount = 1;
15710 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15711 nullptr, 1, &img_barrier2);
15712 err = vkEndCommandBuffer(primary_command_buffer);
15713 ASSERT_VK_SUCCESS(err);
15714 VkSubmitInfo submit_info = {};
15715 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15716 submit_info.commandBufferCount = 1;
15717 submit_info.pCommandBuffers = &primary_command_buffer;
15718 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15719 ASSERT_VK_SUCCESS(err);
15720 m_errorMonitor->VerifyNotFound();
15721 err = vkDeviceWaitIdle(m_device->device());
15722 ASSERT_VK_SUCCESS(err);
15723 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15724 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15725}
15726
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015727// This is a positive test. No failures are expected.
15728TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15729 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15730 "is ignoring VkWriteDescriptorSet members that are not "
15731 "related to the descriptor type specified by "
15732 "VkWriteDescriptorSet::descriptorType. Correct "
15733 "validation behavior will result in the test running to "
15734 "completion without validation errors.");
15735
15736 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15737
15738 ASSERT_NO_FATAL_FAILURE(InitState());
15739
15740 // Image Case
15741 {
15742 m_errorMonitor->ExpectSuccess();
15743
15744 VkImage image;
15745 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15746 const int32_t tex_width = 32;
15747 const int32_t tex_height = 32;
15748 VkImageCreateInfo image_create_info = {};
15749 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15750 image_create_info.pNext = NULL;
15751 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15752 image_create_info.format = tex_format;
15753 image_create_info.extent.width = tex_width;
15754 image_create_info.extent.height = tex_height;
15755 image_create_info.extent.depth = 1;
15756 image_create_info.mipLevels = 1;
15757 image_create_info.arrayLayers = 1;
15758 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15759 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15760 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15761 image_create_info.flags = 0;
15762 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15763 ASSERT_VK_SUCCESS(err);
15764
15765 VkMemoryRequirements memory_reqs;
15766 VkDeviceMemory image_memory;
15767 bool pass;
15768 VkMemoryAllocateInfo memory_info = {};
15769 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15770 memory_info.pNext = NULL;
15771 memory_info.allocationSize = 0;
15772 memory_info.memoryTypeIndex = 0;
15773 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15774 memory_info.allocationSize = memory_reqs.size;
15775 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15776 ASSERT_TRUE(pass);
15777 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15778 ASSERT_VK_SUCCESS(err);
15779 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15780 ASSERT_VK_SUCCESS(err);
15781
15782 VkImageViewCreateInfo image_view_create_info = {};
15783 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15784 image_view_create_info.image = image;
15785 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15786 image_view_create_info.format = tex_format;
15787 image_view_create_info.subresourceRange.layerCount = 1;
15788 image_view_create_info.subresourceRange.baseMipLevel = 0;
15789 image_view_create_info.subresourceRange.levelCount = 1;
15790 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15791
15792 VkImageView view;
15793 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15794 ASSERT_VK_SUCCESS(err);
15795
15796 VkDescriptorPoolSize ds_type_count = {};
15797 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15798 ds_type_count.descriptorCount = 1;
15799
15800 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15801 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15802 ds_pool_ci.pNext = NULL;
15803 ds_pool_ci.maxSets = 1;
15804 ds_pool_ci.poolSizeCount = 1;
15805 ds_pool_ci.pPoolSizes = &ds_type_count;
15806
15807 VkDescriptorPool ds_pool;
15808 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15809 ASSERT_VK_SUCCESS(err);
15810
15811 VkDescriptorSetLayoutBinding dsl_binding = {};
15812 dsl_binding.binding = 0;
15813 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15814 dsl_binding.descriptorCount = 1;
15815 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15816 dsl_binding.pImmutableSamplers = NULL;
15817
15818 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15819 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15820 ds_layout_ci.pNext = NULL;
15821 ds_layout_ci.bindingCount = 1;
15822 ds_layout_ci.pBindings = &dsl_binding;
15823 VkDescriptorSetLayout ds_layout;
15824 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15825 ASSERT_VK_SUCCESS(err);
15826
15827 VkDescriptorSet descriptor_set;
15828 VkDescriptorSetAllocateInfo alloc_info = {};
15829 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15830 alloc_info.descriptorSetCount = 1;
15831 alloc_info.descriptorPool = ds_pool;
15832 alloc_info.pSetLayouts = &ds_layout;
15833 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15834 ASSERT_VK_SUCCESS(err);
15835
15836 VkDescriptorImageInfo image_info = {};
15837 image_info.imageView = view;
15838 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15839
15840 VkWriteDescriptorSet descriptor_write;
15841 memset(&descriptor_write, 0, sizeof(descriptor_write));
15842 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15843 descriptor_write.dstSet = descriptor_set;
15844 descriptor_write.dstBinding = 0;
15845 descriptor_write.descriptorCount = 1;
15846 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15847 descriptor_write.pImageInfo = &image_info;
15848
15849 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15850 // be
15851 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15852 // This will most likely produce a crash if the parameter_validation
15853 // layer
15854 // does not correctly ignore pBufferInfo.
15855 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15856 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15857
15858 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15859
15860 m_errorMonitor->VerifyNotFound();
15861
15862 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15863 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15864 vkDestroyImageView(m_device->device(), view, NULL);
15865 vkDestroyImage(m_device->device(), image, NULL);
15866 vkFreeMemory(m_device->device(), image_memory, NULL);
15867 }
15868
15869 // Buffer Case
15870 {
15871 m_errorMonitor->ExpectSuccess();
15872
15873 VkBuffer buffer;
15874 uint32_t queue_family_index = 0;
15875 VkBufferCreateInfo buffer_create_info = {};
15876 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15877 buffer_create_info.size = 1024;
15878 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15879 buffer_create_info.queueFamilyIndexCount = 1;
15880 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15881
15882 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15883 ASSERT_VK_SUCCESS(err);
15884
15885 VkMemoryRequirements memory_reqs;
15886 VkDeviceMemory buffer_memory;
15887 bool pass;
15888 VkMemoryAllocateInfo memory_info = {};
15889 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15890 memory_info.pNext = NULL;
15891 memory_info.allocationSize = 0;
15892 memory_info.memoryTypeIndex = 0;
15893
15894 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15895 memory_info.allocationSize = memory_reqs.size;
15896 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15897 ASSERT_TRUE(pass);
15898
15899 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15900 ASSERT_VK_SUCCESS(err);
15901 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15902 ASSERT_VK_SUCCESS(err);
15903
15904 VkDescriptorPoolSize ds_type_count = {};
15905 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15906 ds_type_count.descriptorCount = 1;
15907
15908 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15909 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15910 ds_pool_ci.pNext = NULL;
15911 ds_pool_ci.maxSets = 1;
15912 ds_pool_ci.poolSizeCount = 1;
15913 ds_pool_ci.pPoolSizes = &ds_type_count;
15914
15915 VkDescriptorPool ds_pool;
15916 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15917 ASSERT_VK_SUCCESS(err);
15918
15919 VkDescriptorSetLayoutBinding dsl_binding = {};
15920 dsl_binding.binding = 0;
15921 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15922 dsl_binding.descriptorCount = 1;
15923 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15924 dsl_binding.pImmutableSamplers = NULL;
15925
15926 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15927 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15928 ds_layout_ci.pNext = NULL;
15929 ds_layout_ci.bindingCount = 1;
15930 ds_layout_ci.pBindings = &dsl_binding;
15931 VkDescriptorSetLayout ds_layout;
15932 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15933 ASSERT_VK_SUCCESS(err);
15934
15935 VkDescriptorSet descriptor_set;
15936 VkDescriptorSetAllocateInfo alloc_info = {};
15937 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15938 alloc_info.descriptorSetCount = 1;
15939 alloc_info.descriptorPool = ds_pool;
15940 alloc_info.pSetLayouts = &ds_layout;
15941 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15942 ASSERT_VK_SUCCESS(err);
15943
15944 VkDescriptorBufferInfo buffer_info = {};
15945 buffer_info.buffer = buffer;
15946 buffer_info.offset = 0;
15947 buffer_info.range = 1024;
15948
15949 VkWriteDescriptorSet descriptor_write;
15950 memset(&descriptor_write, 0, sizeof(descriptor_write));
15951 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15952 descriptor_write.dstSet = descriptor_set;
15953 descriptor_write.dstBinding = 0;
15954 descriptor_write.descriptorCount = 1;
15955 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15956 descriptor_write.pBufferInfo = &buffer_info;
15957
15958 // Set pImageInfo and pTexelBufferView to invalid values, which should
15959 // be
15960 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15961 // This will most likely produce a crash if the parameter_validation
15962 // layer
15963 // does not correctly ignore pImageInfo.
15964 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15965 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15966
15967 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15968
15969 m_errorMonitor->VerifyNotFound();
15970
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015971 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15972 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15973 vkDestroyBuffer(m_device->device(), buffer, NULL);
15974 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15975 }
15976
15977 // Texel Buffer Case
15978 {
15979 m_errorMonitor->ExpectSuccess();
15980
15981 VkBuffer buffer;
15982 uint32_t queue_family_index = 0;
15983 VkBufferCreateInfo buffer_create_info = {};
15984 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15985 buffer_create_info.size = 1024;
15986 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15987 buffer_create_info.queueFamilyIndexCount = 1;
15988 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15989
15990 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15991 ASSERT_VK_SUCCESS(err);
15992
15993 VkMemoryRequirements memory_reqs;
15994 VkDeviceMemory buffer_memory;
15995 bool pass;
15996 VkMemoryAllocateInfo memory_info = {};
15997 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15998 memory_info.pNext = NULL;
15999 memory_info.allocationSize = 0;
16000 memory_info.memoryTypeIndex = 0;
16001
16002 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16003 memory_info.allocationSize = memory_reqs.size;
16004 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16005 ASSERT_TRUE(pass);
16006
16007 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16008 ASSERT_VK_SUCCESS(err);
16009 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16010 ASSERT_VK_SUCCESS(err);
16011
16012 VkBufferViewCreateInfo buff_view_ci = {};
16013 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16014 buff_view_ci.buffer = buffer;
16015 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16016 buff_view_ci.range = VK_WHOLE_SIZE;
16017 VkBufferView buffer_view;
16018 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16019
16020 VkDescriptorPoolSize ds_type_count = {};
16021 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16022 ds_type_count.descriptorCount = 1;
16023
16024 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16025 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16026 ds_pool_ci.pNext = NULL;
16027 ds_pool_ci.maxSets = 1;
16028 ds_pool_ci.poolSizeCount = 1;
16029 ds_pool_ci.pPoolSizes = &ds_type_count;
16030
16031 VkDescriptorPool ds_pool;
16032 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16033 ASSERT_VK_SUCCESS(err);
16034
16035 VkDescriptorSetLayoutBinding dsl_binding = {};
16036 dsl_binding.binding = 0;
16037 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16038 dsl_binding.descriptorCount = 1;
16039 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16040 dsl_binding.pImmutableSamplers = NULL;
16041
16042 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16043 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16044 ds_layout_ci.pNext = NULL;
16045 ds_layout_ci.bindingCount = 1;
16046 ds_layout_ci.pBindings = &dsl_binding;
16047 VkDescriptorSetLayout ds_layout;
16048 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16049 ASSERT_VK_SUCCESS(err);
16050
16051 VkDescriptorSet descriptor_set;
16052 VkDescriptorSetAllocateInfo alloc_info = {};
16053 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16054 alloc_info.descriptorSetCount = 1;
16055 alloc_info.descriptorPool = ds_pool;
16056 alloc_info.pSetLayouts = &ds_layout;
16057 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16058 ASSERT_VK_SUCCESS(err);
16059
16060 VkWriteDescriptorSet descriptor_write;
16061 memset(&descriptor_write, 0, sizeof(descriptor_write));
16062 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16063 descriptor_write.dstSet = descriptor_set;
16064 descriptor_write.dstBinding = 0;
16065 descriptor_write.descriptorCount = 1;
16066 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16067 descriptor_write.pTexelBufferView = &buffer_view;
16068
16069 // Set pImageInfo and pBufferInfo to invalid values, which should be
16070 // ignored for descriptorType ==
16071 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16072 // This will most likely produce a crash if the parameter_validation
16073 // layer
16074 // does not correctly ignore pImageInfo and pBufferInfo.
16075 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16076 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16077
16078 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16079
16080 m_errorMonitor->VerifyNotFound();
16081
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016082 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16083 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16084 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16085 vkDestroyBuffer(m_device->device(), buffer, NULL);
16086 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16087 }
16088}
16089
Tobin Ehlisf7428442016-10-25 07:58:24 -060016090TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16091 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16092
16093 ASSERT_NO_FATAL_FAILURE(InitState());
16094 // Create layout where two binding #s are "1"
16095 static const uint32_t NUM_BINDINGS = 3;
16096 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16097 dsl_binding[0].binding = 1;
16098 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16099 dsl_binding[0].descriptorCount = 1;
16100 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16101 dsl_binding[0].pImmutableSamplers = NULL;
16102 dsl_binding[1].binding = 0;
16103 dsl_binding[1].descriptorCount = 1;
16104 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16105 dsl_binding[1].descriptorCount = 1;
16106 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16107 dsl_binding[1].pImmutableSamplers = NULL;
16108 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16109 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16110 dsl_binding[2].descriptorCount = 1;
16111 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16112 dsl_binding[2].pImmutableSamplers = NULL;
16113
16114 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16115 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16116 ds_layout_ci.pNext = NULL;
16117 ds_layout_ci.bindingCount = NUM_BINDINGS;
16118 ds_layout_ci.pBindings = dsl_binding;
16119 VkDescriptorSetLayout ds_layout;
16120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16121 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16122 m_errorMonitor->VerifyFound();
16123}
16124
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016125TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016126 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16127
16128 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016129
16130 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016131
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016132 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16133
16134 {
16135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16136 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16137 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16138 m_errorMonitor->VerifyFound();
16139 }
16140
16141 {
16142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16143 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16144 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16145 m_errorMonitor->VerifyFound();
16146 }
16147
16148 {
16149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16150 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16151 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16152 m_errorMonitor->VerifyFound();
16153 }
16154
16155 {
16156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16157 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16158 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16159 m_errorMonitor->VerifyFound();
16160 }
16161
16162 {
16163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16164 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16165 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16166 m_errorMonitor->VerifyFound();
16167 }
16168
16169 {
16170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16171 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16172 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16173 m_errorMonitor->VerifyFound();
16174 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016175
16176 {
16177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16178 VkRect2D scissor = {{-1, 0}, {16, 16}};
16179 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16180 m_errorMonitor->VerifyFound();
16181 }
16182
16183 {
16184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16185 VkRect2D scissor = {{0, -2}, {16, 16}};
16186 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16187 m_errorMonitor->VerifyFound();
16188 }
16189
16190 {
16191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16192 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16193 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16194 m_errorMonitor->VerifyFound();
16195 }
16196
16197 {
16198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16199 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16200 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16201 m_errorMonitor->VerifyFound();
16202 }
16203
16204 EndCommandBuffer();
16205}
16206
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016207// This is a positive test. No failures are expected.
16208TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16209 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16210 VkResult err;
16211
16212 ASSERT_NO_FATAL_FAILURE(InitState());
16213 m_errorMonitor->ExpectSuccess();
16214 VkDescriptorPoolSize ds_type_count = {};
16215 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16216 ds_type_count.descriptorCount = 2;
16217
16218 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16219 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16220 ds_pool_ci.pNext = NULL;
16221 ds_pool_ci.maxSets = 1;
16222 ds_pool_ci.poolSizeCount = 1;
16223 ds_pool_ci.pPoolSizes = &ds_type_count;
16224
16225 VkDescriptorPool ds_pool;
16226 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16227 ASSERT_VK_SUCCESS(err);
16228
16229 // Create layout with two uniform buffer descriptors w/ empty binding between them
16230 static const uint32_t NUM_BINDINGS = 3;
16231 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16232 dsl_binding[0].binding = 0;
16233 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16234 dsl_binding[0].descriptorCount = 1;
16235 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16236 dsl_binding[0].pImmutableSamplers = NULL;
16237 dsl_binding[1].binding = 1;
16238 dsl_binding[1].descriptorCount = 0; // empty binding
16239 dsl_binding[2].binding = 2;
16240 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16241 dsl_binding[2].descriptorCount = 1;
16242 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16243 dsl_binding[2].pImmutableSamplers = NULL;
16244
16245 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16246 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16247 ds_layout_ci.pNext = NULL;
16248 ds_layout_ci.bindingCount = NUM_BINDINGS;
16249 ds_layout_ci.pBindings = dsl_binding;
16250 VkDescriptorSetLayout ds_layout;
16251 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16252 ASSERT_VK_SUCCESS(err);
16253
16254 VkDescriptorSet descriptor_set = {};
16255 VkDescriptorSetAllocateInfo alloc_info = {};
16256 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16257 alloc_info.descriptorSetCount = 1;
16258 alloc_info.descriptorPool = ds_pool;
16259 alloc_info.pSetLayouts = &ds_layout;
16260 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16261 ASSERT_VK_SUCCESS(err);
16262
16263 // Create a buffer to be used for update
16264 VkBufferCreateInfo buff_ci = {};
16265 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16266 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16267 buff_ci.size = 256;
16268 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16269 VkBuffer buffer;
16270 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16271 ASSERT_VK_SUCCESS(err);
16272 // Have to bind memory to buffer before descriptor update
16273 VkMemoryAllocateInfo mem_alloc = {};
16274 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16275 mem_alloc.pNext = NULL;
16276 mem_alloc.allocationSize = 512; // one allocation for both buffers
16277 mem_alloc.memoryTypeIndex = 0;
16278
16279 VkMemoryRequirements mem_reqs;
16280 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16281 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16282 if (!pass) {
16283 vkDestroyBuffer(m_device->device(), buffer, NULL);
16284 return;
16285 }
16286
16287 VkDeviceMemory mem;
16288 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16289 ASSERT_VK_SUCCESS(err);
16290 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16291 ASSERT_VK_SUCCESS(err);
16292
16293 // Only update the descriptor at binding 2
16294 VkDescriptorBufferInfo buff_info = {};
16295 buff_info.buffer = buffer;
16296 buff_info.offset = 0;
16297 buff_info.range = VK_WHOLE_SIZE;
16298 VkWriteDescriptorSet descriptor_write = {};
16299 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16300 descriptor_write.dstBinding = 2;
16301 descriptor_write.descriptorCount = 1;
16302 descriptor_write.pTexelBufferView = nullptr;
16303 descriptor_write.pBufferInfo = &buff_info;
16304 descriptor_write.pImageInfo = nullptr;
16305 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16306 descriptor_write.dstSet = descriptor_set;
16307
16308 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16309
16310 m_errorMonitor->VerifyNotFound();
16311 // Cleanup
16312 vkFreeMemory(m_device->device(), mem, NULL);
16313 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16314 vkDestroyBuffer(m_device->device(), buffer, NULL);
16315 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16316}
16317
16318// This is a positive test. No failures are expected.
16319TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16320 VkResult err;
16321 bool pass;
16322
16323 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16324 "the buffer, create an image, and bind the same memory to "
16325 "it");
16326
16327 m_errorMonitor->ExpectSuccess();
16328
16329 ASSERT_NO_FATAL_FAILURE(InitState());
16330
16331 VkBuffer buffer;
16332 VkImage image;
16333 VkDeviceMemory mem;
16334 VkMemoryRequirements mem_reqs;
16335
16336 VkBufferCreateInfo buf_info = {};
16337 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16338 buf_info.pNext = NULL;
16339 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16340 buf_info.size = 256;
16341 buf_info.queueFamilyIndexCount = 0;
16342 buf_info.pQueueFamilyIndices = NULL;
16343 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16344 buf_info.flags = 0;
16345 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16346 ASSERT_VK_SUCCESS(err);
16347
16348 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16349
16350 VkMemoryAllocateInfo alloc_info = {};
16351 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16352 alloc_info.pNext = NULL;
16353 alloc_info.memoryTypeIndex = 0;
16354
16355 // Ensure memory is big enough for both bindings
16356 alloc_info.allocationSize = 0x10000;
16357
16358 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16359 if (!pass) {
16360 vkDestroyBuffer(m_device->device(), buffer, NULL);
16361 return;
16362 }
16363
16364 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16365 ASSERT_VK_SUCCESS(err);
16366
16367 uint8_t *pData;
16368 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16369 ASSERT_VK_SUCCESS(err);
16370
16371 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16372
16373 vkUnmapMemory(m_device->device(), mem);
16374
16375 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16376 ASSERT_VK_SUCCESS(err);
16377
16378 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16379 // memory. In fact, it was never used by the GPU.
16380 // Just be be sure, wait for idle.
16381 vkDestroyBuffer(m_device->device(), buffer, NULL);
16382 vkDeviceWaitIdle(m_device->device());
16383
16384 VkImageCreateInfo image_create_info = {};
16385 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16386 image_create_info.pNext = NULL;
16387 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16388 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16389 image_create_info.extent.width = 64;
16390 image_create_info.extent.height = 64;
16391 image_create_info.extent.depth = 1;
16392 image_create_info.mipLevels = 1;
16393 image_create_info.arrayLayers = 1;
16394 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16395 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16396 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16397 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16398 image_create_info.queueFamilyIndexCount = 0;
16399 image_create_info.pQueueFamilyIndices = NULL;
16400 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16401 image_create_info.flags = 0;
16402
16403 VkMemoryAllocateInfo mem_alloc = {};
16404 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16405 mem_alloc.pNext = NULL;
16406 mem_alloc.allocationSize = 0;
16407 mem_alloc.memoryTypeIndex = 0;
16408
16409 /* Create a mappable image. It will be the texture if linear images are ok
16410 * to be textures or it will be the staging image if they are not.
16411 */
16412 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16413 ASSERT_VK_SUCCESS(err);
16414
16415 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16416
16417 mem_alloc.allocationSize = mem_reqs.size;
16418
16419 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16420 if (!pass) {
16421 vkDestroyImage(m_device->device(), image, NULL);
16422 return;
16423 }
16424
16425 // VALIDATION FAILURE:
16426 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16427 ASSERT_VK_SUCCESS(err);
16428
16429 m_errorMonitor->VerifyNotFound();
16430
16431 vkFreeMemory(m_device->device(), mem, NULL);
16432 vkDestroyBuffer(m_device->device(), buffer, NULL);
16433 vkDestroyImage(m_device->device(), image, NULL);
16434}
16435
Tobin Ehlis953e8392016-11-17 10:54:13 -070016436TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16437 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16438 // We previously had a bug where dynamic offset of inactive bindings was still being used
16439 VkResult err;
16440 m_errorMonitor->ExpectSuccess();
16441
16442 ASSERT_NO_FATAL_FAILURE(InitState());
16443 ASSERT_NO_FATAL_FAILURE(InitViewport());
16444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16445
16446 VkDescriptorPoolSize ds_type_count = {};
16447 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16448 ds_type_count.descriptorCount = 3;
16449
16450 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16451 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16452 ds_pool_ci.pNext = NULL;
16453 ds_pool_ci.maxSets = 1;
16454 ds_pool_ci.poolSizeCount = 1;
16455 ds_pool_ci.pPoolSizes = &ds_type_count;
16456
16457 VkDescriptorPool ds_pool;
16458 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16459 ASSERT_VK_SUCCESS(err);
16460
16461 const uint32_t BINDING_COUNT = 3;
16462 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
16463 dsl_binding[0].binding = 0;
16464 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16465 dsl_binding[0].descriptorCount = 1;
16466 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16467 dsl_binding[0].pImmutableSamplers = NULL;
16468 dsl_binding[1].binding = 1;
16469 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16470 dsl_binding[1].descriptorCount = 1;
16471 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16472 dsl_binding[1].pImmutableSamplers = NULL;
16473 dsl_binding[2].binding = 2;
16474 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16475 dsl_binding[2].descriptorCount = 1;
16476 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16477 dsl_binding[2].pImmutableSamplers = NULL;
16478
16479 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16480 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16481 ds_layout_ci.pNext = NULL;
16482 ds_layout_ci.bindingCount = BINDING_COUNT;
16483 ds_layout_ci.pBindings = dsl_binding;
16484 VkDescriptorSetLayout ds_layout;
16485 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16486 ASSERT_VK_SUCCESS(err);
16487
16488 VkDescriptorSet descriptor_set;
16489 VkDescriptorSetAllocateInfo alloc_info = {};
16490 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16491 alloc_info.descriptorSetCount = 1;
16492 alloc_info.descriptorPool = ds_pool;
16493 alloc_info.pSetLayouts = &ds_layout;
16494 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16495 ASSERT_VK_SUCCESS(err);
16496
16497 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16498 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16499 pipeline_layout_ci.pNext = NULL;
16500 pipeline_layout_ci.setLayoutCount = 1;
16501 pipeline_layout_ci.pSetLayouts = &ds_layout;
16502
16503 VkPipelineLayout pipeline_layout;
16504 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16505 ASSERT_VK_SUCCESS(err);
16506
16507 // Create two buffers to update the descriptors with
16508 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16509 uint32_t qfi = 0;
16510 VkBufferCreateInfo buffCI = {};
16511 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16512 buffCI.size = 2048;
16513 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16514 buffCI.queueFamilyIndexCount = 1;
16515 buffCI.pQueueFamilyIndices = &qfi;
16516
16517 VkBuffer dyub1;
16518 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16519 ASSERT_VK_SUCCESS(err);
16520 // buffer2
16521 buffCI.size = 1024;
16522 VkBuffer dyub2;
16523 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16524 ASSERT_VK_SUCCESS(err);
16525 // Allocate memory and bind to buffers
16526 VkMemoryAllocateInfo mem_alloc[2] = {};
16527 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16528 mem_alloc[0].pNext = NULL;
16529 mem_alloc[0].memoryTypeIndex = 0;
16530 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16531 mem_alloc[1].pNext = NULL;
16532 mem_alloc[1].memoryTypeIndex = 0;
16533
16534 VkMemoryRequirements mem_reqs1;
16535 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16536 VkMemoryRequirements mem_reqs2;
16537 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16538 mem_alloc[0].allocationSize = mem_reqs1.size;
16539 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16540 mem_alloc[1].allocationSize = mem_reqs2.size;
16541 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16542 if (!pass) {
16543 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16544 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16545 return;
16546 }
16547
16548 VkDeviceMemory mem1;
16549 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16550 ASSERT_VK_SUCCESS(err);
16551 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16552 ASSERT_VK_SUCCESS(err);
16553 VkDeviceMemory mem2;
16554 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16555 ASSERT_VK_SUCCESS(err);
16556 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16557 ASSERT_VK_SUCCESS(err);
16558 // Update descriptors
16559 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16560 buff_info[0].buffer = dyub1;
16561 buff_info[0].offset = 0;
16562 buff_info[0].range = 256;
16563 buff_info[1].buffer = dyub1;
16564 buff_info[1].offset = 256;
16565 buff_info[1].range = 512;
16566 buff_info[2].buffer = dyub2;
16567 buff_info[2].offset = 0;
16568 buff_info[2].range = 512;
16569
16570 VkWriteDescriptorSet descriptor_write;
16571 memset(&descriptor_write, 0, sizeof(descriptor_write));
16572 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16573 descriptor_write.dstSet = descriptor_set;
16574 descriptor_write.dstBinding = 0;
16575 descriptor_write.descriptorCount = BINDING_COUNT;
16576 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16577 descriptor_write.pBufferInfo = buff_info;
16578
16579 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16580
16581 BeginCommandBuffer();
16582
16583 // Create PSO to be used for draw-time errors below
16584 char const *vsSource = "#version 450\n"
16585 "\n"
16586 "out gl_PerVertex { \n"
16587 " vec4 gl_Position;\n"
16588 "};\n"
16589 "void main(){\n"
16590 " gl_Position = vec4(1);\n"
16591 "}\n";
16592 char const *fsSource = "#version 450\n"
16593 "\n"
16594 "layout(location=0) out vec4 x;\n"
16595 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16596 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16597 "void main(){\n"
16598 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16599 "}\n";
16600 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16601 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16602 VkPipelineObj pipe(m_device);
16603 pipe.SetViewport(m_viewports);
16604 pipe.SetScissor(m_scissors);
16605 pipe.AddShader(&vs);
16606 pipe.AddShader(&fs);
16607 pipe.AddColorAttachment();
16608 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16609
16610 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16611 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16612 // we used to have a bug in this case.
16613 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16614 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16615 &descriptor_set, BINDING_COUNT, dyn_off);
16616 Draw(1, 0, 0, 0);
16617 m_errorMonitor->VerifyNotFound();
16618
16619 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16620 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16621 vkFreeMemory(m_device->device(), mem1, NULL);
16622 vkFreeMemory(m_device->device(), mem2, NULL);
16623
16624 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16625 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16626 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16627}
16628
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016629TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16630
16631 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16632 "mapping while using VK_WHOLE_SIZE does not cause access "
16633 "violations");
16634 VkResult err;
16635 uint8_t *pData;
16636 ASSERT_NO_FATAL_FAILURE(InitState());
16637
16638 VkDeviceMemory mem;
16639 VkMemoryRequirements mem_reqs;
16640 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16641 VkMemoryAllocateInfo alloc_info = {};
16642 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16643 alloc_info.pNext = NULL;
16644 alloc_info.memoryTypeIndex = 0;
16645
16646 static const VkDeviceSize allocation_size = 0x1000;
16647 alloc_info.allocationSize = allocation_size;
16648
16649 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16650 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16651 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16652 if (!pass) {
16653 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16654 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16655 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16656 if (!pass) {
16657 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16658 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16659 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16660 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16661 if (!pass) {
16662 return;
16663 }
16664 }
16665 }
16666
16667 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16668 ASSERT_VK_SUCCESS(err);
16669
16670 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16671 // mapped range
16672 m_errorMonitor->ExpectSuccess();
16673 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16674 ASSERT_VK_SUCCESS(err);
16675 VkMappedMemoryRange mmr = {};
16676 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16677 mmr.memory = mem;
16678 mmr.offset = 0;
16679 mmr.size = VK_WHOLE_SIZE;
16680 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16681 ASSERT_VK_SUCCESS(err);
16682 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16683 ASSERT_VK_SUCCESS(err);
16684 m_errorMonitor->VerifyNotFound();
16685 vkUnmapMemory(m_device->device(), mem);
16686
16687 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16688 // mapped range
16689 m_errorMonitor->ExpectSuccess();
16690 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16691 ASSERT_VK_SUCCESS(err);
16692 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16693 mmr.memory = mem;
16694 mmr.offset = 13;
16695 mmr.size = VK_WHOLE_SIZE;
16696 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16697 ASSERT_VK_SUCCESS(err);
16698 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16699 ASSERT_VK_SUCCESS(err);
16700 m_errorMonitor->VerifyNotFound();
16701 vkUnmapMemory(m_device->device(), mem);
16702
16703 // Map with prime offset and size
16704 // Flush/Invalidate subrange of mapped area with prime offset and size
16705 m_errorMonitor->ExpectSuccess();
16706 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16707 ASSERT_VK_SUCCESS(err);
16708 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16709 mmr.memory = mem;
16710 mmr.offset = allocation_size - 107;
16711 mmr.size = 61;
16712 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16713 ASSERT_VK_SUCCESS(err);
16714 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16715 ASSERT_VK_SUCCESS(err);
16716 m_errorMonitor->VerifyNotFound();
16717 vkUnmapMemory(m_device->device(), mem);
16718
16719 // Map without offset and flush WHOLE_SIZE with two separate offsets
16720 m_errorMonitor->ExpectSuccess();
16721 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16722 ASSERT_VK_SUCCESS(err);
16723 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16724 mmr.memory = mem;
16725 mmr.offset = allocation_size - 100;
16726 mmr.size = VK_WHOLE_SIZE;
16727 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16728 ASSERT_VK_SUCCESS(err);
16729 mmr.offset = allocation_size - 200;
16730 mmr.size = VK_WHOLE_SIZE;
16731 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16732 ASSERT_VK_SUCCESS(err);
16733 m_errorMonitor->VerifyNotFound();
16734 vkUnmapMemory(m_device->device(), mem);
16735
16736 vkFreeMemory(m_device->device(), mem, NULL);
16737}
16738
16739// This is a positive test. We used to expect error in this case but spec now allows it
16740TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16741 m_errorMonitor->ExpectSuccess();
16742 vk_testing::Fence testFence;
16743 VkFenceCreateInfo fenceInfo = {};
16744 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16745 fenceInfo.pNext = NULL;
16746
16747 ASSERT_NO_FATAL_FAILURE(InitState());
16748 testFence.init(*m_device, fenceInfo);
16749 VkFence fences[1] = { testFence.handle() };
16750 VkResult result = vkResetFences(m_device->device(), 1, fences);
16751 ASSERT_VK_SUCCESS(result);
16752
16753 m_errorMonitor->VerifyNotFound();
16754}
16755
16756TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16757 m_errorMonitor->ExpectSuccess();
16758
16759 ASSERT_NO_FATAL_FAILURE(InitState());
16760 VkResult err;
16761
16762 // Record (empty!) command buffer that can be submitted multiple times
16763 // simultaneously.
16764 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16765 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16766 m_commandBuffer->BeginCommandBuffer(&cbbi);
16767 m_commandBuffer->EndCommandBuffer();
16768
16769 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16770 VkFence fence;
16771 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16772 ASSERT_VK_SUCCESS(err);
16773
16774 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16775 VkSemaphore s1, s2;
16776 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16777 ASSERT_VK_SUCCESS(err);
16778 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16779 ASSERT_VK_SUCCESS(err);
16780
16781 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16782 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16783 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16784 ASSERT_VK_SUCCESS(err);
16785
16786 // Submit CB again, signaling s2.
16787 si.pSignalSemaphores = &s2;
16788 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16789 ASSERT_VK_SUCCESS(err);
16790
16791 // Wait for fence.
16792 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16793 ASSERT_VK_SUCCESS(err);
16794
16795 // CB is still in flight from second submission, but semaphore s1 is no
16796 // longer in flight. delete it.
16797 vkDestroySemaphore(m_device->device(), s1, nullptr);
16798
16799 m_errorMonitor->VerifyNotFound();
16800
16801 // Force device idle and clean up remaining objects
16802 vkDeviceWaitIdle(m_device->device());
16803 vkDestroySemaphore(m_device->device(), s2, nullptr);
16804 vkDestroyFence(m_device->device(), fence, nullptr);
16805}
16806
16807TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16808 m_errorMonitor->ExpectSuccess();
16809
16810 ASSERT_NO_FATAL_FAILURE(InitState());
16811 VkResult err;
16812
16813 // A fence created signaled
16814 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16815 VkFence f1;
16816 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16817 ASSERT_VK_SUCCESS(err);
16818
16819 // A fence created not
16820 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16821 VkFence f2;
16822 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16823 ASSERT_VK_SUCCESS(err);
16824
16825 // Submit the unsignaled fence
16826 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16827 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16828
16829 // Wait on both fences, with signaled first.
16830 VkFence fences[] = { f1, f2 };
16831 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16832
16833 // Should have both retired!
16834 vkDestroyFence(m_device->device(), f1, nullptr);
16835 vkDestroyFence(m_device->device(), f2, nullptr);
16836
16837 m_errorMonitor->VerifyNotFound();
16838}
16839
16840TEST_F(VkPositiveLayerTest, ValidUsage) {
16841 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16842 "doesn't generate validation errors");
16843
16844 ASSERT_NO_FATAL_FAILURE(InitState());
16845
16846 m_errorMonitor->ExpectSuccess();
16847 // Verify that we can create a view with usage INPUT_ATTACHMENT
16848 VkImageObj image(m_device);
16849 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16850 ASSERT_TRUE(image.initialized());
16851 VkImageView imageView;
16852 VkImageViewCreateInfo ivci = {};
16853 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16854 ivci.image = image.handle();
16855 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16856 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16857 ivci.subresourceRange.layerCount = 1;
16858 ivci.subresourceRange.baseMipLevel = 0;
16859 ivci.subresourceRange.levelCount = 1;
16860 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16861
16862 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16863 m_errorMonitor->VerifyNotFound();
16864 vkDestroyImageView(m_device->device(), imageView, NULL);
16865}
16866
16867// This is a positive test. No failures are expected.
16868TEST_F(VkPositiveLayerTest, BindSparse) {
16869 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16870 "and then free the memory");
16871
16872 ASSERT_NO_FATAL_FAILURE(InitState());
16873
16874 auto index = m_device->graphics_queue_node_index_;
16875 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16876 return;
16877
16878 m_errorMonitor->ExpectSuccess();
16879
16880 VkImage image;
16881 VkImageCreateInfo image_create_info = {};
16882 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16883 image_create_info.pNext = NULL;
16884 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16885 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16886 image_create_info.extent.width = 64;
16887 image_create_info.extent.height = 64;
16888 image_create_info.extent.depth = 1;
16889 image_create_info.mipLevels = 1;
16890 image_create_info.arrayLayers = 1;
16891 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16892 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16893 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16894 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16895 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16896 ASSERT_VK_SUCCESS(err);
16897
16898 VkMemoryRequirements memory_reqs;
16899 VkDeviceMemory memory_one, memory_two;
16900 bool pass;
16901 VkMemoryAllocateInfo memory_info = {};
16902 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16903 memory_info.pNext = NULL;
16904 memory_info.allocationSize = 0;
16905 memory_info.memoryTypeIndex = 0;
16906 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16907 // Find an image big enough to allow sparse mapping of 2 memory regions
16908 // Increase the image size until it is at least twice the
16909 // size of the required alignment, to ensure we can bind both
16910 // allocated memory blocks to the image on aligned offsets.
16911 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16912 vkDestroyImage(m_device->device(), image, nullptr);
16913 image_create_info.extent.width *= 2;
16914 image_create_info.extent.height *= 2;
16915 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16916 ASSERT_VK_SUCCESS(err);
16917 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16918 }
16919 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16920 // at the end of the first
16921 memory_info.allocationSize = memory_reqs.alignment;
16922 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16923 ASSERT_TRUE(pass);
16924 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16925 ASSERT_VK_SUCCESS(err);
16926 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16927 ASSERT_VK_SUCCESS(err);
16928 VkSparseMemoryBind binds[2];
16929 binds[0].flags = 0;
16930 binds[0].memory = memory_one;
16931 binds[0].memoryOffset = 0;
16932 binds[0].resourceOffset = 0;
16933 binds[0].size = memory_info.allocationSize;
16934 binds[1].flags = 0;
16935 binds[1].memory = memory_two;
16936 binds[1].memoryOffset = 0;
16937 binds[1].resourceOffset = memory_info.allocationSize;
16938 binds[1].size = memory_info.allocationSize;
16939
16940 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16941 opaqueBindInfo.image = image;
16942 opaqueBindInfo.bindCount = 2;
16943 opaqueBindInfo.pBinds = binds;
16944
16945 VkFence fence = VK_NULL_HANDLE;
16946 VkBindSparseInfo bindSparseInfo = {};
16947 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16948 bindSparseInfo.imageOpaqueBindCount = 1;
16949 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16950
16951 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16952 vkQueueWaitIdle(m_device->m_queue);
16953 vkDestroyImage(m_device->device(), image, NULL);
16954 vkFreeMemory(m_device->device(), memory_one, NULL);
16955 vkFreeMemory(m_device->device(), memory_two, NULL);
16956 m_errorMonitor->VerifyNotFound();
16957}
16958
16959TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16960 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16961 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16962 "the command buffer has prior knowledge of that "
16963 "attachment's layout.");
16964
16965 m_errorMonitor->ExpectSuccess();
16966
16967 ASSERT_NO_FATAL_FAILURE(InitState());
16968
16969 // A renderpass with one color attachment.
16970 VkAttachmentDescription attachment = { 0,
16971 VK_FORMAT_R8G8B8A8_UNORM,
16972 VK_SAMPLE_COUNT_1_BIT,
16973 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16974 VK_ATTACHMENT_STORE_OP_STORE,
16975 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16976 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16977 VK_IMAGE_LAYOUT_UNDEFINED,
16978 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16979
16980 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16981
16982 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16983
16984 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16985
16986 VkRenderPass rp;
16987 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16988 ASSERT_VK_SUCCESS(err);
16989
16990 // A compatible framebuffer.
16991 VkImageObj image(m_device);
16992 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16993 ASSERT_TRUE(image.initialized());
16994
16995 VkImageViewCreateInfo ivci = {
16996 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16997 nullptr,
16998 0,
16999 image.handle(),
17000 VK_IMAGE_VIEW_TYPE_2D,
17001 VK_FORMAT_R8G8B8A8_UNORM,
17002 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17003 VK_COMPONENT_SWIZZLE_IDENTITY },
17004 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17005 };
17006 VkImageView view;
17007 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17008 ASSERT_VK_SUCCESS(err);
17009
17010 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17011 VkFramebuffer fb;
17012 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17013 ASSERT_VK_SUCCESS(err);
17014
17015 // Record a single command buffer which uses this renderpass twice. The
17016 // bug is triggered at the beginning of the second renderpass, when the
17017 // command buffer already has a layout recorded for the attachment.
17018 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17019 BeginCommandBuffer();
17020 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17021 vkCmdEndRenderPass(m_commandBuffer->handle());
17022 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17023
17024 m_errorMonitor->VerifyNotFound();
17025
17026 vkCmdEndRenderPass(m_commandBuffer->handle());
17027 EndCommandBuffer();
17028
17029 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17030 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17031 vkDestroyImageView(m_device->device(), view, nullptr);
17032}
17033
17034TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17035 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17036 "command buffer, bind them together, then destroy "
17037 "command pool and framebuffer and verify there are no "
17038 "errors.");
17039
17040 m_errorMonitor->ExpectSuccess();
17041
17042 ASSERT_NO_FATAL_FAILURE(InitState());
17043
17044 // A renderpass with one color attachment.
17045 VkAttachmentDescription attachment = { 0,
17046 VK_FORMAT_R8G8B8A8_UNORM,
17047 VK_SAMPLE_COUNT_1_BIT,
17048 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17049 VK_ATTACHMENT_STORE_OP_STORE,
17050 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17051 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17052 VK_IMAGE_LAYOUT_UNDEFINED,
17053 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17054
17055 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17056
17057 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17058
17059 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17060
17061 VkRenderPass rp;
17062 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17063 ASSERT_VK_SUCCESS(err);
17064
17065 // A compatible framebuffer.
17066 VkImageObj image(m_device);
17067 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17068 ASSERT_TRUE(image.initialized());
17069
17070 VkImageViewCreateInfo ivci = {
17071 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17072 nullptr,
17073 0,
17074 image.handle(),
17075 VK_IMAGE_VIEW_TYPE_2D,
17076 VK_FORMAT_R8G8B8A8_UNORM,
17077 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17078 VK_COMPONENT_SWIZZLE_IDENTITY },
17079 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17080 };
17081 VkImageView view;
17082 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17083 ASSERT_VK_SUCCESS(err);
17084
17085 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17086 VkFramebuffer fb;
17087 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17088 ASSERT_VK_SUCCESS(err);
17089
17090 // Explicitly create a command buffer to bind the FB to so that we can then
17091 // destroy the command pool in order to implicitly free command buffer
17092 VkCommandPool command_pool;
17093 VkCommandPoolCreateInfo pool_create_info{};
17094 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17095 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17096 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17097 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17098
17099 VkCommandBuffer command_buffer;
17100 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17101 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17102 command_buffer_allocate_info.commandPool = command_pool;
17103 command_buffer_allocate_info.commandBufferCount = 1;
17104 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17105 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17106
17107 // Begin our cmd buffer with renderpass using our framebuffer
17108 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17109 VkCommandBufferBeginInfo begin_info{};
17110 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17111 vkBeginCommandBuffer(command_buffer, &begin_info);
17112
17113 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17114 vkCmdEndRenderPass(command_buffer);
17115 vkEndCommandBuffer(command_buffer);
17116 vkDestroyImageView(m_device->device(), view, nullptr);
17117 // Destroy command pool to implicitly free command buffer
17118 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17119 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17120 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17121 m_errorMonitor->VerifyNotFound();
17122}
17123
17124TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17125 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17126 "transitions for the first subpass");
17127
17128 m_errorMonitor->ExpectSuccess();
17129
17130 ASSERT_NO_FATAL_FAILURE(InitState());
17131
17132 // A renderpass with one color attachment.
17133 VkAttachmentDescription attachment = { 0,
17134 VK_FORMAT_R8G8B8A8_UNORM,
17135 VK_SAMPLE_COUNT_1_BIT,
17136 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17137 VK_ATTACHMENT_STORE_OP_STORE,
17138 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17139 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17140 VK_IMAGE_LAYOUT_UNDEFINED,
17141 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17142
17143 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17144
17145 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17146
17147 VkSubpassDependency dep = { 0,
17148 0,
17149 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17150 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17151 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17152 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17153 VK_DEPENDENCY_BY_REGION_BIT };
17154
17155 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17156
17157 VkResult err;
17158 VkRenderPass rp;
17159 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17160 ASSERT_VK_SUCCESS(err);
17161
17162 // A compatible framebuffer.
17163 VkImageObj image(m_device);
17164 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17165 ASSERT_TRUE(image.initialized());
17166
17167 VkImageViewCreateInfo ivci = {
17168 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17169 nullptr,
17170 0,
17171 image.handle(),
17172 VK_IMAGE_VIEW_TYPE_2D,
17173 VK_FORMAT_R8G8B8A8_UNORM,
17174 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17175 VK_COMPONENT_SWIZZLE_IDENTITY },
17176 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17177 };
17178 VkImageView view;
17179 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17180 ASSERT_VK_SUCCESS(err);
17181
17182 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17183 VkFramebuffer fb;
17184 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17185 ASSERT_VK_SUCCESS(err);
17186
17187 // Record a single command buffer which issues a pipeline barrier w/
17188 // image memory barrier for the attachment. This detects the previously
17189 // missing tracking of the subpass layout by throwing a validation error
17190 // if it doesn't occur.
17191 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17192 BeginCommandBuffer();
17193 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17194
17195 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17196 nullptr,
17197 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17198 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17199 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17200 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17201 VK_QUEUE_FAMILY_IGNORED,
17202 VK_QUEUE_FAMILY_IGNORED,
17203 image.handle(),
17204 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17205 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17206 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17207 &imb);
17208
17209 vkCmdEndRenderPass(m_commandBuffer->handle());
17210 m_errorMonitor->VerifyNotFound();
17211 EndCommandBuffer();
17212
17213 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17214 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17215 vkDestroyImageView(m_device->device(), view, nullptr);
17216}
17217
17218TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17219 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17220 "is used as a depth/stencil framebuffer attachment, the "
17221 "aspectMask is ignored and both depth and stencil image "
17222 "subresources are used.");
17223
17224 VkFormatProperties format_properties;
17225 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17226 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17227 return;
17228 }
17229
17230 m_errorMonitor->ExpectSuccess();
17231
17232 ASSERT_NO_FATAL_FAILURE(InitState());
17233
17234 VkAttachmentDescription attachment = { 0,
17235 VK_FORMAT_D32_SFLOAT_S8_UINT,
17236 VK_SAMPLE_COUNT_1_BIT,
17237 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17238 VK_ATTACHMENT_STORE_OP_STORE,
17239 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17240 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17241 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17242 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17243
17244 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17245
17246 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17247
17248 VkSubpassDependency dep = { 0,
17249 0,
17250 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17251 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17252 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17253 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17254 VK_DEPENDENCY_BY_REGION_BIT};
17255
17256 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17257
17258 VkResult err;
17259 VkRenderPass rp;
17260 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17261 ASSERT_VK_SUCCESS(err);
17262
17263 VkImageObj image(m_device);
17264 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17265 0x26, // usage
17266 VK_IMAGE_TILING_OPTIMAL, 0);
17267 ASSERT_TRUE(image.initialized());
17268 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17269
17270 VkImageViewCreateInfo ivci = {
17271 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17272 nullptr,
17273 0,
17274 image.handle(),
17275 VK_IMAGE_VIEW_TYPE_2D,
17276 VK_FORMAT_D32_SFLOAT_S8_UINT,
17277 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17278 { 0x2, 0, 1, 0, 1 },
17279 };
17280 VkImageView view;
17281 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17282 ASSERT_VK_SUCCESS(err);
17283
17284 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17285 VkFramebuffer fb;
17286 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17287 ASSERT_VK_SUCCESS(err);
17288
17289 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17290 BeginCommandBuffer();
17291 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17292
17293 VkImageMemoryBarrier imb = {};
17294 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17295 imb.pNext = nullptr;
17296 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17297 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17298 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17299 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17300 imb.srcQueueFamilyIndex = 0;
17301 imb.dstQueueFamilyIndex = 0;
17302 imb.image = image.handle();
17303 imb.subresourceRange.aspectMask = 0x6;
17304 imb.subresourceRange.baseMipLevel = 0;
17305 imb.subresourceRange.levelCount = 0x1;
17306 imb.subresourceRange.baseArrayLayer = 0;
17307 imb.subresourceRange.layerCount = 0x1;
17308
17309 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17310 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17311 &imb);
17312
17313 vkCmdEndRenderPass(m_commandBuffer->handle());
17314 EndCommandBuffer();
17315 QueueCommandBuffer(false);
17316 m_errorMonitor->VerifyNotFound();
17317
17318 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17319 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17320 vkDestroyImageView(m_device->device(), view, nullptr);
17321}
17322
17323TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17324 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17325 "errors, when an attachment reference is "
17326 "VK_ATTACHMENT_UNUSED");
17327
17328 m_errorMonitor->ExpectSuccess();
17329
17330 ASSERT_NO_FATAL_FAILURE(InitState());
17331
17332 // A renderpass with no attachments
17333 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17334
17335 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17336
17337 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17338
17339 VkRenderPass rp;
17340 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17341 ASSERT_VK_SUCCESS(err);
17342
17343 // A compatible framebuffer.
17344 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17345 VkFramebuffer fb;
17346 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17347 ASSERT_VK_SUCCESS(err);
17348
17349 // Record a command buffer which just begins and ends the renderpass. The
17350 // bug manifests in BeginRenderPass.
17351 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17352 BeginCommandBuffer();
17353 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17354 vkCmdEndRenderPass(m_commandBuffer->handle());
17355 m_errorMonitor->VerifyNotFound();
17356 EndCommandBuffer();
17357
17358 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17359 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17360}
17361
17362// This is a positive test. No errors are expected.
17363TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17364 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17365 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17366 VkResult result = VK_SUCCESS;
17367 VkImageFormatProperties formatProps;
17368 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17369 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17370 &formatProps);
17371 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17372 return;
17373 }
17374
17375 ASSERT_NO_FATAL_FAILURE(InitState());
17376 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17377 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17378 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17379 VkAttachmentDescription att = {};
17380 VkAttachmentReference ref = {};
17381 att.format = depth_stencil_fmt;
17382 att.samples = VK_SAMPLE_COUNT_1_BIT;
17383 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17384 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17385 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17386 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17387 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17388 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17389
17390 VkClearValue clear;
17391 clear.depthStencil.depth = 1.0;
17392 clear.depthStencil.stencil = 0;
17393 ref.attachment = 0;
17394 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17395
17396 VkSubpassDescription subpass = {};
17397 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17398 subpass.flags = 0;
17399 subpass.inputAttachmentCount = 0;
17400 subpass.pInputAttachments = NULL;
17401 subpass.colorAttachmentCount = 0;
17402 subpass.pColorAttachments = NULL;
17403 subpass.pResolveAttachments = NULL;
17404 subpass.pDepthStencilAttachment = &ref;
17405 subpass.preserveAttachmentCount = 0;
17406 subpass.pPreserveAttachments = NULL;
17407
17408 VkRenderPass rp;
17409 VkRenderPassCreateInfo rp_info = {};
17410 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17411 rp_info.attachmentCount = 1;
17412 rp_info.pAttachments = &att;
17413 rp_info.subpassCount = 1;
17414 rp_info.pSubpasses = &subpass;
17415 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17416 ASSERT_VK_SUCCESS(result);
17417
17418 VkImageView *depthView = m_depthStencil->BindInfo();
17419 VkFramebufferCreateInfo fb_info = {};
17420 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17421 fb_info.pNext = NULL;
17422 fb_info.renderPass = rp;
17423 fb_info.attachmentCount = 1;
17424 fb_info.pAttachments = depthView;
17425 fb_info.width = 100;
17426 fb_info.height = 100;
17427 fb_info.layers = 1;
17428 VkFramebuffer fb;
17429 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17430 ASSERT_VK_SUCCESS(result);
17431
17432 VkRenderPassBeginInfo rpbinfo = {};
17433 rpbinfo.clearValueCount = 1;
17434 rpbinfo.pClearValues = &clear;
17435 rpbinfo.pNext = NULL;
17436 rpbinfo.renderPass = rp;
17437 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17438 rpbinfo.renderArea.extent.width = 100;
17439 rpbinfo.renderArea.extent.height = 100;
17440 rpbinfo.renderArea.offset.x = 0;
17441 rpbinfo.renderArea.offset.y = 0;
17442 rpbinfo.framebuffer = fb;
17443
17444 VkFence fence = {};
17445 VkFenceCreateInfo fence_ci = {};
17446 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17447 fence_ci.pNext = nullptr;
17448 fence_ci.flags = 0;
17449 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17450 ASSERT_VK_SUCCESS(result);
17451
17452 m_commandBuffer->BeginCommandBuffer();
17453 m_commandBuffer->BeginRenderPass(rpbinfo);
17454 m_commandBuffer->EndRenderPass();
17455 m_commandBuffer->EndCommandBuffer();
17456 m_commandBuffer->QueueCommandBuffer(fence);
17457
17458 VkImageObj destImage(m_device);
17459 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17460 VK_IMAGE_TILING_OPTIMAL, 0);
17461 VkImageMemoryBarrier barrier = {};
17462 VkImageSubresourceRange range;
17463 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17464 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17465 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17466 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17467 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17468 barrier.image = m_depthStencil->handle();
17469 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17470 range.baseMipLevel = 0;
17471 range.levelCount = 1;
17472 range.baseArrayLayer = 0;
17473 range.layerCount = 1;
17474 barrier.subresourceRange = range;
17475 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17476 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17477 cmdbuf.BeginCommandBuffer();
17478 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17479 &barrier);
17480 barrier.srcAccessMask = 0;
17481 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17482 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17483 barrier.image = destImage.handle();
17484 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17485 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17486 &barrier);
17487 VkImageCopy cregion;
17488 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17489 cregion.srcSubresource.mipLevel = 0;
17490 cregion.srcSubresource.baseArrayLayer = 0;
17491 cregion.srcSubresource.layerCount = 1;
17492 cregion.srcOffset.x = 0;
17493 cregion.srcOffset.y = 0;
17494 cregion.srcOffset.z = 0;
17495 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17496 cregion.dstSubresource.mipLevel = 0;
17497 cregion.dstSubresource.baseArrayLayer = 0;
17498 cregion.dstSubresource.layerCount = 1;
17499 cregion.dstOffset.x = 0;
17500 cregion.dstOffset.y = 0;
17501 cregion.dstOffset.z = 0;
17502 cregion.extent.width = 100;
17503 cregion.extent.height = 100;
17504 cregion.extent.depth = 1;
17505 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17506 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17507 cmdbuf.EndCommandBuffer();
17508
17509 VkSubmitInfo submit_info;
17510 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17511 submit_info.pNext = NULL;
17512 submit_info.waitSemaphoreCount = 0;
17513 submit_info.pWaitSemaphores = NULL;
17514 submit_info.pWaitDstStageMask = NULL;
17515 submit_info.commandBufferCount = 1;
17516 submit_info.pCommandBuffers = &cmdbuf.handle();
17517 submit_info.signalSemaphoreCount = 0;
17518 submit_info.pSignalSemaphores = NULL;
17519
17520 m_errorMonitor->ExpectSuccess();
17521 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17522 m_errorMonitor->VerifyNotFound();
17523
17524 vkQueueWaitIdle(m_device->m_queue);
17525 vkDestroyFence(m_device->device(), fence, nullptr);
17526 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17527 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17528}
17529
17530// This is a positive test. No errors should be generated.
17531TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17532 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17533
17534 m_errorMonitor->ExpectSuccess();
17535 ASSERT_NO_FATAL_FAILURE(InitState());
17536
17537 VkEvent event;
17538 VkEventCreateInfo event_create_info{};
17539 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17540 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17541
17542 VkCommandPool command_pool;
17543 VkCommandPoolCreateInfo pool_create_info{};
17544 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17545 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17546 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17547 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17548
17549 VkCommandBuffer command_buffer;
17550 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17551 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17552 command_buffer_allocate_info.commandPool = command_pool;
17553 command_buffer_allocate_info.commandBufferCount = 1;
17554 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17555 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17556
17557 VkQueue queue = VK_NULL_HANDLE;
17558 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17559
17560 {
17561 VkCommandBufferBeginInfo begin_info{};
17562 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17563 vkBeginCommandBuffer(command_buffer, &begin_info);
17564
17565 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17566 nullptr, 0, nullptr);
17567 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17568 vkEndCommandBuffer(command_buffer);
17569 }
17570 {
17571 VkSubmitInfo submit_info{};
17572 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17573 submit_info.commandBufferCount = 1;
17574 submit_info.pCommandBuffers = &command_buffer;
17575 submit_info.signalSemaphoreCount = 0;
17576 submit_info.pSignalSemaphores = nullptr;
17577 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17578 }
17579 { vkSetEvent(m_device->device(), event); }
17580
17581 vkQueueWaitIdle(queue);
17582
17583 vkDestroyEvent(m_device->device(), event, nullptr);
17584 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17585 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17586
17587 m_errorMonitor->VerifyNotFound();
17588}
17589// This is a positive test. No errors should be generated.
17590TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17591 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17592
17593 ASSERT_NO_FATAL_FAILURE(InitState());
17594 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17595 return;
17596
17597 m_errorMonitor->ExpectSuccess();
17598
17599 VkQueryPool query_pool;
17600 VkQueryPoolCreateInfo query_pool_create_info{};
17601 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17602 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17603 query_pool_create_info.queryCount = 1;
17604 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17605
17606 VkCommandPool command_pool;
17607 VkCommandPoolCreateInfo pool_create_info{};
17608 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17609 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17610 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17611 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17612
17613 VkCommandBuffer command_buffer;
17614 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17615 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17616 command_buffer_allocate_info.commandPool = command_pool;
17617 command_buffer_allocate_info.commandBufferCount = 1;
17618 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17619 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17620
17621 VkCommandBuffer secondary_command_buffer;
17622 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17623 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17624
17625 VkQueue queue = VK_NULL_HANDLE;
17626 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17627
17628 uint32_t qfi = 0;
17629 VkBufferCreateInfo buff_create_info = {};
17630 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17631 buff_create_info.size = 1024;
17632 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17633 buff_create_info.queueFamilyIndexCount = 1;
17634 buff_create_info.pQueueFamilyIndices = &qfi;
17635
17636 VkResult err;
17637 VkBuffer buffer;
17638 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17639 ASSERT_VK_SUCCESS(err);
17640 VkMemoryAllocateInfo mem_alloc = {};
17641 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17642 mem_alloc.pNext = NULL;
17643 mem_alloc.allocationSize = 1024;
17644 mem_alloc.memoryTypeIndex = 0;
17645
17646 VkMemoryRequirements memReqs;
17647 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17648 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17649 if (!pass) {
17650 vkDestroyBuffer(m_device->device(), buffer, NULL);
17651 return;
17652 }
17653
17654 VkDeviceMemory mem;
17655 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17656 ASSERT_VK_SUCCESS(err);
17657 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17658 ASSERT_VK_SUCCESS(err);
17659
17660 VkCommandBufferInheritanceInfo hinfo = {};
17661 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17662 hinfo.renderPass = VK_NULL_HANDLE;
17663 hinfo.subpass = 0;
17664 hinfo.framebuffer = VK_NULL_HANDLE;
17665 hinfo.occlusionQueryEnable = VK_FALSE;
17666 hinfo.queryFlags = 0;
17667 hinfo.pipelineStatistics = 0;
17668
17669 {
17670 VkCommandBufferBeginInfo begin_info{};
17671 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17672 begin_info.pInheritanceInfo = &hinfo;
17673 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17674
17675 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17676 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17677
17678 vkEndCommandBuffer(secondary_command_buffer);
17679
17680 begin_info.pInheritanceInfo = nullptr;
17681 vkBeginCommandBuffer(command_buffer, &begin_info);
17682
17683 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17684 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17685
17686 vkEndCommandBuffer(command_buffer);
17687 }
17688 {
17689 VkSubmitInfo submit_info{};
17690 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17691 submit_info.commandBufferCount = 1;
17692 submit_info.pCommandBuffers = &command_buffer;
17693 submit_info.signalSemaphoreCount = 0;
17694 submit_info.pSignalSemaphores = nullptr;
17695 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17696 }
17697
17698 vkQueueWaitIdle(queue);
17699
17700 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17701 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17702 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17703 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17704 vkDestroyBuffer(m_device->device(), buffer, NULL);
17705 vkFreeMemory(m_device->device(), mem, NULL);
17706
17707 m_errorMonitor->VerifyNotFound();
17708}
17709
17710// This is a positive test. No errors should be generated.
17711TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17712 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17713
17714 ASSERT_NO_FATAL_FAILURE(InitState());
17715 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17716 return;
17717
17718 m_errorMonitor->ExpectSuccess();
17719
17720 VkQueryPool query_pool;
17721 VkQueryPoolCreateInfo query_pool_create_info{};
17722 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17723 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17724 query_pool_create_info.queryCount = 1;
17725 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17726
17727 VkCommandPool command_pool;
17728 VkCommandPoolCreateInfo pool_create_info{};
17729 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17730 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17731 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17732 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17733
17734 VkCommandBuffer command_buffer[2];
17735 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17736 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17737 command_buffer_allocate_info.commandPool = command_pool;
17738 command_buffer_allocate_info.commandBufferCount = 2;
17739 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17740 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17741
17742 VkQueue queue = VK_NULL_HANDLE;
17743 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17744
17745 uint32_t qfi = 0;
17746 VkBufferCreateInfo buff_create_info = {};
17747 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17748 buff_create_info.size = 1024;
17749 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17750 buff_create_info.queueFamilyIndexCount = 1;
17751 buff_create_info.pQueueFamilyIndices = &qfi;
17752
17753 VkResult err;
17754 VkBuffer buffer;
17755 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17756 ASSERT_VK_SUCCESS(err);
17757 VkMemoryAllocateInfo mem_alloc = {};
17758 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17759 mem_alloc.pNext = NULL;
17760 mem_alloc.allocationSize = 1024;
17761 mem_alloc.memoryTypeIndex = 0;
17762
17763 VkMemoryRequirements memReqs;
17764 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17765 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17766 if (!pass) {
17767 vkDestroyBuffer(m_device->device(), buffer, NULL);
17768 return;
17769 }
17770
17771 VkDeviceMemory mem;
17772 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17773 ASSERT_VK_SUCCESS(err);
17774 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17775 ASSERT_VK_SUCCESS(err);
17776
17777 {
17778 VkCommandBufferBeginInfo begin_info{};
17779 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17780 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17781
17782 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17783 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17784
17785 vkEndCommandBuffer(command_buffer[0]);
17786
17787 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17788
17789 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17790
17791 vkEndCommandBuffer(command_buffer[1]);
17792 }
17793 {
17794 VkSubmitInfo submit_info{};
17795 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17796 submit_info.commandBufferCount = 2;
17797 submit_info.pCommandBuffers = command_buffer;
17798 submit_info.signalSemaphoreCount = 0;
17799 submit_info.pSignalSemaphores = nullptr;
17800 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17801 }
17802
17803 vkQueueWaitIdle(queue);
17804
17805 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17806 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17807 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17808 vkDestroyBuffer(m_device->device(), buffer, NULL);
17809 vkFreeMemory(m_device->device(), mem, NULL);
17810
17811 m_errorMonitor->VerifyNotFound();
17812}
17813
Tony Barbourc46924f2016-11-04 11:49:52 -060017814TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017815 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17816
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017817 ASSERT_NO_FATAL_FAILURE(InitState());
17818 VkEvent event;
17819 VkEventCreateInfo event_create_info{};
17820 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17821 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17822
17823 VkCommandPool command_pool;
17824 VkCommandPoolCreateInfo pool_create_info{};
17825 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17826 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17827 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17828 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17829
17830 VkCommandBuffer command_buffer;
17831 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17832 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17833 command_buffer_allocate_info.commandPool = command_pool;
17834 command_buffer_allocate_info.commandBufferCount = 1;
17835 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17836 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17837
17838 VkQueue queue = VK_NULL_HANDLE;
17839 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17840
17841 {
17842 VkCommandBufferBeginInfo begin_info{};
17843 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17844 vkBeginCommandBuffer(command_buffer, &begin_info);
17845
17846 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017847 vkEndCommandBuffer(command_buffer);
17848 }
17849 {
17850 VkSubmitInfo submit_info{};
17851 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17852 submit_info.commandBufferCount = 1;
17853 submit_info.pCommandBuffers = &command_buffer;
17854 submit_info.signalSemaphoreCount = 0;
17855 submit_info.pSignalSemaphores = nullptr;
17856 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17857 }
17858 {
17859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17860 "command buffer.");
17861 vkSetEvent(m_device->device(), event);
17862 m_errorMonitor->VerifyFound();
17863 }
17864
17865 vkQueueWaitIdle(queue);
17866
17867 vkDestroyEvent(m_device->device(), event, nullptr);
17868 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17869 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17870}
17871
17872// This is a positive test. No errors should be generated.
17873TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17874 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17875 "run through a Submit & WaitForFences cycle 3 times. This "
17876 "previously revealed a bug so running this positive test "
17877 "to prevent a regression.");
17878 m_errorMonitor->ExpectSuccess();
17879
17880 ASSERT_NO_FATAL_FAILURE(InitState());
17881 VkQueue queue = VK_NULL_HANDLE;
17882 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17883
17884 static const uint32_t NUM_OBJECTS = 2;
17885 static const uint32_t NUM_FRAMES = 3;
17886 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17887 VkFence fences[NUM_OBJECTS] = {};
17888
17889 VkCommandPool cmd_pool;
17890 VkCommandPoolCreateInfo cmd_pool_ci = {};
17891 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17892 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17893 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17894 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17895 ASSERT_VK_SUCCESS(err);
17896
17897 VkCommandBufferAllocateInfo cmd_buf_info = {};
17898 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17899 cmd_buf_info.commandPool = cmd_pool;
17900 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17901 cmd_buf_info.commandBufferCount = 1;
17902
17903 VkFenceCreateInfo fence_ci = {};
17904 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17905 fence_ci.pNext = nullptr;
17906 fence_ci.flags = 0;
17907
17908 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17909 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17910 ASSERT_VK_SUCCESS(err);
17911 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17912 ASSERT_VK_SUCCESS(err);
17913 }
17914
17915 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17916 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17917 // Create empty cmd buffer
17918 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17919 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17920
17921 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17922 ASSERT_VK_SUCCESS(err);
17923 err = vkEndCommandBuffer(cmd_buffers[obj]);
17924 ASSERT_VK_SUCCESS(err);
17925
17926 VkSubmitInfo submit_info = {};
17927 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17928 submit_info.commandBufferCount = 1;
17929 submit_info.pCommandBuffers = &cmd_buffers[obj];
17930 // Submit cmd buffer and wait for fence
17931 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17932 ASSERT_VK_SUCCESS(err);
17933 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17934 ASSERT_VK_SUCCESS(err);
17935 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17936 ASSERT_VK_SUCCESS(err);
17937 }
17938 }
17939 m_errorMonitor->VerifyNotFound();
17940 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17941 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17942 vkDestroyFence(m_device->device(), fences[i], nullptr);
17943 }
17944}
17945// This is a positive test. No errors should be generated.
17946TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17947
17948 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17949 "submitted on separate queues followed by a QueueWaitIdle.");
17950
17951 ASSERT_NO_FATAL_FAILURE(InitState());
17952 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17953 return;
17954
17955 m_errorMonitor->ExpectSuccess();
17956
17957 VkSemaphore semaphore;
17958 VkSemaphoreCreateInfo semaphore_create_info{};
17959 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17960 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17961
17962 VkCommandPool command_pool;
17963 VkCommandPoolCreateInfo pool_create_info{};
17964 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17965 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17966 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17967 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17968
17969 VkCommandBuffer command_buffer[2];
17970 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17971 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17972 command_buffer_allocate_info.commandPool = command_pool;
17973 command_buffer_allocate_info.commandBufferCount = 2;
17974 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17975 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17976
17977 VkQueue queue = VK_NULL_HANDLE;
17978 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17979
17980 {
17981 VkCommandBufferBeginInfo begin_info{};
17982 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17983 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17984
17985 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17986 nullptr, 0, nullptr, 0, nullptr);
17987
17988 VkViewport viewport{};
17989 viewport.maxDepth = 1.0f;
17990 viewport.minDepth = 0.0f;
17991 viewport.width = 512;
17992 viewport.height = 512;
17993 viewport.x = 0;
17994 viewport.y = 0;
17995 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17996 vkEndCommandBuffer(command_buffer[0]);
17997 }
17998 {
17999 VkCommandBufferBeginInfo begin_info{};
18000 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18001 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18002
18003 VkViewport viewport{};
18004 viewport.maxDepth = 1.0f;
18005 viewport.minDepth = 0.0f;
18006 viewport.width = 512;
18007 viewport.height = 512;
18008 viewport.x = 0;
18009 viewport.y = 0;
18010 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18011 vkEndCommandBuffer(command_buffer[1]);
18012 }
18013 {
18014 VkSubmitInfo submit_info{};
18015 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18016 submit_info.commandBufferCount = 1;
18017 submit_info.pCommandBuffers = &command_buffer[0];
18018 submit_info.signalSemaphoreCount = 1;
18019 submit_info.pSignalSemaphores = &semaphore;
18020 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18021 }
18022 {
18023 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18024 VkSubmitInfo submit_info{};
18025 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18026 submit_info.commandBufferCount = 1;
18027 submit_info.pCommandBuffers = &command_buffer[1];
18028 submit_info.waitSemaphoreCount = 1;
18029 submit_info.pWaitSemaphores = &semaphore;
18030 submit_info.pWaitDstStageMask = flags;
18031 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18032 }
18033
18034 vkQueueWaitIdle(m_device->m_queue);
18035
18036 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18037 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18038 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18039
18040 m_errorMonitor->VerifyNotFound();
18041}
18042
18043// This is a positive test. No errors should be generated.
18044TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18045
18046 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18047 "submitted on separate queues, the second having a fence"
18048 "followed by a QueueWaitIdle.");
18049
18050 ASSERT_NO_FATAL_FAILURE(InitState());
18051 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18052 return;
18053
18054 m_errorMonitor->ExpectSuccess();
18055
18056 VkFence fence;
18057 VkFenceCreateInfo fence_create_info{};
18058 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18059 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18060
18061 VkSemaphore semaphore;
18062 VkSemaphoreCreateInfo semaphore_create_info{};
18063 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18064 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18065
18066 VkCommandPool command_pool;
18067 VkCommandPoolCreateInfo pool_create_info{};
18068 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18069 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18070 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18071 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18072
18073 VkCommandBuffer command_buffer[2];
18074 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18075 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18076 command_buffer_allocate_info.commandPool = command_pool;
18077 command_buffer_allocate_info.commandBufferCount = 2;
18078 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18079 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18080
18081 VkQueue queue = VK_NULL_HANDLE;
18082 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18083
18084 {
18085 VkCommandBufferBeginInfo begin_info{};
18086 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18087 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18088
18089 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18090 nullptr, 0, nullptr, 0, nullptr);
18091
18092 VkViewport viewport{};
18093 viewport.maxDepth = 1.0f;
18094 viewport.minDepth = 0.0f;
18095 viewport.width = 512;
18096 viewport.height = 512;
18097 viewport.x = 0;
18098 viewport.y = 0;
18099 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18100 vkEndCommandBuffer(command_buffer[0]);
18101 }
18102 {
18103 VkCommandBufferBeginInfo begin_info{};
18104 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18105 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18106
18107 VkViewport viewport{};
18108 viewport.maxDepth = 1.0f;
18109 viewport.minDepth = 0.0f;
18110 viewport.width = 512;
18111 viewport.height = 512;
18112 viewport.x = 0;
18113 viewport.y = 0;
18114 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18115 vkEndCommandBuffer(command_buffer[1]);
18116 }
18117 {
18118 VkSubmitInfo submit_info{};
18119 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18120 submit_info.commandBufferCount = 1;
18121 submit_info.pCommandBuffers = &command_buffer[0];
18122 submit_info.signalSemaphoreCount = 1;
18123 submit_info.pSignalSemaphores = &semaphore;
18124 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18125 }
18126 {
18127 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18128 VkSubmitInfo submit_info{};
18129 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18130 submit_info.commandBufferCount = 1;
18131 submit_info.pCommandBuffers = &command_buffer[1];
18132 submit_info.waitSemaphoreCount = 1;
18133 submit_info.pWaitSemaphores = &semaphore;
18134 submit_info.pWaitDstStageMask = flags;
18135 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18136 }
18137
18138 vkQueueWaitIdle(m_device->m_queue);
18139
18140 vkDestroyFence(m_device->device(), fence, nullptr);
18141 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18142 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18143 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18144
18145 m_errorMonitor->VerifyNotFound();
18146}
18147
18148// This is a positive test. No errors should be generated.
18149TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18150
18151 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18152 "submitted on separate queues, the second having a fence"
18153 "followed by two consecutive WaitForFences calls on the same fence.");
18154
18155 ASSERT_NO_FATAL_FAILURE(InitState());
18156 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18157 return;
18158
18159 m_errorMonitor->ExpectSuccess();
18160
18161 VkFence fence;
18162 VkFenceCreateInfo fence_create_info{};
18163 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18164 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18165
18166 VkSemaphore semaphore;
18167 VkSemaphoreCreateInfo semaphore_create_info{};
18168 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18169 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18170
18171 VkCommandPool command_pool;
18172 VkCommandPoolCreateInfo pool_create_info{};
18173 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18174 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18175 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18176 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18177
18178 VkCommandBuffer command_buffer[2];
18179 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18180 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18181 command_buffer_allocate_info.commandPool = command_pool;
18182 command_buffer_allocate_info.commandBufferCount = 2;
18183 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18184 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18185
18186 VkQueue queue = VK_NULL_HANDLE;
18187 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18188
18189 {
18190 VkCommandBufferBeginInfo begin_info{};
18191 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18192 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18193
18194 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18195 nullptr, 0, nullptr, 0, nullptr);
18196
18197 VkViewport viewport{};
18198 viewport.maxDepth = 1.0f;
18199 viewport.minDepth = 0.0f;
18200 viewport.width = 512;
18201 viewport.height = 512;
18202 viewport.x = 0;
18203 viewport.y = 0;
18204 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18205 vkEndCommandBuffer(command_buffer[0]);
18206 }
18207 {
18208 VkCommandBufferBeginInfo begin_info{};
18209 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18210 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18211
18212 VkViewport viewport{};
18213 viewport.maxDepth = 1.0f;
18214 viewport.minDepth = 0.0f;
18215 viewport.width = 512;
18216 viewport.height = 512;
18217 viewport.x = 0;
18218 viewport.y = 0;
18219 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18220 vkEndCommandBuffer(command_buffer[1]);
18221 }
18222 {
18223 VkSubmitInfo submit_info{};
18224 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18225 submit_info.commandBufferCount = 1;
18226 submit_info.pCommandBuffers = &command_buffer[0];
18227 submit_info.signalSemaphoreCount = 1;
18228 submit_info.pSignalSemaphores = &semaphore;
18229 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18230 }
18231 {
18232 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18233 VkSubmitInfo submit_info{};
18234 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18235 submit_info.commandBufferCount = 1;
18236 submit_info.pCommandBuffers = &command_buffer[1];
18237 submit_info.waitSemaphoreCount = 1;
18238 submit_info.pWaitSemaphores = &semaphore;
18239 submit_info.pWaitDstStageMask = flags;
18240 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18241 }
18242
18243 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18244 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18245
18246 vkDestroyFence(m_device->device(), fence, nullptr);
18247 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18248 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18249 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18250
18251 m_errorMonitor->VerifyNotFound();
18252}
18253
18254TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18255
18256 ASSERT_NO_FATAL_FAILURE(InitState());
18257 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18258 printf("Test requires two queues, skipping\n");
18259 return;
18260 }
18261
18262 VkResult err;
18263
18264 m_errorMonitor->ExpectSuccess();
18265
18266 VkQueue q0 = m_device->m_queue;
18267 VkQueue q1 = nullptr;
18268 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18269 ASSERT_NE(q1, nullptr);
18270
18271 // An (empty) command buffer. We must have work in the first submission --
18272 // the layer treats unfenced work differently from fenced work.
18273 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18274 VkCommandPool pool;
18275 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18276 ASSERT_VK_SUCCESS(err);
18277 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18278 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18279 VkCommandBuffer cb;
18280 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18281 ASSERT_VK_SUCCESS(err);
18282 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18283 err = vkBeginCommandBuffer(cb, &cbbi);
18284 ASSERT_VK_SUCCESS(err);
18285 err = vkEndCommandBuffer(cb);
18286 ASSERT_VK_SUCCESS(err);
18287
18288 // A semaphore
18289 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18290 VkSemaphore s;
18291 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18292 ASSERT_VK_SUCCESS(err);
18293
18294 // First submission, to q0
18295 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18296
18297 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18298 ASSERT_VK_SUCCESS(err);
18299
18300 // Second submission, to q1, waiting on s
18301 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18302 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18303
18304 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18305 ASSERT_VK_SUCCESS(err);
18306
18307 // Wait for q0 idle
18308 err = vkQueueWaitIdle(q0);
18309 ASSERT_VK_SUCCESS(err);
18310
18311 // Command buffer should have been completed (it was on q0); reset the pool.
18312 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18313
18314 m_errorMonitor->VerifyNotFound();
18315
18316 // Force device completely idle and clean up resources
18317 vkDeviceWaitIdle(m_device->device());
18318 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18319 vkDestroySemaphore(m_device->device(), s, nullptr);
18320}
18321
18322// This is a positive test. No errors should be generated.
18323TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18324
18325 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18326 "submitted on separate queues, the second having a fence, "
18327 "followed by a WaitForFences call.");
18328
18329 ASSERT_NO_FATAL_FAILURE(InitState());
18330 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18331 return;
18332
18333 m_errorMonitor->ExpectSuccess();
18334
18335 ASSERT_NO_FATAL_FAILURE(InitState());
18336 VkFence fence;
18337 VkFenceCreateInfo fence_create_info{};
18338 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18339 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18340
18341 VkSemaphore semaphore;
18342 VkSemaphoreCreateInfo semaphore_create_info{};
18343 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18344 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18345
18346 VkCommandPool command_pool;
18347 VkCommandPoolCreateInfo pool_create_info{};
18348 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18349 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18350 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18351 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18352
18353 VkCommandBuffer command_buffer[2];
18354 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18355 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18356 command_buffer_allocate_info.commandPool = command_pool;
18357 command_buffer_allocate_info.commandBufferCount = 2;
18358 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18359 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18360
18361 VkQueue queue = VK_NULL_HANDLE;
18362 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18363
18364 {
18365 VkCommandBufferBeginInfo begin_info{};
18366 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18367 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18368
18369 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18370 nullptr, 0, nullptr, 0, nullptr);
18371
18372 VkViewport viewport{};
18373 viewport.maxDepth = 1.0f;
18374 viewport.minDepth = 0.0f;
18375 viewport.width = 512;
18376 viewport.height = 512;
18377 viewport.x = 0;
18378 viewport.y = 0;
18379 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18380 vkEndCommandBuffer(command_buffer[0]);
18381 }
18382 {
18383 VkCommandBufferBeginInfo begin_info{};
18384 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18385 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18386
18387 VkViewport viewport{};
18388 viewport.maxDepth = 1.0f;
18389 viewport.minDepth = 0.0f;
18390 viewport.width = 512;
18391 viewport.height = 512;
18392 viewport.x = 0;
18393 viewport.y = 0;
18394 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18395 vkEndCommandBuffer(command_buffer[1]);
18396 }
18397 {
18398 VkSubmitInfo submit_info{};
18399 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18400 submit_info.commandBufferCount = 1;
18401 submit_info.pCommandBuffers = &command_buffer[0];
18402 submit_info.signalSemaphoreCount = 1;
18403 submit_info.pSignalSemaphores = &semaphore;
18404 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18405 }
18406 {
18407 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18408 VkSubmitInfo submit_info{};
18409 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18410 submit_info.commandBufferCount = 1;
18411 submit_info.pCommandBuffers = &command_buffer[1];
18412 submit_info.waitSemaphoreCount = 1;
18413 submit_info.pWaitSemaphores = &semaphore;
18414 submit_info.pWaitDstStageMask = flags;
18415 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18416 }
18417
18418 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18419
18420 vkDestroyFence(m_device->device(), fence, nullptr);
18421 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18422 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18423 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18424
18425 m_errorMonitor->VerifyNotFound();
18426}
18427
18428// This is a positive test. No errors should be generated.
18429TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18430
18431 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18432 "on the same queue, sharing a signal/wait semaphore, the "
18433 "second having a fence, "
18434 "followed by a WaitForFences call.");
18435
18436 m_errorMonitor->ExpectSuccess();
18437
18438 ASSERT_NO_FATAL_FAILURE(InitState());
18439 VkFence fence;
18440 VkFenceCreateInfo fence_create_info{};
18441 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18442 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18443
18444 VkSemaphore semaphore;
18445 VkSemaphoreCreateInfo semaphore_create_info{};
18446 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18447 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18448
18449 VkCommandPool command_pool;
18450 VkCommandPoolCreateInfo pool_create_info{};
18451 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18452 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18453 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18454 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18455
18456 VkCommandBuffer command_buffer[2];
18457 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18458 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18459 command_buffer_allocate_info.commandPool = command_pool;
18460 command_buffer_allocate_info.commandBufferCount = 2;
18461 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18462 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18463
18464 {
18465 VkCommandBufferBeginInfo begin_info{};
18466 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18467 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18468
18469 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18470 nullptr, 0, nullptr, 0, nullptr);
18471
18472 VkViewport viewport{};
18473 viewport.maxDepth = 1.0f;
18474 viewport.minDepth = 0.0f;
18475 viewport.width = 512;
18476 viewport.height = 512;
18477 viewport.x = 0;
18478 viewport.y = 0;
18479 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18480 vkEndCommandBuffer(command_buffer[0]);
18481 }
18482 {
18483 VkCommandBufferBeginInfo begin_info{};
18484 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18485 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18486
18487 VkViewport viewport{};
18488 viewport.maxDepth = 1.0f;
18489 viewport.minDepth = 0.0f;
18490 viewport.width = 512;
18491 viewport.height = 512;
18492 viewport.x = 0;
18493 viewport.y = 0;
18494 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18495 vkEndCommandBuffer(command_buffer[1]);
18496 }
18497 {
18498 VkSubmitInfo submit_info{};
18499 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18500 submit_info.commandBufferCount = 1;
18501 submit_info.pCommandBuffers = &command_buffer[0];
18502 submit_info.signalSemaphoreCount = 1;
18503 submit_info.pSignalSemaphores = &semaphore;
18504 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18505 }
18506 {
18507 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18508 VkSubmitInfo submit_info{};
18509 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18510 submit_info.commandBufferCount = 1;
18511 submit_info.pCommandBuffers = &command_buffer[1];
18512 submit_info.waitSemaphoreCount = 1;
18513 submit_info.pWaitSemaphores = &semaphore;
18514 submit_info.pWaitDstStageMask = flags;
18515 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18516 }
18517
18518 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18519
18520 vkDestroyFence(m_device->device(), fence, nullptr);
18521 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18522 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18523 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18524
18525 m_errorMonitor->VerifyNotFound();
18526}
18527
18528// This is a positive test. No errors should be generated.
18529TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18530
18531 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18532 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18533 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18534
18535 m_errorMonitor->ExpectSuccess();
18536
18537 ASSERT_NO_FATAL_FAILURE(InitState());
18538 VkFence fence;
18539 VkFenceCreateInfo fence_create_info{};
18540 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18541 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18542
18543 VkCommandPool command_pool;
18544 VkCommandPoolCreateInfo pool_create_info{};
18545 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18546 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18547 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18548 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18549
18550 VkCommandBuffer command_buffer[2];
18551 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18552 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18553 command_buffer_allocate_info.commandPool = command_pool;
18554 command_buffer_allocate_info.commandBufferCount = 2;
18555 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18556 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18557
18558 {
18559 VkCommandBufferBeginInfo begin_info{};
18560 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18561 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18562
18563 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18564 nullptr, 0, nullptr, 0, nullptr);
18565
18566 VkViewport viewport{};
18567 viewport.maxDepth = 1.0f;
18568 viewport.minDepth = 0.0f;
18569 viewport.width = 512;
18570 viewport.height = 512;
18571 viewport.x = 0;
18572 viewport.y = 0;
18573 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18574 vkEndCommandBuffer(command_buffer[0]);
18575 }
18576 {
18577 VkCommandBufferBeginInfo begin_info{};
18578 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18579 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18580
18581 VkViewport viewport{};
18582 viewport.maxDepth = 1.0f;
18583 viewport.minDepth = 0.0f;
18584 viewport.width = 512;
18585 viewport.height = 512;
18586 viewport.x = 0;
18587 viewport.y = 0;
18588 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18589 vkEndCommandBuffer(command_buffer[1]);
18590 }
18591 {
18592 VkSubmitInfo submit_info{};
18593 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18594 submit_info.commandBufferCount = 1;
18595 submit_info.pCommandBuffers = &command_buffer[0];
18596 submit_info.signalSemaphoreCount = 0;
18597 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18598 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18599 }
18600 {
18601 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18602 VkSubmitInfo submit_info{};
18603 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18604 submit_info.commandBufferCount = 1;
18605 submit_info.pCommandBuffers = &command_buffer[1];
18606 submit_info.waitSemaphoreCount = 0;
18607 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18608 submit_info.pWaitDstStageMask = flags;
18609 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18610 }
18611
18612 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18613
18614 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18615 ASSERT_VK_SUCCESS(err);
18616
18617 vkDestroyFence(m_device->device(), fence, nullptr);
18618 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18619 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18620
18621 m_errorMonitor->VerifyNotFound();
18622}
18623
18624// This is a positive test. No errors should be generated.
18625TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18626
18627 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18628 "on the same queue, the second having a fence, followed "
18629 "by a WaitForFences call.");
18630
18631 m_errorMonitor->ExpectSuccess();
18632
18633 ASSERT_NO_FATAL_FAILURE(InitState());
18634 VkFence fence;
18635 VkFenceCreateInfo fence_create_info{};
18636 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18637 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18638
18639 VkCommandPool command_pool;
18640 VkCommandPoolCreateInfo pool_create_info{};
18641 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18642 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18643 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18644 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18645
18646 VkCommandBuffer command_buffer[2];
18647 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18648 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18649 command_buffer_allocate_info.commandPool = command_pool;
18650 command_buffer_allocate_info.commandBufferCount = 2;
18651 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18652 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18653
18654 {
18655 VkCommandBufferBeginInfo begin_info{};
18656 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18657 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18658
18659 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18660 nullptr, 0, nullptr, 0, nullptr);
18661
18662 VkViewport viewport{};
18663 viewport.maxDepth = 1.0f;
18664 viewport.minDepth = 0.0f;
18665 viewport.width = 512;
18666 viewport.height = 512;
18667 viewport.x = 0;
18668 viewport.y = 0;
18669 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18670 vkEndCommandBuffer(command_buffer[0]);
18671 }
18672 {
18673 VkCommandBufferBeginInfo begin_info{};
18674 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18675 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18676
18677 VkViewport viewport{};
18678 viewport.maxDepth = 1.0f;
18679 viewport.minDepth = 0.0f;
18680 viewport.width = 512;
18681 viewport.height = 512;
18682 viewport.x = 0;
18683 viewport.y = 0;
18684 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18685 vkEndCommandBuffer(command_buffer[1]);
18686 }
18687 {
18688 VkSubmitInfo submit_info{};
18689 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18690 submit_info.commandBufferCount = 1;
18691 submit_info.pCommandBuffers = &command_buffer[0];
18692 submit_info.signalSemaphoreCount = 0;
18693 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18694 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18695 }
18696 {
18697 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18698 VkSubmitInfo submit_info{};
18699 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18700 submit_info.commandBufferCount = 1;
18701 submit_info.pCommandBuffers = &command_buffer[1];
18702 submit_info.waitSemaphoreCount = 0;
18703 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18704 submit_info.pWaitDstStageMask = flags;
18705 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18706 }
18707
18708 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18709
18710 vkDestroyFence(m_device->device(), fence, nullptr);
18711 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18712 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18713
18714 m_errorMonitor->VerifyNotFound();
18715}
18716
18717// This is a positive test. No errors should be generated.
18718TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18719
18720 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18721 "QueueSubmit call followed by a WaitForFences call.");
18722 ASSERT_NO_FATAL_FAILURE(InitState());
18723
18724 m_errorMonitor->ExpectSuccess();
18725
18726 VkFence fence;
18727 VkFenceCreateInfo fence_create_info{};
18728 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18729 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18730
18731 VkSemaphore semaphore;
18732 VkSemaphoreCreateInfo semaphore_create_info{};
18733 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18734 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18735
18736 VkCommandPool command_pool;
18737 VkCommandPoolCreateInfo pool_create_info{};
18738 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18739 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18740 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18741 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18742
18743 VkCommandBuffer command_buffer[2];
18744 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18745 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18746 command_buffer_allocate_info.commandPool = command_pool;
18747 command_buffer_allocate_info.commandBufferCount = 2;
18748 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18749 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18750
18751 {
18752 VkCommandBufferBeginInfo begin_info{};
18753 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18754 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18755
18756 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18757 nullptr, 0, nullptr, 0, nullptr);
18758
18759 VkViewport viewport{};
18760 viewport.maxDepth = 1.0f;
18761 viewport.minDepth = 0.0f;
18762 viewport.width = 512;
18763 viewport.height = 512;
18764 viewport.x = 0;
18765 viewport.y = 0;
18766 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18767 vkEndCommandBuffer(command_buffer[0]);
18768 }
18769 {
18770 VkCommandBufferBeginInfo begin_info{};
18771 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18772 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18773
18774 VkViewport viewport{};
18775 viewport.maxDepth = 1.0f;
18776 viewport.minDepth = 0.0f;
18777 viewport.width = 512;
18778 viewport.height = 512;
18779 viewport.x = 0;
18780 viewport.y = 0;
18781 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18782 vkEndCommandBuffer(command_buffer[1]);
18783 }
18784 {
18785 VkSubmitInfo submit_info[2];
18786 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18787
18788 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18789 submit_info[0].pNext = NULL;
18790 submit_info[0].commandBufferCount = 1;
18791 submit_info[0].pCommandBuffers = &command_buffer[0];
18792 submit_info[0].signalSemaphoreCount = 1;
18793 submit_info[0].pSignalSemaphores = &semaphore;
18794 submit_info[0].waitSemaphoreCount = 0;
18795 submit_info[0].pWaitSemaphores = NULL;
18796 submit_info[0].pWaitDstStageMask = 0;
18797
18798 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18799 submit_info[1].pNext = NULL;
18800 submit_info[1].commandBufferCount = 1;
18801 submit_info[1].pCommandBuffers = &command_buffer[1];
18802 submit_info[1].waitSemaphoreCount = 1;
18803 submit_info[1].pWaitSemaphores = &semaphore;
18804 submit_info[1].pWaitDstStageMask = flags;
18805 submit_info[1].signalSemaphoreCount = 0;
18806 submit_info[1].pSignalSemaphores = NULL;
18807 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18808 }
18809
18810 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18811
18812 vkDestroyFence(m_device->device(), fence, nullptr);
18813 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18814 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18815 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18816
18817 m_errorMonitor->VerifyNotFound();
18818}
18819
18820TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18821 m_errorMonitor->ExpectSuccess();
18822
18823 ASSERT_NO_FATAL_FAILURE(InitState());
18824 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18825
18826 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18827 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18828
18829 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18830 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18831 m_errorMonitor->VerifyNotFound();
18832 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18833 m_errorMonitor->VerifyNotFound();
18834 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18835 m_errorMonitor->VerifyNotFound();
18836
18837 m_commandBuffer->EndCommandBuffer();
18838 m_errorMonitor->VerifyNotFound();
18839}
18840
18841TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18842 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18843 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18844 "has a valid layout, and a second subpass then uses a "
18845 "valid *READ_ONLY* layout.");
18846 m_errorMonitor->ExpectSuccess();
18847 ASSERT_NO_FATAL_FAILURE(InitState());
18848
18849 VkAttachmentReference attach[2] = {};
18850 attach[0].attachment = 0;
18851 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18852 attach[1].attachment = 0;
18853 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18854 VkSubpassDescription subpasses[2] = {};
18855 // First subpass clears DS attach on load
18856 subpasses[0].pDepthStencilAttachment = &attach[0];
18857 // 2nd subpass reads in DS as input attachment
18858 subpasses[1].inputAttachmentCount = 1;
18859 subpasses[1].pInputAttachments = &attach[1];
18860 VkAttachmentDescription attach_desc = {};
18861 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18862 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18863 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18864 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18865 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18866 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18867 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18868 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18869 VkRenderPassCreateInfo rpci = {};
18870 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18871 rpci.attachmentCount = 1;
18872 rpci.pAttachments = &attach_desc;
18873 rpci.subpassCount = 2;
18874 rpci.pSubpasses = subpasses;
18875
18876 // Now create RenderPass and verify no errors
18877 VkRenderPass rp;
18878 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18879 m_errorMonitor->VerifyNotFound();
18880
18881 vkDestroyRenderPass(m_device->device(), rp, NULL);
18882}
18883
18884TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18885 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18886 "as vertex attributes");
18887 m_errorMonitor->ExpectSuccess();
18888
18889 ASSERT_NO_FATAL_FAILURE(InitState());
18890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18891
18892 VkVertexInputBindingDescription input_binding;
18893 memset(&input_binding, 0, sizeof(input_binding));
18894
18895 VkVertexInputAttributeDescription input_attribs[2];
18896 memset(input_attribs, 0, sizeof(input_attribs));
18897
18898 for (int i = 0; i < 2; i++) {
18899 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18900 input_attribs[i].location = i;
18901 }
18902
18903 char const *vsSource = "#version 450\n"
18904 "\n"
18905 "layout(location=0) in mat2x4 x;\n"
18906 "out gl_PerVertex {\n"
18907 " vec4 gl_Position;\n"
18908 "};\n"
18909 "void main(){\n"
18910 " gl_Position = x[0] + x[1];\n"
18911 "}\n";
18912 char const *fsSource = "#version 450\n"
18913 "\n"
18914 "layout(location=0) out vec4 color;\n"
18915 "void main(){\n"
18916 " color = vec4(1);\n"
18917 "}\n";
18918
18919 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18920 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18921
18922 VkPipelineObj pipe(m_device);
18923 pipe.AddColorAttachment();
18924 pipe.AddShader(&vs);
18925 pipe.AddShader(&fs);
18926
18927 pipe.AddVertexInputBindings(&input_binding, 1);
18928 pipe.AddVertexInputAttribs(input_attribs, 2);
18929
18930 VkDescriptorSetObj descriptorSet(m_device);
18931 descriptorSet.AppendDummy();
18932 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18933
18934 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18935
18936 /* expect success */
18937 m_errorMonitor->VerifyNotFound();
18938}
18939
18940TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18941 m_errorMonitor->ExpectSuccess();
18942
18943 ASSERT_NO_FATAL_FAILURE(InitState());
18944 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18945
18946 VkVertexInputBindingDescription input_binding;
18947 memset(&input_binding, 0, sizeof(input_binding));
18948
18949 VkVertexInputAttributeDescription input_attribs[2];
18950 memset(input_attribs, 0, sizeof(input_attribs));
18951
18952 for (int i = 0; i < 2; i++) {
18953 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18954 input_attribs[i].location = i;
18955 }
18956
18957 char const *vsSource = "#version 450\n"
18958 "\n"
18959 "layout(location=0) in vec4 x[2];\n"
18960 "out gl_PerVertex {\n"
18961 " vec4 gl_Position;\n"
18962 "};\n"
18963 "void main(){\n"
18964 " gl_Position = x[0] + x[1];\n"
18965 "}\n";
18966 char const *fsSource = "#version 450\n"
18967 "\n"
18968 "layout(location=0) out vec4 color;\n"
18969 "void main(){\n"
18970 " color = vec4(1);\n"
18971 "}\n";
18972
18973 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18974 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18975
18976 VkPipelineObj pipe(m_device);
18977 pipe.AddColorAttachment();
18978 pipe.AddShader(&vs);
18979 pipe.AddShader(&fs);
18980
18981 pipe.AddVertexInputBindings(&input_binding, 1);
18982 pipe.AddVertexInputAttribs(input_attribs, 2);
18983
18984 VkDescriptorSetObj descriptorSet(m_device);
18985 descriptorSet.AppendDummy();
18986 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18987
18988 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18989
18990 m_errorMonitor->VerifyNotFound();
18991}
18992
18993TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18994 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18995 "through multiple vertex shader inputs, each consuming a different "
18996 "subset of the components.");
18997 m_errorMonitor->ExpectSuccess();
18998
18999 ASSERT_NO_FATAL_FAILURE(InitState());
19000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19001
19002 VkVertexInputBindingDescription input_binding;
19003 memset(&input_binding, 0, sizeof(input_binding));
19004
19005 VkVertexInputAttributeDescription input_attribs[3];
19006 memset(input_attribs, 0, sizeof(input_attribs));
19007
19008 for (int i = 0; i < 3; i++) {
19009 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19010 input_attribs[i].location = i;
19011 }
19012
19013 char const *vsSource = "#version 450\n"
19014 "\n"
19015 "layout(location=0) in vec4 x;\n"
19016 "layout(location=1) in vec3 y1;\n"
19017 "layout(location=1, component=3) in float y2;\n"
19018 "layout(location=2) in vec4 z;\n"
19019 "out gl_PerVertex {\n"
19020 " vec4 gl_Position;\n"
19021 "};\n"
19022 "void main(){\n"
19023 " gl_Position = x + vec4(y1, y2) + z;\n"
19024 "}\n";
19025 char const *fsSource = "#version 450\n"
19026 "\n"
19027 "layout(location=0) out vec4 color;\n"
19028 "void main(){\n"
19029 " color = vec4(1);\n"
19030 "}\n";
19031
19032 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19033 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19034
19035 VkPipelineObj pipe(m_device);
19036 pipe.AddColorAttachment();
19037 pipe.AddShader(&vs);
19038 pipe.AddShader(&fs);
19039
19040 pipe.AddVertexInputBindings(&input_binding, 1);
19041 pipe.AddVertexInputAttribs(input_attribs, 3);
19042
19043 VkDescriptorSetObj descriptorSet(m_device);
19044 descriptorSet.AppendDummy();
19045 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19046
19047 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19048
19049 m_errorMonitor->VerifyNotFound();
19050}
19051
19052TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19053 m_errorMonitor->ExpectSuccess();
19054
19055 ASSERT_NO_FATAL_FAILURE(InitState());
19056 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19057
19058 char const *vsSource = "#version 450\n"
19059 "out gl_PerVertex {\n"
19060 " vec4 gl_Position;\n"
19061 "};\n"
19062 "void main(){\n"
19063 " gl_Position = vec4(0);\n"
19064 "}\n";
19065 char const *fsSource = "#version 450\n"
19066 "\n"
19067 "layout(location=0) out vec4 color;\n"
19068 "void main(){\n"
19069 " color = vec4(1);\n"
19070 "}\n";
19071
19072 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19073 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19074
19075 VkPipelineObj pipe(m_device);
19076 pipe.AddColorAttachment();
19077 pipe.AddShader(&vs);
19078 pipe.AddShader(&fs);
19079
19080 VkDescriptorSetObj descriptorSet(m_device);
19081 descriptorSet.AppendDummy();
19082 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19083
19084 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19085
19086 m_errorMonitor->VerifyNotFound();
19087}
19088
19089TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19090 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19091 "set out in 14.1.3: fundamental type must match, and producer side must "
19092 "have at least as many components");
19093 m_errorMonitor->ExpectSuccess();
19094
19095 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19096
19097 ASSERT_NO_FATAL_FAILURE(InitState());
19098 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19099
19100 char const *vsSource = "#version 450\n"
19101 "out gl_PerVertex {\n"
19102 " vec4 gl_Position;\n"
19103 "};\n"
19104 "layout(location=0) out vec3 x;\n"
19105 "layout(location=1) out ivec3 y;\n"
19106 "layout(location=2) out vec3 z;\n"
19107 "void main(){\n"
19108 " gl_Position = vec4(0);\n"
19109 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19110 "}\n";
19111 char const *fsSource = "#version 450\n"
19112 "\n"
19113 "layout(location=0) out vec4 color;\n"
19114 "layout(location=0) in float x;\n"
19115 "layout(location=1) flat in int y;\n"
19116 "layout(location=2) in vec2 z;\n"
19117 "void main(){\n"
19118 " color = vec4(1 + x + y + z.x);\n"
19119 "}\n";
19120
19121 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19122 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19123
19124 VkPipelineObj pipe(m_device);
19125 pipe.AddColorAttachment();
19126 pipe.AddShader(&vs);
19127 pipe.AddShader(&fs);
19128
19129 VkDescriptorSetObj descriptorSet(m_device);
19130 descriptorSet.AppendDummy();
19131 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19132
19133 VkResult err = VK_SUCCESS;
19134 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19135 ASSERT_VK_SUCCESS(err);
19136
19137 m_errorMonitor->VerifyNotFound();
19138}
19139
19140TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19141 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19142 "passed between the TCS and TES stages");
19143 m_errorMonitor->ExpectSuccess();
19144
19145 ASSERT_NO_FATAL_FAILURE(InitState());
19146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19147
19148 if (!m_device->phy().features().tessellationShader) {
19149 printf("Device does not support tessellation shaders; skipped.\n");
19150 return;
19151 }
19152
19153 char const *vsSource = "#version 450\n"
19154 "void main(){}\n";
19155 char const *tcsSource = "#version 450\n"
19156 "layout(location=0) out int x[];\n"
19157 "layout(vertices=3) out;\n"
19158 "void main(){\n"
19159 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19160 " gl_TessLevelInner[0] = 1;\n"
19161 " x[gl_InvocationID] = gl_InvocationID;\n"
19162 "}\n";
19163 char const *tesSource = "#version 450\n"
19164 "layout(triangles, equal_spacing, cw) in;\n"
19165 "layout(location=0) in int x[];\n"
19166 "out gl_PerVertex { vec4 gl_Position; };\n"
19167 "void main(){\n"
19168 " gl_Position.xyz = gl_TessCoord;\n"
19169 " gl_Position.w = x[0] + x[1] + x[2];\n"
19170 "}\n";
19171 char const *fsSource = "#version 450\n"
19172 "layout(location=0) out vec4 color;\n"
19173 "void main(){\n"
19174 " color = vec4(1);\n"
19175 "}\n";
19176
19177 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19178 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19179 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19180 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19181
19182 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19183 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19184
19185 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19186
19187 VkPipelineObj pipe(m_device);
19188 pipe.SetInputAssembly(&iasci);
19189 pipe.SetTessellation(&tsci);
19190 pipe.AddColorAttachment();
19191 pipe.AddShader(&vs);
19192 pipe.AddShader(&tcs);
19193 pipe.AddShader(&tes);
19194 pipe.AddShader(&fs);
19195
19196 VkDescriptorSetObj descriptorSet(m_device);
19197 descriptorSet.AppendDummy();
19198 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19199
19200 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19201
19202 m_errorMonitor->VerifyNotFound();
19203}
19204
19205TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19206 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19207 "interface block passed into the geometry shader. This "
19208 "is interesting because the 'extra' array level is not "
19209 "present on the member type, but on the block instance.");
19210 m_errorMonitor->ExpectSuccess();
19211
19212 ASSERT_NO_FATAL_FAILURE(InitState());
19213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19214
19215 if (!m_device->phy().features().geometryShader) {
19216 printf("Device does not support geometry shaders; skipped.\n");
19217 return;
19218 }
19219
19220 char const *vsSource = "#version 450\n"
19221 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19222 "void main(){\n"
19223 " vs_out.x = vec4(1);\n"
19224 "}\n";
19225 char const *gsSource = "#version 450\n"
19226 "layout(triangles) in;\n"
19227 "layout(triangle_strip, max_vertices=3) out;\n"
19228 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19229 "out gl_PerVertex { vec4 gl_Position; };\n"
19230 "void main() {\n"
19231 " gl_Position = gs_in[0].x;\n"
19232 " EmitVertex();\n"
19233 "}\n";
19234 char const *fsSource = "#version 450\n"
19235 "layout(location=0) out vec4 color;\n"
19236 "void main(){\n"
19237 " color = vec4(1);\n"
19238 "}\n";
19239
19240 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19241 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19242 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19243
19244 VkPipelineObj pipe(m_device);
19245 pipe.AddColorAttachment();
19246 pipe.AddShader(&vs);
19247 pipe.AddShader(&gs);
19248 pipe.AddShader(&fs);
19249
19250 VkDescriptorSetObj descriptorSet(m_device);
19251 descriptorSet.AppendDummy();
19252 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19253
19254 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19255
19256 m_errorMonitor->VerifyNotFound();
19257}
19258
19259TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19260 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19261 "attributes. This is interesting because they consume multiple "
19262 "locations.");
19263 m_errorMonitor->ExpectSuccess();
19264
19265 ASSERT_NO_FATAL_FAILURE(InitState());
19266 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19267
19268 if (!m_device->phy().features().shaderFloat64) {
19269 printf("Device does not support 64bit vertex attributes; skipped.\n");
19270 return;
19271 }
19272
19273 VkVertexInputBindingDescription input_bindings[1];
19274 memset(input_bindings, 0, sizeof(input_bindings));
19275
19276 VkVertexInputAttributeDescription input_attribs[4];
19277 memset(input_attribs, 0, sizeof(input_attribs));
19278 input_attribs[0].location = 0;
19279 input_attribs[0].offset = 0;
19280 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19281 input_attribs[1].location = 2;
19282 input_attribs[1].offset = 32;
19283 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19284 input_attribs[2].location = 4;
19285 input_attribs[2].offset = 64;
19286 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19287 input_attribs[3].location = 6;
19288 input_attribs[3].offset = 96;
19289 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19290
19291 char const *vsSource = "#version 450\n"
19292 "\n"
19293 "layout(location=0) in dmat4 x;\n"
19294 "out gl_PerVertex {\n"
19295 " vec4 gl_Position;\n"
19296 "};\n"
19297 "void main(){\n"
19298 " gl_Position = vec4(x[0][0]);\n"
19299 "}\n";
19300 char const *fsSource = "#version 450\n"
19301 "\n"
19302 "layout(location=0) out vec4 color;\n"
19303 "void main(){\n"
19304 " color = vec4(1);\n"
19305 "}\n";
19306
19307 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19308 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19309
19310 VkPipelineObj pipe(m_device);
19311 pipe.AddColorAttachment();
19312 pipe.AddShader(&vs);
19313 pipe.AddShader(&fs);
19314
19315 pipe.AddVertexInputBindings(input_bindings, 1);
19316 pipe.AddVertexInputAttribs(input_attribs, 4);
19317
19318 VkDescriptorSetObj descriptorSet(m_device);
19319 descriptorSet.AppendDummy();
19320 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19321
19322 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19323
19324 m_errorMonitor->VerifyNotFound();
19325}
19326
19327TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19328 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19329 m_errorMonitor->ExpectSuccess();
19330
19331 ASSERT_NO_FATAL_FAILURE(InitState());
19332
19333 char const *vsSource = "#version 450\n"
19334 "\n"
19335 "out gl_PerVertex {\n"
19336 " vec4 gl_Position;\n"
19337 "};\n"
19338 "void main(){\n"
19339 " gl_Position = vec4(1);\n"
19340 "}\n";
19341 char const *fsSource = "#version 450\n"
19342 "\n"
19343 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19344 "layout(location=0) out vec4 color;\n"
19345 "void main() {\n"
19346 " color = subpassLoad(x);\n"
19347 "}\n";
19348
19349 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19350 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19351
19352 VkPipelineObj pipe(m_device);
19353 pipe.AddShader(&vs);
19354 pipe.AddShader(&fs);
19355 pipe.AddColorAttachment();
19356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19357
19358 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19359 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19360 VkDescriptorSetLayout dsl;
19361 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19362 ASSERT_VK_SUCCESS(err);
19363
19364 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19365 VkPipelineLayout pl;
19366 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19367 ASSERT_VK_SUCCESS(err);
19368
19369 VkAttachmentDescription descs[2] = {
19370 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19371 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19372 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19373 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19374 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19375 };
19376 VkAttachmentReference color = {
19377 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19378 };
19379 VkAttachmentReference input = {
19380 1, VK_IMAGE_LAYOUT_GENERAL,
19381 };
19382
19383 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19384
19385 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19386 VkRenderPass rp;
19387 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19388 ASSERT_VK_SUCCESS(err);
19389
19390 // should be OK. would go wrong here if it's going to...
19391 pipe.CreateVKPipeline(pl, rp);
19392
19393 m_errorMonitor->VerifyNotFound();
19394
19395 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19396 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19397 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19398}
19399
19400TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19401 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19402 "descriptor-backed resource which is not provided, but the shader does not "
19403 "statically use it. This is interesting because it requires compute pipelines "
19404 "to have a proper descriptor use walk, which they didn't for some time.");
19405 m_errorMonitor->ExpectSuccess();
19406
19407 ASSERT_NO_FATAL_FAILURE(InitState());
19408
19409 char const *csSource = "#version 450\n"
19410 "\n"
19411 "layout(local_size_x=1) in;\n"
19412 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19413 "void main(){\n"
19414 " // x is not used.\n"
19415 "}\n";
19416
19417 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19418
19419 VkDescriptorSetObj descriptorSet(m_device);
19420 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19421
19422 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19423 nullptr,
19424 0,
19425 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19426 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19427 descriptorSet.GetPipelineLayout(),
19428 VK_NULL_HANDLE,
19429 -1 };
19430
19431 VkPipeline pipe;
19432 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19433
19434 m_errorMonitor->VerifyNotFound();
19435
19436 if (err == VK_SUCCESS) {
19437 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19438 }
19439}
19440
19441TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19442 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19443 "sampler portion of a combined image + sampler");
19444 m_errorMonitor->ExpectSuccess();
19445
19446 ASSERT_NO_FATAL_FAILURE(InitState());
19447
19448 VkDescriptorSetLayoutBinding bindings[] = {
19449 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19450 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19451 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19452 };
19453 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19454 VkDescriptorSetLayout dsl;
19455 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19456 ASSERT_VK_SUCCESS(err);
19457
19458 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19459 VkPipelineLayout pl;
19460 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19461 ASSERT_VK_SUCCESS(err);
19462
19463 char const *csSource = "#version 450\n"
19464 "\n"
19465 "layout(local_size_x=1) in;\n"
19466 "layout(set=0, binding=0) uniform sampler s;\n"
19467 "layout(set=0, binding=1) uniform texture2D t;\n"
19468 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19469 "void main() {\n"
19470 " x = texture(sampler2D(t, s), vec2(0));\n"
19471 "}\n";
19472 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19473
19474 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19475 nullptr,
19476 0,
19477 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19478 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19479 pl,
19480 VK_NULL_HANDLE,
19481 -1 };
19482
19483 VkPipeline pipe;
19484 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19485
19486 m_errorMonitor->VerifyNotFound();
19487
19488 if (err == VK_SUCCESS) {
19489 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19490 }
19491
19492 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19493 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19494}
19495
19496TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19497 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19498 "image portion of a combined image + sampler");
19499 m_errorMonitor->ExpectSuccess();
19500
19501 ASSERT_NO_FATAL_FAILURE(InitState());
19502
19503 VkDescriptorSetLayoutBinding bindings[] = {
19504 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19505 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19506 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19507 };
19508 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19509 VkDescriptorSetLayout dsl;
19510 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19511 ASSERT_VK_SUCCESS(err);
19512
19513 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19514 VkPipelineLayout pl;
19515 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19516 ASSERT_VK_SUCCESS(err);
19517
19518 char const *csSource = "#version 450\n"
19519 "\n"
19520 "layout(local_size_x=1) in;\n"
19521 "layout(set=0, binding=0) uniform texture2D t;\n"
19522 "layout(set=0, binding=1) uniform sampler s;\n"
19523 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19524 "void main() {\n"
19525 " x = texture(sampler2D(t, s), vec2(0));\n"
19526 "}\n";
19527 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19528
19529 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19530 nullptr,
19531 0,
19532 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19533 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19534 pl,
19535 VK_NULL_HANDLE,
19536 -1 };
19537
19538 VkPipeline pipe;
19539 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19540
19541 m_errorMonitor->VerifyNotFound();
19542
19543 if (err == VK_SUCCESS) {
19544 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19545 }
19546
19547 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19548 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19549}
19550
19551TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19552 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19553 "both the sampler and the image of a combined image+sampler "
19554 "but via separate variables");
19555 m_errorMonitor->ExpectSuccess();
19556
19557 ASSERT_NO_FATAL_FAILURE(InitState());
19558
19559 VkDescriptorSetLayoutBinding bindings[] = {
19560 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19561 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19562 };
19563 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19564 VkDescriptorSetLayout dsl;
19565 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19566 ASSERT_VK_SUCCESS(err);
19567
19568 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19569 VkPipelineLayout pl;
19570 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19571 ASSERT_VK_SUCCESS(err);
19572
19573 char const *csSource = "#version 450\n"
19574 "\n"
19575 "layout(local_size_x=1) in;\n"
19576 "layout(set=0, binding=0) uniform texture2D t;\n"
19577 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19578 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19579 "void main() {\n"
19580 " x = texture(sampler2D(t, s), vec2(0));\n"
19581 "}\n";
19582 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19583
19584 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19585 nullptr,
19586 0,
19587 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19588 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19589 pl,
19590 VK_NULL_HANDLE,
19591 -1 };
19592
19593 VkPipeline pipe;
19594 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19595
19596 m_errorMonitor->VerifyNotFound();
19597
19598 if (err == VK_SUCCESS) {
19599 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19600 }
19601
19602 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19603 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19604}
19605
19606TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19607 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19608
19609 ASSERT_NO_FATAL_FAILURE(InitState());
19610
19611 // Positive test to check parameter_validation and unique_objects support
19612 // for NV_dedicated_allocation
19613 uint32_t extension_count = 0;
19614 bool supports_nv_dedicated_allocation = false;
19615 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19616 ASSERT_VK_SUCCESS(err);
19617
19618 if (extension_count > 0) {
19619 std::vector<VkExtensionProperties> available_extensions(extension_count);
19620
19621 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19622 ASSERT_VK_SUCCESS(err);
19623
19624 for (const auto &extension_props : available_extensions) {
19625 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19626 supports_nv_dedicated_allocation = true;
19627 }
19628 }
19629 }
19630
19631 if (supports_nv_dedicated_allocation) {
19632 m_errorMonitor->ExpectSuccess();
19633
19634 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19635 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19636 dedicated_buffer_create_info.pNext = nullptr;
19637 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19638
19639 uint32_t queue_family_index = 0;
19640 VkBufferCreateInfo buffer_create_info = {};
19641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19642 buffer_create_info.pNext = &dedicated_buffer_create_info;
19643 buffer_create_info.size = 1024;
19644 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19645 buffer_create_info.queueFamilyIndexCount = 1;
19646 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19647
19648 VkBuffer buffer;
19649 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19650 ASSERT_VK_SUCCESS(err);
19651
19652 VkMemoryRequirements memory_reqs;
19653 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19654
19655 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19656 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19657 dedicated_memory_info.pNext = nullptr;
19658 dedicated_memory_info.buffer = buffer;
19659 dedicated_memory_info.image = VK_NULL_HANDLE;
19660
19661 VkMemoryAllocateInfo memory_info = {};
19662 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19663 memory_info.pNext = &dedicated_memory_info;
19664 memory_info.allocationSize = memory_reqs.size;
19665
19666 bool pass;
19667 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19668 ASSERT_TRUE(pass);
19669
19670 VkDeviceMemory buffer_memory;
19671 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19672 ASSERT_VK_SUCCESS(err);
19673
19674 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19675 ASSERT_VK_SUCCESS(err);
19676
19677 vkDestroyBuffer(m_device->device(), buffer, NULL);
19678 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19679
19680 m_errorMonitor->VerifyNotFound();
19681 }
19682}
19683
19684TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19685 VkResult err;
19686
19687 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19688
19689 ASSERT_NO_FATAL_FAILURE(InitState());
19690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19691
19692 std::vector<const char *> device_extension_names;
19693 auto features = m_device->phy().features();
19694 // Artificially disable support for non-solid fill modes
19695 features.fillModeNonSolid = false;
19696 // The sacrificial device object
19697 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19698
19699 VkRenderpassObj render_pass(&test_device);
19700
19701 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19702 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19703 pipeline_layout_ci.setLayoutCount = 0;
19704 pipeline_layout_ci.pSetLayouts = NULL;
19705
19706 VkPipelineLayout pipeline_layout;
19707 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19708 ASSERT_VK_SUCCESS(err);
19709
19710 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19711 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19712 rs_ci.pNext = nullptr;
19713 rs_ci.lineWidth = 1.0f;
19714 rs_ci.rasterizerDiscardEnable = true;
19715
19716 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19717 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19718
19719 // Set polygonMode=FILL. No error is expected
19720 m_errorMonitor->ExpectSuccess();
19721 {
19722 VkPipelineObj pipe(&test_device);
19723 pipe.AddShader(&vs);
19724 pipe.AddShader(&fs);
19725 pipe.AddColorAttachment();
19726 // Set polygonMode to a good value
19727 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19728 pipe.SetRasterization(&rs_ci);
19729 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19730 }
19731 m_errorMonitor->VerifyNotFound();
19732
19733 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19734}
19735
19736TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19737 VkResult err;
19738 ASSERT_NO_FATAL_FAILURE(InitState());
19739 ASSERT_NO_FATAL_FAILURE(InitViewport());
19740 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19741
19742 VkPipelineLayout pipeline_layout;
19743 VkPushConstantRange pc_range = {};
19744 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19745 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19746 pipeline_layout_ci.pushConstantRangeCount = 1;
19747 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19748
19749 //
19750 // Check for invalid push constant ranges in pipeline layouts.
19751 //
19752 struct PipelineLayoutTestCase {
19753 VkPushConstantRange const range;
19754 char const *msg;
19755 };
19756
19757 // Check for overlapping ranges
19758 const uint32_t ranges_per_test = 5;
19759 struct OverlappingRangeTestCase {
19760 VkPushConstantRange const ranges[ranges_per_test];
19761 char const *msg;
19762 };
19763
19764 // Run some positive tests to make sure overlap checking in the layer is OK
19765 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19766 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19767 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19768 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19769 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19770 "" },
19771 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19772 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19773 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19774 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19775 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19776 "" } } };
19777 for (const auto &iter : overlapping_range_tests_pos) {
19778 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19779 m_errorMonitor->ExpectSuccess();
19780 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19781 m_errorMonitor->VerifyNotFound();
19782 if (VK_SUCCESS == err) {
19783 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19784 }
19785 }
19786
19787 //
19788 // CmdPushConstants tests
19789 //
19790 const uint8_t dummy_values[100] = {};
19791
19792 BeginCommandBuffer();
19793
19794 // positive overlapping range tests with cmd
19795 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19796 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19797 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19798 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19799 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19800 } };
19801
19802 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19803 const VkPushConstantRange pc_range4[] = {
19804 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19805 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19806 };
19807
19808 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19809 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19810 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19811 ASSERT_VK_SUCCESS(err);
19812 for (const auto &iter : cmd_overlap_tests_pos) {
19813 m_errorMonitor->ExpectSuccess();
19814 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19815 iter.range.size, dummy_values);
19816 m_errorMonitor->VerifyNotFound();
19817 }
19818 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19819
19820 EndCommandBuffer();
19821}
19822
19823
19824
19825
19826
19827
19828
19829#if 0 // A few devices have issues with this test so disabling for now
19830TEST_F(VkPositiveLayerTest, LongFenceChain)
19831{
19832 m_errorMonitor->ExpectSuccess();
19833
19834 ASSERT_NO_FATAL_FAILURE(InitState());
19835 VkResult err;
19836
19837 std::vector<VkFence> fences;
19838
19839 const int chainLength = 32768;
19840
19841 for (int i = 0; i < chainLength; i++) {
19842 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19843 VkFence fence;
19844 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19845 ASSERT_VK_SUCCESS(err);
19846
19847 fences.push_back(fence);
19848
19849 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19850 0, nullptr, 0, nullptr };
19851 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19852 ASSERT_VK_SUCCESS(err);
19853
19854 }
19855
19856 // BOOM, stack overflow.
19857 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19858
19859 for (auto fence : fences)
19860 vkDestroyFence(m_device->device(), fence, nullptr);
19861
19862 m_errorMonitor->VerifyNotFound();
19863}
19864#endif
19865
19866
Cody Northrop1242dfd2016-07-13 17:24:59 -060019867#if defined(ANDROID) && defined(VALIDATION_APK)
19868static bool initialized = false;
19869static bool active = false;
19870
19871// Convert Intents to argv
19872// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019873std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019874 std::vector<std::string> args;
19875 JavaVM &vm = *app.activity->vm;
19876 JNIEnv *p_env;
19877 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19878 return args;
19879
19880 JNIEnv &env = *p_env;
19881 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019882 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019883 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019884 jmethodID get_string_extra_method =
19885 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019886 jvalue get_string_extra_args;
19887 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019888 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019889
19890 std::string args_str;
19891 if (extra_str) {
19892 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19893 args_str = extra_utf;
19894 env.ReleaseStringUTFChars(extra_str, extra_utf);
19895 env.DeleteLocalRef(extra_str);
19896 }
19897
19898 env.DeleteLocalRef(get_string_extra_args.l);
19899 env.DeleteLocalRef(intent);
19900 vm.DetachCurrentThread();
19901
19902 // split args_str
19903 std::stringstream ss(args_str);
19904 std::string arg;
19905 while (std::getline(ss, arg, ' ')) {
19906 if (!arg.empty())
19907 args.push_back(arg);
19908 }
19909
19910 return args;
19911}
19912
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019913static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019914
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019915static void processCommand(struct android_app *app, int32_t cmd) {
19916 switch (cmd) {
19917 case APP_CMD_INIT_WINDOW: {
19918 if (app->window) {
19919 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019920 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019921 break;
19922 }
19923 case APP_CMD_GAINED_FOCUS: {
19924 active = true;
19925 break;
19926 }
19927 case APP_CMD_LOST_FOCUS: {
19928 active = false;
19929 break;
19930 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019931 }
19932}
19933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019934void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019935 app_dummy();
19936
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019937 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019938
19939 int vulkanSupport = InitVulkan();
19940 if (vulkanSupport == 0) {
19941 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19942 return;
19943 }
19944
19945 app->onAppCmd = processCommand;
19946 app->onInputEvent = processInput;
19947
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019948 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019949 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019950 struct android_poll_source *source;
19951 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019952 if (source) {
19953 source->process(app, source);
19954 }
19955
19956 if (app->destroyRequested != 0) {
19957 VkTestFramework::Finish();
19958 return;
19959 }
19960 }
19961
19962 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019963 // Use the following key to send arguments to gtest, i.e.
19964 // --es args "--gtest_filter=-VkLayerTest.foo"
19965 const char key[] = "args";
19966 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019968 std::string filter = "";
19969 if (args.size() > 0) {
19970 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19971 filter += args[0];
19972 } else {
19973 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19974 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019976 int argc = 2;
19977 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19978 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019980 // Route output to files until we can override the gtest output
19981 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19982 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019983
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019984 ::testing::InitGoogleTest(&argc, argv);
19985 VkTestFramework::InitArgs(&argc, argv);
19986 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019988 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019989
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019990 if (result != 0) {
19991 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19992 } else {
19993 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19994 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019995
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019996 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019997
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019998 fclose(stdout);
19999 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020001 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020003 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020004 }
20005 }
20006}
20007#endif
20008
Tony Barbour300a6082015-04-07 13:44:53 -060020009int main(int argc, char **argv) {
20010 int result;
20011
Cody Northrop8e54a402016-03-08 22:25:52 -070020012#ifdef ANDROID
20013 int vulkanSupport = InitVulkan();
20014 if (vulkanSupport == 0)
20015 return 1;
20016#endif
20017
Tony Barbour300a6082015-04-07 13:44:53 -060020018 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020019 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020020
20021 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20022
20023 result = RUN_ALL_TESTS();
20024
Tony Barbour6918cd52015-04-09 12:58:51 -060020025 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020026 return result;
20027}