blob: 2331f8a00c9c52f967293f37fe57f22295100efa [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 Ehlisf93f1e32015-10-20 16:16:04 -06003640 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003641 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3644 "type "
3645 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003646
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003647 ASSERT_NO_FATAL_FAILURE(InitState());
3648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003649
Karl Schultz6addd812016-02-02 17:17:23 -07003650 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3651 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003652 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003653 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3654 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003655
3656 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003657 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3658 ds_pool_ci.pNext = NULL;
3659 ds_pool_ci.flags = 0;
3660 ds_pool_ci.maxSets = 1;
3661 ds_pool_ci.poolSizeCount = 1;
3662 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003663
3664 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003665 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003666 ASSERT_VK_SUCCESS(err);
3667
3668 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003669 dsl_binding.binding = 0;
3670 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3671 dsl_binding.descriptorCount = 1;
3672 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3673 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003674
3675 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003676 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3677 ds_layout_ci.pNext = NULL;
3678 ds_layout_ci.bindingCount = 1;
3679 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003680
3681 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003682 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003683 ASSERT_VK_SUCCESS(err);
3684
3685 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003686 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003687 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003688 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003689 alloc_info.descriptorPool = ds_pool;
3690 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003692
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003693 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003694
Chia-I Wuf7458c52015-10-26 21:10:41 +08003695 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3696 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003697}
3698
Karl Schultz6addd812016-02-02 17:17:23 -07003699TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3700 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003701
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3703 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3704 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003705
Tobin Ehlise735c692015-10-08 13:13:50 -06003706 ASSERT_NO_FATAL_FAILURE(InitState());
3707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003708
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003709 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003710 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3711 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003712
3713 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003714 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3715 ds_pool_ci.pNext = NULL;
3716 ds_pool_ci.maxSets = 1;
3717 ds_pool_ci.poolSizeCount = 1;
3718 ds_pool_ci.flags = 0;
3719 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3720 // app can only call vkResetDescriptorPool on this pool.;
3721 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003722
3723 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003724 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003725 ASSERT_VK_SUCCESS(err);
3726
3727 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003728 dsl_binding.binding = 0;
3729 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3730 dsl_binding.descriptorCount = 1;
3731 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3732 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003733
3734 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003735 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3736 ds_layout_ci.pNext = NULL;
3737 ds_layout_ci.bindingCount = 1;
3738 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003739
3740 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003741 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003742 ASSERT_VK_SUCCESS(err);
3743
3744 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003745 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003746 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003747 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003748 alloc_info.descriptorPool = ds_pool;
3749 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003750 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003751 ASSERT_VK_SUCCESS(err);
3752
3753 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003754 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003755
Chia-I Wuf7458c52015-10-26 21:10:41 +08003756 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3757 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003758}
3759
Karl Schultz6addd812016-02-02 17:17:23 -07003760TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003761 // Attempt to clear Descriptor Pool with bad object.
3762 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003763
3764 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003766 uint64_t fake_pool_handle = 0xbaad6001;
3767 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3768 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003769 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003770}
3771
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003772TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003773 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3774 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003775 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003776 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003777
3778 uint64_t fake_set_handle = 0xbaad6001;
3779 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003780 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003782
3783 ASSERT_NO_FATAL_FAILURE(InitState());
3784
3785 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3786 layout_bindings[0].binding = 0;
3787 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3788 layout_bindings[0].descriptorCount = 1;
3789 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3790 layout_bindings[0].pImmutableSamplers = NULL;
3791
3792 VkDescriptorSetLayout descriptor_set_layout;
3793 VkDescriptorSetLayoutCreateInfo dslci = {};
3794 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3795 dslci.pNext = NULL;
3796 dslci.bindingCount = 1;
3797 dslci.pBindings = layout_bindings;
3798 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003799 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003800
3801 VkPipelineLayout pipeline_layout;
3802 VkPipelineLayoutCreateInfo plci = {};
3803 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3804 plci.pNext = NULL;
3805 plci.setLayoutCount = 1;
3806 plci.pSetLayouts = &descriptor_set_layout;
3807 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003808 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003809
3810 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003811 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3812 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003813 m_errorMonitor->VerifyFound();
3814 EndCommandBuffer();
3815 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3816 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003817}
3818
Karl Schultz6addd812016-02-02 17:17:23 -07003819TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003820 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3821 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003822 uint64_t fake_layout_handle = 0xbaad6001;
3823 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003825 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003826 VkPipelineLayout pipeline_layout;
3827 VkPipelineLayoutCreateInfo plci = {};
3828 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3829 plci.pNext = NULL;
3830 plci.setLayoutCount = 1;
3831 plci.pSetLayouts = &bad_layout;
3832 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3833
3834 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003835}
3836
Mark Muellerd4914412016-06-13 17:52:06 -06003837TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3838 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3839 "1) A uniform buffer update must have a valid buffer index."
3840 "2) When using an array of descriptors in a single WriteDescriptor,"
3841 " the descriptor types and stageflags must all be the same."
3842 "3) Immutable Sampler state must match across descriptors");
3843
3844 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003845 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3846 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3847 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3848 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3849 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003850
Mark Muellerd4914412016-06-13 17:52:06 -06003851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3852
3853 ASSERT_NO_FATAL_FAILURE(InitState());
3854 VkDescriptorPoolSize ds_type_count[4] = {};
3855 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3856 ds_type_count[0].descriptorCount = 1;
3857 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3858 ds_type_count[1].descriptorCount = 1;
3859 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3860 ds_type_count[2].descriptorCount = 1;
3861 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3862 ds_type_count[3].descriptorCount = 1;
3863
3864 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3865 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3866 ds_pool_ci.maxSets = 1;
3867 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3868 ds_pool_ci.pPoolSizes = ds_type_count;
3869
3870 VkDescriptorPool ds_pool;
3871 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3872 ASSERT_VK_SUCCESS(err);
3873
Mark Muellerb9896722016-06-16 09:54:29 -06003874 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003875 layout_binding[0].binding = 0;
3876 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3877 layout_binding[0].descriptorCount = 1;
3878 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3879 layout_binding[0].pImmutableSamplers = NULL;
3880
3881 layout_binding[1].binding = 1;
3882 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3883 layout_binding[1].descriptorCount = 1;
3884 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3885 layout_binding[1].pImmutableSamplers = NULL;
3886
3887 VkSamplerCreateInfo sampler_ci = {};
3888 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3889 sampler_ci.pNext = NULL;
3890 sampler_ci.magFilter = VK_FILTER_NEAREST;
3891 sampler_ci.minFilter = VK_FILTER_NEAREST;
3892 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3893 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3894 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3895 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3896 sampler_ci.mipLodBias = 1.0;
3897 sampler_ci.anisotropyEnable = VK_FALSE;
3898 sampler_ci.maxAnisotropy = 1;
3899 sampler_ci.compareEnable = VK_FALSE;
3900 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3901 sampler_ci.minLod = 1.0;
3902 sampler_ci.maxLod = 1.0;
3903 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3904 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3905 VkSampler sampler;
3906
3907 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3908 ASSERT_VK_SUCCESS(err);
3909
3910 layout_binding[2].binding = 2;
3911 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3912 layout_binding[2].descriptorCount = 1;
3913 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3914 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3915
Mark Muellerd4914412016-06-13 17:52:06 -06003916 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3917 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3918 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3919 ds_layout_ci.pBindings = layout_binding;
3920 VkDescriptorSetLayout ds_layout;
3921 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3922 ASSERT_VK_SUCCESS(err);
3923
3924 VkDescriptorSetAllocateInfo alloc_info = {};
3925 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3926 alloc_info.descriptorSetCount = 1;
3927 alloc_info.descriptorPool = ds_pool;
3928 alloc_info.pSetLayouts = &ds_layout;
3929 VkDescriptorSet descriptorSet;
3930 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3931 ASSERT_VK_SUCCESS(err);
3932
3933 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3934 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3935 pipeline_layout_ci.pNext = NULL;
3936 pipeline_layout_ci.setLayoutCount = 1;
3937 pipeline_layout_ci.pSetLayouts = &ds_layout;
3938
3939 VkPipelineLayout pipeline_layout;
3940 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3941 ASSERT_VK_SUCCESS(err);
3942
Mark Mueller5c838ce2016-06-16 09:54:29 -06003943 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003944 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3945 descriptor_write.dstSet = descriptorSet;
3946 descriptor_write.dstBinding = 0;
3947 descriptor_write.descriptorCount = 1;
3948 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3949
Mark Mueller5c838ce2016-06-16 09:54:29 -06003950 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003951 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3952 m_errorMonitor->VerifyFound();
3953
3954 // Create a buffer to update the descriptor with
3955 uint32_t qfi = 0;
3956 VkBufferCreateInfo buffCI = {};
3957 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3958 buffCI.size = 1024;
3959 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3960 buffCI.queueFamilyIndexCount = 1;
3961 buffCI.pQueueFamilyIndices = &qfi;
3962
3963 VkBuffer dyub;
3964 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3965 ASSERT_VK_SUCCESS(err);
3966 VkDescriptorBufferInfo buffInfo = {};
3967 buffInfo.buffer = dyub;
3968 buffInfo.offset = 0;
3969 buffInfo.range = 1024;
3970
3971 descriptor_write.pBufferInfo = &buffInfo;
3972 descriptor_write.descriptorCount = 2;
3973
Mark Mueller5c838ce2016-06-16 09:54:29 -06003974 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3976 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3977 m_errorMonitor->VerifyFound();
3978
Mark Mueller5c838ce2016-06-16 09:54:29 -06003979 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3980 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003981 descriptor_write.dstBinding = 1;
3982 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003983
Mark Mueller5c838ce2016-06-16 09:54:29 -06003984 // Make pImageInfo index non-null to avoid complaints of it missing
3985 VkDescriptorImageInfo imageInfo = {};
3986 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3987 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3989 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3990 m_errorMonitor->VerifyFound();
3991
Mark Muellerd4914412016-06-13 17:52:06 -06003992 vkDestroyBuffer(m_device->device(), dyub, NULL);
3993 vkDestroySampler(m_device->device(), sampler, NULL);
3994 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3995 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3996 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3997}
3998
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003999TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4000 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4001 "due to a buffer dependency being destroyed.");
4002 ASSERT_NO_FATAL_FAILURE(InitState());
4003
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004004 VkBuffer buffer;
4005 VkDeviceMemory mem;
4006 VkMemoryRequirements mem_reqs;
4007
4008 VkBufferCreateInfo buf_info = {};
4009 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004010 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004011 buf_info.size = 256;
4012 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4013 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4014 ASSERT_VK_SUCCESS(err);
4015
4016 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4017
4018 VkMemoryAllocateInfo alloc_info = {};
4019 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4020 alloc_info.allocationSize = 256;
4021 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004022 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 -06004023 if (!pass) {
4024 vkDestroyBuffer(m_device->device(), buffer, NULL);
4025 return;
4026 }
4027 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4028 ASSERT_VK_SUCCESS(err);
4029
4030 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4031 ASSERT_VK_SUCCESS(err);
4032
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004033 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004034 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004035 m_commandBuffer->EndCommandBuffer();
4036
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004038 // Destroy buffer dependency prior to submit to cause ERROR
4039 vkDestroyBuffer(m_device->device(), buffer, NULL);
4040
4041 VkSubmitInfo submit_info = {};
4042 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4043 submit_info.commandBufferCount = 1;
4044 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4045 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4046
4047 m_errorMonitor->VerifyFound();
4048 vkFreeMemory(m_device->handle(), mem, NULL);
4049}
4050
Tobin Ehlisea413442016-09-28 10:23:59 -06004051TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4052 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4053
4054 ASSERT_NO_FATAL_FAILURE(InitState());
4055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4056
4057 VkDescriptorPoolSize ds_type_count;
4058 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4059 ds_type_count.descriptorCount = 1;
4060
4061 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4062 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4063 ds_pool_ci.maxSets = 1;
4064 ds_pool_ci.poolSizeCount = 1;
4065 ds_pool_ci.pPoolSizes = &ds_type_count;
4066
4067 VkDescriptorPool ds_pool;
4068 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4069 ASSERT_VK_SUCCESS(err);
4070
4071 VkDescriptorSetLayoutBinding layout_binding;
4072 layout_binding.binding = 0;
4073 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4074 layout_binding.descriptorCount = 1;
4075 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4076 layout_binding.pImmutableSamplers = NULL;
4077
4078 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4079 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4080 ds_layout_ci.bindingCount = 1;
4081 ds_layout_ci.pBindings = &layout_binding;
4082 VkDescriptorSetLayout ds_layout;
4083 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4084 ASSERT_VK_SUCCESS(err);
4085
4086 VkDescriptorSetAllocateInfo alloc_info = {};
4087 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4088 alloc_info.descriptorSetCount = 1;
4089 alloc_info.descriptorPool = ds_pool;
4090 alloc_info.pSetLayouts = &ds_layout;
4091 VkDescriptorSet descriptor_set;
4092 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4093 ASSERT_VK_SUCCESS(err);
4094
4095 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4096 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4097 pipeline_layout_ci.pNext = NULL;
4098 pipeline_layout_ci.setLayoutCount = 1;
4099 pipeline_layout_ci.pSetLayouts = &ds_layout;
4100
4101 VkPipelineLayout pipeline_layout;
4102 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4103 ASSERT_VK_SUCCESS(err);
4104
4105 VkBuffer buffer;
4106 uint32_t queue_family_index = 0;
4107 VkBufferCreateInfo buffer_create_info = {};
4108 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4109 buffer_create_info.size = 1024;
4110 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4111 buffer_create_info.queueFamilyIndexCount = 1;
4112 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4113
4114 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4115 ASSERT_VK_SUCCESS(err);
4116
4117 VkMemoryRequirements memory_reqs;
4118 VkDeviceMemory buffer_memory;
4119
4120 VkMemoryAllocateInfo memory_info = {};
4121 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4122 memory_info.allocationSize = 0;
4123 memory_info.memoryTypeIndex = 0;
4124
4125 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4126 memory_info.allocationSize = memory_reqs.size;
4127 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4128 ASSERT_TRUE(pass);
4129
4130 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4131 ASSERT_VK_SUCCESS(err);
4132 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4133 ASSERT_VK_SUCCESS(err);
4134
4135 VkBufferView view;
4136 VkBufferViewCreateInfo bvci = {};
4137 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4138 bvci.buffer = buffer;
4139 bvci.format = VK_FORMAT_R8_UNORM;
4140 bvci.range = VK_WHOLE_SIZE;
4141
4142 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4143 ASSERT_VK_SUCCESS(err);
4144
4145 VkWriteDescriptorSet descriptor_write = {};
4146 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4147 descriptor_write.dstSet = descriptor_set;
4148 descriptor_write.dstBinding = 0;
4149 descriptor_write.descriptorCount = 1;
4150 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4151 descriptor_write.pTexelBufferView = &view;
4152
4153 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4154
4155 char const *vsSource = "#version 450\n"
4156 "\n"
4157 "out gl_PerVertex { \n"
4158 " vec4 gl_Position;\n"
4159 "};\n"
4160 "void main(){\n"
4161 " gl_Position = vec4(1);\n"
4162 "}\n";
4163 char const *fsSource = "#version 450\n"
4164 "\n"
4165 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4166 "layout(location=0) out vec4 x;\n"
4167 "void main(){\n"
4168 " x = imageLoad(s, 0);\n"
4169 "}\n";
4170 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4171 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4172 VkPipelineObj pipe(m_device);
4173 pipe.AddShader(&vs);
4174 pipe.AddShader(&fs);
4175 pipe.AddColorAttachment();
4176 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4177
4178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4180
4181 BeginCommandBuffer();
4182 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4183 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4184 VkRect2D scissor = {{0, 0}, {16, 16}};
4185 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4186 // Bind pipeline to cmd buffer
4187 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4188 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4189 &descriptor_set, 0, nullptr);
4190 Draw(1, 0, 0, 0);
4191 EndCommandBuffer();
4192
4193 // Delete BufferView in order to invalidate cmd buffer
4194 vkDestroyBufferView(m_device->device(), view, NULL);
4195 // Now attempt submit of cmd buffer
4196 VkSubmitInfo submit_info = {};
4197 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4198 submit_info.commandBufferCount = 1;
4199 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4200 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4201 m_errorMonitor->VerifyFound();
4202
4203 // Clean-up
4204 vkDestroyBuffer(m_device->device(), buffer, NULL);
4205 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4206 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4207 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4208 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4209}
4210
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004211TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4212 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4213 "due to an image dependency being destroyed.");
4214 ASSERT_NO_FATAL_FAILURE(InitState());
4215
4216 VkImage image;
4217 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4218 VkImageCreateInfo image_create_info = {};
4219 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4220 image_create_info.pNext = NULL;
4221 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4222 image_create_info.format = tex_format;
4223 image_create_info.extent.width = 32;
4224 image_create_info.extent.height = 32;
4225 image_create_info.extent.depth = 1;
4226 image_create_info.mipLevels = 1;
4227 image_create_info.arrayLayers = 1;
4228 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4229 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004230 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004231 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004232 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004233 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004234 // Have to bind memory to image before recording cmd in cmd buffer using it
4235 VkMemoryRequirements mem_reqs;
4236 VkDeviceMemory image_mem;
4237 bool pass;
4238 VkMemoryAllocateInfo mem_alloc = {};
4239 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4240 mem_alloc.pNext = NULL;
4241 mem_alloc.memoryTypeIndex = 0;
4242 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4243 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004244 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004245 ASSERT_TRUE(pass);
4246 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4247 ASSERT_VK_SUCCESS(err);
4248 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4249 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004250
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004251 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004252 VkClearColorValue ccv;
4253 ccv.float32[0] = 1.0f;
4254 ccv.float32[1] = 1.0f;
4255 ccv.float32[2] = 1.0f;
4256 ccv.float32[3] = 1.0f;
4257 VkImageSubresourceRange isr = {};
4258 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004259 isr.baseArrayLayer = 0;
4260 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004261 isr.layerCount = 1;
4262 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004263 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004264 m_commandBuffer->EndCommandBuffer();
4265
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004267 // Destroy image dependency prior to submit to cause ERROR
4268 vkDestroyImage(m_device->device(), image, NULL);
4269
4270 VkSubmitInfo submit_info = {};
4271 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4272 submit_info.commandBufferCount = 1;
4273 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4274 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4275
4276 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004277 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004278}
4279
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004280TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4281 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4282 "due to a framebuffer image dependency being destroyed.");
4283 VkFormatProperties format_properties;
4284 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004285 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4286 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004287 return;
4288 }
4289
4290 ASSERT_NO_FATAL_FAILURE(InitState());
4291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4292
4293 VkImageCreateInfo image_ci = {};
4294 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4295 image_ci.pNext = NULL;
4296 image_ci.imageType = VK_IMAGE_TYPE_2D;
4297 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4298 image_ci.extent.width = 32;
4299 image_ci.extent.height = 32;
4300 image_ci.extent.depth = 1;
4301 image_ci.mipLevels = 1;
4302 image_ci.arrayLayers = 1;
4303 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4304 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004305 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004306 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4307 image_ci.flags = 0;
4308 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004309 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004310
4311 VkMemoryRequirements memory_reqs;
4312 VkDeviceMemory image_memory;
4313 bool pass;
4314 VkMemoryAllocateInfo memory_info = {};
4315 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4316 memory_info.pNext = NULL;
4317 memory_info.allocationSize = 0;
4318 memory_info.memoryTypeIndex = 0;
4319 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4320 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004321 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004322 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004323 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004324 ASSERT_VK_SUCCESS(err);
4325 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4326 ASSERT_VK_SUCCESS(err);
4327
4328 VkImageViewCreateInfo ivci = {
4329 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4330 nullptr,
4331 0,
4332 image,
4333 VK_IMAGE_VIEW_TYPE_2D,
4334 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004335 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004336 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4337 };
4338 VkImageView view;
4339 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4340 ASSERT_VK_SUCCESS(err);
4341
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004342 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004343 VkFramebuffer fb;
4344 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4345 ASSERT_VK_SUCCESS(err);
4346
4347 // Just use default renderpass with our framebuffer
4348 m_renderPassBeginInfo.framebuffer = fb;
4349 // Create Null cmd buffer for submit
4350 BeginCommandBuffer();
4351 EndCommandBuffer();
4352 // Destroy image attached to framebuffer to invalidate cmd buffer
4353 vkDestroyImage(m_device->device(), image, NULL);
4354 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004356 QueueCommandBuffer(false);
4357 m_errorMonitor->VerifyFound();
4358
4359 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4360 vkDestroyImageView(m_device->device(), view, nullptr);
4361 vkFreeMemory(m_device->device(), image_memory, nullptr);
4362}
4363
Tobin Ehlisb329f992016-10-12 13:20:29 -06004364TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4365 TEST_DESCRIPTION("Delete in-use framebuffer.");
4366 VkFormatProperties format_properties;
4367 VkResult err = VK_SUCCESS;
4368 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4369
4370 ASSERT_NO_FATAL_FAILURE(InitState());
4371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4372
4373 VkImageObj image(m_device);
4374 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4375 ASSERT_TRUE(image.initialized());
4376 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4377
4378 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4379 VkFramebuffer fb;
4380 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4381 ASSERT_VK_SUCCESS(err);
4382
4383 // Just use default renderpass with our framebuffer
4384 m_renderPassBeginInfo.framebuffer = fb;
4385 // Create Null cmd buffer for submit
4386 BeginCommandBuffer();
4387 EndCommandBuffer();
4388 // Submit cmd buffer to put it in-flight
4389 VkSubmitInfo submit_info = {};
4390 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4391 submit_info.commandBufferCount = 1;
4392 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4393 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4394 // Destroy framebuffer while in-flight
4395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4396 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4397 m_errorMonitor->VerifyFound();
4398 // Wait for queue to complete so we can safely destroy everything
4399 vkQueueWaitIdle(m_device->m_queue);
4400 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4401}
4402
Tobin Ehlis88becd72016-09-21 14:33:41 -06004403TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4404 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4405 VkFormatProperties format_properties;
4406 VkResult err = VK_SUCCESS;
4407 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004408
4409 ASSERT_NO_FATAL_FAILURE(InitState());
4410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4411
4412 VkImageCreateInfo image_ci = {};
4413 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4414 image_ci.pNext = NULL;
4415 image_ci.imageType = VK_IMAGE_TYPE_2D;
4416 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4417 image_ci.extent.width = 256;
4418 image_ci.extent.height = 256;
4419 image_ci.extent.depth = 1;
4420 image_ci.mipLevels = 1;
4421 image_ci.arrayLayers = 1;
4422 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4423 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004424 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004425 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4426 image_ci.flags = 0;
4427 VkImage image;
4428 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4429
4430 VkMemoryRequirements memory_reqs;
4431 VkDeviceMemory image_memory;
4432 bool pass;
4433 VkMemoryAllocateInfo memory_info = {};
4434 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4435 memory_info.pNext = NULL;
4436 memory_info.allocationSize = 0;
4437 memory_info.memoryTypeIndex = 0;
4438 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4439 memory_info.allocationSize = memory_reqs.size;
4440 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4441 ASSERT_TRUE(pass);
4442 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4443 ASSERT_VK_SUCCESS(err);
4444 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4445 ASSERT_VK_SUCCESS(err);
4446
4447 VkImageViewCreateInfo ivci = {
4448 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4449 nullptr,
4450 0,
4451 image,
4452 VK_IMAGE_VIEW_TYPE_2D,
4453 VK_FORMAT_B8G8R8A8_UNORM,
4454 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4455 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4456 };
4457 VkImageView view;
4458 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4459 ASSERT_VK_SUCCESS(err);
4460
4461 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4462 VkFramebuffer fb;
4463 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4464 ASSERT_VK_SUCCESS(err);
4465
4466 // Just use default renderpass with our framebuffer
4467 m_renderPassBeginInfo.framebuffer = fb;
4468 // Create Null cmd buffer for submit
4469 BeginCommandBuffer();
4470 EndCommandBuffer();
4471 // Submit cmd buffer to put it (and attached imageView) in-flight
4472 VkSubmitInfo submit_info = {};
4473 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4474 submit_info.commandBufferCount = 1;
4475 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4476 // Submit cmd buffer to put framebuffer and children in-flight
4477 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4478 // Destroy image attached to framebuffer while in-flight
4479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4480 vkDestroyImage(m_device->device(), image, NULL);
4481 m_errorMonitor->VerifyFound();
4482 // Wait for queue to complete so we can safely destroy image and other objects
4483 vkQueueWaitIdle(m_device->m_queue);
4484 vkDestroyImage(m_device->device(), image, NULL);
4485 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4486 vkDestroyImageView(m_device->device(), view, nullptr);
4487 vkFreeMemory(m_device->device(), image_memory, nullptr);
4488}
4489
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004490TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4491 TEST_DESCRIPTION("Delete in-use renderPass.");
4492
4493 ASSERT_NO_FATAL_FAILURE(InitState());
4494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4495
4496 // Create simple renderpass
4497 VkAttachmentReference attach = {};
4498 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4499 VkSubpassDescription subpass = {};
4500 subpass.pColorAttachments = &attach;
4501 VkRenderPassCreateInfo rpci = {};
4502 rpci.subpassCount = 1;
4503 rpci.pSubpasses = &subpass;
4504 rpci.attachmentCount = 1;
4505 VkAttachmentDescription attach_desc = {};
4506 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4507 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4508 rpci.pAttachments = &attach_desc;
4509 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4510 VkRenderPass rp;
4511 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4512 ASSERT_VK_SUCCESS(err);
4513
4514 // Create a pipeline that uses the given renderpass
4515 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4516 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4517
4518 VkPipelineLayout pipeline_layout;
4519 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4520 ASSERT_VK_SUCCESS(err);
4521
4522 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4523 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4524 vp_state_ci.viewportCount = 1;
4525 VkViewport vp = {}; // Just need dummy vp to point to
4526 vp_state_ci.pViewports = &vp;
4527 vp_state_ci.scissorCount = 1;
4528 VkRect2D scissors = {}; // Dummy scissors to point to
4529 vp_state_ci.pScissors = &scissors;
4530
4531 VkPipelineShaderStageCreateInfo shaderStages[2];
4532 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4533
4534 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4535 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4536 // but add it to be able to run on more devices
4537 shaderStages[0] = vs.GetStageCreateInfo();
4538 shaderStages[1] = fs.GetStageCreateInfo();
4539
4540 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4541 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4542
4543 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4544 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4545 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4546
4547 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4548 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4549 rs_ci.rasterizerDiscardEnable = true;
4550 rs_ci.lineWidth = 1.0f;
4551
4552 VkPipelineColorBlendAttachmentState att = {};
4553 att.blendEnable = VK_FALSE;
4554 att.colorWriteMask = 0xf;
4555
4556 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4557 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4558 cb_ci.attachmentCount = 1;
4559 cb_ci.pAttachments = &att;
4560
4561 VkGraphicsPipelineCreateInfo gp_ci = {};
4562 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4563 gp_ci.stageCount = 2;
4564 gp_ci.pStages = shaderStages;
4565 gp_ci.pVertexInputState = &vi_ci;
4566 gp_ci.pInputAssemblyState = &ia_ci;
4567 gp_ci.pViewportState = &vp_state_ci;
4568 gp_ci.pRasterizationState = &rs_ci;
4569 gp_ci.pColorBlendState = &cb_ci;
4570 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4571 gp_ci.layout = pipeline_layout;
4572 gp_ci.renderPass = rp;
4573
4574 VkPipelineCacheCreateInfo pc_ci = {};
4575 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4576
4577 VkPipeline pipeline;
4578 VkPipelineCache pipe_cache;
4579 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4580 ASSERT_VK_SUCCESS(err);
4581
4582 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4583 ASSERT_VK_SUCCESS(err);
4584 // Bind pipeline to cmd buffer, will also bind renderpass
4585 m_commandBuffer->BeginCommandBuffer();
4586 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4587 m_commandBuffer->EndCommandBuffer();
4588
4589 VkSubmitInfo submit_info = {};
4590 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4591 submit_info.commandBufferCount = 1;
4592 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4593 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4594
4595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4596 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4597 m_errorMonitor->VerifyFound();
4598
4599 // Wait for queue to complete so we can safely destroy everything
4600 vkQueueWaitIdle(m_device->m_queue);
4601 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4602 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4603 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4604 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4605}
4606
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004607TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004608 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004609 ASSERT_NO_FATAL_FAILURE(InitState());
4610
4611 VkImage image;
4612 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4613 VkImageCreateInfo image_create_info = {};
4614 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4615 image_create_info.pNext = NULL;
4616 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4617 image_create_info.format = tex_format;
4618 image_create_info.extent.width = 32;
4619 image_create_info.extent.height = 32;
4620 image_create_info.extent.depth = 1;
4621 image_create_info.mipLevels = 1;
4622 image_create_info.arrayLayers = 1;
4623 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4624 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004625 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004626 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004627 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004628 ASSERT_VK_SUCCESS(err);
4629 // Have to bind memory to image before recording cmd in cmd buffer using it
4630 VkMemoryRequirements mem_reqs;
4631 VkDeviceMemory image_mem;
4632 bool pass;
4633 VkMemoryAllocateInfo mem_alloc = {};
4634 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4635 mem_alloc.pNext = NULL;
4636 mem_alloc.memoryTypeIndex = 0;
4637 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4638 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004639 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004640 ASSERT_TRUE(pass);
4641 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4642 ASSERT_VK_SUCCESS(err);
4643
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004644 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004646 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004647
4648 m_commandBuffer->BeginCommandBuffer();
4649 VkClearColorValue ccv;
4650 ccv.float32[0] = 1.0f;
4651 ccv.float32[1] = 1.0f;
4652 ccv.float32[2] = 1.0f;
4653 ccv.float32[3] = 1.0f;
4654 VkImageSubresourceRange isr = {};
4655 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4656 isr.baseArrayLayer = 0;
4657 isr.baseMipLevel = 0;
4658 isr.layerCount = 1;
4659 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004660 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004661 m_commandBuffer->EndCommandBuffer();
4662
4663 m_errorMonitor->VerifyFound();
4664 vkDestroyImage(m_device->device(), image, NULL);
4665 vkFreeMemory(m_device->device(), image_mem, nullptr);
4666}
4667
4668TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004669 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004670 ASSERT_NO_FATAL_FAILURE(InitState());
4671
4672 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004673 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 -06004674 VK_IMAGE_TILING_OPTIMAL, 0);
4675 ASSERT_TRUE(image.initialized());
4676
4677 VkBuffer buffer;
4678 VkDeviceMemory mem;
4679 VkMemoryRequirements mem_reqs;
4680
4681 VkBufferCreateInfo buf_info = {};
4682 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004683 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004684 buf_info.size = 256;
4685 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4686 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4687 ASSERT_VK_SUCCESS(err);
4688
4689 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4690
4691 VkMemoryAllocateInfo alloc_info = {};
4692 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4693 alloc_info.allocationSize = 256;
4694 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004695 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 -06004696 if (!pass) {
4697 vkDestroyBuffer(m_device->device(), buffer, NULL);
4698 return;
4699 }
4700 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4701 ASSERT_VK_SUCCESS(err);
4702
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004703 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004705 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004706 VkBufferImageCopy region = {};
4707 region.bufferRowLength = 128;
4708 region.bufferImageHeight = 128;
4709 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4710
4711 region.imageSubresource.layerCount = 1;
4712 region.imageExtent.height = 4;
4713 region.imageExtent.width = 4;
4714 region.imageExtent.depth = 1;
4715 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004716 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4717 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004718 m_commandBuffer->EndCommandBuffer();
4719
4720 m_errorMonitor->VerifyFound();
4721
4722 vkDestroyBuffer(m_device->device(), buffer, NULL);
4723 vkFreeMemory(m_device->handle(), mem, NULL);
4724}
4725
Tobin Ehlis85940f52016-07-07 16:57:21 -06004726TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4727 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4728 "due to an event dependency being destroyed.");
4729 ASSERT_NO_FATAL_FAILURE(InitState());
4730
4731 VkEvent event;
4732 VkEventCreateInfo evci = {};
4733 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4734 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4735 ASSERT_VK_SUCCESS(result);
4736
4737 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004738 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004739 m_commandBuffer->EndCommandBuffer();
4740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004742 // Destroy event dependency prior to submit to cause ERROR
4743 vkDestroyEvent(m_device->device(), event, NULL);
4744
4745 VkSubmitInfo submit_info = {};
4746 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4747 submit_info.commandBufferCount = 1;
4748 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4749 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4750
4751 m_errorMonitor->VerifyFound();
4752}
4753
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004754TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4755 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4756 "due to a query pool dependency being destroyed.");
4757 ASSERT_NO_FATAL_FAILURE(InitState());
4758
4759 VkQueryPool query_pool;
4760 VkQueryPoolCreateInfo qpci{};
4761 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4762 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4763 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004764 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004765 ASSERT_VK_SUCCESS(result);
4766
4767 m_commandBuffer->BeginCommandBuffer();
4768 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4769 m_commandBuffer->EndCommandBuffer();
4770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004772 // Destroy query pool dependency prior to submit to cause ERROR
4773 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4774
4775 VkSubmitInfo submit_info = {};
4776 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4777 submit_info.commandBufferCount = 1;
4778 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4779 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4780
4781 m_errorMonitor->VerifyFound();
4782}
4783
Tobin Ehlis24130d92016-07-08 15:50:53 -06004784TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4785 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4786 "due to a pipeline dependency being destroyed.");
4787 ASSERT_NO_FATAL_FAILURE(InitState());
4788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4789
4790 VkResult err;
4791
4792 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4793 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4794
4795 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004796 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004797 ASSERT_VK_SUCCESS(err);
4798
4799 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4800 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4801 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004802 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004803 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004804 vp_state_ci.scissorCount = 1;
4805 VkRect2D scissors = {}; // Dummy scissors to point to
4806 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004807
4808 VkPipelineShaderStageCreateInfo shaderStages[2];
4809 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4810
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004811 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4812 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4813 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004814 shaderStages[0] = vs.GetStageCreateInfo();
4815 shaderStages[1] = fs.GetStageCreateInfo();
4816
4817 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4818 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4819
4820 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4821 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4822 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4823
4824 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4825 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004826 rs_ci.rasterizerDiscardEnable = true;
4827 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004828
4829 VkPipelineColorBlendAttachmentState att = {};
4830 att.blendEnable = VK_FALSE;
4831 att.colorWriteMask = 0xf;
4832
4833 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4834 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4835 cb_ci.attachmentCount = 1;
4836 cb_ci.pAttachments = &att;
4837
4838 VkGraphicsPipelineCreateInfo gp_ci = {};
4839 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4840 gp_ci.stageCount = 2;
4841 gp_ci.pStages = shaderStages;
4842 gp_ci.pVertexInputState = &vi_ci;
4843 gp_ci.pInputAssemblyState = &ia_ci;
4844 gp_ci.pViewportState = &vp_state_ci;
4845 gp_ci.pRasterizationState = &rs_ci;
4846 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004847 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4848 gp_ci.layout = pipeline_layout;
4849 gp_ci.renderPass = renderPass();
4850
4851 VkPipelineCacheCreateInfo pc_ci = {};
4852 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4853
4854 VkPipeline pipeline;
4855 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004856 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004857 ASSERT_VK_SUCCESS(err);
4858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004859 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004860 ASSERT_VK_SUCCESS(err);
4861
4862 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004863 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004864 m_commandBuffer->EndCommandBuffer();
4865 // Now destroy pipeline in order to cause error when submitting
4866 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004869
4870 VkSubmitInfo submit_info = {};
4871 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4872 submit_info.commandBufferCount = 1;
4873 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4874 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4875
4876 m_errorMonitor->VerifyFound();
4877 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4878 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4879}
4880
Tobin Ehlis31289162016-08-17 14:57:58 -06004881TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4882 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4883 "due to a bound descriptor set with a buffer dependency "
4884 "being destroyed.");
4885 ASSERT_NO_FATAL_FAILURE(InitState());
4886 ASSERT_NO_FATAL_FAILURE(InitViewport());
4887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4888
4889 VkDescriptorPoolSize ds_type_count = {};
4890 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4891 ds_type_count.descriptorCount = 1;
4892
4893 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4894 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4895 ds_pool_ci.pNext = NULL;
4896 ds_pool_ci.maxSets = 1;
4897 ds_pool_ci.poolSizeCount = 1;
4898 ds_pool_ci.pPoolSizes = &ds_type_count;
4899
4900 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004901 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004902 ASSERT_VK_SUCCESS(err);
4903
4904 VkDescriptorSetLayoutBinding dsl_binding = {};
4905 dsl_binding.binding = 0;
4906 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4907 dsl_binding.descriptorCount = 1;
4908 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4909 dsl_binding.pImmutableSamplers = NULL;
4910
4911 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4912 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4913 ds_layout_ci.pNext = NULL;
4914 ds_layout_ci.bindingCount = 1;
4915 ds_layout_ci.pBindings = &dsl_binding;
4916 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004917 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004918 ASSERT_VK_SUCCESS(err);
4919
4920 VkDescriptorSet descriptorSet;
4921 VkDescriptorSetAllocateInfo alloc_info = {};
4922 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4923 alloc_info.descriptorSetCount = 1;
4924 alloc_info.descriptorPool = ds_pool;
4925 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004926 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004927 ASSERT_VK_SUCCESS(err);
4928
4929 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4930 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4931 pipeline_layout_ci.pNext = NULL;
4932 pipeline_layout_ci.setLayoutCount = 1;
4933 pipeline_layout_ci.pSetLayouts = &ds_layout;
4934
4935 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004936 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004937 ASSERT_VK_SUCCESS(err);
4938
4939 // Create a buffer to update the descriptor with
4940 uint32_t qfi = 0;
4941 VkBufferCreateInfo buffCI = {};
4942 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4943 buffCI.size = 1024;
4944 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4945 buffCI.queueFamilyIndexCount = 1;
4946 buffCI.pQueueFamilyIndices = &qfi;
4947
4948 VkBuffer buffer;
4949 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4950 ASSERT_VK_SUCCESS(err);
4951 // Allocate memory and bind to buffer so we can make it to the appropriate
4952 // error
4953 VkMemoryAllocateInfo mem_alloc = {};
4954 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4955 mem_alloc.pNext = NULL;
4956 mem_alloc.allocationSize = 1024;
4957 mem_alloc.memoryTypeIndex = 0;
4958
4959 VkMemoryRequirements memReqs;
4960 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004961 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004962 if (!pass) {
4963 vkDestroyBuffer(m_device->device(), buffer, NULL);
4964 return;
4965 }
4966
4967 VkDeviceMemory mem;
4968 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4969 ASSERT_VK_SUCCESS(err);
4970 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4971 ASSERT_VK_SUCCESS(err);
4972 // Correctly update descriptor to avoid "NOT_UPDATED" error
4973 VkDescriptorBufferInfo buffInfo = {};
4974 buffInfo.buffer = buffer;
4975 buffInfo.offset = 0;
4976 buffInfo.range = 1024;
4977
4978 VkWriteDescriptorSet descriptor_write;
4979 memset(&descriptor_write, 0, sizeof(descriptor_write));
4980 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4981 descriptor_write.dstSet = descriptorSet;
4982 descriptor_write.dstBinding = 0;
4983 descriptor_write.descriptorCount = 1;
4984 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4985 descriptor_write.pBufferInfo = &buffInfo;
4986
4987 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4988
4989 // Create PSO to be used for draw-time errors below
4990 char const *vsSource = "#version 450\n"
4991 "\n"
4992 "out gl_PerVertex { \n"
4993 " vec4 gl_Position;\n"
4994 "};\n"
4995 "void main(){\n"
4996 " gl_Position = vec4(1);\n"
4997 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004998 char const *fsSource = "#version 450\n"
4999 "\n"
5000 "layout(location=0) out vec4 x;\n"
5001 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5002 "void main(){\n"
5003 " x = vec4(bar.y);\n"
5004 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005005 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5006 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5007 VkPipelineObj pipe(m_device);
5008 pipe.AddShader(&vs);
5009 pipe.AddShader(&fs);
5010 pipe.AddColorAttachment();
5011 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5012
5013 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005014 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5015 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5016 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005017 Draw(1, 0, 0, 0);
5018 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005020 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5021 vkDestroyBuffer(m_device->device(), buffer, NULL);
5022 // Attempt to submit cmd buffer
5023 VkSubmitInfo submit_info = {};
5024 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5025 submit_info.commandBufferCount = 1;
5026 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5027 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5028 m_errorMonitor->VerifyFound();
5029 // Cleanup
5030 vkFreeMemory(m_device->device(), mem, NULL);
5031
5032 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5033 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5034 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5035}
5036
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005037TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5038 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5039 "due to a bound descriptor sets with a combined image "
5040 "sampler having their image, sampler, and descriptor set "
5041 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005042 "submit associated cmd buffers. Attempt to destroy a "
5043 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005044 ASSERT_NO_FATAL_FAILURE(InitState());
5045 ASSERT_NO_FATAL_FAILURE(InitViewport());
5046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5047
5048 VkDescriptorPoolSize ds_type_count = {};
5049 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5050 ds_type_count.descriptorCount = 1;
5051
5052 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5053 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5054 ds_pool_ci.pNext = NULL;
5055 ds_pool_ci.maxSets = 1;
5056 ds_pool_ci.poolSizeCount = 1;
5057 ds_pool_ci.pPoolSizes = &ds_type_count;
5058
5059 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005060 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005061 ASSERT_VK_SUCCESS(err);
5062
5063 VkDescriptorSetLayoutBinding dsl_binding = {};
5064 dsl_binding.binding = 0;
5065 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5066 dsl_binding.descriptorCount = 1;
5067 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5068 dsl_binding.pImmutableSamplers = NULL;
5069
5070 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5071 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5072 ds_layout_ci.pNext = NULL;
5073 ds_layout_ci.bindingCount = 1;
5074 ds_layout_ci.pBindings = &dsl_binding;
5075 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005076 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005077 ASSERT_VK_SUCCESS(err);
5078
5079 VkDescriptorSet descriptorSet;
5080 VkDescriptorSetAllocateInfo alloc_info = {};
5081 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5082 alloc_info.descriptorSetCount = 1;
5083 alloc_info.descriptorPool = ds_pool;
5084 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005085 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005086 ASSERT_VK_SUCCESS(err);
5087
5088 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5089 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5090 pipeline_layout_ci.pNext = NULL;
5091 pipeline_layout_ci.setLayoutCount = 1;
5092 pipeline_layout_ci.pSetLayouts = &ds_layout;
5093
5094 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005095 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005096 ASSERT_VK_SUCCESS(err);
5097
5098 // Create images to update the descriptor with
5099 VkImage image;
5100 VkImage image2;
5101 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5102 const int32_t tex_width = 32;
5103 const int32_t tex_height = 32;
5104 VkImageCreateInfo image_create_info = {};
5105 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5106 image_create_info.pNext = NULL;
5107 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5108 image_create_info.format = tex_format;
5109 image_create_info.extent.width = tex_width;
5110 image_create_info.extent.height = tex_height;
5111 image_create_info.extent.depth = 1;
5112 image_create_info.mipLevels = 1;
5113 image_create_info.arrayLayers = 1;
5114 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5115 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5116 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5117 image_create_info.flags = 0;
5118 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5119 ASSERT_VK_SUCCESS(err);
5120 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5121 ASSERT_VK_SUCCESS(err);
5122
5123 VkMemoryRequirements memory_reqs;
5124 VkDeviceMemory image_memory;
5125 bool pass;
5126 VkMemoryAllocateInfo memory_info = {};
5127 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5128 memory_info.pNext = NULL;
5129 memory_info.allocationSize = 0;
5130 memory_info.memoryTypeIndex = 0;
5131 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5132 // Allocate enough memory for both images
5133 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005134 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005135 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005136 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005137 ASSERT_VK_SUCCESS(err);
5138 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5139 ASSERT_VK_SUCCESS(err);
5140 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005141 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005142 ASSERT_VK_SUCCESS(err);
5143
5144 VkImageViewCreateInfo image_view_create_info = {};
5145 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5146 image_view_create_info.image = image;
5147 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5148 image_view_create_info.format = tex_format;
5149 image_view_create_info.subresourceRange.layerCount = 1;
5150 image_view_create_info.subresourceRange.baseMipLevel = 0;
5151 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005152 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005153
5154 VkImageView view;
5155 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005156 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005157 ASSERT_VK_SUCCESS(err);
5158 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005159 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005160 ASSERT_VK_SUCCESS(err);
5161 // Create Samplers
5162 VkSamplerCreateInfo sampler_ci = {};
5163 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5164 sampler_ci.pNext = NULL;
5165 sampler_ci.magFilter = VK_FILTER_NEAREST;
5166 sampler_ci.minFilter = VK_FILTER_NEAREST;
5167 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5168 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5169 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5170 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5171 sampler_ci.mipLodBias = 1.0;
5172 sampler_ci.anisotropyEnable = VK_FALSE;
5173 sampler_ci.maxAnisotropy = 1;
5174 sampler_ci.compareEnable = VK_FALSE;
5175 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5176 sampler_ci.minLod = 1.0;
5177 sampler_ci.maxLod = 1.0;
5178 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5179 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5180 VkSampler sampler;
5181 VkSampler sampler2;
5182 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5183 ASSERT_VK_SUCCESS(err);
5184 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5185 ASSERT_VK_SUCCESS(err);
5186 // Update descriptor with image and sampler
5187 VkDescriptorImageInfo img_info = {};
5188 img_info.sampler = sampler;
5189 img_info.imageView = view;
5190 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5191
5192 VkWriteDescriptorSet descriptor_write;
5193 memset(&descriptor_write, 0, sizeof(descriptor_write));
5194 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5195 descriptor_write.dstSet = descriptorSet;
5196 descriptor_write.dstBinding = 0;
5197 descriptor_write.descriptorCount = 1;
5198 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5199 descriptor_write.pImageInfo = &img_info;
5200
5201 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5202
5203 // Create PSO to be used for draw-time errors below
5204 char const *vsSource = "#version 450\n"
5205 "\n"
5206 "out gl_PerVertex { \n"
5207 " vec4 gl_Position;\n"
5208 "};\n"
5209 "void main(){\n"
5210 " gl_Position = vec4(1);\n"
5211 "}\n";
5212 char const *fsSource = "#version 450\n"
5213 "\n"
5214 "layout(set=0, binding=0) uniform sampler2D s;\n"
5215 "layout(location=0) out vec4 x;\n"
5216 "void main(){\n"
5217 " x = texture(s, vec2(1));\n"
5218 "}\n";
5219 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5220 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5221 VkPipelineObj pipe(m_device);
5222 pipe.AddShader(&vs);
5223 pipe.AddShader(&fs);
5224 pipe.AddColorAttachment();
5225 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5226
5227 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005229 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005230 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5231 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5232 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005233 Draw(1, 0, 0, 0);
5234 EndCommandBuffer();
5235 // Destroy sampler invalidates the cmd buffer, causing error on submit
5236 vkDestroySampler(m_device->device(), sampler, NULL);
5237 // Attempt to submit cmd buffer
5238 VkSubmitInfo submit_info = {};
5239 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5240 submit_info.commandBufferCount = 1;
5241 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5242 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5243 m_errorMonitor->VerifyFound();
5244 // Now re-update descriptor with valid sampler and delete image
5245 img_info.sampler = sampler2;
5246 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005248 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005249 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5250 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5251 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005252 Draw(1, 0, 0, 0);
5253 EndCommandBuffer();
5254 // Destroy image invalidates the cmd buffer, causing error on submit
5255 vkDestroyImage(m_device->device(), image, NULL);
5256 // Attempt to submit cmd buffer
5257 submit_info = {};
5258 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5259 submit_info.commandBufferCount = 1;
5260 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5261 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5262 m_errorMonitor->VerifyFound();
5263 // Now update descriptor to be valid, but then free descriptor
5264 img_info.imageView = view2;
5265 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005267 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005268 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5269 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5270 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005271 Draw(1, 0, 0, 0);
5272 EndCommandBuffer();
5273 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005275 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005276 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005277 // Attempt to submit cmd buffer
5278 submit_info = {};
5279 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5280 submit_info.commandBufferCount = 1;
5281 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5282 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5283 m_errorMonitor->VerifyFound();
5284 // Cleanup
5285 vkFreeMemory(m_device->device(), image_memory, NULL);
5286 vkDestroySampler(m_device->device(), sampler2, NULL);
5287 vkDestroyImage(m_device->device(), image2, NULL);
5288 vkDestroyImageView(m_device->device(), view, NULL);
5289 vkDestroyImageView(m_device->device(), view2, NULL);
5290 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5291 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5293}
5294
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005295TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5296 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5297 ASSERT_NO_FATAL_FAILURE(InitState());
5298 ASSERT_NO_FATAL_FAILURE(InitViewport());
5299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5300
5301 VkDescriptorPoolSize ds_type_count = {};
5302 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5303 ds_type_count.descriptorCount = 1;
5304
5305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5307 ds_pool_ci.pNext = NULL;
5308 ds_pool_ci.maxSets = 1;
5309 ds_pool_ci.poolSizeCount = 1;
5310 ds_pool_ci.pPoolSizes = &ds_type_count;
5311
5312 VkDescriptorPool ds_pool;
5313 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5314 ASSERT_VK_SUCCESS(err);
5315
5316 VkDescriptorSetLayoutBinding dsl_binding = {};
5317 dsl_binding.binding = 0;
5318 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5319 dsl_binding.descriptorCount = 1;
5320 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5321 dsl_binding.pImmutableSamplers = NULL;
5322
5323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5325 ds_layout_ci.pNext = NULL;
5326 ds_layout_ci.bindingCount = 1;
5327 ds_layout_ci.pBindings = &dsl_binding;
5328 VkDescriptorSetLayout ds_layout;
5329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5330 ASSERT_VK_SUCCESS(err);
5331
5332 VkDescriptorSet descriptor_set;
5333 VkDescriptorSetAllocateInfo alloc_info = {};
5334 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5335 alloc_info.descriptorSetCount = 1;
5336 alloc_info.descriptorPool = ds_pool;
5337 alloc_info.pSetLayouts = &ds_layout;
5338 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5339 ASSERT_VK_SUCCESS(err);
5340
5341 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5342 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5343 pipeline_layout_ci.pNext = NULL;
5344 pipeline_layout_ci.setLayoutCount = 1;
5345 pipeline_layout_ci.pSetLayouts = &ds_layout;
5346
5347 VkPipelineLayout pipeline_layout;
5348 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5349 ASSERT_VK_SUCCESS(err);
5350
5351 // Create image to update the descriptor with
5352 VkImageObj image(m_device);
5353 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5354 ASSERT_TRUE(image.initialized());
5355
5356 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5357 // Create Sampler
5358 VkSamplerCreateInfo sampler_ci = {};
5359 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5360 sampler_ci.pNext = NULL;
5361 sampler_ci.magFilter = VK_FILTER_NEAREST;
5362 sampler_ci.minFilter = VK_FILTER_NEAREST;
5363 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5364 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5365 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5366 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5367 sampler_ci.mipLodBias = 1.0;
5368 sampler_ci.anisotropyEnable = VK_FALSE;
5369 sampler_ci.maxAnisotropy = 1;
5370 sampler_ci.compareEnable = VK_FALSE;
5371 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5372 sampler_ci.minLod = 1.0;
5373 sampler_ci.maxLod = 1.0;
5374 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5375 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5376 VkSampler sampler;
5377 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5378 ASSERT_VK_SUCCESS(err);
5379 // Update descriptor with image and sampler
5380 VkDescriptorImageInfo img_info = {};
5381 img_info.sampler = sampler;
5382 img_info.imageView = view;
5383 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5384
5385 VkWriteDescriptorSet descriptor_write;
5386 memset(&descriptor_write, 0, sizeof(descriptor_write));
5387 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5388 descriptor_write.dstSet = descriptor_set;
5389 descriptor_write.dstBinding = 0;
5390 descriptor_write.descriptorCount = 1;
5391 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5392 descriptor_write.pImageInfo = &img_info;
5393
5394 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5395
5396 // Create PSO to be used for draw-time errors below
5397 char const *vsSource = "#version 450\n"
5398 "\n"
5399 "out gl_PerVertex { \n"
5400 " vec4 gl_Position;\n"
5401 "};\n"
5402 "void main(){\n"
5403 " gl_Position = vec4(1);\n"
5404 "}\n";
5405 char const *fsSource = "#version 450\n"
5406 "\n"
5407 "layout(set=0, binding=0) uniform sampler2D s;\n"
5408 "layout(location=0) out vec4 x;\n"
5409 "void main(){\n"
5410 " x = texture(s, vec2(1));\n"
5411 "}\n";
5412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5413 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5414 VkPipelineObj pipe(m_device);
5415 pipe.AddShader(&vs);
5416 pipe.AddShader(&fs);
5417 pipe.AddColorAttachment();
5418 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5419
5420 BeginCommandBuffer();
5421 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5422 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5423 &descriptor_set, 0, NULL);
5424 Draw(1, 0, 0, 0);
5425 EndCommandBuffer();
5426 // Submit cmd buffer to put pool in-flight
5427 VkSubmitInfo submit_info = {};
5428 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5429 submit_info.commandBufferCount = 1;
5430 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5431 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5432 // Destroy pool while in-flight, causing error
5433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5434 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5435 m_errorMonitor->VerifyFound();
5436 vkQueueWaitIdle(m_device->m_queue);
5437 // Cleanup
5438 vkDestroySampler(m_device->device(), sampler, NULL);
5439 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5440 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5441 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5442}
5443
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005444TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5445 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5446 ASSERT_NO_FATAL_FAILURE(InitState());
5447 ASSERT_NO_FATAL_FAILURE(InitViewport());
5448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5449
5450 VkDescriptorPoolSize ds_type_count = {};
5451 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5452 ds_type_count.descriptorCount = 1;
5453
5454 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5455 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5456 ds_pool_ci.pNext = NULL;
5457 ds_pool_ci.maxSets = 1;
5458 ds_pool_ci.poolSizeCount = 1;
5459 ds_pool_ci.pPoolSizes = &ds_type_count;
5460
5461 VkDescriptorPool ds_pool;
5462 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5463 ASSERT_VK_SUCCESS(err);
5464
5465 VkDescriptorSetLayoutBinding dsl_binding = {};
5466 dsl_binding.binding = 0;
5467 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5468 dsl_binding.descriptorCount = 1;
5469 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5470 dsl_binding.pImmutableSamplers = NULL;
5471
5472 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5473 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5474 ds_layout_ci.pNext = NULL;
5475 ds_layout_ci.bindingCount = 1;
5476 ds_layout_ci.pBindings = &dsl_binding;
5477 VkDescriptorSetLayout ds_layout;
5478 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5479 ASSERT_VK_SUCCESS(err);
5480
5481 VkDescriptorSet descriptorSet;
5482 VkDescriptorSetAllocateInfo alloc_info = {};
5483 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5484 alloc_info.descriptorSetCount = 1;
5485 alloc_info.descriptorPool = ds_pool;
5486 alloc_info.pSetLayouts = &ds_layout;
5487 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5488 ASSERT_VK_SUCCESS(err);
5489
5490 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5491 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5492 pipeline_layout_ci.pNext = NULL;
5493 pipeline_layout_ci.setLayoutCount = 1;
5494 pipeline_layout_ci.pSetLayouts = &ds_layout;
5495
5496 VkPipelineLayout pipeline_layout;
5497 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5498 ASSERT_VK_SUCCESS(err);
5499
5500 // Create images to update the descriptor with
5501 VkImage image;
5502 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5503 const int32_t tex_width = 32;
5504 const int32_t tex_height = 32;
5505 VkImageCreateInfo image_create_info = {};
5506 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5507 image_create_info.pNext = NULL;
5508 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5509 image_create_info.format = tex_format;
5510 image_create_info.extent.width = tex_width;
5511 image_create_info.extent.height = tex_height;
5512 image_create_info.extent.depth = 1;
5513 image_create_info.mipLevels = 1;
5514 image_create_info.arrayLayers = 1;
5515 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5516 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5517 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5518 image_create_info.flags = 0;
5519 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5520 ASSERT_VK_SUCCESS(err);
5521 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5522 VkMemoryRequirements memory_reqs;
5523 VkDeviceMemory image_memory;
5524 bool pass;
5525 VkMemoryAllocateInfo memory_info = {};
5526 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5527 memory_info.pNext = NULL;
5528 memory_info.allocationSize = 0;
5529 memory_info.memoryTypeIndex = 0;
5530 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5531 // Allocate enough memory for image
5532 memory_info.allocationSize = memory_reqs.size;
5533 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5534 ASSERT_TRUE(pass);
5535 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5536 ASSERT_VK_SUCCESS(err);
5537 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5538 ASSERT_VK_SUCCESS(err);
5539
5540 VkImageViewCreateInfo image_view_create_info = {};
5541 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5542 image_view_create_info.image = image;
5543 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5544 image_view_create_info.format = tex_format;
5545 image_view_create_info.subresourceRange.layerCount = 1;
5546 image_view_create_info.subresourceRange.baseMipLevel = 0;
5547 image_view_create_info.subresourceRange.levelCount = 1;
5548 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5549
5550 VkImageView view;
5551 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5552 ASSERT_VK_SUCCESS(err);
5553 // Create Samplers
5554 VkSamplerCreateInfo sampler_ci = {};
5555 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5556 sampler_ci.pNext = NULL;
5557 sampler_ci.magFilter = VK_FILTER_NEAREST;
5558 sampler_ci.minFilter = VK_FILTER_NEAREST;
5559 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5560 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5561 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5562 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5563 sampler_ci.mipLodBias = 1.0;
5564 sampler_ci.anisotropyEnable = VK_FALSE;
5565 sampler_ci.maxAnisotropy = 1;
5566 sampler_ci.compareEnable = VK_FALSE;
5567 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5568 sampler_ci.minLod = 1.0;
5569 sampler_ci.maxLod = 1.0;
5570 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5571 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5572 VkSampler sampler;
5573 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5574 ASSERT_VK_SUCCESS(err);
5575 // Update descriptor with image and sampler
5576 VkDescriptorImageInfo img_info = {};
5577 img_info.sampler = sampler;
5578 img_info.imageView = view;
5579 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5580
5581 VkWriteDescriptorSet descriptor_write;
5582 memset(&descriptor_write, 0, sizeof(descriptor_write));
5583 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5584 descriptor_write.dstSet = descriptorSet;
5585 descriptor_write.dstBinding = 0;
5586 descriptor_write.descriptorCount = 1;
5587 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5588 descriptor_write.pImageInfo = &img_info;
5589 // Break memory binding and attempt update
5590 vkFreeMemory(m_device->device(), image_memory, nullptr);
5591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005592 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5594 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5595 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5596 m_errorMonitor->VerifyFound();
5597 // Cleanup
5598 vkDestroyImage(m_device->device(), image, NULL);
5599 vkDestroySampler(m_device->device(), sampler, NULL);
5600 vkDestroyImageView(m_device->device(), view, NULL);
5601 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5602 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5603 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5604}
5605
Karl Schultz6addd812016-02-02 17:17:23 -07005606TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005607 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5608 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005609 // Create a valid cmd buffer
5610 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005611 uint64_t fake_pipeline_handle = 0xbaad6001;
5612 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005613 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5615
5616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005617 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005618 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005619 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005620
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005621 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005622 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 -06005623 Draw(1, 0, 0, 0);
5624 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005625
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005626 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005627 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 +12005628 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005629 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5630 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005631}
5632
Karl Schultz6addd812016-02-02 17:17:23 -07005633TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005634 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005635 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005636
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005638
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005639 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005640 ASSERT_NO_FATAL_FAILURE(InitViewport());
5641 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005642 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005643 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5644 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005645
5646 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005647 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5648 ds_pool_ci.pNext = NULL;
5649 ds_pool_ci.maxSets = 1;
5650 ds_pool_ci.poolSizeCount = 1;
5651 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005652
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005653 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005654 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005655 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005656
Tony Barboureb254902015-07-15 12:50:33 -06005657 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005658 dsl_binding.binding = 0;
5659 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5660 dsl_binding.descriptorCount = 1;
5661 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5662 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005663
Tony Barboureb254902015-07-15 12:50:33 -06005664 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005665 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5666 ds_layout_ci.pNext = NULL;
5667 ds_layout_ci.bindingCount = 1;
5668 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005669 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005670 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005671 ASSERT_VK_SUCCESS(err);
5672
5673 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005674 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005675 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005676 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005677 alloc_info.descriptorPool = ds_pool;
5678 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005679 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005680 ASSERT_VK_SUCCESS(err);
5681
Tony Barboureb254902015-07-15 12:50:33 -06005682 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005683 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5684 pipeline_layout_ci.pNext = NULL;
5685 pipeline_layout_ci.setLayoutCount = 1;
5686 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005687
5688 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005689 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005690 ASSERT_VK_SUCCESS(err);
5691
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005692 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005693 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005694 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005695 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005696
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005697 VkPipelineObj pipe(m_device);
5698 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005699 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005700 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005701 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005702
5703 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005704 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5705 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5706 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005708 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005709
Chia-I Wuf7458c52015-10-26 21:10:41 +08005710 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5711 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5712 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005713}
5714
Karl Schultz6addd812016-02-02 17:17:23 -07005715TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005716 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005717 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5720 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005721
5722 ASSERT_NO_FATAL_FAILURE(InitState());
5723 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005724 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5725 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005726
5727 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005728 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5729 ds_pool_ci.pNext = NULL;
5730 ds_pool_ci.maxSets = 1;
5731 ds_pool_ci.poolSizeCount = 1;
5732 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005733
5734 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005735 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005736 ASSERT_VK_SUCCESS(err);
5737
5738 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005739 dsl_binding.binding = 0;
5740 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5741 dsl_binding.descriptorCount = 1;
5742 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5743 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005744
5745 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005746 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5747 ds_layout_ci.pNext = NULL;
5748 ds_layout_ci.bindingCount = 1;
5749 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005750 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005751 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005752 ASSERT_VK_SUCCESS(err);
5753
5754 VkDescriptorSet descriptorSet;
5755 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005756 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005757 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005758 alloc_info.descriptorPool = ds_pool;
5759 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005760 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005761 ASSERT_VK_SUCCESS(err);
5762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005763 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005764 VkWriteDescriptorSet descriptor_write;
5765 memset(&descriptor_write, 0, sizeof(descriptor_write));
5766 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5767 descriptor_write.dstSet = descriptorSet;
5768 descriptor_write.dstBinding = 0;
5769 descriptor_write.descriptorCount = 1;
5770 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5771 descriptor_write.pTexelBufferView = &view;
5772
5773 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5774
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005775 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005776
5777 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5778 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5779}
5780
Mark Youngd339ba32016-05-30 13:28:35 -06005781TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005782 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 -06005783
5784 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005786 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005787
5788 ASSERT_NO_FATAL_FAILURE(InitState());
5789
5790 // Create a buffer with no bound memory and then attempt to create
5791 // a buffer view.
5792 VkBufferCreateInfo buff_ci = {};
5793 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005794 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005795 buff_ci.size = 256;
5796 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5797 VkBuffer buffer;
5798 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5799 ASSERT_VK_SUCCESS(err);
5800
5801 VkBufferViewCreateInfo buff_view_ci = {};
5802 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5803 buff_view_ci.buffer = buffer;
5804 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5805 buff_view_ci.range = VK_WHOLE_SIZE;
5806 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005807 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005808
5809 m_errorMonitor->VerifyFound();
5810 vkDestroyBuffer(m_device->device(), buffer, NULL);
5811 // If last error is success, it still created the view, so delete it.
5812 if (err == VK_SUCCESS) {
5813 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5814 }
5815}
5816
Karl Schultz6addd812016-02-02 17:17:23 -07005817TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5818 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5819 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005820 // 1. No dynamicOffset supplied
5821 // 2. Too many dynamicOffsets supplied
5822 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005823 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5825 "0 dynamicOffsets are left in "
5826 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005827
5828 ASSERT_NO_FATAL_FAILURE(InitState());
5829 ASSERT_NO_FATAL_FAILURE(InitViewport());
5830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5831
5832 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005833 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5834 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005835
5836 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005837 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5838 ds_pool_ci.pNext = NULL;
5839 ds_pool_ci.maxSets = 1;
5840 ds_pool_ci.poolSizeCount = 1;
5841 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005842
5843 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005844 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005845 ASSERT_VK_SUCCESS(err);
5846
5847 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005848 dsl_binding.binding = 0;
5849 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5850 dsl_binding.descriptorCount = 1;
5851 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5852 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005853
5854 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005855 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5856 ds_layout_ci.pNext = NULL;
5857 ds_layout_ci.bindingCount = 1;
5858 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005859 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005860 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005861 ASSERT_VK_SUCCESS(err);
5862
5863 VkDescriptorSet descriptorSet;
5864 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005865 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005866 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005867 alloc_info.descriptorPool = ds_pool;
5868 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005869 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005870 ASSERT_VK_SUCCESS(err);
5871
5872 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005873 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5874 pipeline_layout_ci.pNext = NULL;
5875 pipeline_layout_ci.setLayoutCount = 1;
5876 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005877
5878 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005879 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005880 ASSERT_VK_SUCCESS(err);
5881
5882 // Create a buffer to update the descriptor with
5883 uint32_t qfi = 0;
5884 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005885 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5886 buffCI.size = 1024;
5887 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5888 buffCI.queueFamilyIndexCount = 1;
5889 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005890
5891 VkBuffer dyub;
5892 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5893 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005894 // Allocate memory and bind to buffer so we can make it to the appropriate
5895 // error
5896 VkMemoryAllocateInfo mem_alloc = {};
5897 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5898 mem_alloc.pNext = NULL;
5899 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005900 mem_alloc.memoryTypeIndex = 0;
5901
5902 VkMemoryRequirements memReqs;
5903 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005904 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005905 if (!pass) {
5906 vkDestroyBuffer(m_device->device(), dyub, NULL);
5907 return;
5908 }
5909
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005910 VkDeviceMemory mem;
5911 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5912 ASSERT_VK_SUCCESS(err);
5913 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5914 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005915 // Correctly update descriptor to avoid "NOT_UPDATED" error
5916 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005917 buffInfo.buffer = dyub;
5918 buffInfo.offset = 0;
5919 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005920
5921 VkWriteDescriptorSet descriptor_write;
5922 memset(&descriptor_write, 0, sizeof(descriptor_write));
5923 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5924 descriptor_write.dstSet = descriptorSet;
5925 descriptor_write.dstBinding = 0;
5926 descriptor_write.descriptorCount = 1;
5927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5928 descriptor_write.pBufferInfo = &buffInfo;
5929
5930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5931
5932 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005933 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5934 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005935 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005936 uint32_t pDynOff[2] = {512, 756};
5937 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5939 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5940 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5941 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005942 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005943 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5945 "offset 0 and range 1024 that "
5946 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005947 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005948 char const *vsSource = "#version 450\n"
5949 "\n"
5950 "out gl_PerVertex { \n"
5951 " vec4 gl_Position;\n"
5952 "};\n"
5953 "void main(){\n"
5954 " gl_Position = vec4(1);\n"
5955 "}\n";
5956 char const *fsSource = "#version 450\n"
5957 "\n"
5958 "layout(location=0) out vec4 x;\n"
5959 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5960 "void main(){\n"
5961 " x = vec4(bar.y);\n"
5962 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005963 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5964 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5965 VkPipelineObj pipe(m_device);
5966 pipe.AddShader(&vs);
5967 pipe.AddShader(&fs);
5968 pipe.AddColorAttachment();
5969 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5970
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005971 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005972 // This update should succeed, but offset size of 512 will overstep buffer
5973 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005974 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5975 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005976 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005977 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005978
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005979 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005980 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005981
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005982 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005983 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005984 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5985}
5986
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005987TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5988 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5989 "that doesn't have memory bound");
5990 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005992 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5994 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005995
5996 ASSERT_NO_FATAL_FAILURE(InitState());
5997 ASSERT_NO_FATAL_FAILURE(InitViewport());
5998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5999
6000 VkDescriptorPoolSize ds_type_count = {};
6001 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6002 ds_type_count.descriptorCount = 1;
6003
6004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6006 ds_pool_ci.pNext = NULL;
6007 ds_pool_ci.maxSets = 1;
6008 ds_pool_ci.poolSizeCount = 1;
6009 ds_pool_ci.pPoolSizes = &ds_type_count;
6010
6011 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006012 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006013 ASSERT_VK_SUCCESS(err);
6014
6015 VkDescriptorSetLayoutBinding dsl_binding = {};
6016 dsl_binding.binding = 0;
6017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6018 dsl_binding.descriptorCount = 1;
6019 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6020 dsl_binding.pImmutableSamplers = NULL;
6021
6022 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6023 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6024 ds_layout_ci.pNext = NULL;
6025 ds_layout_ci.bindingCount = 1;
6026 ds_layout_ci.pBindings = &dsl_binding;
6027 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006029 ASSERT_VK_SUCCESS(err);
6030
6031 VkDescriptorSet descriptorSet;
6032 VkDescriptorSetAllocateInfo alloc_info = {};
6033 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6034 alloc_info.descriptorSetCount = 1;
6035 alloc_info.descriptorPool = ds_pool;
6036 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006037 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006038 ASSERT_VK_SUCCESS(err);
6039
6040 // Create a buffer to update the descriptor with
6041 uint32_t qfi = 0;
6042 VkBufferCreateInfo buffCI = {};
6043 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6044 buffCI.size = 1024;
6045 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6046 buffCI.queueFamilyIndexCount = 1;
6047 buffCI.pQueueFamilyIndices = &qfi;
6048
6049 VkBuffer dyub;
6050 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6051 ASSERT_VK_SUCCESS(err);
6052
6053 // Attempt to update descriptor without binding memory to it
6054 VkDescriptorBufferInfo buffInfo = {};
6055 buffInfo.buffer = dyub;
6056 buffInfo.offset = 0;
6057 buffInfo.range = 1024;
6058
6059 VkWriteDescriptorSet descriptor_write;
6060 memset(&descriptor_write, 0, sizeof(descriptor_write));
6061 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6062 descriptor_write.dstSet = descriptorSet;
6063 descriptor_write.dstBinding = 0;
6064 descriptor_write.descriptorCount = 1;
6065 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6066 descriptor_write.pBufferInfo = &buffInfo;
6067
6068 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6069 m_errorMonitor->VerifyFound();
6070
6071 vkDestroyBuffer(m_device->device(), dyub, NULL);
6072 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6073 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6074}
6075
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006076TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006077 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006078 ASSERT_NO_FATAL_FAILURE(InitState());
6079 ASSERT_NO_FATAL_FAILURE(InitViewport());
6080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6081
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006082 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006083 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006084 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6085 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6086 pipeline_layout_ci.pushConstantRangeCount = 1;
6087 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6088
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006089 //
6090 // Check for invalid push constant ranges in pipeline layouts.
6091 //
6092 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006093 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006094 char const *msg;
6095 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006096
Karl Schultzc81037d2016-05-12 08:11:23 -06006097 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6098 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6099 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6100 "vkCreatePipelineLayout() call has push constants index 0 with "
6101 "size 0."},
6102 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6103 "vkCreatePipelineLayout() call has push constants index 0 with "
6104 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006105 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006106 "vkCreatePipelineLayout() call has push constants index 0 with "
6107 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006108 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006109 "vkCreatePipelineLayout() call has push constants index 0 with "
6110 "size 0."},
6111 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6112 "vkCreatePipelineLayout() call has push constants index 0 with "
6113 "offset 1. Offset must"},
6114 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6115 "vkCreatePipelineLayout() call has push constants index 0 "
6116 "with offset "},
6117 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6118 "vkCreatePipelineLayout() call has push constants "
6119 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006120 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006121 "vkCreatePipelineLayout() call has push constants index 0 "
6122 "with offset "},
6123 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6124 "vkCreatePipelineLayout() call has push "
6125 "constants index 0 with offset "},
6126 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6127 "vkCreatePipelineLayout() call has push "
6128 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006129 }};
6130
6131 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006132 for (const auto &iter : range_tests) {
6133 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6135 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006136 m_errorMonitor->VerifyFound();
6137 if (VK_SUCCESS == err) {
6138 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6139 }
6140 }
6141
6142 // Check for invalid stage flag
6143 pc_range.offset = 0;
6144 pc_range.size = 16;
6145 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006146 m_errorMonitor->SetDesiredFailureMsg(
6147 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6148 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006149 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006150 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006151 if (VK_SUCCESS == err) {
6152 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6153 }
6154
6155 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006156 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006157 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006158 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006159 char const *msg;
6160 };
6161
Karl Schultzc81037d2016-05-12 08:11:23 -06006162 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006163 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6164 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6165 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6166 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6167 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006168 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006169 {
6170 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6171 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6172 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6173 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6174 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006175 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006176 },
6177 {
6178 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6179 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6180 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6181 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6182 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006183 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006184 },
6185 {
6186 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6187 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6188 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6189 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6190 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006191 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006192 },
6193 {
6194 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6195 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6196 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6197 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6198 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006199 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006200 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006201
Karl Schultzc81037d2016-05-12 08:11:23 -06006202 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006203 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006204 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6206 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006207 m_errorMonitor->VerifyFound();
6208 if (VK_SUCCESS == err) {
6209 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6210 }
6211 }
6212
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006213 //
6214 // CmdPushConstants tests
6215 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006216 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006217
6218 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006219 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6220 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006221 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6222 "vkCmdPushConstants() call has push constants with size 1. Size "
6223 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006224 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006225 "vkCmdPushConstants() call has push constants with size 1. Size "
6226 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006227 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006228 "vkCmdPushConstants() call has push constants with offset 1. "
6229 "Offset must be a multiple of 4."},
6230 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6231 "vkCmdPushConstants() call has push constants with offset 1. "
6232 "Offset must be a multiple of 4."},
6233 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6234 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6235 "0x1 not within flag-matching ranges in pipeline layout"},
6236 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6237 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6238 "0x1 not within flag-matching ranges in pipeline layout"},
6239 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6240 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6241 "0x1 not within flag-matching ranges in pipeline layout"},
6242 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6243 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6244 "0x1 not within flag-matching ranges in pipeline layout"},
6245 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6246 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6247 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006248 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006249 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6250 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006251 }};
6252
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006253 BeginCommandBuffer();
6254
6255 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006256 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006257 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006258 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006259 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006260 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006261 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006262 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006263 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6265 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006266 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006267 m_errorMonitor->VerifyFound();
6268 }
6269
6270 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006272 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006273 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006274 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006275
Karl Schultzc81037d2016-05-12 08:11:23 -06006276 // overlapping range tests with cmd
6277 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6278 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6279 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6280 "0x1 not within flag-matching ranges in pipeline layout"},
6281 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6282 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6283 "0x1 not within flag-matching ranges in pipeline layout"},
6284 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6285 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6286 "0x1 not within flag-matching ranges in pipeline layout"},
6287 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006288 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006289 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006290 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6291 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006292 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006293 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006294 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006295 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006296 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006297 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6299 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006300 iter.range.size, dummy_values);
6301 m_errorMonitor->VerifyFound();
6302 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6304
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006305 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006306}
6307
Karl Schultz6addd812016-02-02 17:17:23 -07006308TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006309 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006310 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006311
6312 ASSERT_NO_FATAL_FAILURE(InitState());
6313 ASSERT_NO_FATAL_FAILURE(InitViewport());
6314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6315
Mike Stroyanb8a61002016-06-20 16:00:28 -06006316 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6317 VkImageTiling tiling;
6318 VkFormatProperties format_properties;
6319 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006320 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006321 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006322 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006323 tiling = VK_IMAGE_TILING_OPTIMAL;
6324 } else {
6325 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6326 "skipped.\n");
6327 return;
6328 }
6329
Tobin Ehlis559c6382015-11-05 09:52:49 -07006330 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6331 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006332 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6333 ds_type_count[0].descriptorCount = 10;
6334 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6335 ds_type_count[1].descriptorCount = 2;
6336 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6337 ds_type_count[2].descriptorCount = 2;
6338 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6339 ds_type_count[3].descriptorCount = 5;
6340 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6341 // type
6342 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6343 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6344 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006345
6346 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006347 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6348 ds_pool_ci.pNext = NULL;
6349 ds_pool_ci.maxSets = 5;
6350 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6351 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006352
6353 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006354 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006355 ASSERT_VK_SUCCESS(err);
6356
6357 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6358 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006359 dsl_binding[0].binding = 0;
6360 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6361 dsl_binding[0].descriptorCount = 5;
6362 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6363 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006364
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006365 // Create layout identical to set0 layout but w/ different stageFlags
6366 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006367 dsl_fs_stage_only.binding = 0;
6368 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6369 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6371 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006372 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006373 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006374 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6375 ds_layout_ci.pNext = NULL;
6376 ds_layout_ci.bindingCount = 1;
6377 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006378 static const uint32_t NUM_LAYOUTS = 4;
6379 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006380 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006381 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6382 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006383 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006384 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006385 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006387 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006388 dsl_binding[0].binding = 0;
6389 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006390 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006391 dsl_binding[1].binding = 1;
6392 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6393 dsl_binding[1].descriptorCount = 2;
6394 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6395 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006396 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006397 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006398 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006399 ASSERT_VK_SUCCESS(err);
6400 dsl_binding[0].binding = 0;
6401 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006402 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006403 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006404 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006405 ASSERT_VK_SUCCESS(err);
6406 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006407 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006409 ASSERT_VK_SUCCESS(err);
6410
6411 static const uint32_t NUM_SETS = 4;
6412 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6413 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006414 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006415 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006416 alloc_info.descriptorPool = ds_pool;
6417 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006419 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006420 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006421 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006422 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006423 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006424 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006425
6426 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006427 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6428 pipeline_layout_ci.pNext = NULL;
6429 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6430 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006431
6432 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006433 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006434 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006435 // Create pipelineLayout with only one setLayout
6436 pipeline_layout_ci.setLayoutCount = 1;
6437 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006438 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006439 ASSERT_VK_SUCCESS(err);
6440 // Create pipelineLayout with 2 descriptor setLayout at index 0
6441 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6442 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006444 ASSERT_VK_SUCCESS(err);
6445 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6446 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6447 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006448 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006449 ASSERT_VK_SUCCESS(err);
6450 // Create pipelineLayout with UB type, but stageFlags for FS only
6451 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6452 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006453 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006454 ASSERT_VK_SUCCESS(err);
6455 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6456 VkDescriptorSetLayout pl_bad_s0[2] = {};
6457 pl_bad_s0[0] = ds_layout_fs_only;
6458 pl_bad_s0[1] = ds_layout[1];
6459 pipeline_layout_ci.setLayoutCount = 2;
6460 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6461 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006462 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006463 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006464
6465 // Create a buffer to update the descriptor with
6466 uint32_t qfi = 0;
6467 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006468 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6469 buffCI.size = 1024;
6470 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6471 buffCI.queueFamilyIndexCount = 1;
6472 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006473
6474 VkBuffer dyub;
6475 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6476 ASSERT_VK_SUCCESS(err);
6477 // Correctly update descriptor to avoid "NOT_UPDATED" error
6478 static const uint32_t NUM_BUFFS = 5;
6479 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006480 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006481 buffInfo[i].buffer = dyub;
6482 buffInfo[i].offset = 0;
6483 buffInfo[i].range = 1024;
6484 }
Karl Schultz6addd812016-02-02 17:17:23 -07006485 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006486 const int32_t tex_width = 32;
6487 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006488 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006489 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6490 image_create_info.pNext = NULL;
6491 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6492 image_create_info.format = tex_format;
6493 image_create_info.extent.width = tex_width;
6494 image_create_info.extent.height = tex_height;
6495 image_create_info.extent.depth = 1;
6496 image_create_info.mipLevels = 1;
6497 image_create_info.arrayLayers = 1;
6498 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006499 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006500 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006501 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006502 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6503 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006504
Karl Schultz6addd812016-02-02 17:17:23 -07006505 VkMemoryRequirements memReqs;
6506 VkDeviceMemory imageMem;
6507 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006508 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006509 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6510 memAlloc.pNext = NULL;
6511 memAlloc.allocationSize = 0;
6512 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006513 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6514 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006515 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006516 ASSERT_TRUE(pass);
6517 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6518 ASSERT_VK_SUCCESS(err);
6519 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6520 ASSERT_VK_SUCCESS(err);
6521
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006522 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006523 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6524 image_view_create_info.image = image;
6525 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6526 image_view_create_info.format = tex_format;
6527 image_view_create_info.subresourceRange.layerCount = 1;
6528 image_view_create_info.subresourceRange.baseMipLevel = 0;
6529 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006530 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006531
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006532 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006533 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006534 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006535 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006536 imageInfo[0].imageView = view;
6537 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6538 imageInfo[1].imageView = view;
6539 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006540 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006541 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006542 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006543 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006544
6545 static const uint32_t NUM_SET_UPDATES = 3;
6546 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6547 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6548 descriptor_write[0].dstSet = descriptorSet[0];
6549 descriptor_write[0].dstBinding = 0;
6550 descriptor_write[0].descriptorCount = 5;
6551 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6552 descriptor_write[0].pBufferInfo = buffInfo;
6553 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6554 descriptor_write[1].dstSet = descriptorSet[1];
6555 descriptor_write[1].dstBinding = 0;
6556 descriptor_write[1].descriptorCount = 2;
6557 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6558 descriptor_write[1].pImageInfo = imageInfo;
6559 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6560 descriptor_write[2].dstSet = descriptorSet[1];
6561 descriptor_write[2].dstBinding = 1;
6562 descriptor_write[2].descriptorCount = 2;
6563 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006564 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006565
6566 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006567
Tobin Ehlis88452832015-12-03 09:40:56 -07006568 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006569 char const *vsSource = "#version 450\n"
6570 "\n"
6571 "out gl_PerVertex {\n"
6572 " vec4 gl_Position;\n"
6573 "};\n"
6574 "void main(){\n"
6575 " gl_Position = vec4(1);\n"
6576 "}\n";
6577 char const *fsSource = "#version 450\n"
6578 "\n"
6579 "layout(location=0) out vec4 x;\n"
6580 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6581 "void main(){\n"
6582 " x = vec4(bar.y);\n"
6583 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006584 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6585 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006586 VkPipelineObj pipe(m_device);
6587 pipe.AddShader(&vs);
6588 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006589 pipe.AddColorAttachment();
6590 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006591
6592 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006593
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006594 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006595 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6596 // of PSO
6597 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6598 // cmd_pipeline.c
6599 // due to the fact that cmd_alloc_dset_data() has not been called in
6600 // cmd_bind_graphics_pipeline()
6601 // TODO : Want to cause various binding incompatibility issues here to test
6602 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006603 // First cause various verify_layout_compatibility() fails
6604 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006605 // verify_set_layout_compatibility fail cases:
6606 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6608 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6609 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006610 m_errorMonitor->VerifyFound();
6611
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006612 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6614 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6615 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006616 m_errorMonitor->VerifyFound();
6617
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006618 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006619 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6620 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6622 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6623 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006624 m_errorMonitor->VerifyFound();
6625
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006626 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6627 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6629 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6630 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006631 m_errorMonitor->VerifyFound();
6632
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006633 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6634 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6636 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6637 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6638 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006639 m_errorMonitor->VerifyFound();
6640
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006641 // Cause INFO messages due to disturbing previously bound Sets
6642 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006643 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6644 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006645 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6647 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6648 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006649 m_errorMonitor->VerifyFound();
6650
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006651 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6652 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006653 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6655 "any subsequent sets were disturbed ");
6656 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6657 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006658 m_errorMonitor->VerifyFound();
6659
Tobin Ehlis10fad692016-07-07 12:00:36 -06006660 // Now that we're done actively using the pipelineLayout that gfx pipeline
6661 // was created with, we should be able to delete it. Do that now to verify
6662 // that validation obeys pipelineLayout lifetime
6663 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6664
Tobin Ehlis88452832015-12-03 09:40:56 -07006665 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006666 // 1. Error due to not binding required set (we actually use same code as
6667 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6669 &descriptorSet[0], 0, NULL);
6670 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6671 &descriptorSet[1], 0, NULL);
6672 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 -07006673 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006674 m_errorMonitor->VerifyFound();
6675
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006676 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006677 // 2. Error due to bound set not being compatible with PSO's
6678 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006679 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6680 &descriptorSet[0], 0, NULL);
6681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006682 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006683 m_errorMonitor->VerifyFound();
6684
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006685 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006686 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006687 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6688 }
6689 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006690 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006691 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6692 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006693 vkFreeMemory(m_device->device(), imageMem, NULL);
6694 vkDestroyImage(m_device->device(), image, NULL);
6695 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006696}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006697
Karl Schultz6addd812016-02-02 17:17:23 -07006698TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006699
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6701 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006702
6703 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006704 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006705 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006706 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006708 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006709}
6710
Karl Schultz6addd812016-02-02 17:17:23 -07006711TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6712 VkResult err;
6713 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006714
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006716
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006717 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006718
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006719 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006720 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006721 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006722 cmd.commandPool = m_commandPool;
6723 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006724 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006725
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006726 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006727 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006728
6729 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006730 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006731 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006732 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006733 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006734 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 -07006735 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006736
6737 // The error should be caught by validation of the BeginCommandBuffer call
6738 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6739
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006740 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006741 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006742}
6743
Karl Schultz6addd812016-02-02 17:17:23 -07006744TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006745 // Cause error due to Begin while recording CB
6746 // Then cause 2 errors for attempting to reset CB w/o having
6747 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6748 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006750
6751 ASSERT_NO_FATAL_FAILURE(InitState());
6752
6753 // Calls AllocateCommandBuffers
6754 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6755
Karl Schultz6addd812016-02-02 17:17:23 -07006756 // Force the failure by setting the Renderpass and Framebuffer fields with
6757 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006758 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006759 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006760 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6761 cmd_buf_info.pNext = NULL;
6762 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006763 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006764
6765 // Begin CB to transition to recording state
6766 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6767 // Can't re-begin. This should trigger error
6768 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006769 m_errorMonitor->VerifyFound();
6770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006772 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6773 // Reset attempt will trigger error due to incorrect CommandPool state
6774 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006775 m_errorMonitor->VerifyFound();
6776
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006778 // Transition CB to RECORDED state
6779 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6780 // Now attempting to Begin will implicitly reset, which triggers error
6781 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006782 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006783}
6784
Karl Schultz6addd812016-02-02 17:17:23 -07006785TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006786 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006787 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006788
Mike Weiblencce7ec72016-10-17 19:33:05 -06006789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006790
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006791 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006793
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006794 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006795 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6796 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006797
6798 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006799 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6800 ds_pool_ci.pNext = NULL;
6801 ds_pool_ci.maxSets = 1;
6802 ds_pool_ci.poolSizeCount = 1;
6803 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006804
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006805 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006806 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006807 ASSERT_VK_SUCCESS(err);
6808
Tony Barboureb254902015-07-15 12:50:33 -06006809 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006810 dsl_binding.binding = 0;
6811 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6812 dsl_binding.descriptorCount = 1;
6813 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6814 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006815
Tony Barboureb254902015-07-15 12:50:33 -06006816 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006817 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6818 ds_layout_ci.pNext = NULL;
6819 ds_layout_ci.bindingCount = 1;
6820 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006821
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006822 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006823 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006824 ASSERT_VK_SUCCESS(err);
6825
6826 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006827 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006828 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006829 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006830 alloc_info.descriptorPool = ds_pool;
6831 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006832 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006833 ASSERT_VK_SUCCESS(err);
6834
Tony Barboureb254902015-07-15 12:50:33 -06006835 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006836 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6837 pipeline_layout_ci.setLayoutCount = 1;
6838 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006839
6840 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006841 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006842 ASSERT_VK_SUCCESS(err);
6843
Tobin Ehlise68360f2015-10-01 11:15:13 -06006844 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006845 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006846
6847 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006848 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6849 vp_state_ci.scissorCount = 1;
6850 vp_state_ci.pScissors = &sc;
6851 vp_state_ci.viewportCount = 1;
6852 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006853
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006854 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6855 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6856 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6857 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6858 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6859 rs_state_ci.depthClampEnable = VK_FALSE;
6860 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6861 rs_state_ci.depthBiasEnable = VK_FALSE;
6862
Tony Barboureb254902015-07-15 12:50:33 -06006863 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006864 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6865 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006866 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006867 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6868 gp_ci.layout = pipeline_layout;
6869 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006870
6871 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006872 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6873 pc_ci.initialDataSize = 0;
6874 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006875
6876 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006877 VkPipelineCache pipelineCache;
6878
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006879 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006880 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006881 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006882
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006883 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006884
Chia-I Wuf7458c52015-10-26 21:10:41 +08006885 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6886 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006889}
Tobin Ehlis912df022015-09-17 08:46:18 -06006890/*// TODO : This test should be good, but needs Tess support in compiler to run
6891TEST_F(VkLayerTest, InvalidPatchControlPoints)
6892{
6893 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006894 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006895
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006897 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6898primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006899
Tobin Ehlis912df022015-09-17 08:46:18 -06006900 ASSERT_NO_FATAL_FAILURE(InitState());
6901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006902
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006903 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006904 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006905 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006906
6907 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6908 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6909 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006910 ds_pool_ci.poolSizeCount = 1;
6911 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006912
6913 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006914 err = vkCreateDescriptorPool(m_device->device(),
6915VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006916 ASSERT_VK_SUCCESS(err);
6917
6918 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006919 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006920 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006921 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006922 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6923 dsl_binding.pImmutableSamplers = NULL;
6924
6925 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006926 ds_layout_ci.sType =
6927VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006928 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006929 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006930 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006931
6932 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6934&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006935 ASSERT_VK_SUCCESS(err);
6936
6937 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006938 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6939VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006940 ASSERT_VK_SUCCESS(err);
6941
6942 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006943 pipeline_layout_ci.sType =
6944VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006945 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006946 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006947 pipeline_layout_ci.pSetLayouts = &ds_layout;
6948
6949 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006950 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6951&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006952 ASSERT_VK_SUCCESS(err);
6953
6954 VkPipelineShaderStageCreateInfo shaderStages[3];
6955 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6956
Karl Schultz6addd812016-02-02 17:17:23 -07006957 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6958this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006959 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006960 VkShaderObj
6961tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6962this);
6963 VkShaderObj
6964te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6965this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006966
Karl Schultz6addd812016-02-02 17:17:23 -07006967 shaderStages[0].sType =
6968VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006969 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006970 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006971 shaderStages[1].sType =
6972VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006973 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006974 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006975 shaderStages[2].sType =
6976VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006977 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006978 shaderStages[2].shader = te.handle();
6979
6980 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006981 iaCI.sType =
6982VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006983 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006984
6985 VkPipelineTessellationStateCreateInfo tsCI = {};
6986 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6987 tsCI.patchControlPoints = 0; // This will cause an error
6988
6989 VkGraphicsPipelineCreateInfo gp_ci = {};
6990 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6991 gp_ci.pNext = NULL;
6992 gp_ci.stageCount = 3;
6993 gp_ci.pStages = shaderStages;
6994 gp_ci.pVertexInputState = NULL;
6995 gp_ci.pInputAssemblyState = &iaCI;
6996 gp_ci.pTessellationState = &tsCI;
6997 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006998 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006999 gp_ci.pMultisampleState = NULL;
7000 gp_ci.pDepthStencilState = NULL;
7001 gp_ci.pColorBlendState = NULL;
7002 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7003 gp_ci.layout = pipeline_layout;
7004 gp_ci.renderPass = renderPass();
7005
7006 VkPipelineCacheCreateInfo pc_ci = {};
7007 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7008 pc_ci.pNext = NULL;
7009 pc_ci.initialSize = 0;
7010 pc_ci.initialData = 0;
7011 pc_ci.maxSize = 0;
7012
7013 VkPipeline pipeline;
7014 VkPipelineCache pipelineCache;
7015
Karl Schultz6addd812016-02-02 17:17:23 -07007016 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7017&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007018 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007019 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7020&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007021
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007022 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007023
Chia-I Wuf7458c52015-10-26 21:10:41 +08007024 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7025 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007028}
7029*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007030// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007031TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007032 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7035 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007036
Tobin Ehlise68360f2015-10-01 11:15:13 -06007037 ASSERT_NO_FATAL_FAILURE(InitState());
7038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007039
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007040 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007041 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7042 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007043
7044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7046 ds_pool_ci.maxSets = 1;
7047 ds_pool_ci.poolSizeCount = 1;
7048 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007049
7050 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007051 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007052 ASSERT_VK_SUCCESS(err);
7053
7054 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007055 dsl_binding.binding = 0;
7056 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7057 dsl_binding.descriptorCount = 1;
7058 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007059
7060 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007061 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7062 ds_layout_ci.bindingCount = 1;
7063 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007064
7065 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007066 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007067 ASSERT_VK_SUCCESS(err);
7068
7069 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007070 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007071 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007072 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007073 alloc_info.descriptorPool = ds_pool;
7074 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007075 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007076 ASSERT_VK_SUCCESS(err);
7077
7078 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007079 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7080 pipeline_layout_ci.setLayoutCount = 1;
7081 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007082
7083 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007084 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007085 ASSERT_VK_SUCCESS(err);
7086
7087 VkViewport vp = {}; // Just need dummy vp to point to
7088
7089 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007090 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7091 vp_state_ci.scissorCount = 0;
7092 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7093 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007094
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007095 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7096 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7097 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7098 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7099 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7100 rs_state_ci.depthClampEnable = VK_FALSE;
7101 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7102 rs_state_ci.depthBiasEnable = VK_FALSE;
7103
Cody Northropeb3a6c12015-10-05 14:44:45 -06007104 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007105 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007106
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007107 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7108 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7109 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007110 shaderStages[0] = vs.GetStageCreateInfo();
7111 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007112
7113 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007114 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7115 gp_ci.stageCount = 2;
7116 gp_ci.pStages = shaderStages;
7117 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007118 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007119 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7120 gp_ci.layout = pipeline_layout;
7121 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007122
7123 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007124 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007125
7126 VkPipeline pipeline;
7127 VkPipelineCache pipelineCache;
7128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007129 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007130 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007131 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007132
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007133 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134
Chia-I Wuf7458c52015-10-26 21:10:41 +08007135 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7136 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7137 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7138 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007139}
Karl Schultz6addd812016-02-02 17:17:23 -07007140// Don't set viewport state in PSO. This is an error b/c we always need this
7141// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007142// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007143TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007144 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007145 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007146
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007148
Tobin Ehlise68360f2015-10-01 11:15:13 -06007149 ASSERT_NO_FATAL_FAILURE(InitState());
7150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007151
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007152 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007153 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7154 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007155
7156 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007157 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7158 ds_pool_ci.maxSets = 1;
7159 ds_pool_ci.poolSizeCount = 1;
7160 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161
7162 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007163 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007164 ASSERT_VK_SUCCESS(err);
7165
7166 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007167 dsl_binding.binding = 0;
7168 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7169 dsl_binding.descriptorCount = 1;
7170 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007171
7172 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007173 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7174 ds_layout_ci.bindingCount = 1;
7175 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007176
7177 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007178 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007179 ASSERT_VK_SUCCESS(err);
7180
7181 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007182 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007183 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007184 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007185 alloc_info.descriptorPool = ds_pool;
7186 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007187 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007188 ASSERT_VK_SUCCESS(err);
7189
7190 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007191 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7192 pipeline_layout_ci.setLayoutCount = 1;
7193 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007194
7195 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007196 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007197 ASSERT_VK_SUCCESS(err);
7198
7199 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7200 // Set scissor as dynamic to avoid second error
7201 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007202 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7203 dyn_state_ci.dynamicStateCount = 1;
7204 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007205
Cody Northropeb3a6c12015-10-05 14:44:45 -06007206 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007207 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007209 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7210 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7211 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007212 shaderStages[0] = vs.GetStageCreateInfo();
7213 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007214
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007215 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7216 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7217 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7218 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7219 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7220 rs_state_ci.depthClampEnable = VK_FALSE;
7221 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7222 rs_state_ci.depthBiasEnable = VK_FALSE;
7223
Tobin Ehlise68360f2015-10-01 11:15:13 -06007224 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007225 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7226 gp_ci.stageCount = 2;
7227 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007228 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007229 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7230 // should cause validation error
7231 gp_ci.pDynamicState = &dyn_state_ci;
7232 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7233 gp_ci.layout = pipeline_layout;
7234 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007235
7236 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007237 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007238
7239 VkPipeline pipeline;
7240 VkPipelineCache pipelineCache;
7241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007242 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007243 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007244 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007245
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007246 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007247
Chia-I Wuf7458c52015-10-26 21:10:41 +08007248 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7249 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7250 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7251 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007252}
7253// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007254// Then run second test where dynamic scissor count doesn't match PSO scissor
7255// count
7256TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7257 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007258
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7260 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007261
Tobin Ehlise68360f2015-10-01 11:15:13 -06007262 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007263
7264 if (!m_device->phy().features().multiViewport) {
7265 printf("Device does not support multiple viewports/scissors; skipped.\n");
7266 return;
7267 }
7268
Tobin Ehlise68360f2015-10-01 11:15:13 -06007269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007270
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007271 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007272 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7273 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007274
7275 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007276 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7277 ds_pool_ci.maxSets = 1;
7278 ds_pool_ci.poolSizeCount = 1;
7279 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007280
7281 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007282 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007283 ASSERT_VK_SUCCESS(err);
7284
7285 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007286 dsl_binding.binding = 0;
7287 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7288 dsl_binding.descriptorCount = 1;
7289 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007290
7291 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007292 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7293 ds_layout_ci.bindingCount = 1;
7294 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007295
7296 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007297 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007298 ASSERT_VK_SUCCESS(err);
7299
7300 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007301 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007302 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007303 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007304 alloc_info.descriptorPool = ds_pool;
7305 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007306 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007307 ASSERT_VK_SUCCESS(err);
7308
7309 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007310 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7311 pipeline_layout_ci.setLayoutCount = 1;
7312 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007313
7314 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007315 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007316 ASSERT_VK_SUCCESS(err);
7317
7318 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007319 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7320 vp_state_ci.viewportCount = 1;
7321 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7322 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007323 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007324
7325 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7326 // Set scissor as dynamic to avoid that error
7327 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007328 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7329 dyn_state_ci.dynamicStateCount = 1;
7330 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007331
Cody Northropeb3a6c12015-10-05 14:44:45 -06007332 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007333 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007334
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007335 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7336 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7337 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007338 shaderStages[0] = vs.GetStageCreateInfo();
7339 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007340
Cody Northropf6622dc2015-10-06 10:33:21 -06007341 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7342 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7343 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007344 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007345 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007346 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007347 vi_ci.pVertexAttributeDescriptions = nullptr;
7348
7349 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7350 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7351 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7352
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007353 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007354 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007355 rs_ci.pNext = nullptr;
7356
Mark Youngc89c6312016-03-31 16:03:20 -06007357 VkPipelineColorBlendAttachmentState att = {};
7358 att.blendEnable = VK_FALSE;
7359 att.colorWriteMask = 0xf;
7360
Cody Northropf6622dc2015-10-06 10:33:21 -06007361 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7362 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7363 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007364 cb_ci.attachmentCount = 1;
7365 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007366
Tobin Ehlise68360f2015-10-01 11:15:13 -06007367 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007368 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7369 gp_ci.stageCount = 2;
7370 gp_ci.pStages = shaderStages;
7371 gp_ci.pVertexInputState = &vi_ci;
7372 gp_ci.pInputAssemblyState = &ia_ci;
7373 gp_ci.pViewportState = &vp_state_ci;
7374 gp_ci.pRasterizationState = &rs_ci;
7375 gp_ci.pColorBlendState = &cb_ci;
7376 gp_ci.pDynamicState = &dyn_state_ci;
7377 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7378 gp_ci.layout = pipeline_layout;
7379 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007380
7381 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007382 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007383
7384 VkPipeline pipeline;
7385 VkPipelineCache pipelineCache;
7386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007387 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007388 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007389 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007390
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007391 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007392
Tobin Ehlisd332f282015-10-02 11:00:56 -06007393 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007394 // First need to successfully create the PSO from above by setting
7395 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007396 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 -07007397
7398 VkViewport vp = {}; // Just need dummy vp to point to
7399 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007400 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007401 ASSERT_VK_SUCCESS(err);
7402 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007403 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007404 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007405 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007406 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007407 Draw(1, 0, 0, 0);
7408
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007409 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007410
7411 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7412 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007415 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007416}
7417// Create PSO w/o non-zero scissorCount but no scissor data
7418// Then run second test where dynamic viewportCount doesn't match PSO
7419// viewportCount
7420TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7421 VkResult err;
7422
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007423 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 -07007424
7425 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007426
7427 if (!m_device->phy().features().multiViewport) {
7428 printf("Device does not support multiple viewports/scissors; skipped.\n");
7429 return;
7430 }
7431
Karl Schultz6addd812016-02-02 17:17:23 -07007432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7433
7434 VkDescriptorPoolSize ds_type_count = {};
7435 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7436 ds_type_count.descriptorCount = 1;
7437
7438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7440 ds_pool_ci.maxSets = 1;
7441 ds_pool_ci.poolSizeCount = 1;
7442 ds_pool_ci.pPoolSizes = &ds_type_count;
7443
7444 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007445 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007446 ASSERT_VK_SUCCESS(err);
7447
7448 VkDescriptorSetLayoutBinding dsl_binding = {};
7449 dsl_binding.binding = 0;
7450 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7451 dsl_binding.descriptorCount = 1;
7452 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7453
7454 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7455 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7456 ds_layout_ci.bindingCount = 1;
7457 ds_layout_ci.pBindings = &dsl_binding;
7458
7459 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007460 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007461 ASSERT_VK_SUCCESS(err);
7462
7463 VkDescriptorSet descriptorSet;
7464 VkDescriptorSetAllocateInfo alloc_info = {};
7465 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7466 alloc_info.descriptorSetCount = 1;
7467 alloc_info.descriptorPool = ds_pool;
7468 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007469 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007470 ASSERT_VK_SUCCESS(err);
7471
7472 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7473 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7474 pipeline_layout_ci.setLayoutCount = 1;
7475 pipeline_layout_ci.pSetLayouts = &ds_layout;
7476
7477 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007478 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007479 ASSERT_VK_SUCCESS(err);
7480
7481 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7482 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7483 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007484 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007485 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007486 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007487
7488 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7489 // Set scissor as dynamic to avoid that error
7490 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7491 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7492 dyn_state_ci.dynamicStateCount = 1;
7493 dyn_state_ci.pDynamicStates = &vp_state;
7494
7495 VkPipelineShaderStageCreateInfo shaderStages[2];
7496 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007498 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7499 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7500 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007501 shaderStages[0] = vs.GetStageCreateInfo();
7502 shaderStages[1] = fs.GetStageCreateInfo();
7503
7504 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7505 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7506 vi_ci.pNext = nullptr;
7507 vi_ci.vertexBindingDescriptionCount = 0;
7508 vi_ci.pVertexBindingDescriptions = nullptr;
7509 vi_ci.vertexAttributeDescriptionCount = 0;
7510 vi_ci.pVertexAttributeDescriptions = nullptr;
7511
7512 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7513 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7514 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7515
7516 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7517 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7518 rs_ci.pNext = nullptr;
7519
Mark Youngc89c6312016-03-31 16:03:20 -06007520 VkPipelineColorBlendAttachmentState att = {};
7521 att.blendEnable = VK_FALSE;
7522 att.colorWriteMask = 0xf;
7523
Karl Schultz6addd812016-02-02 17:17:23 -07007524 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7525 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7526 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007527 cb_ci.attachmentCount = 1;
7528 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007529
7530 VkGraphicsPipelineCreateInfo gp_ci = {};
7531 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7532 gp_ci.stageCount = 2;
7533 gp_ci.pStages = shaderStages;
7534 gp_ci.pVertexInputState = &vi_ci;
7535 gp_ci.pInputAssemblyState = &ia_ci;
7536 gp_ci.pViewportState = &vp_state_ci;
7537 gp_ci.pRasterizationState = &rs_ci;
7538 gp_ci.pColorBlendState = &cb_ci;
7539 gp_ci.pDynamicState = &dyn_state_ci;
7540 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7541 gp_ci.layout = pipeline_layout;
7542 gp_ci.renderPass = renderPass();
7543
7544 VkPipelineCacheCreateInfo pc_ci = {};
7545 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7546
7547 VkPipeline pipeline;
7548 VkPipelineCache pipelineCache;
7549
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007550 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007551 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007552 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007553
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007554 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007555
7556 // Now hit second fail case where we set scissor w/ different count than PSO
7557 // First need to successfully create the PSO from above by setting
7558 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007559 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 -06007560
Tobin Ehlisd332f282015-10-02 11:00:56 -06007561 VkRect2D sc = {}; // Just need dummy vp to point to
7562 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007563 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007564 ASSERT_VK_SUCCESS(err);
7565 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007566 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007567 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007568 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007569 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007570 Draw(1, 0, 0, 0);
7571
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007572 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007573
Chia-I Wuf7458c52015-10-26 21:10:41 +08007574 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7575 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7576 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7577 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007578 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007579}
7580
Mark Young7394fdd2016-03-31 14:56:43 -06007581TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7582 VkResult err;
7583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007585
7586 ASSERT_NO_FATAL_FAILURE(InitState());
7587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7588
7589 VkDescriptorPoolSize ds_type_count = {};
7590 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7591 ds_type_count.descriptorCount = 1;
7592
7593 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7594 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7595 ds_pool_ci.maxSets = 1;
7596 ds_pool_ci.poolSizeCount = 1;
7597 ds_pool_ci.pPoolSizes = &ds_type_count;
7598
7599 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007600 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007601 ASSERT_VK_SUCCESS(err);
7602
7603 VkDescriptorSetLayoutBinding dsl_binding = {};
7604 dsl_binding.binding = 0;
7605 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7606 dsl_binding.descriptorCount = 1;
7607 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7608
7609 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7610 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7611 ds_layout_ci.bindingCount = 1;
7612 ds_layout_ci.pBindings = &dsl_binding;
7613
7614 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007615 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007616 ASSERT_VK_SUCCESS(err);
7617
7618 VkDescriptorSet descriptorSet;
7619 VkDescriptorSetAllocateInfo alloc_info = {};
7620 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7621 alloc_info.descriptorSetCount = 1;
7622 alloc_info.descriptorPool = ds_pool;
7623 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007624 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007625 ASSERT_VK_SUCCESS(err);
7626
7627 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7628 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7629 pipeline_layout_ci.setLayoutCount = 1;
7630 pipeline_layout_ci.pSetLayouts = &ds_layout;
7631
7632 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007633 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007634 ASSERT_VK_SUCCESS(err);
7635
7636 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7637 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7638 vp_state_ci.scissorCount = 1;
7639 vp_state_ci.pScissors = NULL;
7640 vp_state_ci.viewportCount = 1;
7641 vp_state_ci.pViewports = NULL;
7642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007643 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007644 // Set scissor as dynamic to avoid that error
7645 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7646 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7647 dyn_state_ci.dynamicStateCount = 2;
7648 dyn_state_ci.pDynamicStates = dynamic_states;
7649
7650 VkPipelineShaderStageCreateInfo shaderStages[2];
7651 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7652
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007653 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7654 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007655 this); // TODO - We shouldn't need a fragment shader
7656 // but add it to be able to run on more devices
7657 shaderStages[0] = vs.GetStageCreateInfo();
7658 shaderStages[1] = fs.GetStageCreateInfo();
7659
7660 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7661 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7662 vi_ci.pNext = nullptr;
7663 vi_ci.vertexBindingDescriptionCount = 0;
7664 vi_ci.pVertexBindingDescriptions = nullptr;
7665 vi_ci.vertexAttributeDescriptionCount = 0;
7666 vi_ci.pVertexAttributeDescriptions = nullptr;
7667
7668 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7669 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7670 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7671
7672 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7673 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7674 rs_ci.pNext = nullptr;
7675
Mark Young47107952016-05-02 15:59:55 -06007676 // Check too low (line width of -1.0f).
7677 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007678
7679 VkPipelineColorBlendAttachmentState att = {};
7680 att.blendEnable = VK_FALSE;
7681 att.colorWriteMask = 0xf;
7682
7683 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7684 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7685 cb_ci.pNext = nullptr;
7686 cb_ci.attachmentCount = 1;
7687 cb_ci.pAttachments = &att;
7688
7689 VkGraphicsPipelineCreateInfo gp_ci = {};
7690 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7691 gp_ci.stageCount = 2;
7692 gp_ci.pStages = shaderStages;
7693 gp_ci.pVertexInputState = &vi_ci;
7694 gp_ci.pInputAssemblyState = &ia_ci;
7695 gp_ci.pViewportState = &vp_state_ci;
7696 gp_ci.pRasterizationState = &rs_ci;
7697 gp_ci.pColorBlendState = &cb_ci;
7698 gp_ci.pDynamicState = &dyn_state_ci;
7699 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7700 gp_ci.layout = pipeline_layout;
7701 gp_ci.renderPass = renderPass();
7702
7703 VkPipelineCacheCreateInfo pc_ci = {};
7704 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7705
7706 VkPipeline pipeline;
7707 VkPipelineCache pipelineCache;
7708
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007709 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007710 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007711 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007712
7713 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007714 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007715
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007717
7718 // Check too high (line width of 65536.0f).
7719 rs_ci.lineWidth = 65536.0f;
7720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007721 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007722 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007723 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007724
7725 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007726 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007729
7730 dyn_state_ci.dynamicStateCount = 3;
7731
7732 rs_ci.lineWidth = 1.0f;
7733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007734 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007735 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007737 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007738 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007739
7740 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007741 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007742 m_errorMonitor->VerifyFound();
7743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007745
7746 // Check too high with dynamic setting.
7747 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7748 m_errorMonitor->VerifyFound();
7749 EndCommandBuffer();
7750
7751 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7752 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7753 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7754 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007755 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007756}
7757
Karl Schultz6addd812016-02-02 17:17:23 -07007758TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007759 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7761 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007762
7763 ASSERT_NO_FATAL_FAILURE(InitState());
7764 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007765
Tony Barbourfe3351b2015-07-28 10:17:20 -06007766 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007767 // Don't care about RenderPass handle b/c error should be flagged before
7768 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007769 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007770
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007771 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007772}
7773
Karl Schultz6addd812016-02-02 17:17:23 -07007774TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007775 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7777 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007778
7779 ASSERT_NO_FATAL_FAILURE(InitState());
7780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007781
Tony Barbourfe3351b2015-07-28 10:17:20 -06007782 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007783 // Just create a dummy Renderpass that's non-NULL so we can get to the
7784 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007785 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007786
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007787 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007788}
7789
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007790TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7791 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7792 "the number of renderPass attachments that use loadOp"
7793 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7794
7795 ASSERT_NO_FATAL_FAILURE(InitState());
7796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7797
7798 // Create a renderPass with a single attachment that uses loadOp CLEAR
7799 VkAttachmentReference attach = {};
7800 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7801 VkSubpassDescription subpass = {};
7802 subpass.inputAttachmentCount = 1;
7803 subpass.pInputAttachments = &attach;
7804 VkRenderPassCreateInfo rpci = {};
7805 rpci.subpassCount = 1;
7806 rpci.pSubpasses = &subpass;
7807 rpci.attachmentCount = 1;
7808 VkAttachmentDescription attach_desc = {};
7809 attach_desc.format = VK_FORMAT_UNDEFINED;
7810 // Set loadOp to CLEAR
7811 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7812 rpci.pAttachments = &attach_desc;
7813 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7814 VkRenderPass rp;
7815 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7816
7817 VkCommandBufferInheritanceInfo hinfo = {};
7818 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7819 hinfo.renderPass = VK_NULL_HANDLE;
7820 hinfo.subpass = 0;
7821 hinfo.framebuffer = VK_NULL_HANDLE;
7822 hinfo.occlusionQueryEnable = VK_FALSE;
7823 hinfo.queryFlags = 0;
7824 hinfo.pipelineStatistics = 0;
7825 VkCommandBufferBeginInfo info = {};
7826 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7827 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7828 info.pInheritanceInfo = &hinfo;
7829
7830 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7831 VkRenderPassBeginInfo rp_begin = {};
7832 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7833 rp_begin.pNext = NULL;
7834 rp_begin.renderPass = renderPass();
7835 rp_begin.framebuffer = framebuffer();
7836 rp_begin.clearValueCount = 0; // Should be 1
7837
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7839 "there must be at least 1 entries in "
7840 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007841
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007842 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007843
7844 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007845
7846 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007847}
7848
Cody Northrop3bb4d962016-05-09 16:15:57 -06007849TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7850
7851 TEST_DESCRIPTION("End a command buffer with an active render pass");
7852
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7854 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007855
7856 ASSERT_NO_FATAL_FAILURE(InitState());
7857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7858
7859 // The framework's BeginCommandBuffer calls CreateRenderPass
7860 BeginCommandBuffer();
7861
7862 // Call directly into vkEndCommandBuffer instead of the
7863 // the framework's EndCommandBuffer, which inserts a
7864 // vkEndRenderPass
7865 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7866
7867 m_errorMonitor->VerifyFound();
7868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007869 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7870 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007871}
7872
Karl Schultz6addd812016-02-02 17:17:23 -07007873TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007874 // Call CmdFillBuffer within an active renderpass
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");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007877
7878 ASSERT_NO_FATAL_FAILURE(InitState());
7879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007880
7881 // Renderpass is started here
7882 BeginCommandBuffer();
7883
7884 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007885 vk_testing::Buffer dstBuffer;
7886 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007887
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007888 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007889
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007890 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007891}
7892
Karl Schultz6addd812016-02-02 17:17:23 -07007893TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007894 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7896 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007897
7898 ASSERT_NO_FATAL_FAILURE(InitState());
7899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007900
7901 // Renderpass is started here
7902 BeginCommandBuffer();
7903
7904 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007905 vk_testing::Buffer dstBuffer;
7906 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007907
Karl Schultz6addd812016-02-02 17:17:23 -07007908 VkDeviceSize dstOffset = 0;
7909 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007910 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007912 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007913
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007914 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007915}
7916
Karl Schultz6addd812016-02-02 17:17:23 -07007917TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007918 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7920 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007921
7922 ASSERT_NO_FATAL_FAILURE(InitState());
7923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007924
7925 // Renderpass is started here
7926 BeginCommandBuffer();
7927
Michael Lentine0a369f62016-02-03 16:51:46 -06007928 VkClearColorValue clear_color;
7929 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007930 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7931 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7932 const int32_t tex_width = 32;
7933 const int32_t tex_height = 32;
7934 VkImageCreateInfo image_create_info = {};
7935 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7936 image_create_info.pNext = NULL;
7937 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7938 image_create_info.format = tex_format;
7939 image_create_info.extent.width = tex_width;
7940 image_create_info.extent.height = tex_height;
7941 image_create_info.extent.depth = 1;
7942 image_create_info.mipLevels = 1;
7943 image_create_info.arrayLayers = 1;
7944 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7945 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7946 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007947
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007948 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007949 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007950
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007951 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007952
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007953 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007954
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007955 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007956}
7957
Karl Schultz6addd812016-02-02 17:17:23 -07007958TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007959 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7961 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007962
7963 ASSERT_NO_FATAL_FAILURE(InitState());
7964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007965
7966 // Renderpass is started here
7967 BeginCommandBuffer();
7968
7969 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007970 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007971 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7972 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7973 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7974 image_create_info.extent.width = 64;
7975 image_create_info.extent.height = 64;
7976 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7977 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007978
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007979 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007980 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007982 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007984 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7985 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007986
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007987 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007988}
7989
Karl Schultz6addd812016-02-02 17:17:23 -07007990TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007991 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007992 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007993
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7995 "must be issued inside an active "
7996 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007997
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007998 ASSERT_NO_FATAL_FAILURE(InitState());
7999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008000
8001 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008002 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008003 ASSERT_VK_SUCCESS(err);
8004
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008005 VkClearAttachment color_attachment;
8006 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8007 color_attachment.clearValue.color.float32[0] = 0;
8008 color_attachment.clearValue.color.float32[1] = 0;
8009 color_attachment.clearValue.color.float32[2] = 0;
8010 color_attachment.clearValue.color.float32[3] = 0;
8011 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008012 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008013 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008014
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008015 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008016}
8017
Chris Forbes3b97e932016-09-07 11:29:24 +12008018TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8019 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8020 "called too many times in a renderpass instance");
8021
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8023 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008024
8025 ASSERT_NO_FATAL_FAILURE(InitState());
8026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8027
8028 BeginCommandBuffer();
8029
8030 // error here.
8031 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8032 m_errorMonitor->VerifyFound();
8033
8034 EndCommandBuffer();
8035}
8036
Chris Forbes6d624702016-09-07 13:57:05 +12008037TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8038 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8039 "called before the final subpass has been reached");
8040
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8042 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008043
8044 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008045 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8046 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008048 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008049
8050 VkRenderPass rp;
8051 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8052 ASSERT_VK_SUCCESS(err);
8053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008054 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008055
8056 VkFramebuffer fb;
8057 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8058 ASSERT_VK_SUCCESS(err);
8059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008060 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008062 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 +12008063
8064 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8065
8066 // Error here.
8067 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8068 m_errorMonitor->VerifyFound();
8069
8070 // Clean up.
8071 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8072 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8073}
8074
Karl Schultz9e66a292016-04-21 15:57:51 -06008075TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8076 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8078 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008079
8080 ASSERT_NO_FATAL_FAILURE(InitState());
8081 BeginCommandBuffer();
8082
8083 VkBufferMemoryBarrier buf_barrier = {};
8084 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8085 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8086 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8087 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8088 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8089 buf_barrier.buffer = VK_NULL_HANDLE;
8090 buf_barrier.offset = 0;
8091 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008092 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8093 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008094
8095 m_errorMonitor->VerifyFound();
8096}
8097
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008098TEST_F(VkLayerTest, InvalidBarriers) {
8099 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8100
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008102
8103 ASSERT_NO_FATAL_FAILURE(InitState());
8104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8105
8106 VkMemoryBarrier mem_barrier = {};
8107 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8108 mem_barrier.pNext = NULL;
8109 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8110 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8111 BeginCommandBuffer();
8112 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008113 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008114 &mem_barrier, 0, nullptr, 0, nullptr);
8115 m_errorMonitor->VerifyFound();
8116
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008118 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008119 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 -06008120 ASSERT_TRUE(image.initialized());
8121 VkImageMemoryBarrier img_barrier = {};
8122 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8123 img_barrier.pNext = NULL;
8124 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8125 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8126 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8127 // New layout can't be UNDEFINED
8128 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8129 img_barrier.image = image.handle();
8130 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8131 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8132 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8133 img_barrier.subresourceRange.baseArrayLayer = 0;
8134 img_barrier.subresourceRange.baseMipLevel = 0;
8135 img_barrier.subresourceRange.layerCount = 1;
8136 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008137 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8138 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008139 m_errorMonitor->VerifyFound();
8140 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8143 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008144 // baseArrayLayer + layerCount must be <= image's arrayLayers
8145 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008146 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8147 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008148 m_errorMonitor->VerifyFound();
8149 img_barrier.subresourceRange.baseArrayLayer = 0;
8150
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008152 // baseMipLevel + levelCount must be <= image's mipLevels
8153 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008154 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8155 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008156 m_errorMonitor->VerifyFound();
8157 img_barrier.subresourceRange.baseMipLevel = 0;
8158
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008159 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 -06008160 vk_testing::Buffer buffer;
8161 buffer.init(*m_device, 256);
8162 VkBufferMemoryBarrier buf_barrier = {};
8163 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8164 buf_barrier.pNext = NULL;
8165 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8166 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8167 buf_barrier.buffer = buffer.handle();
8168 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8169 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8170 buf_barrier.offset = 0;
8171 buf_barrier.size = VK_WHOLE_SIZE;
8172 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8174 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008175 m_errorMonitor->VerifyFound();
8176 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8177
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008179 buf_barrier.offset = 257;
8180 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008181 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8182 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008183 m_errorMonitor->VerifyFound();
8184 buf_barrier.offset = 0;
8185
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008187 buf_barrier.size = 257;
8188 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008189 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8190 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008191 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008192
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008193 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008194 m_errorMonitor->SetDesiredFailureMsg(
8195 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8196 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8197 m_errorMonitor->SetDesiredFailureMsg(
8198 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8199 "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 -06008200 VkDepthStencilObj ds_image(m_device);
8201 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8202 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008203 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8204 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008205 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008206 // Use of COLOR aspect on DS image is error
8207 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008208 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8209 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008210 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008211 // Now test depth-only
8212 VkFormatProperties format_props;
8213
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008214 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8215 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8217 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8219 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008220 VkDepthStencilObj d_image(m_device);
8221 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8222 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008223 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008224 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008225 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008226 // Use of COLOR aspect on depth image is error
8227 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008228 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8229 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008230 m_errorMonitor->VerifyFound();
8231 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008232 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8233 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008234 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8236 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008237 VkDepthStencilObj s_image(m_device);
8238 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8239 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008240 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008241 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008242 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008243 // Use of COLOR aspect on depth image is error
8244 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008245 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8246 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008247 m_errorMonitor->VerifyFound();
8248 }
8249 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8251 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8253 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008254 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008255 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 -06008256 ASSERT_TRUE(c_image.initialized());
8257 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8258 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8259 img_barrier.image = c_image.handle();
8260 // Set aspect to depth (non-color)
8261 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008262 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8263 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008264 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008265}
8266
Tony Barbour18ba25c2016-09-29 13:42:40 -06008267TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8268 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8269
8270 m_errorMonitor->SetDesiredFailureMsg(
8271 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8272 "must have required access bit");
8273 ASSERT_NO_FATAL_FAILURE(InitState());
8274 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008275 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 -06008276 ASSERT_TRUE(image.initialized());
8277
8278 VkImageMemoryBarrier barrier = {};
8279 VkImageSubresourceRange range;
8280 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8281 barrier.srcAccessMask = 0;
8282 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8283 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8284 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8285 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8286 barrier.image = image.handle();
8287 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8288 range.baseMipLevel = 0;
8289 range.levelCount = 1;
8290 range.baseArrayLayer = 0;
8291 range.layerCount = 1;
8292 barrier.subresourceRange = range;
8293 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8294 cmdbuf.BeginCommandBuffer();
8295 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8296 &barrier);
8297 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8298 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8299 barrier.srcAccessMask = 0;
8300 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8301 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8302 &barrier);
8303
8304 m_errorMonitor->VerifyFound();
8305}
8306
Karl Schultz6addd812016-02-02 17:17:23 -07008307TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008308 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008309 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008310
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008312
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008313 ASSERT_NO_FATAL_FAILURE(InitState());
8314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008315 uint32_t qfi = 0;
8316 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008317 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8318 buffCI.size = 1024;
8319 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8320 buffCI.queueFamilyIndexCount = 1;
8321 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008322
8323 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008324 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008325 ASSERT_VK_SUCCESS(err);
8326
8327 BeginCommandBuffer();
8328 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008329 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8330 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008331 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008332 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008334 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008335
Chia-I Wuf7458c52015-10-26 21:10:41 +08008336 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008337}
8338
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008339TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8340 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8342 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8343 "of the indices specified when the device was created, via the "
8344 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008345
8346 ASSERT_NO_FATAL_FAILURE(InitState());
8347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8348 VkBufferCreateInfo buffCI = {};
8349 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8350 buffCI.size = 1024;
8351 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8352 buffCI.queueFamilyIndexCount = 1;
8353 // Introduce failure by specifying invalid queue_family_index
8354 uint32_t qfi = 777;
8355 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008356 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008357
8358 VkBuffer ib;
8359 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008361 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008362 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008363}
8364
Karl Schultz6addd812016-02-02 17:17:23 -07008365TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008366TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008367 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008368
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008369 ASSERT_NO_FATAL_FAILURE(InitState());
8370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008371
Chris Forbesf29a84f2016-10-06 18:39:28 +13008372 // An empty primary command buffer
8373 VkCommandBufferObj cb(m_device, m_commandPool);
8374 cb.BeginCommandBuffer();
8375 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008376
Chris Forbesf29a84f2016-10-06 18:39:28 +13008377 m_commandBuffer->BeginCommandBuffer();
8378 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8379 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008380
Chris Forbesf29a84f2016-10-06 18:39:28 +13008381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8382 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008383 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008384}
8385
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008386TEST_F(VkLayerTest, DSUsageBitsErrors) {
8387 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8388 "that do not have correct usage bits sets.");
8389 VkResult err;
8390
8391 ASSERT_NO_FATAL_FAILURE(InitState());
8392 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8393 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8394 ds_type_count[i].type = VkDescriptorType(i);
8395 ds_type_count[i].descriptorCount = 1;
8396 }
8397 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8398 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8399 ds_pool_ci.pNext = NULL;
8400 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8401 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8402 ds_pool_ci.pPoolSizes = ds_type_count;
8403
8404 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008406 ASSERT_VK_SUCCESS(err);
8407
8408 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008409 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008410 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8411 dsl_binding[i].binding = 0;
8412 dsl_binding[i].descriptorType = VkDescriptorType(i);
8413 dsl_binding[i].descriptorCount = 1;
8414 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8415 dsl_binding[i].pImmutableSamplers = NULL;
8416 }
8417
8418 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8419 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8420 ds_layout_ci.pNext = NULL;
8421 ds_layout_ci.bindingCount = 1;
8422 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8423 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8424 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008425 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008426 ASSERT_VK_SUCCESS(err);
8427 }
8428 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8429 VkDescriptorSetAllocateInfo alloc_info = {};
8430 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8431 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8432 alloc_info.descriptorPool = ds_pool;
8433 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008435 ASSERT_VK_SUCCESS(err);
8436
8437 // Create a buffer & bufferView to be used for invalid updates
8438 VkBufferCreateInfo buff_ci = {};
8439 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8440 // This usage is not valid for any descriptor type
8441 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8442 buff_ci.size = 256;
8443 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8444 VkBuffer buffer;
8445 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8446 ASSERT_VK_SUCCESS(err);
8447
8448 VkBufferViewCreateInfo buff_view_ci = {};
8449 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8450 buff_view_ci.buffer = buffer;
8451 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8452 buff_view_ci.range = VK_WHOLE_SIZE;
8453 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008455 ASSERT_VK_SUCCESS(err);
8456
8457 // Create an image to be used for invalid updates
8458 VkImageCreateInfo image_ci = {};
8459 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8460 image_ci.imageType = VK_IMAGE_TYPE_2D;
8461 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8462 image_ci.extent.width = 64;
8463 image_ci.extent.height = 64;
8464 image_ci.extent.depth = 1;
8465 image_ci.mipLevels = 1;
8466 image_ci.arrayLayers = 1;
8467 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8468 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8469 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8470 // This usage is not valid for any descriptor type
8471 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8472 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8473 VkImage image;
8474 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8475 ASSERT_VK_SUCCESS(err);
8476 // Bind memory to image
8477 VkMemoryRequirements mem_reqs;
8478 VkDeviceMemory image_mem;
8479 bool pass;
8480 VkMemoryAllocateInfo mem_alloc = {};
8481 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8482 mem_alloc.pNext = NULL;
8483 mem_alloc.allocationSize = 0;
8484 mem_alloc.memoryTypeIndex = 0;
8485 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8486 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008488 ASSERT_TRUE(pass);
8489 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8490 ASSERT_VK_SUCCESS(err);
8491 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8492 ASSERT_VK_SUCCESS(err);
8493 // Now create view for image
8494 VkImageViewCreateInfo image_view_ci = {};
8495 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8496 image_view_ci.image = image;
8497 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8498 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8499 image_view_ci.subresourceRange.layerCount = 1;
8500 image_view_ci.subresourceRange.baseArrayLayer = 0;
8501 image_view_ci.subresourceRange.levelCount = 1;
8502 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8503 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008504 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008505 ASSERT_VK_SUCCESS(err);
8506
8507 VkDescriptorBufferInfo buff_info = {};
8508 buff_info.buffer = buffer;
8509 VkDescriptorImageInfo img_info = {};
8510 img_info.imageView = image_view;
8511 VkWriteDescriptorSet descriptor_write = {};
8512 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8513 descriptor_write.dstBinding = 0;
8514 descriptor_write.descriptorCount = 1;
8515 descriptor_write.pTexelBufferView = &buff_view;
8516 descriptor_write.pBufferInfo = &buff_info;
8517 descriptor_write.pImageInfo = &img_info;
8518
8519 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008520 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8521 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8522 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8523 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8524 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8525 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8526 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8527 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8528 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8529 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8530 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008531 // Start loop at 1 as SAMPLER desc type has no usage bit error
8532 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8533 descriptor_write.descriptorType = VkDescriptorType(i);
8534 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008536
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008537 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008538
8539 m_errorMonitor->VerifyFound();
8540 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8541 }
8542 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8543 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008544 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008545 vkDestroyImageView(m_device->device(), image_view, NULL);
8546 vkDestroyBuffer(m_device->device(), buffer, NULL);
8547 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008548 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008549 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8550}
8551
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008552TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008553 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8554 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8555 "1. offset value greater than buffer size\n"
8556 "2. range value of 0\n"
8557 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008558 VkResult err;
8559
8560 ASSERT_NO_FATAL_FAILURE(InitState());
8561 VkDescriptorPoolSize ds_type_count = {};
8562 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8563 ds_type_count.descriptorCount = 1;
8564
8565 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8566 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8567 ds_pool_ci.pNext = NULL;
8568 ds_pool_ci.maxSets = 1;
8569 ds_pool_ci.poolSizeCount = 1;
8570 ds_pool_ci.pPoolSizes = &ds_type_count;
8571
8572 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008573 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008574 ASSERT_VK_SUCCESS(err);
8575
8576 // Create layout with single uniform buffer descriptor
8577 VkDescriptorSetLayoutBinding dsl_binding = {};
8578 dsl_binding.binding = 0;
8579 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8580 dsl_binding.descriptorCount = 1;
8581 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8582 dsl_binding.pImmutableSamplers = NULL;
8583
8584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8586 ds_layout_ci.pNext = NULL;
8587 ds_layout_ci.bindingCount = 1;
8588 ds_layout_ci.pBindings = &dsl_binding;
8589 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008590 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008591 ASSERT_VK_SUCCESS(err);
8592
8593 VkDescriptorSet descriptor_set = {};
8594 VkDescriptorSetAllocateInfo alloc_info = {};
8595 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8596 alloc_info.descriptorSetCount = 1;
8597 alloc_info.descriptorPool = ds_pool;
8598 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008599 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008600 ASSERT_VK_SUCCESS(err);
8601
8602 // Create a buffer to be used for invalid updates
8603 VkBufferCreateInfo buff_ci = {};
8604 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8605 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8606 buff_ci.size = 256;
8607 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8608 VkBuffer buffer;
8609 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8610 ASSERT_VK_SUCCESS(err);
8611 // Have to bind memory to buffer before descriptor update
8612 VkMemoryAllocateInfo mem_alloc = {};
8613 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8614 mem_alloc.pNext = NULL;
8615 mem_alloc.allocationSize = 256;
8616 mem_alloc.memoryTypeIndex = 0;
8617
8618 VkMemoryRequirements mem_reqs;
8619 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008620 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008621 if (!pass) {
8622 vkDestroyBuffer(m_device->device(), buffer, NULL);
8623 return;
8624 }
8625
8626 VkDeviceMemory mem;
8627 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8628 ASSERT_VK_SUCCESS(err);
8629 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8630 ASSERT_VK_SUCCESS(err);
8631
8632 VkDescriptorBufferInfo buff_info = {};
8633 buff_info.buffer = buffer;
8634 // First make offset 1 larger than buffer size
8635 buff_info.offset = 257;
8636 buff_info.range = VK_WHOLE_SIZE;
8637 VkWriteDescriptorSet descriptor_write = {};
8638 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8639 descriptor_write.dstBinding = 0;
8640 descriptor_write.descriptorCount = 1;
8641 descriptor_write.pTexelBufferView = nullptr;
8642 descriptor_write.pBufferInfo = &buff_info;
8643 descriptor_write.pImageInfo = nullptr;
8644
8645 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8646 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008648
8649 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8650
8651 m_errorMonitor->VerifyFound();
8652 // Now cause error due to range of 0
8653 buff_info.offset = 0;
8654 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8656 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008657
8658 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8659
8660 m_errorMonitor->VerifyFound();
8661 // Now cause error due to range exceeding buffer size - offset
8662 buff_info.offset = 128;
8663 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008664 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 -06008665
8666 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8667
8668 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008669 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008670 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8671 vkDestroyBuffer(m_device->device(), buffer, NULL);
8672 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8673 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8674}
8675
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008676TEST_F(VkLayerTest, DSAspectBitsErrors) {
8677 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8678 // are set, but could expand this test to hit more cases.
8679 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8680 "that do not have correct aspect bits sets.");
8681 VkResult err;
8682
8683 ASSERT_NO_FATAL_FAILURE(InitState());
8684 VkDescriptorPoolSize ds_type_count = {};
8685 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8686 ds_type_count.descriptorCount = 1;
8687
8688 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8689 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8690 ds_pool_ci.pNext = NULL;
8691 ds_pool_ci.maxSets = 5;
8692 ds_pool_ci.poolSizeCount = 1;
8693 ds_pool_ci.pPoolSizes = &ds_type_count;
8694
8695 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008697 ASSERT_VK_SUCCESS(err);
8698
8699 VkDescriptorSetLayoutBinding dsl_binding = {};
8700 dsl_binding.binding = 0;
8701 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8702 dsl_binding.descriptorCount = 1;
8703 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8704 dsl_binding.pImmutableSamplers = NULL;
8705
8706 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8707 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8708 ds_layout_ci.pNext = NULL;
8709 ds_layout_ci.bindingCount = 1;
8710 ds_layout_ci.pBindings = &dsl_binding;
8711 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008712 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008713 ASSERT_VK_SUCCESS(err);
8714
8715 VkDescriptorSet descriptor_set = {};
8716 VkDescriptorSetAllocateInfo alloc_info = {};
8717 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8718 alloc_info.descriptorSetCount = 1;
8719 alloc_info.descriptorPool = ds_pool;
8720 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008721 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008722 ASSERT_VK_SUCCESS(err);
8723
8724 // Create an image to be used for invalid updates
8725 VkImageCreateInfo image_ci = {};
8726 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8727 image_ci.imageType = VK_IMAGE_TYPE_2D;
8728 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8729 image_ci.extent.width = 64;
8730 image_ci.extent.height = 64;
8731 image_ci.extent.depth = 1;
8732 image_ci.mipLevels = 1;
8733 image_ci.arrayLayers = 1;
8734 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8735 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8736 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8737 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8738 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8739 VkImage image;
8740 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8741 ASSERT_VK_SUCCESS(err);
8742 // Bind memory to image
8743 VkMemoryRequirements mem_reqs;
8744 VkDeviceMemory image_mem;
8745 bool pass;
8746 VkMemoryAllocateInfo mem_alloc = {};
8747 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8748 mem_alloc.pNext = NULL;
8749 mem_alloc.allocationSize = 0;
8750 mem_alloc.memoryTypeIndex = 0;
8751 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8752 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008753 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008754 ASSERT_TRUE(pass);
8755 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8756 ASSERT_VK_SUCCESS(err);
8757 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8758 ASSERT_VK_SUCCESS(err);
8759 // Now create view for image
8760 VkImageViewCreateInfo image_view_ci = {};
8761 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8762 image_view_ci.image = image;
8763 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8764 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8765 image_view_ci.subresourceRange.layerCount = 1;
8766 image_view_ci.subresourceRange.baseArrayLayer = 0;
8767 image_view_ci.subresourceRange.levelCount = 1;
8768 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008769 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008770
8771 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008772 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008773 ASSERT_VK_SUCCESS(err);
8774
8775 VkDescriptorImageInfo img_info = {};
8776 img_info.imageView = image_view;
8777 VkWriteDescriptorSet descriptor_write = {};
8778 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8779 descriptor_write.dstBinding = 0;
8780 descriptor_write.descriptorCount = 1;
8781 descriptor_write.pTexelBufferView = NULL;
8782 descriptor_write.pBufferInfo = NULL;
8783 descriptor_write.pImageInfo = &img_info;
8784 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8785 descriptor_write.dstSet = descriptor_set;
8786 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8787 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008789
8790 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8791
8792 m_errorMonitor->VerifyFound();
8793 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8794 vkDestroyImage(m_device->device(), image, NULL);
8795 vkFreeMemory(m_device->device(), image_mem, NULL);
8796 vkDestroyImageView(m_device->device(), image_view, NULL);
8797 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8798 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8799}
8800
Karl Schultz6addd812016-02-02 17:17:23 -07008801TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008802 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008803 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008804
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8806 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8807 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008808
Tobin Ehlis3b780662015-05-28 12:11:26 -06008809 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008810 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008811 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008812 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8813 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008814
8815 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008816 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8817 ds_pool_ci.pNext = NULL;
8818 ds_pool_ci.maxSets = 1;
8819 ds_pool_ci.poolSizeCount = 1;
8820 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008821
Tobin Ehlis3b780662015-05-28 12:11:26 -06008822 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008823 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008824 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008825 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008826 dsl_binding.binding = 0;
8827 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8828 dsl_binding.descriptorCount = 1;
8829 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8830 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008831
Tony Barboureb254902015-07-15 12:50:33 -06008832 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008833 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8834 ds_layout_ci.pNext = NULL;
8835 ds_layout_ci.bindingCount = 1;
8836 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008837
Tobin Ehlis3b780662015-05-28 12:11:26 -06008838 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008839 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008840 ASSERT_VK_SUCCESS(err);
8841
8842 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008843 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008844 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008845 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008846 alloc_info.descriptorPool = ds_pool;
8847 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008848 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008849 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008850
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008851 VkSamplerCreateInfo sampler_ci = {};
8852 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8853 sampler_ci.pNext = NULL;
8854 sampler_ci.magFilter = VK_FILTER_NEAREST;
8855 sampler_ci.minFilter = VK_FILTER_NEAREST;
8856 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8857 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8858 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8859 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8860 sampler_ci.mipLodBias = 1.0;
8861 sampler_ci.anisotropyEnable = VK_FALSE;
8862 sampler_ci.maxAnisotropy = 1;
8863 sampler_ci.compareEnable = VK_FALSE;
8864 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8865 sampler_ci.minLod = 1.0;
8866 sampler_ci.maxLod = 1.0;
8867 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8868 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8869 VkSampler sampler;
8870 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8871 ASSERT_VK_SUCCESS(err);
8872
8873 VkDescriptorImageInfo info = {};
8874 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008875
8876 VkWriteDescriptorSet descriptor_write;
8877 memset(&descriptor_write, 0, sizeof(descriptor_write));
8878 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008879 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008880 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008881 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008882 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008883 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008884
8885 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8886
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008887 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008888
Chia-I Wuf7458c52015-10-26 21:10:41 +08008889 vkDestroySampler(m_device->device(), sampler, NULL);
8890 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8891 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008892}
8893
Karl Schultz6addd812016-02-02 17:17:23 -07008894TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008895 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008896 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008897
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8899 " binding #0 with 1 total descriptors but update of 1 descriptors "
8900 "starting at binding offset of 0 combined with update array element "
8901 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008902
Tobin Ehlis3b780662015-05-28 12:11:26 -06008903 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008904 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008905 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008906 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8907 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008908
8909 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008910 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8911 ds_pool_ci.pNext = NULL;
8912 ds_pool_ci.maxSets = 1;
8913 ds_pool_ci.poolSizeCount = 1;
8914 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008915
Tobin Ehlis3b780662015-05-28 12:11:26 -06008916 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008917 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008918 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008919
Tony Barboureb254902015-07-15 12:50:33 -06008920 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008921 dsl_binding.binding = 0;
8922 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8923 dsl_binding.descriptorCount = 1;
8924 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8925 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008926
8927 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008928 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8929 ds_layout_ci.pNext = NULL;
8930 ds_layout_ci.bindingCount = 1;
8931 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008932
Tobin Ehlis3b780662015-05-28 12:11:26 -06008933 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008934 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008935 ASSERT_VK_SUCCESS(err);
8936
8937 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008938 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008939 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008940 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008941 alloc_info.descriptorPool = ds_pool;
8942 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008943 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008944 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008945
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008946 // Correctly update descriptor to avoid "NOT_UPDATED" error
8947 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008948 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008949 buff_info.offset = 0;
8950 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008951
8952 VkWriteDescriptorSet descriptor_write;
8953 memset(&descriptor_write, 0, sizeof(descriptor_write));
8954 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008955 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008956 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008957 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008958 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8959 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008960
8961 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8962
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008963 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008964
Chia-I Wuf7458c52015-10-26 21:10:41 +08008965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8966 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008967}
8968
Karl Schultz6addd812016-02-02 17:17:23 -07008969TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8970 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8971 // index 2
8972 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008973
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008975
Tobin Ehlis3b780662015-05-28 12:11:26 -06008976 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008977 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008978 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008979 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8980 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008981
8982 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008983 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8984 ds_pool_ci.pNext = NULL;
8985 ds_pool_ci.maxSets = 1;
8986 ds_pool_ci.poolSizeCount = 1;
8987 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008988
Tobin Ehlis3b780662015-05-28 12:11:26 -06008989 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008990 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008991 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008992
Tony Barboureb254902015-07-15 12:50:33 -06008993 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008994 dsl_binding.binding = 0;
8995 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8996 dsl_binding.descriptorCount = 1;
8997 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8998 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008999
9000 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009001 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9002 ds_layout_ci.pNext = NULL;
9003 ds_layout_ci.bindingCount = 1;
9004 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009005 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009006 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009007 ASSERT_VK_SUCCESS(err);
9008
9009 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009010 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009011 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009012 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009013 alloc_info.descriptorPool = ds_pool;
9014 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009015 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009016 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009017
Tony Barboureb254902015-07-15 12:50:33 -06009018 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009019 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9020 sampler_ci.pNext = NULL;
9021 sampler_ci.magFilter = VK_FILTER_NEAREST;
9022 sampler_ci.minFilter = VK_FILTER_NEAREST;
9023 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9024 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9025 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9026 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9027 sampler_ci.mipLodBias = 1.0;
9028 sampler_ci.anisotropyEnable = VK_FALSE;
9029 sampler_ci.maxAnisotropy = 1;
9030 sampler_ci.compareEnable = VK_FALSE;
9031 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9032 sampler_ci.minLod = 1.0;
9033 sampler_ci.maxLod = 1.0;
9034 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9035 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009036
Tobin Ehlis3b780662015-05-28 12:11:26 -06009037 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009038 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009039 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009040
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009041 VkDescriptorImageInfo info = {};
9042 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009043
9044 VkWriteDescriptorSet descriptor_write;
9045 memset(&descriptor_write, 0, sizeof(descriptor_write));
9046 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009047 descriptor_write.dstSet = descriptorSet;
9048 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009049 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009050 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009051 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009052 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009053
9054 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9055
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009056 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009057
Chia-I Wuf7458c52015-10-26 21:10:41 +08009058 vkDestroySampler(m_device->device(), sampler, NULL);
9059 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9060 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009061}
9062
Karl Schultz6addd812016-02-02 17:17:23 -07009063TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9064 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9065 // types
9066 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009067
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009068 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 -06009069
Tobin Ehlis3b780662015-05-28 12:11:26 -06009070 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009071
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009072 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009073 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9074 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009075
9076 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009077 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9078 ds_pool_ci.pNext = NULL;
9079 ds_pool_ci.maxSets = 1;
9080 ds_pool_ci.poolSizeCount = 1;
9081 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009082
Tobin Ehlis3b780662015-05-28 12:11:26 -06009083 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009084 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009085 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009086 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009087 dsl_binding.binding = 0;
9088 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9089 dsl_binding.descriptorCount = 1;
9090 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9091 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009092
Tony Barboureb254902015-07-15 12:50:33 -06009093 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009094 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9095 ds_layout_ci.pNext = NULL;
9096 ds_layout_ci.bindingCount = 1;
9097 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009098
Tobin Ehlis3b780662015-05-28 12:11:26 -06009099 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009100 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009101 ASSERT_VK_SUCCESS(err);
9102
9103 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009104 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009105 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009106 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009107 alloc_info.descriptorPool = ds_pool;
9108 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009109 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009110 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009111
Tony Barboureb254902015-07-15 12:50:33 -06009112 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009113 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9114 sampler_ci.pNext = NULL;
9115 sampler_ci.magFilter = VK_FILTER_NEAREST;
9116 sampler_ci.minFilter = VK_FILTER_NEAREST;
9117 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9118 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9119 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9120 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9121 sampler_ci.mipLodBias = 1.0;
9122 sampler_ci.anisotropyEnable = VK_FALSE;
9123 sampler_ci.maxAnisotropy = 1;
9124 sampler_ci.compareEnable = VK_FALSE;
9125 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9126 sampler_ci.minLod = 1.0;
9127 sampler_ci.maxLod = 1.0;
9128 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9129 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009130 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009131 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009132 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009133
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009134 VkDescriptorImageInfo info = {};
9135 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009136
9137 VkWriteDescriptorSet descriptor_write;
9138 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009139 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009140 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009141 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009142 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009143 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009144 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009145
9146 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9147
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009148 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009149
Chia-I Wuf7458c52015-10-26 21:10:41 +08009150 vkDestroySampler(m_device->device(), sampler, NULL);
9151 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9152 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009153}
9154
Karl Schultz6addd812016-02-02 17:17:23 -07009155TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009156 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009157 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009158
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9160 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009161
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009162 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009163 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9164 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009165 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009166 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9167 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009168
9169 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009170 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9171 ds_pool_ci.pNext = NULL;
9172 ds_pool_ci.maxSets = 1;
9173 ds_pool_ci.poolSizeCount = 1;
9174 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009175
9176 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009177 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009178 ASSERT_VK_SUCCESS(err);
9179
9180 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009181 dsl_binding.binding = 0;
9182 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9183 dsl_binding.descriptorCount = 1;
9184 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9185 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009186
9187 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009188 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9189 ds_layout_ci.pNext = NULL;
9190 ds_layout_ci.bindingCount = 1;
9191 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009192 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009193 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009194 ASSERT_VK_SUCCESS(err);
9195
9196 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009197 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009198 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009199 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009200 alloc_info.descriptorPool = ds_pool;
9201 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009202 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009203 ASSERT_VK_SUCCESS(err);
9204
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009205 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009206
9207 VkDescriptorImageInfo descriptor_info;
9208 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9209 descriptor_info.sampler = sampler;
9210
9211 VkWriteDescriptorSet descriptor_write;
9212 memset(&descriptor_write, 0, sizeof(descriptor_write));
9213 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009214 descriptor_write.dstSet = descriptorSet;
9215 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009216 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009217 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9218 descriptor_write.pImageInfo = &descriptor_info;
9219
9220 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9221
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009222 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009223
Chia-I Wuf7458c52015-10-26 21:10:41 +08009224 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9225 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009226}
9227
Karl Schultz6addd812016-02-02 17:17:23 -07009228TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9229 // Create a single combined Image/Sampler descriptor and send it an invalid
9230 // imageView
9231 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009232
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9234 "image sampler descriptor failed due "
9235 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009236
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009237 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009238 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009239 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9240 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009241
9242 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009243 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9244 ds_pool_ci.pNext = NULL;
9245 ds_pool_ci.maxSets = 1;
9246 ds_pool_ci.poolSizeCount = 1;
9247 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009248
9249 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009250 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009251 ASSERT_VK_SUCCESS(err);
9252
9253 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009254 dsl_binding.binding = 0;
9255 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9256 dsl_binding.descriptorCount = 1;
9257 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9258 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009259
9260 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009261 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9262 ds_layout_ci.pNext = NULL;
9263 ds_layout_ci.bindingCount = 1;
9264 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009265 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009266 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009267 ASSERT_VK_SUCCESS(err);
9268
9269 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009270 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009271 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009272 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009273 alloc_info.descriptorPool = ds_pool;
9274 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009275 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009276 ASSERT_VK_SUCCESS(err);
9277
9278 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009279 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9280 sampler_ci.pNext = NULL;
9281 sampler_ci.magFilter = VK_FILTER_NEAREST;
9282 sampler_ci.minFilter = VK_FILTER_NEAREST;
9283 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9284 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9285 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9286 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9287 sampler_ci.mipLodBias = 1.0;
9288 sampler_ci.anisotropyEnable = VK_FALSE;
9289 sampler_ci.maxAnisotropy = 1;
9290 sampler_ci.compareEnable = VK_FALSE;
9291 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9292 sampler_ci.minLod = 1.0;
9293 sampler_ci.maxLod = 1.0;
9294 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9295 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009296
9297 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009298 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009299 ASSERT_VK_SUCCESS(err);
9300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009301 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009302
9303 VkDescriptorImageInfo descriptor_info;
9304 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9305 descriptor_info.sampler = sampler;
9306 descriptor_info.imageView = view;
9307
9308 VkWriteDescriptorSet descriptor_write;
9309 memset(&descriptor_write, 0, sizeof(descriptor_write));
9310 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009311 descriptor_write.dstSet = descriptorSet;
9312 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009313 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009314 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9315 descriptor_write.pImageInfo = &descriptor_info;
9316
9317 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9318
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009319 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009320
Chia-I Wuf7458c52015-10-26 21:10:41 +08009321 vkDestroySampler(m_device->device(), sampler, NULL);
9322 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9323 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009324}
9325
Karl Schultz6addd812016-02-02 17:17:23 -07009326TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9327 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9328 // into the other
9329 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009330
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9332 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9333 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009334
Tobin Ehlis04356f92015-10-27 16:35:27 -06009335 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009336 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009337 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009338 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9339 ds_type_count[0].descriptorCount = 1;
9340 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9341 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009342
9343 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009344 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9345 ds_pool_ci.pNext = NULL;
9346 ds_pool_ci.maxSets = 1;
9347 ds_pool_ci.poolSizeCount = 2;
9348 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009349
9350 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009351 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009352 ASSERT_VK_SUCCESS(err);
9353 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009354 dsl_binding[0].binding = 0;
9355 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9356 dsl_binding[0].descriptorCount = 1;
9357 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9358 dsl_binding[0].pImmutableSamplers = NULL;
9359 dsl_binding[1].binding = 1;
9360 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9361 dsl_binding[1].descriptorCount = 1;
9362 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9363 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009364
9365 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009366 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9367 ds_layout_ci.pNext = NULL;
9368 ds_layout_ci.bindingCount = 2;
9369 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009370
9371 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009372 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009373 ASSERT_VK_SUCCESS(err);
9374
9375 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009376 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009377 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009378 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009379 alloc_info.descriptorPool = ds_pool;
9380 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009381 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009382 ASSERT_VK_SUCCESS(err);
9383
9384 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009385 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9386 sampler_ci.pNext = NULL;
9387 sampler_ci.magFilter = VK_FILTER_NEAREST;
9388 sampler_ci.minFilter = VK_FILTER_NEAREST;
9389 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9390 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9391 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9392 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9393 sampler_ci.mipLodBias = 1.0;
9394 sampler_ci.anisotropyEnable = VK_FALSE;
9395 sampler_ci.maxAnisotropy = 1;
9396 sampler_ci.compareEnable = VK_FALSE;
9397 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9398 sampler_ci.minLod = 1.0;
9399 sampler_ci.maxLod = 1.0;
9400 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9401 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009402
9403 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009404 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009405 ASSERT_VK_SUCCESS(err);
9406
9407 VkDescriptorImageInfo info = {};
9408 info.sampler = sampler;
9409
9410 VkWriteDescriptorSet descriptor_write;
9411 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9412 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009413 descriptor_write.dstSet = descriptorSet;
9414 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009415 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009416 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9417 descriptor_write.pImageInfo = &info;
9418 // This write update should succeed
9419 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9420 // Now perform a copy update that fails due to type mismatch
9421 VkCopyDescriptorSet copy_ds_update;
9422 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9423 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9424 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009425 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009426 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009427 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009428 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009429 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9430
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009431 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009432 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009433 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 -06009434 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9435 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9436 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009437 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009438 copy_ds_update.dstSet = descriptorSet;
9439 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009440 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009441 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9442
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009443 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009444
Tobin Ehlis04356f92015-10-27 16:35:27 -06009445 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9447 "update array offset of 0 and update of "
9448 "5 descriptors oversteps total number "
9449 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009450
Tobin Ehlis04356f92015-10-27 16:35:27 -06009451 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9452 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9453 copy_ds_update.srcSet = descriptorSet;
9454 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009455 copy_ds_update.dstSet = descriptorSet;
9456 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009457 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009458 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9459
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009460 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009461
Chia-I Wuf7458c52015-10-26 21:10:41 +08009462 vkDestroySampler(m_device->device(), sampler, NULL);
9463 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9464 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009465}
9466
Karl Schultz6addd812016-02-02 17:17:23 -07009467TEST_F(VkLayerTest, NumSamplesMismatch) {
9468 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9469 // sampleCount
9470 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009471
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009473
Tobin Ehlis3b780662015-05-28 12:11:26 -06009474 ASSERT_NO_FATAL_FAILURE(InitState());
9475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009476 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009477 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009478 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009479
9480 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009481 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9482 ds_pool_ci.pNext = NULL;
9483 ds_pool_ci.maxSets = 1;
9484 ds_pool_ci.poolSizeCount = 1;
9485 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009486
Tobin Ehlis3b780662015-05-28 12:11:26 -06009487 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009488 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009489 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009490
Tony Barboureb254902015-07-15 12:50:33 -06009491 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009492 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009493 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009494 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009495 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9496 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009497
Tony Barboureb254902015-07-15 12:50:33 -06009498 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9499 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9500 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009501 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009502 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009503
Tobin Ehlis3b780662015-05-28 12:11:26 -06009504 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009505 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009506 ASSERT_VK_SUCCESS(err);
9507
9508 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009509 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009510 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009511 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009512 alloc_info.descriptorPool = ds_pool;
9513 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009514 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009515 ASSERT_VK_SUCCESS(err);
9516
Tony Barboureb254902015-07-15 12:50:33 -06009517 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009518 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009519 pipe_ms_state_ci.pNext = NULL;
9520 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9521 pipe_ms_state_ci.sampleShadingEnable = 0;
9522 pipe_ms_state_ci.minSampleShading = 1.0;
9523 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009524
Tony Barboureb254902015-07-15 12:50:33 -06009525 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009526 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9527 pipeline_layout_ci.pNext = NULL;
9528 pipeline_layout_ci.setLayoutCount = 1;
9529 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009530
9531 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009532 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009533 ASSERT_VK_SUCCESS(err);
9534
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009535 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9536 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9537 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009538 VkPipelineObj pipe(m_device);
9539 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009540 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009541 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009542 pipe.SetMSAA(&pipe_ms_state_ci);
9543 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009544
Tony Barbourfe3351b2015-07-28 10:17:20 -06009545 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009546 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009547
Mark Young29927482016-05-04 14:38:51 -06009548 // Render triangle (the error should trigger on the attempt to draw).
9549 Draw(3, 1, 0, 0);
9550
9551 // Finalize recording of the command buffer
9552 EndCommandBuffer();
9553
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009554 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009555
Chia-I Wuf7458c52015-10-26 21:10:41 +08009556 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9557 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9558 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009559}
Mark Young29927482016-05-04 14:38:51 -06009560
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009561TEST_F(VkLayerTest, RenderPassIncompatible) {
9562 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9563 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009564 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009565 VkResult err;
9566
9567 ASSERT_NO_FATAL_FAILURE(InitState());
9568 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9569
9570 VkDescriptorSetLayoutBinding dsl_binding = {};
9571 dsl_binding.binding = 0;
9572 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9573 dsl_binding.descriptorCount = 1;
9574 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9575 dsl_binding.pImmutableSamplers = NULL;
9576
9577 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9578 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9579 ds_layout_ci.pNext = NULL;
9580 ds_layout_ci.bindingCount = 1;
9581 ds_layout_ci.pBindings = &dsl_binding;
9582
9583 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009584 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009585 ASSERT_VK_SUCCESS(err);
9586
9587 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9588 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9589 pipeline_layout_ci.pNext = NULL;
9590 pipeline_layout_ci.setLayoutCount = 1;
9591 pipeline_layout_ci.pSetLayouts = &ds_layout;
9592
9593 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009594 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009595 ASSERT_VK_SUCCESS(err);
9596
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009597 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9598 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9599 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009600 // Create a renderpass that will be incompatible with default renderpass
9601 VkAttachmentReference attach = {};
9602 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9603 VkAttachmentReference color_att = {};
9604 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9605 VkSubpassDescription subpass = {};
9606 subpass.inputAttachmentCount = 1;
9607 subpass.pInputAttachments = &attach;
9608 subpass.colorAttachmentCount = 1;
9609 subpass.pColorAttachments = &color_att;
9610 VkRenderPassCreateInfo rpci = {};
9611 rpci.subpassCount = 1;
9612 rpci.pSubpasses = &subpass;
9613 rpci.attachmentCount = 1;
9614 VkAttachmentDescription attach_desc = {};
9615 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009616 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9617 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009618 rpci.pAttachments = &attach_desc;
9619 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9620 VkRenderPass rp;
9621 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9622 VkPipelineObj pipe(m_device);
9623 pipe.AddShader(&vs);
9624 pipe.AddShader(&fs);
9625 pipe.AddColorAttachment();
9626 VkViewport view_port = {};
9627 m_viewports.push_back(view_port);
9628 pipe.SetViewport(m_viewports);
9629 VkRect2D rect = {};
9630 m_scissors.push_back(rect);
9631 pipe.SetScissor(m_scissors);
9632 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9633
9634 VkCommandBufferInheritanceInfo cbii = {};
9635 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9636 cbii.renderPass = rp;
9637 cbii.subpass = 0;
9638 VkCommandBufferBeginInfo cbbi = {};
9639 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9640 cbbi.pInheritanceInfo = &cbii;
9641 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9642 VkRenderPassBeginInfo rpbi = {};
9643 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9644 rpbi.framebuffer = m_framebuffer;
9645 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009646 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9647 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009648
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009650 // Render triangle (the error should trigger on the attempt to draw).
9651 Draw(3, 1, 0, 0);
9652
9653 // Finalize recording of the command buffer
9654 EndCommandBuffer();
9655
9656 m_errorMonitor->VerifyFound();
9657
9658 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9659 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9660 vkDestroyRenderPass(m_device->device(), rp, NULL);
9661}
9662
Mark Youngc89c6312016-03-31 16:03:20 -06009663TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9664 // Create Pipeline where the number of blend attachments doesn't match the
9665 // number of color attachments. In this case, we don't add any color
9666 // blend attachments even though we have a color attachment.
9667 VkResult err;
9668
9669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009670 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009671
9672 ASSERT_NO_FATAL_FAILURE(InitState());
9673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9674 VkDescriptorPoolSize ds_type_count = {};
9675 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9676 ds_type_count.descriptorCount = 1;
9677
9678 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9679 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9680 ds_pool_ci.pNext = NULL;
9681 ds_pool_ci.maxSets = 1;
9682 ds_pool_ci.poolSizeCount = 1;
9683 ds_pool_ci.pPoolSizes = &ds_type_count;
9684
9685 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009686 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009687 ASSERT_VK_SUCCESS(err);
9688
9689 VkDescriptorSetLayoutBinding dsl_binding = {};
9690 dsl_binding.binding = 0;
9691 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9692 dsl_binding.descriptorCount = 1;
9693 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9694 dsl_binding.pImmutableSamplers = NULL;
9695
9696 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9697 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9698 ds_layout_ci.pNext = NULL;
9699 ds_layout_ci.bindingCount = 1;
9700 ds_layout_ci.pBindings = &dsl_binding;
9701
9702 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009703 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009704 ASSERT_VK_SUCCESS(err);
9705
9706 VkDescriptorSet descriptorSet;
9707 VkDescriptorSetAllocateInfo alloc_info = {};
9708 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9709 alloc_info.descriptorSetCount = 1;
9710 alloc_info.descriptorPool = ds_pool;
9711 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009712 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009713 ASSERT_VK_SUCCESS(err);
9714
9715 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009716 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009717 pipe_ms_state_ci.pNext = NULL;
9718 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9719 pipe_ms_state_ci.sampleShadingEnable = 0;
9720 pipe_ms_state_ci.minSampleShading = 1.0;
9721 pipe_ms_state_ci.pSampleMask = NULL;
9722
9723 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9724 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9725 pipeline_layout_ci.pNext = NULL;
9726 pipeline_layout_ci.setLayoutCount = 1;
9727 pipeline_layout_ci.pSetLayouts = &ds_layout;
9728
9729 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009730 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009731 ASSERT_VK_SUCCESS(err);
9732
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009733 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9734 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9735 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009736 VkPipelineObj pipe(m_device);
9737 pipe.AddShader(&vs);
9738 pipe.AddShader(&fs);
9739 pipe.SetMSAA(&pipe_ms_state_ci);
9740 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9741
9742 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009743 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009744
Mark Young29927482016-05-04 14:38:51 -06009745 // Render triangle (the error should trigger on the attempt to draw).
9746 Draw(3, 1, 0, 0);
9747
9748 // Finalize recording of the command buffer
9749 EndCommandBuffer();
9750
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009751 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009752
9753 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9754 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9755 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9756}
Mark Young29927482016-05-04 14:38:51 -06009757
Mark Muellerd4914412016-06-13 17:52:06 -06009758TEST_F(VkLayerTest, MissingClearAttachment) {
9759 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9760 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009761 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009763 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009764
9765 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9766 m_errorMonitor->VerifyFound();
9767}
9768
Karl Schultz6addd812016-02-02 17:17:23 -07009769TEST_F(VkLayerTest, ClearCmdNoDraw) {
9770 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9771 // to issuing a Draw
9772 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009773
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009775 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009776
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009777 ASSERT_NO_FATAL_FAILURE(InitState());
9778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009779
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009780 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009781 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9782 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009783
9784 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009785 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9786 ds_pool_ci.pNext = NULL;
9787 ds_pool_ci.maxSets = 1;
9788 ds_pool_ci.poolSizeCount = 1;
9789 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009790
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009791 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009792 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009793 ASSERT_VK_SUCCESS(err);
9794
Tony Barboureb254902015-07-15 12:50:33 -06009795 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009796 dsl_binding.binding = 0;
9797 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9798 dsl_binding.descriptorCount = 1;
9799 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9800 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009801
Tony Barboureb254902015-07-15 12:50:33 -06009802 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009803 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9804 ds_layout_ci.pNext = NULL;
9805 ds_layout_ci.bindingCount = 1;
9806 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009807
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009808 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009809 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009810 ASSERT_VK_SUCCESS(err);
9811
9812 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009813 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009814 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009815 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009816 alloc_info.descriptorPool = ds_pool;
9817 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009818 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009819 ASSERT_VK_SUCCESS(err);
9820
Tony Barboureb254902015-07-15 12:50:33 -06009821 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009822 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009823 pipe_ms_state_ci.pNext = NULL;
9824 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9825 pipe_ms_state_ci.sampleShadingEnable = 0;
9826 pipe_ms_state_ci.minSampleShading = 1.0;
9827 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009828
Tony Barboureb254902015-07-15 12:50:33 -06009829 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009830 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9831 pipeline_layout_ci.pNext = NULL;
9832 pipeline_layout_ci.setLayoutCount = 1;
9833 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009834
9835 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009836 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009837 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009838
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009839 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009840 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009841 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009842 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009843
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009844 VkPipelineObj pipe(m_device);
9845 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009846 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009847 pipe.SetMSAA(&pipe_ms_state_ci);
9848 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009849
9850 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009851
Karl Schultz6addd812016-02-02 17:17:23 -07009852 // Main thing we care about for this test is that the VkImage obj we're
9853 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009854 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009855 VkClearAttachment color_attachment;
9856 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9857 color_attachment.clearValue.color.float32[0] = 1.0;
9858 color_attachment.clearValue.color.float32[1] = 1.0;
9859 color_attachment.clearValue.color.float32[2] = 1.0;
9860 color_attachment.clearValue.color.float32[3] = 1.0;
9861 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009862 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009863
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009864 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009865
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009866 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009867
Chia-I Wuf7458c52015-10-26 21:10:41 +08009868 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9869 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9870 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009871}
9872
Karl Schultz6addd812016-02-02 17:17:23 -07009873TEST_F(VkLayerTest, VtxBufferBadIndex) {
9874 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009875
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9877 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009878
Tobin Ehlis502480b2015-06-24 15:53:07 -06009879 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009880 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009882
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009883 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009884 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9885 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009886
9887 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009888 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9889 ds_pool_ci.pNext = NULL;
9890 ds_pool_ci.maxSets = 1;
9891 ds_pool_ci.poolSizeCount = 1;
9892 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009893
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009894 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009896 ASSERT_VK_SUCCESS(err);
9897
Tony Barboureb254902015-07-15 12:50:33 -06009898 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009899 dsl_binding.binding = 0;
9900 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9901 dsl_binding.descriptorCount = 1;
9902 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9903 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009904
Tony Barboureb254902015-07-15 12:50:33 -06009905 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009906 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9907 ds_layout_ci.pNext = NULL;
9908 ds_layout_ci.bindingCount = 1;
9909 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009910
Tobin Ehlis502480b2015-06-24 15:53:07 -06009911 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009912 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009913 ASSERT_VK_SUCCESS(err);
9914
9915 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009916 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009917 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009918 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009919 alloc_info.descriptorPool = ds_pool;
9920 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009921 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009922 ASSERT_VK_SUCCESS(err);
9923
Tony Barboureb254902015-07-15 12:50:33 -06009924 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009925 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009926 pipe_ms_state_ci.pNext = NULL;
9927 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9928 pipe_ms_state_ci.sampleShadingEnable = 0;
9929 pipe_ms_state_ci.minSampleShading = 1.0;
9930 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009931
Tony Barboureb254902015-07-15 12:50:33 -06009932 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009933 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9934 pipeline_layout_ci.pNext = NULL;
9935 pipeline_layout_ci.setLayoutCount = 1;
9936 pipeline_layout_ci.pSetLayouts = &ds_layout;
9937 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009939 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009940 ASSERT_VK_SUCCESS(err);
9941
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009942 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9943 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9944 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009945 VkPipelineObj pipe(m_device);
9946 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009947 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009948 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009949 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009950 pipe.SetViewport(m_viewports);
9951 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009952 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009953
9954 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009955 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009956 // Don't care about actual data, just need to get to draw to flag error
9957 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009958 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009959 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009960 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009961
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009962 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009963
Chia-I Wuf7458c52015-10-26 21:10:41 +08009964 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9966 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009967}
Mark Muellerdfe37552016-07-07 14:47:42 -06009968
Mark Mueller2ee294f2016-08-04 12:59:48 -06009969TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9970 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9971 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009972 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009973
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009974 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9975 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009976
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009977 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9978 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009980 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009983 // The following test fails with recent NVidia drivers.
9984 // By the time core_validation is reached, the NVidia
9985 // driver has sanitized the invalid condition and core_validation
9986 // is not introduced to the failure condition. This is not the case
9987 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009988 // uint32_t count = static_cast<uint32_t>(~0);
9989 // VkPhysicalDevice physical_device;
9990 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9991 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009992
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009994 float queue_priority = 0.0;
9995
9996 VkDeviceQueueCreateInfo queue_create_info = {};
9997 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9998 queue_create_info.queueCount = 1;
9999 queue_create_info.pQueuePriorities = &queue_priority;
10000 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10001
10002 VkPhysicalDeviceFeatures features = m_device->phy().features();
10003 VkDevice testDevice;
10004 VkDeviceCreateInfo device_create_info = {};
10005 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10006 device_create_info.queueCreateInfoCount = 1;
10007 device_create_info.pQueueCreateInfos = &queue_create_info;
10008 device_create_info.pEnabledFeatures = &features;
10009 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10010 m_errorMonitor->VerifyFound();
10011
10012 queue_create_info.queueFamilyIndex = 1;
10013
10014 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10015 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10016 for (unsigned i = 0; i < feature_count; i++) {
10017 if (VK_FALSE == feature_array[i]) {
10018 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010020 device_create_info.pEnabledFeatures = &features;
10021 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10022 m_errorMonitor->VerifyFound();
10023 break;
10024 }
10025 }
10026}
10027
10028TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10029 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10030 "End a command buffer with a query still in progress.");
10031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010032 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10033 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10034 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010036 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010039
10040 ASSERT_NO_FATAL_FAILURE(InitState());
10041
10042 VkEvent event;
10043 VkEventCreateInfo event_create_info{};
10044 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10045 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10046
Mark Mueller2ee294f2016-08-04 12:59:48 -060010047 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010048 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010049
10050 BeginCommandBuffer();
10051
10052 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010053 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 -060010054 ASSERT_TRUE(image.initialized());
10055 VkImageMemoryBarrier img_barrier = {};
10056 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10057 img_barrier.pNext = NULL;
10058 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10059 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10060 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10061 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10062 img_barrier.image = image.handle();
10063 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010064
10065 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10066 // that layer validation catches the case when it is not.
10067 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010068 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10069 img_barrier.subresourceRange.baseArrayLayer = 0;
10070 img_barrier.subresourceRange.baseMipLevel = 0;
10071 img_barrier.subresourceRange.layerCount = 1;
10072 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010073 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10074 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010075 m_errorMonitor->VerifyFound();
10076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010078
10079 VkQueryPool query_pool;
10080 VkQueryPoolCreateInfo query_pool_create_info = {};
10081 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10082 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10083 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010084 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010085
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010086 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010087 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10088
10089 vkEndCommandBuffer(m_commandBuffer->handle());
10090 m_errorMonitor->VerifyFound();
10091
10092 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10093 vkDestroyEvent(m_device->device(), event, nullptr);
10094}
10095
Mark Muellerdfe37552016-07-07 14:47:42 -060010096TEST_F(VkLayerTest, VertexBufferInvalid) {
10097 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10098 "delete a buffer twice, use an invalid offset for each "
10099 "buffer type, and attempt to bind a null buffer");
10100
10101 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10102 "using deleted buffer ";
10103 const char *double_destroy_message = "Cannot free buffer 0x";
10104 const char *invalid_offset_message = "vkBindBufferMemory(): "
10105 "memoryOffset is 0x";
10106 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10107 "storage memoryOffset "
10108 "is 0x";
10109 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10110 "texel memoryOffset "
10111 "is 0x";
10112 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10113 "uniform memoryOffset "
10114 "is 0x";
10115 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
10116 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -060010117 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010118
10119 ASSERT_NO_FATAL_FAILURE(InitState());
10120 ASSERT_NO_FATAL_FAILURE(InitViewport());
10121 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10122
10123 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010124 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010125 pipe_ms_state_ci.pNext = NULL;
10126 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10127 pipe_ms_state_ci.sampleShadingEnable = 0;
10128 pipe_ms_state_ci.minSampleShading = 1.0;
10129 pipe_ms_state_ci.pSampleMask = nullptr;
10130
10131 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10132 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10133 VkPipelineLayout pipeline_layout;
10134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010135 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010136 ASSERT_VK_SUCCESS(err);
10137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010138 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10139 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010140 VkPipelineObj pipe(m_device);
10141 pipe.AddShader(&vs);
10142 pipe.AddShader(&fs);
10143 pipe.AddColorAttachment();
10144 pipe.SetMSAA(&pipe_ms_state_ci);
10145 pipe.SetViewport(m_viewports);
10146 pipe.SetScissor(m_scissors);
10147 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10148
10149 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010150 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010151
10152 {
10153 // Create and bind a vertex buffer in a reduced scope, which will cause
10154 // it to be deleted upon leaving this scope
10155 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010156 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010157 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10158 draw_verticies.AddVertexInputToPipe(pipe);
10159 }
10160
10161 Draw(1, 0, 0, 0);
10162
10163 EndCommandBuffer();
10164
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010166 QueueCommandBuffer(false);
10167 m_errorMonitor->VerifyFound();
10168
10169 {
10170 // Create and bind a vertex buffer in a reduced scope, and delete it
10171 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010172 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010174 buffer_test.TestDoubleDestroy();
10175 }
10176 m_errorMonitor->VerifyFound();
10177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010178 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010179 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10181 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10182 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010183 m_errorMonitor->VerifyFound();
10184 }
10185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010186 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10187 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010188 // Create and bind a memory buffer with an invalid offset again,
10189 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10191 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10192 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010193 m_errorMonitor->VerifyFound();
10194 }
10195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010196 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010197 // Create and bind a memory buffer with an invalid offset again, but
10198 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10200 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10201 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010202 m_errorMonitor->VerifyFound();
10203 }
10204
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010205 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010206 // Create and bind a memory buffer with an invalid offset again, but
10207 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10209 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10210 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010211 m_errorMonitor->VerifyFound();
10212 }
10213
10214 {
10215 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10217 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10218 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010219 m_errorMonitor->VerifyFound();
10220 }
10221
10222 {
10223 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10225 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10226 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010227 }
10228 m_errorMonitor->VerifyFound();
10229
10230 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10231}
10232
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010233// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10234TEST_F(VkLayerTest, InvalidImageLayout) {
10235 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010236 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10237 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010238 // 3 in ValidateCmdBufImageLayouts
10239 // * -1 Attempt to submit cmd buf w/ deleted image
10240 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10241 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10243 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010244
10245 ASSERT_NO_FATAL_FAILURE(InitState());
10246 // Create src & dst images to use for copy operations
10247 VkImage src_image;
10248 VkImage dst_image;
10249
10250 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10251 const int32_t tex_width = 32;
10252 const int32_t tex_height = 32;
10253
10254 VkImageCreateInfo image_create_info = {};
10255 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10256 image_create_info.pNext = NULL;
10257 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10258 image_create_info.format = tex_format;
10259 image_create_info.extent.width = tex_width;
10260 image_create_info.extent.height = tex_height;
10261 image_create_info.extent.depth = 1;
10262 image_create_info.mipLevels = 1;
10263 image_create_info.arrayLayers = 4;
10264 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10265 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10266 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10267 image_create_info.flags = 0;
10268
10269 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10270 ASSERT_VK_SUCCESS(err);
10271 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10272 ASSERT_VK_SUCCESS(err);
10273
10274 BeginCommandBuffer();
10275 VkImageCopy copyRegion;
10276 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10277 copyRegion.srcSubresource.mipLevel = 0;
10278 copyRegion.srcSubresource.baseArrayLayer = 0;
10279 copyRegion.srcSubresource.layerCount = 1;
10280 copyRegion.srcOffset.x = 0;
10281 copyRegion.srcOffset.y = 0;
10282 copyRegion.srcOffset.z = 0;
10283 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10284 copyRegion.dstSubresource.mipLevel = 0;
10285 copyRegion.dstSubresource.baseArrayLayer = 0;
10286 copyRegion.dstSubresource.layerCount = 1;
10287 copyRegion.dstOffset.x = 0;
10288 copyRegion.dstOffset.y = 0;
10289 copyRegion.dstOffset.z = 0;
10290 copyRegion.extent.width = 1;
10291 copyRegion.extent.height = 1;
10292 copyRegion.extent.depth = 1;
10293 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10294 m_errorMonitor->VerifyFound();
10295 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10297 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10298 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010299 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10300 m_errorMonitor->VerifyFound();
10301 // Final src error is due to bad layout type
10302 m_errorMonitor->SetDesiredFailureMsg(
10303 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10304 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10305 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10306 m_errorMonitor->VerifyFound();
10307 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10309 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010310 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10311 m_errorMonitor->VerifyFound();
10312 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10314 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10315 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010316 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10317 m_errorMonitor->VerifyFound();
10318 m_errorMonitor->SetDesiredFailureMsg(
10319 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10320 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10321 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10322 m_errorMonitor->VerifyFound();
10323 // Now cause error due to bad image layout transition in PipelineBarrier
10324 VkImageMemoryBarrier image_barrier[1] = {};
10325 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10326 image_barrier[0].image = src_image;
10327 image_barrier[0].subresourceRange.layerCount = 2;
10328 image_barrier[0].subresourceRange.levelCount = 2;
10329 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10331 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10332 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10333 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10334 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010335 m_errorMonitor->VerifyFound();
10336
10337 // Finally some layout errors at RenderPass create time
10338 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10339 VkAttachmentReference attach = {};
10340 // perf warning for GENERAL layout w/ non-DS input attachment
10341 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10342 VkSubpassDescription subpass = {};
10343 subpass.inputAttachmentCount = 1;
10344 subpass.pInputAttachments = &attach;
10345 VkRenderPassCreateInfo rpci = {};
10346 rpci.subpassCount = 1;
10347 rpci.pSubpasses = &subpass;
10348 rpci.attachmentCount = 1;
10349 VkAttachmentDescription attach_desc = {};
10350 attach_desc.format = VK_FORMAT_UNDEFINED;
10351 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010352 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010353 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10355 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010356 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10357 m_errorMonitor->VerifyFound();
10358 // error w/ non-general layout
10359 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10360
10361 m_errorMonitor->SetDesiredFailureMsg(
10362 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10363 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10364 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10365 m_errorMonitor->VerifyFound();
10366 subpass.inputAttachmentCount = 0;
10367 subpass.colorAttachmentCount = 1;
10368 subpass.pColorAttachments = &attach;
10369 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10370 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10372 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010373 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10374 m_errorMonitor->VerifyFound();
10375 // error w/ non-color opt or GENERAL layout for color attachment
10376 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10377 m_errorMonitor->SetDesiredFailureMsg(
10378 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10379 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10380 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10381 m_errorMonitor->VerifyFound();
10382 subpass.colorAttachmentCount = 0;
10383 subpass.pDepthStencilAttachment = &attach;
10384 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10385 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10387 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010388 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10389 m_errorMonitor->VerifyFound();
10390 // error w/ non-ds opt or GENERAL layout for color attachment
10391 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10393 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10394 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010395 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10396 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010397 // For this error we need a valid renderpass so create default one
10398 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10399 attach.attachment = 0;
10400 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10401 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10402 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10403 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10404 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10405 // Can't do a CLEAR load on READ_ONLY initialLayout
10406 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10407 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10408 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10410 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10411 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010412 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10413 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010414
10415 vkDestroyImage(m_device->device(), src_image, NULL);
10416 vkDestroyImage(m_device->device(), dst_image, NULL);
10417}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010418
Tobin Ehlise0936662016-10-11 08:10:51 -060010419TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10420 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10421 VkResult err;
10422
10423 ASSERT_NO_FATAL_FAILURE(InitState());
10424
10425 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10426 VkImageTiling tiling;
10427 VkFormatProperties format_properties;
10428 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10429 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10430 tiling = VK_IMAGE_TILING_LINEAR;
10431 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10432 tiling = VK_IMAGE_TILING_OPTIMAL;
10433 } else {
10434 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10435 "skipped.\n");
10436 return;
10437 }
10438
10439 VkDescriptorPoolSize ds_type = {};
10440 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10441 ds_type.descriptorCount = 1;
10442
10443 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10444 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10445 ds_pool_ci.maxSets = 1;
10446 ds_pool_ci.poolSizeCount = 1;
10447 ds_pool_ci.pPoolSizes = &ds_type;
10448 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10449
10450 VkDescriptorPool ds_pool;
10451 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10452 ASSERT_VK_SUCCESS(err);
10453
10454 VkDescriptorSetLayoutBinding dsl_binding = {};
10455 dsl_binding.binding = 0;
10456 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10457 dsl_binding.descriptorCount = 1;
10458 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10459 dsl_binding.pImmutableSamplers = NULL;
10460
10461 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10462 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10463 ds_layout_ci.pNext = NULL;
10464 ds_layout_ci.bindingCount = 1;
10465 ds_layout_ci.pBindings = &dsl_binding;
10466
10467 VkDescriptorSetLayout ds_layout;
10468 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10469 ASSERT_VK_SUCCESS(err);
10470
10471 VkDescriptorSetAllocateInfo alloc_info = {};
10472 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10473 alloc_info.descriptorSetCount = 1;
10474 alloc_info.descriptorPool = ds_pool;
10475 alloc_info.pSetLayouts = &ds_layout;
10476 VkDescriptorSet descriptor_set;
10477 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10478 ASSERT_VK_SUCCESS(err);
10479
10480 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10481 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10482 pipeline_layout_ci.pNext = NULL;
10483 pipeline_layout_ci.setLayoutCount = 1;
10484 pipeline_layout_ci.pSetLayouts = &ds_layout;
10485 VkPipelineLayout pipeline_layout;
10486 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10487 ASSERT_VK_SUCCESS(err);
10488
10489 VkImageObj image(m_device);
10490 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10491 ASSERT_TRUE(image.initialized());
10492 VkImageView view = image.targetView(tex_format);
10493
10494 VkDescriptorImageInfo image_info = {};
10495 image_info.imageView = view;
10496 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10497
10498 VkWriteDescriptorSet descriptor_write = {};
10499 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10500 descriptor_write.dstSet = descriptor_set;
10501 descriptor_write.dstBinding = 0;
10502 descriptor_write.descriptorCount = 1;
10503 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10504 descriptor_write.pImageInfo = &image_info;
10505
10506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10507 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10508 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10509 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10510 m_errorMonitor->VerifyFound();
10511
10512 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10513 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10514 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10515 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10516}
10517
Mark Mueller93b938f2016-08-18 10:27:40 -060010518TEST_F(VkLayerTest, SimultaneousUse) {
10519 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10520 "in primary and secondary command buffers.");
10521
10522 ASSERT_NO_FATAL_FAILURE(InitState());
10523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10524
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010525 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010526 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10527 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010528
10529 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010530 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010531 command_buffer_allocate_info.commandPool = m_commandPool;
10532 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10533 command_buffer_allocate_info.commandBufferCount = 1;
10534
10535 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010536 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010537 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10538 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010539 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010540 command_buffer_inheritance_info.renderPass = m_renderPass;
10541 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10542 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010543 command_buffer_begin_info.flags =
10544 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010545 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10546
10547 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010548 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10549 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010550 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010551 vkEndCommandBuffer(secondary_command_buffer);
10552
Mark Mueller93b938f2016-08-18 10:27:40 -060010553 VkSubmitInfo submit_info = {};
10554 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10555 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010556 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010557 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010558
Mark Mueller4042b652016-09-05 22:52:21 -060010559 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010560 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10562 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010563 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010564 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10565 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010566
10567 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010568 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10569
Mark Mueller4042b652016-09-05 22:52:21 -060010570 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010571 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010572 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10575 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010576 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010577 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10578 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010579}
10580
Mark Mueller917f6bc2016-08-30 10:57:19 -060010581TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10582 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10583 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010584 "Delete objects that are inuse. Call VkQueueSubmit "
10585 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010586
10587 ASSERT_NO_FATAL_FAILURE(InitState());
10588 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10589
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010590 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10591 const char *cannot_delete_event_message = "Cannot delete event 0x";
10592 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10593 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010594
10595 BeginCommandBuffer();
10596
10597 VkEvent event;
10598 VkEventCreateInfo event_create_info = {};
10599 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10600 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010601 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010602
Mark Muellerc8d441e2016-08-23 17:36:00 -060010603 EndCommandBuffer();
10604 vkDestroyEvent(m_device->device(), event, nullptr);
10605
10606 VkSubmitInfo submit_info = {};
10607 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10608 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010609 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010611 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10612 m_errorMonitor->VerifyFound();
10613
10614 m_errorMonitor->SetDesiredFailureMsg(0, "");
10615 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10616
10617 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10618
Mark Mueller917f6bc2016-08-30 10:57:19 -060010619 VkSemaphoreCreateInfo semaphore_create_info = {};
10620 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10621 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010622 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010623 VkFenceCreateInfo fence_create_info = {};
10624 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10625 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010626 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010627
10628 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010629 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010630 descriptor_pool_type_count.descriptorCount = 1;
10631
10632 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10633 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10634 descriptor_pool_create_info.maxSets = 1;
10635 descriptor_pool_create_info.poolSizeCount = 1;
10636 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010637 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010638
10639 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010640 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010641
10642 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010643 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010644 descriptorset_layout_binding.descriptorCount = 1;
10645 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10646
10647 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010648 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010649 descriptorset_layout_create_info.bindingCount = 1;
10650 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10651
10652 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010653 ASSERT_VK_SUCCESS(
10654 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010655
10656 VkDescriptorSet descriptorset;
10657 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010658 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010659 descriptorset_allocate_info.descriptorSetCount = 1;
10660 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10661 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010662 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010663
Mark Mueller4042b652016-09-05 22:52:21 -060010664 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10665
10666 VkDescriptorBufferInfo buffer_info = {};
10667 buffer_info.buffer = buffer_test.GetBuffer();
10668 buffer_info.offset = 0;
10669 buffer_info.range = 1024;
10670
10671 VkWriteDescriptorSet write_descriptor_set = {};
10672 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10673 write_descriptor_set.dstSet = descriptorset;
10674 write_descriptor_set.descriptorCount = 1;
10675 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10676 write_descriptor_set.pBufferInfo = &buffer_info;
10677
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010678 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010679
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010680 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10681 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010682
10683 VkPipelineObj pipe(m_device);
10684 pipe.AddColorAttachment();
10685 pipe.AddShader(&vs);
10686 pipe.AddShader(&fs);
10687
10688 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010689 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010690 pipeline_layout_create_info.setLayoutCount = 1;
10691 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10692
10693 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010694 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010695
10696 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10697
Mark Muellerc8d441e2016-08-23 17:36:00 -060010698 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010699 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010700
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010701 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10702 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10703 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010704
Mark Muellerc8d441e2016-08-23 17:36:00 -060010705 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010706
Mark Mueller917f6bc2016-08-30 10:57:19 -060010707 submit_info.signalSemaphoreCount = 1;
10708 submit_info.pSignalSemaphores = &semaphore;
10709 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010710
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010712 vkDestroyEvent(m_device->device(), event, nullptr);
10713 m_errorMonitor->VerifyFound();
10714
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010716 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10717 m_errorMonitor->VerifyFound();
10718
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010720 vkDestroyFence(m_device->device(), fence, nullptr);
10721 m_errorMonitor->VerifyFound();
10722
Tobin Ehlis122207b2016-09-01 08:50:06 -070010723 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010724 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10725 vkDestroyFence(m_device->device(), fence, nullptr);
10726 vkDestroyEvent(m_device->device(), event, nullptr);
10727 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010728 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010729 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10730}
10731
Tobin Ehlis2adda372016-09-01 08:51:06 -070010732TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10733 TEST_DESCRIPTION("Delete in-use query pool.");
10734
10735 ASSERT_NO_FATAL_FAILURE(InitState());
10736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10737
10738 VkQueryPool query_pool;
10739 VkQueryPoolCreateInfo query_pool_ci{};
10740 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10741 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10742 query_pool_ci.queryCount = 1;
10743 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10744 BeginCommandBuffer();
10745 // Reset query pool to create binding with cmd buffer
10746 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10747
10748 EndCommandBuffer();
10749
10750 VkSubmitInfo submit_info = {};
10751 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10752 submit_info.commandBufferCount = 1;
10753 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10754 // Submit cmd buffer and then destroy query pool while in-flight
10755 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10756
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010758 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10759 m_errorMonitor->VerifyFound();
10760
10761 vkQueueWaitIdle(m_device->m_queue);
10762 // Now that cmd buffer done we can safely destroy query_pool
10763 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10764}
10765
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010766TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10767 TEST_DESCRIPTION("Delete in-use pipeline.");
10768
10769 ASSERT_NO_FATAL_FAILURE(InitState());
10770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10771
10772 // Empty pipeline layout used for binding PSO
10773 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10774 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10775 pipeline_layout_ci.setLayoutCount = 0;
10776 pipeline_layout_ci.pSetLayouts = NULL;
10777
10778 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010779 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010780 ASSERT_VK_SUCCESS(err);
10781
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010783 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010784 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10785 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010786 // Store pipeline handle so we can actually delete it before test finishes
10787 VkPipeline delete_this_pipeline;
10788 { // Scope pipeline so it will be auto-deleted
10789 VkPipelineObj pipe(m_device);
10790 pipe.AddShader(&vs);
10791 pipe.AddShader(&fs);
10792 pipe.AddColorAttachment();
10793 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10794 delete_this_pipeline = pipe.handle();
10795
10796 BeginCommandBuffer();
10797 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010798 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010799
10800 EndCommandBuffer();
10801
10802 VkSubmitInfo submit_info = {};
10803 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10804 submit_info.commandBufferCount = 1;
10805 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10806 // Submit cmd buffer and then pipeline destroyed while in-flight
10807 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10808 } // Pipeline deletion triggered here
10809 m_errorMonitor->VerifyFound();
10810 // Make sure queue finished and then actually delete pipeline
10811 vkQueueWaitIdle(m_device->m_queue);
10812 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10813 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10814}
10815
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010816TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10817 TEST_DESCRIPTION("Delete in-use imageView.");
10818
10819 ASSERT_NO_FATAL_FAILURE(InitState());
10820 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10821
10822 VkDescriptorPoolSize ds_type_count;
10823 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10824 ds_type_count.descriptorCount = 1;
10825
10826 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10827 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10828 ds_pool_ci.maxSets = 1;
10829 ds_pool_ci.poolSizeCount = 1;
10830 ds_pool_ci.pPoolSizes = &ds_type_count;
10831
10832 VkDescriptorPool ds_pool;
10833 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10834 ASSERT_VK_SUCCESS(err);
10835
10836 VkSamplerCreateInfo sampler_ci = {};
10837 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10838 sampler_ci.pNext = NULL;
10839 sampler_ci.magFilter = VK_FILTER_NEAREST;
10840 sampler_ci.minFilter = VK_FILTER_NEAREST;
10841 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10842 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10843 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10844 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10845 sampler_ci.mipLodBias = 1.0;
10846 sampler_ci.anisotropyEnable = VK_FALSE;
10847 sampler_ci.maxAnisotropy = 1;
10848 sampler_ci.compareEnable = VK_FALSE;
10849 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10850 sampler_ci.minLod = 1.0;
10851 sampler_ci.maxLod = 1.0;
10852 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10853 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10854 VkSampler sampler;
10855
10856 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10857 ASSERT_VK_SUCCESS(err);
10858
10859 VkDescriptorSetLayoutBinding layout_binding;
10860 layout_binding.binding = 0;
10861 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10862 layout_binding.descriptorCount = 1;
10863 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10864 layout_binding.pImmutableSamplers = NULL;
10865
10866 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10867 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10868 ds_layout_ci.bindingCount = 1;
10869 ds_layout_ci.pBindings = &layout_binding;
10870 VkDescriptorSetLayout ds_layout;
10871 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10872 ASSERT_VK_SUCCESS(err);
10873
10874 VkDescriptorSetAllocateInfo alloc_info = {};
10875 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10876 alloc_info.descriptorSetCount = 1;
10877 alloc_info.descriptorPool = ds_pool;
10878 alloc_info.pSetLayouts = &ds_layout;
10879 VkDescriptorSet descriptor_set;
10880 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10881 ASSERT_VK_SUCCESS(err);
10882
10883 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10884 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10885 pipeline_layout_ci.pNext = NULL;
10886 pipeline_layout_ci.setLayoutCount = 1;
10887 pipeline_layout_ci.pSetLayouts = &ds_layout;
10888
10889 VkPipelineLayout pipeline_layout;
10890 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10891 ASSERT_VK_SUCCESS(err);
10892
10893 VkImageObj image(m_device);
10894 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10895 ASSERT_TRUE(image.initialized());
10896
10897 VkImageView view;
10898 VkImageViewCreateInfo ivci = {};
10899 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10900 ivci.image = image.handle();
10901 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10902 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10903 ivci.subresourceRange.layerCount = 1;
10904 ivci.subresourceRange.baseMipLevel = 0;
10905 ivci.subresourceRange.levelCount = 1;
10906 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10907
10908 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10909 ASSERT_VK_SUCCESS(err);
10910
10911 VkDescriptorImageInfo image_info{};
10912 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10913 image_info.imageView = view;
10914 image_info.sampler = sampler;
10915
10916 VkWriteDescriptorSet descriptor_write = {};
10917 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10918 descriptor_write.dstSet = descriptor_set;
10919 descriptor_write.dstBinding = 0;
10920 descriptor_write.descriptorCount = 1;
10921 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10922 descriptor_write.pImageInfo = &image_info;
10923
10924 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10925
10926 // Create PSO to use the sampler
10927 char const *vsSource = "#version 450\n"
10928 "\n"
10929 "out gl_PerVertex { \n"
10930 " vec4 gl_Position;\n"
10931 "};\n"
10932 "void main(){\n"
10933 " gl_Position = vec4(1);\n"
10934 "}\n";
10935 char const *fsSource = "#version 450\n"
10936 "\n"
10937 "layout(set=0, binding=0) uniform sampler2D s;\n"
10938 "layout(location=0) out vec4 x;\n"
10939 "void main(){\n"
10940 " x = texture(s, vec2(1));\n"
10941 "}\n";
10942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10944 VkPipelineObj pipe(m_device);
10945 pipe.AddShader(&vs);
10946 pipe.AddShader(&fs);
10947 pipe.AddColorAttachment();
10948 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10949
10950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10951
10952 BeginCommandBuffer();
10953 // Bind pipeline to cmd buffer
10954 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10955 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10956 &descriptor_set, 0, nullptr);
10957 Draw(1, 0, 0, 0);
10958 EndCommandBuffer();
10959 // Submit cmd buffer then destroy sampler
10960 VkSubmitInfo submit_info = {};
10961 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10962 submit_info.commandBufferCount = 1;
10963 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10964 // Submit cmd buffer and then destroy imageView while in-flight
10965 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10966
10967 vkDestroyImageView(m_device->device(), view, nullptr);
10968 m_errorMonitor->VerifyFound();
10969 vkQueueWaitIdle(m_device->m_queue);
10970 // Now we can actually destroy imageView
10971 vkDestroyImageView(m_device->device(), view, NULL);
10972 vkDestroySampler(m_device->device(), sampler, nullptr);
10973 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10974 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10975 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10976}
10977
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010978TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10979 TEST_DESCRIPTION("Delete in-use bufferView.");
10980
10981 ASSERT_NO_FATAL_FAILURE(InitState());
10982 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10983
10984 VkDescriptorPoolSize ds_type_count;
10985 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10986 ds_type_count.descriptorCount = 1;
10987
10988 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10989 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10990 ds_pool_ci.maxSets = 1;
10991 ds_pool_ci.poolSizeCount = 1;
10992 ds_pool_ci.pPoolSizes = &ds_type_count;
10993
10994 VkDescriptorPool ds_pool;
10995 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10996 ASSERT_VK_SUCCESS(err);
10997
10998 VkDescriptorSetLayoutBinding layout_binding;
10999 layout_binding.binding = 0;
11000 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11001 layout_binding.descriptorCount = 1;
11002 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11003 layout_binding.pImmutableSamplers = NULL;
11004
11005 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11006 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11007 ds_layout_ci.bindingCount = 1;
11008 ds_layout_ci.pBindings = &layout_binding;
11009 VkDescriptorSetLayout ds_layout;
11010 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11011 ASSERT_VK_SUCCESS(err);
11012
11013 VkDescriptorSetAllocateInfo alloc_info = {};
11014 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11015 alloc_info.descriptorSetCount = 1;
11016 alloc_info.descriptorPool = ds_pool;
11017 alloc_info.pSetLayouts = &ds_layout;
11018 VkDescriptorSet descriptor_set;
11019 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11020 ASSERT_VK_SUCCESS(err);
11021
11022 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11023 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11024 pipeline_layout_ci.pNext = NULL;
11025 pipeline_layout_ci.setLayoutCount = 1;
11026 pipeline_layout_ci.pSetLayouts = &ds_layout;
11027
11028 VkPipelineLayout pipeline_layout;
11029 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11030 ASSERT_VK_SUCCESS(err);
11031
11032 VkBuffer buffer;
11033 uint32_t queue_family_index = 0;
11034 VkBufferCreateInfo buffer_create_info = {};
11035 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11036 buffer_create_info.size = 1024;
11037 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11038 buffer_create_info.queueFamilyIndexCount = 1;
11039 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11040
11041 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11042 ASSERT_VK_SUCCESS(err);
11043
11044 VkMemoryRequirements memory_reqs;
11045 VkDeviceMemory buffer_memory;
11046
11047 VkMemoryAllocateInfo memory_info = {};
11048 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11049 memory_info.allocationSize = 0;
11050 memory_info.memoryTypeIndex = 0;
11051
11052 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11053 memory_info.allocationSize = memory_reqs.size;
11054 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11055 ASSERT_TRUE(pass);
11056
11057 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11058 ASSERT_VK_SUCCESS(err);
11059 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11060 ASSERT_VK_SUCCESS(err);
11061
11062 VkBufferView view;
11063 VkBufferViewCreateInfo bvci = {};
11064 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11065 bvci.buffer = buffer;
11066 bvci.format = VK_FORMAT_R8_UNORM;
11067 bvci.range = VK_WHOLE_SIZE;
11068
11069 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11070 ASSERT_VK_SUCCESS(err);
11071
11072 VkWriteDescriptorSet descriptor_write = {};
11073 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11074 descriptor_write.dstSet = descriptor_set;
11075 descriptor_write.dstBinding = 0;
11076 descriptor_write.descriptorCount = 1;
11077 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11078 descriptor_write.pTexelBufferView = &view;
11079
11080 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11081
11082 char const *vsSource = "#version 450\n"
11083 "\n"
11084 "out gl_PerVertex { \n"
11085 " vec4 gl_Position;\n"
11086 "};\n"
11087 "void main(){\n"
11088 " gl_Position = vec4(1);\n"
11089 "}\n";
11090 char const *fsSource = "#version 450\n"
11091 "\n"
11092 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11093 "layout(location=0) out vec4 x;\n"
11094 "void main(){\n"
11095 " x = imageLoad(s, 0);\n"
11096 "}\n";
11097 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11098 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11099 VkPipelineObj pipe(m_device);
11100 pipe.AddShader(&vs);
11101 pipe.AddShader(&fs);
11102 pipe.AddColorAttachment();
11103 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11104
11105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11106
11107 BeginCommandBuffer();
11108 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11109 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11110 VkRect2D scissor = {{0, 0}, {16, 16}};
11111 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11112 // Bind pipeline to cmd buffer
11113 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11114 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11115 &descriptor_set, 0, nullptr);
11116 Draw(1, 0, 0, 0);
11117 EndCommandBuffer();
11118
11119 VkSubmitInfo submit_info = {};
11120 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11121 submit_info.commandBufferCount = 1;
11122 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11123 // Submit cmd buffer and then destroy bufferView while in-flight
11124 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11125
11126 vkDestroyBufferView(m_device->device(), view, nullptr);
11127 m_errorMonitor->VerifyFound();
11128 vkQueueWaitIdle(m_device->m_queue);
11129 // Now we can actually destroy bufferView
11130 vkDestroyBufferView(m_device->device(), view, NULL);
11131 vkDestroyBuffer(m_device->device(), buffer, NULL);
11132 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11133 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11134 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11135 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11136}
11137
Tobin Ehlis209532e2016-09-07 13:52:18 -060011138TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11139 TEST_DESCRIPTION("Delete in-use sampler.");
11140
11141 ASSERT_NO_FATAL_FAILURE(InitState());
11142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11143
11144 VkDescriptorPoolSize ds_type_count;
11145 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11146 ds_type_count.descriptorCount = 1;
11147
11148 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11149 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11150 ds_pool_ci.maxSets = 1;
11151 ds_pool_ci.poolSizeCount = 1;
11152 ds_pool_ci.pPoolSizes = &ds_type_count;
11153
11154 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011155 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011156 ASSERT_VK_SUCCESS(err);
11157
11158 VkSamplerCreateInfo sampler_ci = {};
11159 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11160 sampler_ci.pNext = NULL;
11161 sampler_ci.magFilter = VK_FILTER_NEAREST;
11162 sampler_ci.minFilter = VK_FILTER_NEAREST;
11163 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11164 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11165 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11166 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11167 sampler_ci.mipLodBias = 1.0;
11168 sampler_ci.anisotropyEnable = VK_FALSE;
11169 sampler_ci.maxAnisotropy = 1;
11170 sampler_ci.compareEnable = VK_FALSE;
11171 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11172 sampler_ci.minLod = 1.0;
11173 sampler_ci.maxLod = 1.0;
11174 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11175 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11176 VkSampler sampler;
11177
11178 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11179 ASSERT_VK_SUCCESS(err);
11180
11181 VkDescriptorSetLayoutBinding layout_binding;
11182 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011183 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011184 layout_binding.descriptorCount = 1;
11185 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11186 layout_binding.pImmutableSamplers = NULL;
11187
11188 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11189 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11190 ds_layout_ci.bindingCount = 1;
11191 ds_layout_ci.pBindings = &layout_binding;
11192 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011193 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011194 ASSERT_VK_SUCCESS(err);
11195
11196 VkDescriptorSetAllocateInfo alloc_info = {};
11197 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11198 alloc_info.descriptorSetCount = 1;
11199 alloc_info.descriptorPool = ds_pool;
11200 alloc_info.pSetLayouts = &ds_layout;
11201 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011202 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011203 ASSERT_VK_SUCCESS(err);
11204
11205 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11206 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11207 pipeline_layout_ci.pNext = NULL;
11208 pipeline_layout_ci.setLayoutCount = 1;
11209 pipeline_layout_ci.pSetLayouts = &ds_layout;
11210
11211 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011212 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011213 ASSERT_VK_SUCCESS(err);
11214
11215 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011216 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 -060011217 ASSERT_TRUE(image.initialized());
11218
11219 VkImageView view;
11220 VkImageViewCreateInfo ivci = {};
11221 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11222 ivci.image = image.handle();
11223 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11224 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11225 ivci.subresourceRange.layerCount = 1;
11226 ivci.subresourceRange.baseMipLevel = 0;
11227 ivci.subresourceRange.levelCount = 1;
11228 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11229
11230 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11231 ASSERT_VK_SUCCESS(err);
11232
11233 VkDescriptorImageInfo image_info{};
11234 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11235 image_info.imageView = view;
11236 image_info.sampler = sampler;
11237
11238 VkWriteDescriptorSet descriptor_write = {};
11239 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11240 descriptor_write.dstSet = descriptor_set;
11241 descriptor_write.dstBinding = 0;
11242 descriptor_write.descriptorCount = 1;
11243 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11244 descriptor_write.pImageInfo = &image_info;
11245
11246 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11247
11248 // Create PSO to use the sampler
11249 char const *vsSource = "#version 450\n"
11250 "\n"
11251 "out gl_PerVertex { \n"
11252 " vec4 gl_Position;\n"
11253 "};\n"
11254 "void main(){\n"
11255 " gl_Position = vec4(1);\n"
11256 "}\n";
11257 char const *fsSource = "#version 450\n"
11258 "\n"
11259 "layout(set=0, binding=0) uniform sampler2D s;\n"
11260 "layout(location=0) out vec4 x;\n"
11261 "void main(){\n"
11262 " x = texture(s, vec2(1));\n"
11263 "}\n";
11264 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11265 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11266 VkPipelineObj pipe(m_device);
11267 pipe.AddShader(&vs);
11268 pipe.AddShader(&fs);
11269 pipe.AddColorAttachment();
11270 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011273
11274 BeginCommandBuffer();
11275 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011276 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11277 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11278 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011279 Draw(1, 0, 0, 0);
11280 EndCommandBuffer();
11281 // Submit cmd buffer then destroy sampler
11282 VkSubmitInfo submit_info = {};
11283 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11284 submit_info.commandBufferCount = 1;
11285 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11286 // Submit cmd buffer and then destroy sampler while in-flight
11287 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11288
11289 vkDestroySampler(m_device->device(), sampler, nullptr);
11290 m_errorMonitor->VerifyFound();
11291 vkQueueWaitIdle(m_device->m_queue);
11292 // Now we can actually destroy sampler
11293 vkDestroySampler(m_device->device(), sampler, nullptr);
11294 vkDestroyImageView(m_device->device(), view, NULL);
11295 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11296 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11297 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11298}
11299
Mark Mueller1cd9f412016-08-25 13:23:52 -060011300TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011301 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011302 "signaled but not waited on by the queue. Wait on a "
11303 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011304
11305 ASSERT_NO_FATAL_FAILURE(InitState());
11306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11307
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011308 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11309 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11310 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011311
11312 BeginCommandBuffer();
11313 EndCommandBuffer();
11314
11315 VkSemaphoreCreateInfo semaphore_create_info = {};
11316 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11317 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011318 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011319 VkSubmitInfo submit_info = {};
11320 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11321 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011322 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011323 submit_info.signalSemaphoreCount = 1;
11324 submit_info.pSignalSemaphores = &semaphore;
11325 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11326 m_errorMonitor->SetDesiredFailureMsg(0, "");
11327 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11328 BeginCommandBuffer();
11329 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011331 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11332 m_errorMonitor->VerifyFound();
11333
Mark Mueller1cd9f412016-08-25 13:23:52 -060011334 VkFenceCreateInfo fence_create_info = {};
11335 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11336 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011337 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011338
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011340 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11341 m_errorMonitor->VerifyFound();
11342
Mark Mueller4042b652016-09-05 22:52:21 -060011343 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011344 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011345 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11346}
11347
Tobin Ehlis4af23302016-07-19 10:50:30 -060011348TEST_F(VkLayerTest, FramebufferIncompatible) {
11349 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11350 "that does not match the framebuffer for the active "
11351 "renderpass.");
11352 ASSERT_NO_FATAL_FAILURE(InitState());
11353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11354
11355 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011356 VkAttachmentDescription attachment = {0,
11357 VK_FORMAT_B8G8R8A8_UNORM,
11358 VK_SAMPLE_COUNT_1_BIT,
11359 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11360 VK_ATTACHMENT_STORE_OP_STORE,
11361 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11362 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11363 VK_IMAGE_LAYOUT_UNDEFINED,
11364 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011366 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011368 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011370 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011371
11372 VkRenderPass rp;
11373 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11374 ASSERT_VK_SUCCESS(err);
11375
11376 // A compatible framebuffer.
11377 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011378 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 -060011379 ASSERT_TRUE(image.initialized());
11380
11381 VkImageViewCreateInfo ivci = {
11382 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11383 nullptr,
11384 0,
11385 image.handle(),
11386 VK_IMAGE_VIEW_TYPE_2D,
11387 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011388 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11389 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011390 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11391 };
11392 VkImageView view;
11393 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11394 ASSERT_VK_SUCCESS(err);
11395
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011396 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011397 VkFramebuffer fb;
11398 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11399 ASSERT_VK_SUCCESS(err);
11400
11401 VkCommandBufferAllocateInfo cbai = {};
11402 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11403 cbai.commandPool = m_commandPool;
11404 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11405 cbai.commandBufferCount = 1;
11406
11407 VkCommandBuffer sec_cb;
11408 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11409 ASSERT_VK_SUCCESS(err);
11410 VkCommandBufferBeginInfo cbbi = {};
11411 VkCommandBufferInheritanceInfo cbii = {};
11412 cbii.renderPass = renderPass();
11413 cbii.framebuffer = fb;
11414 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11415 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011416 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 -060011417 cbbi.pInheritanceInfo = &cbii;
11418 vkBeginCommandBuffer(sec_cb, &cbbi);
11419 vkEndCommandBuffer(sec_cb);
11420
Chris Forbes3400bc52016-09-13 18:10:34 +120011421 VkCommandBufferBeginInfo cbbi2 = {
11422 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11423 0, nullptr
11424 };
11425 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11426 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011427
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011429 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011430 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11431 m_errorMonitor->VerifyFound();
11432 // Cleanup
11433 vkDestroyImageView(m_device->device(), view, NULL);
11434 vkDestroyRenderPass(m_device->device(), rp, NULL);
11435 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11436}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011437
11438TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11439 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11440 "invalid value. If logicOp is not available, attempt to "
11441 "use it and verify that we see the correct error.");
11442 ASSERT_NO_FATAL_FAILURE(InitState());
11443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11444
11445 auto features = m_device->phy().features();
11446 // Set the expected error depending on whether or not logicOp available
11447 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11449 "enabled, logicOpEnable must be "
11450 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011451 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011453 }
11454 // Create a pipeline using logicOp
11455 VkResult err;
11456
11457 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11458 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11459
11460 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011461 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011462 ASSERT_VK_SUCCESS(err);
11463
11464 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11465 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11466 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011467 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011468 vp_state_ci.pViewports = &vp;
11469 vp_state_ci.scissorCount = 1;
11470 VkRect2D scissors = {}; // Dummy scissors to point to
11471 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011472
11473 VkPipelineShaderStageCreateInfo shaderStages[2];
11474 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11475
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011476 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11477 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011478 shaderStages[0] = vs.GetStageCreateInfo();
11479 shaderStages[1] = fs.GetStageCreateInfo();
11480
11481 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11482 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11483
11484 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11485 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11486 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11487
11488 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11489 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011490 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011491
11492 VkPipelineColorBlendAttachmentState att = {};
11493 att.blendEnable = VK_FALSE;
11494 att.colorWriteMask = 0xf;
11495
11496 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11497 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11498 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11499 cb_ci.logicOpEnable = VK_TRUE;
11500 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11501 cb_ci.attachmentCount = 1;
11502 cb_ci.pAttachments = &att;
11503
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011504 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11505 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11506 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11507
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011508 VkGraphicsPipelineCreateInfo gp_ci = {};
11509 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11510 gp_ci.stageCount = 2;
11511 gp_ci.pStages = shaderStages;
11512 gp_ci.pVertexInputState = &vi_ci;
11513 gp_ci.pInputAssemblyState = &ia_ci;
11514 gp_ci.pViewportState = &vp_state_ci;
11515 gp_ci.pRasterizationState = &rs_ci;
11516 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011517 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011518 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11519 gp_ci.layout = pipeline_layout;
11520 gp_ci.renderPass = renderPass();
11521
11522 VkPipelineCacheCreateInfo pc_ci = {};
11523 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11524
11525 VkPipeline pipeline;
11526 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011527 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011528 ASSERT_VK_SUCCESS(err);
11529
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011530 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011531 m_errorMonitor->VerifyFound();
11532 if (VK_SUCCESS == err) {
11533 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11534 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011535 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11536 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11537}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011538#endif // DRAW_STATE_TESTS
11539
Tobin Ehlis0788f522015-05-26 16:11:58 -060011540#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011541#if GTEST_IS_THREADSAFE
11542struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011543 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011544 VkEvent event;
11545 bool bailout;
11546};
11547
Karl Schultz6addd812016-02-02 17:17:23 -070011548extern "C" void *AddToCommandBuffer(void *arg) {
11549 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011550
Mike Stroyana6d14942016-07-13 15:10:05 -060011551 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011552 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011553 if (data->bailout) {
11554 break;
11555 }
11556 }
11557 return NULL;
11558}
11559
Karl Schultz6addd812016-02-02 17:17:23 -070011560TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011561 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011562
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011564
Mike Stroyanaccf7692015-05-12 16:00:45 -060011565 ASSERT_NO_FATAL_FAILURE(InitState());
11566 ASSERT_NO_FATAL_FAILURE(InitViewport());
11567 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11568
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011569 // Calls AllocateCommandBuffers
11570 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011571
11572 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011573 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011574
11575 VkEventCreateInfo event_info;
11576 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011577 VkResult err;
11578
11579 memset(&event_info, 0, sizeof(event_info));
11580 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11581
Chia-I Wuf7458c52015-10-26 21:10:41 +080011582 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011583 ASSERT_VK_SUCCESS(err);
11584
Mike Stroyanaccf7692015-05-12 16:00:45 -060011585 err = vkResetEvent(device(), event);
11586 ASSERT_VK_SUCCESS(err);
11587
11588 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011589 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011590 data.event = event;
11591 data.bailout = false;
11592 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011593
11594 // First do some correct operations using multiple threads.
11595 // Add many entries to command buffer from another thread.
11596 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11597 // Make non-conflicting calls from this thread at the same time.
11598 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011599 uint32_t count;
11600 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011601 }
11602 test_platform_thread_join(thread, NULL);
11603
11604 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011605 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011606 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011607 // Add many entries to command buffer from this thread at the same time.
11608 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011609
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011610 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011611 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011612
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011613 m_errorMonitor->SetBailout(NULL);
11614
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011615 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011616
Chia-I Wuf7458c52015-10-26 21:10:41 +080011617 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011618}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011619#endif // GTEST_IS_THREADSAFE
11620#endif // THREADING_TESTS
11621
Chris Forbes9f7ff632015-05-25 11:13:08 +120011622#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011623TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011624 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11625 "with an impossible code size");
11626
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011628
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011629 ASSERT_NO_FATAL_FAILURE(InitState());
11630 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11631
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011632 VkShaderModule module;
11633 VkShaderModuleCreateInfo moduleCreateInfo;
11634 struct icd_spv_header spv;
11635
11636 spv.magic = ICD_SPV_MAGIC;
11637 spv.version = ICD_SPV_VERSION;
11638 spv.gen_magic = 0;
11639
11640 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11641 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011642 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011643 moduleCreateInfo.codeSize = 4;
11644 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011645 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011646
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011647 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011648}
11649
Karl Schultz6addd812016-02-02 17:17:23 -070011650TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011651 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11652 "with a bad magic number");
11653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011655
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011656 ASSERT_NO_FATAL_FAILURE(InitState());
11657 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11658
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011659 VkShaderModule module;
11660 VkShaderModuleCreateInfo moduleCreateInfo;
11661 struct icd_spv_header spv;
11662
11663 spv.magic = ~ICD_SPV_MAGIC;
11664 spv.version = ICD_SPV_VERSION;
11665 spv.gen_magic = 0;
11666
11667 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11668 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011669 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011670 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11671 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011672 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011673
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011674 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011675}
11676
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011677#if 0
11678// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011679TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011681 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011682
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011683 ASSERT_NO_FATAL_FAILURE(InitState());
11684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11685
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011686 VkShaderModule module;
11687 VkShaderModuleCreateInfo moduleCreateInfo;
11688 struct icd_spv_header spv;
11689
11690 spv.magic = ICD_SPV_MAGIC;
11691 spv.version = ~ICD_SPV_VERSION;
11692 spv.gen_magic = 0;
11693
11694 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11695 moduleCreateInfo.pNext = NULL;
11696
Karl Schultz6addd812016-02-02 17:17:23 -070011697 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011698 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11699 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011700 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011701
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011702 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011703}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011704#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011705
Karl Schultz6addd812016-02-02 17:17:23 -070011706TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011707 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11708 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011710
Chris Forbes9f7ff632015-05-25 11:13:08 +120011711 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011712 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011713
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011714 char const *vsSource = "#version 450\n"
11715 "\n"
11716 "layout(location=0) out float x;\n"
11717 "out gl_PerVertex {\n"
11718 " vec4 gl_Position;\n"
11719 "};\n"
11720 "void main(){\n"
11721 " gl_Position = vec4(1);\n"
11722 " x = 0;\n"
11723 "}\n";
11724 char const *fsSource = "#version 450\n"
11725 "\n"
11726 "layout(location=0) out vec4 color;\n"
11727 "void main(){\n"
11728 " color = vec4(1);\n"
11729 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011730
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011731 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11732 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011733
11734 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011735 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011736 pipe.AddShader(&vs);
11737 pipe.AddShader(&fs);
11738
Chris Forbes9f7ff632015-05-25 11:13:08 +120011739 VkDescriptorSetObj descriptorSet(m_device);
11740 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011741 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011742
Tony Barbour5781e8f2015-08-04 16:23:11 -060011743 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011744
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011745 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011746}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011747
Mark Mueller098c9cb2016-09-08 09:01:57 -060011748TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11749 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11750
11751 ASSERT_NO_FATAL_FAILURE(InitState());
11752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11753
11754 const char *bad_specialization_message =
11755 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11756
11757 char const *vsSource =
11758 "#version 450\n"
11759 "\n"
11760 "out gl_PerVertex {\n"
11761 " vec4 gl_Position;\n"
11762 "};\n"
11763 "void main(){\n"
11764 " gl_Position = vec4(1);\n"
11765 "}\n";
11766
11767 char const *fsSource =
11768 "#version 450\n"
11769 "\n"
11770 "layout (constant_id = 0) const float r = 0.0f;\n"
11771 "layout(location = 0) out vec4 uFragColor;\n"
11772 "void main(){\n"
11773 " uFragColor = vec4(r,1,0,1);\n"
11774 "}\n";
11775
11776 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11777 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11778
11779 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11780 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11781
11782 VkPipelineLayout pipeline_layout;
11783 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11784
11785 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11786 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11787 vp_state_create_info.viewportCount = 1;
11788 VkViewport viewport = {};
11789 vp_state_create_info.pViewports = &viewport;
11790 vp_state_create_info.scissorCount = 1;
11791 VkRect2D scissors = {};
11792 vp_state_create_info.pScissors = &scissors;
11793
11794 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11795
11796 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11797 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11798 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11799 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11800
11801 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11802 vs.GetStageCreateInfo(),
11803 fs.GetStageCreateInfo()
11804 };
11805
11806 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11807 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11808
11809 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11810 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11811 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11812
11813 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11814 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11815 rasterization_state_create_info.pNext = nullptr;
11816 rasterization_state_create_info.lineWidth = 1.0f;
11817 rasterization_state_create_info.rasterizerDiscardEnable = true;
11818
11819 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11820 color_blend_attachment_state.blendEnable = VK_FALSE;
11821 color_blend_attachment_state.colorWriteMask = 0xf;
11822
11823 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11824 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11825 color_blend_state_create_info.attachmentCount = 1;
11826 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11827
11828 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11829 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11830 graphicspipe_create_info.stageCount = 2;
11831 graphicspipe_create_info.pStages = shader_stage_create_info;
11832 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11833 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11834 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11835 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11836 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11837 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11838 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11839 graphicspipe_create_info.layout = pipeline_layout;
11840 graphicspipe_create_info.renderPass = renderPass();
11841
11842 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11843 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11844
11845 VkPipelineCache pipelineCache;
11846 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11847
11848 // This structure maps constant ids to data locations.
11849 const VkSpecializationMapEntry entry =
11850 // id, offset, size
11851 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11852
11853 uint32_t data = 1;
11854
11855 // Set up the info describing spec map and data
11856 const VkSpecializationInfo specialization_info = {
11857 1,
11858 &entry,
11859 1 * sizeof(float),
11860 &data,
11861 };
11862 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11863
11864 VkPipeline pipeline;
11865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11866 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11867 m_errorMonitor->VerifyFound();
11868
11869 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11870 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11871}
11872
11873TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11874 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11875
11876 ASSERT_NO_FATAL_FAILURE(InitState());
11877 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11878
11879 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11880
11881 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11882 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11883 descriptor_pool_type_count[0].descriptorCount = 1;
11884 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11885 descriptor_pool_type_count[1].descriptorCount = 1;
11886
11887 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11888 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11889 descriptor_pool_create_info.maxSets = 1;
11890 descriptor_pool_create_info.poolSizeCount = 2;
11891 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11892 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11893
11894 VkDescriptorPool descriptorset_pool;
11895 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11896
11897 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11898 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11899 descriptorset_layout_binding.descriptorCount = 1;
11900 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11901
11902 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11903 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11904 descriptorset_layout_create_info.bindingCount = 1;
11905 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11906
11907 VkDescriptorSetLayout descriptorset_layout;
11908 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11909
11910 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11911 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11912 descriptorset_allocate_info.descriptorSetCount = 1;
11913 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11914 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11915 VkDescriptorSet descriptorset;
11916 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11917
11918 // Challenge core_validation with a non uniform buffer type.
11919 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11920
Mark Mueller098c9cb2016-09-08 09:01:57 -060011921 char const *vsSource =
11922 "#version 450\n"
11923 "\n"
11924 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11925 " mat4 mvp;\n"
11926 "} ubuf;\n"
11927 "out gl_PerVertex {\n"
11928 " vec4 gl_Position;\n"
11929 "};\n"
11930 "void main(){\n"
11931 " gl_Position = ubuf.mvp * vec4(1);\n"
11932 "}\n";
11933
11934 char const *fsSource =
11935 "#version 450\n"
11936 "\n"
11937 "layout(location = 0) out vec4 uFragColor;\n"
11938 "void main(){\n"
11939 " uFragColor = vec4(0,1,0,1);\n"
11940 "}\n";
11941
11942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11944
11945 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11946 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11947 pipeline_layout_create_info.setLayoutCount = 1;
11948 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11949
11950 VkPipelineLayout pipeline_layout;
11951 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11952
11953 VkPipelineObj pipe(m_device);
11954 pipe.AddColorAttachment();
11955 pipe.AddShader(&vs);
11956 pipe.AddShader(&fs);
11957
11958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11959 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11960 m_errorMonitor->VerifyFound();
11961
11962 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11963 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11964 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11965}
11966
11967TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11968 TEST_DESCRIPTION(
11969 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11970
11971 ASSERT_NO_FATAL_FAILURE(InitState());
11972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11973
11974 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11975
11976 VkDescriptorPoolSize descriptor_pool_type_count = {};
11977 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11978 descriptor_pool_type_count.descriptorCount = 1;
11979
11980 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11981 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11982 descriptor_pool_create_info.maxSets = 1;
11983 descriptor_pool_create_info.poolSizeCount = 1;
11984 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11985 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11986
11987 VkDescriptorPool descriptorset_pool;
11988 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11989
11990 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11991 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11992 descriptorset_layout_binding.descriptorCount = 1;
11993 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11994 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11995
11996 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11997 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11998 descriptorset_layout_create_info.bindingCount = 1;
11999 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12000
12001 VkDescriptorSetLayout descriptorset_layout;
12002 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12003 nullptr, &descriptorset_layout));
12004
12005 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12006 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12007 descriptorset_allocate_info.descriptorSetCount = 1;
12008 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12009 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12010 VkDescriptorSet descriptorset;
12011 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12012
12013 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12014
Mark Mueller098c9cb2016-09-08 09:01:57 -060012015 char const *vsSource =
12016 "#version 450\n"
12017 "\n"
12018 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12019 " mat4 mvp;\n"
12020 "} ubuf;\n"
12021 "out gl_PerVertex {\n"
12022 " vec4 gl_Position;\n"
12023 "};\n"
12024 "void main(){\n"
12025 " gl_Position = ubuf.mvp * vec4(1);\n"
12026 "}\n";
12027
12028 char const *fsSource =
12029 "#version 450\n"
12030 "\n"
12031 "layout(location = 0) out vec4 uFragColor;\n"
12032 "void main(){\n"
12033 " uFragColor = vec4(0,1,0,1);\n"
12034 "}\n";
12035
12036 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12037 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12038
12039 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12040 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12041 pipeline_layout_create_info.setLayoutCount = 1;
12042 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12043
12044 VkPipelineLayout pipeline_layout;
12045 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12046
12047 VkPipelineObj pipe(m_device);
12048 pipe.AddColorAttachment();
12049 pipe.AddShader(&vs);
12050 pipe.AddShader(&fs);
12051
12052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12053 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12054 m_errorMonitor->VerifyFound();
12055
12056 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12057 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12058 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12059}
12060
12061TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12062 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12063 "accessible from the current shader stage.");
12064
12065 ASSERT_NO_FATAL_FAILURE(InitState());
12066 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12067
12068 const char *push_constant_not_accessible_message =
12069 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12070
12071 char const *vsSource =
12072 "#version 450\n"
12073 "\n"
12074 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12075 "out gl_PerVertex {\n"
12076 " vec4 gl_Position;\n"
12077 "};\n"
12078 "void main(){\n"
12079 " gl_Position = vec4(consts.x);\n"
12080 "}\n";
12081
12082 char const *fsSource =
12083 "#version 450\n"
12084 "\n"
12085 "layout(location = 0) out vec4 uFragColor;\n"
12086 "void main(){\n"
12087 " uFragColor = vec4(0,1,0,1);\n"
12088 "}\n";
12089
12090 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12091 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12092
12093 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12094 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12095
12096 // Set up a push constant range
12097 VkPushConstantRange push_constant_ranges = {};
12098 // Set to the wrong stage to challenge core_validation
12099 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12100 push_constant_ranges.size = 4;
12101
12102 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12103 pipeline_layout_create_info.pushConstantRangeCount = 1;
12104
12105 VkPipelineLayout pipeline_layout;
12106 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12107
12108 VkPipelineObj pipe(m_device);
12109 pipe.AddColorAttachment();
12110 pipe.AddShader(&vs);
12111 pipe.AddShader(&fs);
12112
12113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12114 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12115 m_errorMonitor->VerifyFound();
12116
12117 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12118}
12119
12120TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12121 TEST_DESCRIPTION(
12122 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12123
12124 ASSERT_NO_FATAL_FAILURE(InitState());
12125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12126
12127 const char *feature_not_enabled_message =
12128 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12129
12130 // Some awkward steps are required to test with custom device features.
12131 std::vector<const char *> device_extension_names;
12132 auto features = m_device->phy().features();
12133 // Disable support for 64 bit floats
12134 features.shaderFloat64 = false;
12135 // The sacrificial device object
12136 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12137
12138 char const *vsSource = "#version 450\n"
12139 "\n"
12140 "out gl_PerVertex {\n"
12141 " vec4 gl_Position;\n"
12142 "};\n"
12143 "void main(){\n"
12144 " gl_Position = vec4(1);\n"
12145 "}\n";
12146 char const *fsSource = "#version 450\n"
12147 "\n"
12148 "layout(location=0) out vec4 color;\n"
12149 "void main(){\n"
12150 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12151 " color = vec4(green);\n"
12152 "}\n";
12153
12154 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12155 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12156
12157 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012158
12159 VkPipelineObj pipe(&test_device);
12160 pipe.AddColorAttachment();
12161 pipe.AddShader(&vs);
12162 pipe.AddShader(&fs);
12163
12164 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12165 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12166 VkPipelineLayout pipeline_layout;
12167 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12168
12169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12170 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12171 m_errorMonitor->VerifyFound();
12172
12173 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12174}
12175
12176TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12177 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12178
12179 ASSERT_NO_FATAL_FAILURE(InitState());
12180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12181
12182 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12183
12184 char const *vsSource = "#version 450\n"
12185 "\n"
12186 "out gl_PerVertex {\n"
12187 " vec4 gl_Position;\n"
12188 "};\n"
12189 "layout(xfb_buffer = 1) out;"
12190 "void main(){\n"
12191 " gl_Position = vec4(1);\n"
12192 "}\n";
12193 char const *fsSource = "#version 450\n"
12194 "\n"
12195 "layout(location=0) out vec4 color;\n"
12196 "void main(){\n"
12197 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12198 " color = vec4(green);\n"
12199 "}\n";
12200
12201 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12202 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12203
12204 VkPipelineObj pipe(m_device);
12205 pipe.AddColorAttachment();
12206 pipe.AddShader(&vs);
12207 pipe.AddShader(&fs);
12208
12209 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12210 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12211 VkPipelineLayout pipeline_layout;
12212 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12213
12214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12215 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12216 m_errorMonitor->VerifyFound();
12217
12218 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12219}
12220
Karl Schultz6addd812016-02-02 17:17:23 -070012221TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012222 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12223 "which is not present in the outputs of the previous stage");
12224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012226
Chris Forbes59cb88d2015-05-25 11:13:13 +120012227 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012228 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012229
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012230 char const *vsSource = "#version 450\n"
12231 "\n"
12232 "out gl_PerVertex {\n"
12233 " vec4 gl_Position;\n"
12234 "};\n"
12235 "void main(){\n"
12236 " gl_Position = vec4(1);\n"
12237 "}\n";
12238 char const *fsSource = "#version 450\n"
12239 "\n"
12240 "layout(location=0) in float x;\n"
12241 "layout(location=0) out vec4 color;\n"
12242 "void main(){\n"
12243 " color = vec4(x);\n"
12244 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012245
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012246 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12247 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012248
12249 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012250 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012251 pipe.AddShader(&vs);
12252 pipe.AddShader(&fs);
12253
Chris Forbes59cb88d2015-05-25 11:13:13 +120012254 VkDescriptorSetObj descriptorSet(m_device);
12255 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012256 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012257
Tony Barbour5781e8f2015-08-04 16:23:11 -060012258 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012259
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012260 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012261}
12262
Karl Schultz6addd812016-02-02 17:17:23 -070012263TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012264 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12265 "within an interace block, which is not present in the outputs "
12266 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012268
12269 ASSERT_NO_FATAL_FAILURE(InitState());
12270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012272 char const *vsSource = "#version 450\n"
12273 "\n"
12274 "out gl_PerVertex {\n"
12275 " vec4 gl_Position;\n"
12276 "};\n"
12277 "void main(){\n"
12278 " gl_Position = vec4(1);\n"
12279 "}\n";
12280 char const *fsSource = "#version 450\n"
12281 "\n"
12282 "in block { layout(location=0) float x; } ins;\n"
12283 "layout(location=0) out vec4 color;\n"
12284 "void main(){\n"
12285 " color = vec4(ins.x);\n"
12286 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012287
12288 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12289 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12290
12291 VkPipelineObj pipe(m_device);
12292 pipe.AddColorAttachment();
12293 pipe.AddShader(&vs);
12294 pipe.AddShader(&fs);
12295
12296 VkDescriptorSetObj descriptorSet(m_device);
12297 descriptorSet.AppendDummy();
12298 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12299
12300 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12301
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012302 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012303}
12304
Karl Schultz6addd812016-02-02 17:17:23 -070012305TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012306 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012307 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12309 "output arr[2] of float32' vs 'ptr to "
12310 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012311
12312 ASSERT_NO_FATAL_FAILURE(InitState());
12313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12314
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012315 char const *vsSource = "#version 450\n"
12316 "\n"
12317 "layout(location=0) out float x[2];\n"
12318 "out gl_PerVertex {\n"
12319 " vec4 gl_Position;\n"
12320 "};\n"
12321 "void main(){\n"
12322 " x[0] = 0; x[1] = 0;\n"
12323 " gl_Position = vec4(1);\n"
12324 "}\n";
12325 char const *fsSource = "#version 450\n"
12326 "\n"
12327 "layout(location=0) in float x[3];\n"
12328 "layout(location=0) out vec4 color;\n"
12329 "void main(){\n"
12330 " color = vec4(x[0] + x[1] + x[2]);\n"
12331 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012332
12333 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12334 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12335
12336 VkPipelineObj pipe(m_device);
12337 pipe.AddColorAttachment();
12338 pipe.AddShader(&vs);
12339 pipe.AddShader(&fs);
12340
12341 VkDescriptorSetObj descriptorSet(m_device);
12342 descriptorSet.AppendDummy();
12343 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12344
12345 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12346
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012347 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012348}
12349
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012350
Karl Schultz6addd812016-02-02 17:17:23 -070012351TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012352 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012353 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012355
Chris Forbesb56af562015-05-25 11:13:17 +120012356 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012357 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012358
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012359 char const *vsSource = "#version 450\n"
12360 "\n"
12361 "layout(location=0) out int x;\n"
12362 "out gl_PerVertex {\n"
12363 " vec4 gl_Position;\n"
12364 "};\n"
12365 "void main(){\n"
12366 " x = 0;\n"
12367 " gl_Position = vec4(1);\n"
12368 "}\n";
12369 char const *fsSource = "#version 450\n"
12370 "\n"
12371 "layout(location=0) in float x;\n" /* VS writes int */
12372 "layout(location=0) out vec4 color;\n"
12373 "void main(){\n"
12374 " color = vec4(x);\n"
12375 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012376
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012377 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12378 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012379
12380 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012381 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012382 pipe.AddShader(&vs);
12383 pipe.AddShader(&fs);
12384
Chris Forbesb56af562015-05-25 11:13:17 +120012385 VkDescriptorSetObj descriptorSet(m_device);
12386 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012387 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012388
Tony Barbour5781e8f2015-08-04 16:23:11 -060012389 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012390
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012391 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012392}
12393
Karl Schultz6addd812016-02-02 17:17:23 -070012394TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012395 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012396 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012397 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012399
12400 ASSERT_NO_FATAL_FAILURE(InitState());
12401 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012403 char const *vsSource = "#version 450\n"
12404 "\n"
12405 "out block { layout(location=0) int x; } outs;\n"
12406 "out gl_PerVertex {\n"
12407 " vec4 gl_Position;\n"
12408 "};\n"
12409 "void main(){\n"
12410 " outs.x = 0;\n"
12411 " gl_Position = vec4(1);\n"
12412 "}\n";
12413 char const *fsSource = "#version 450\n"
12414 "\n"
12415 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12416 "layout(location=0) out vec4 color;\n"
12417 "void main(){\n"
12418 " color = vec4(ins.x);\n"
12419 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012420
12421 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12422 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12423
12424 VkPipelineObj pipe(m_device);
12425 pipe.AddColorAttachment();
12426 pipe.AddShader(&vs);
12427 pipe.AddShader(&fs);
12428
12429 VkDescriptorSetObj descriptorSet(m_device);
12430 descriptorSet.AppendDummy();
12431 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12432
12433 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12434
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012435 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012436}
12437
12438TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012439 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012440 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012441 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012442 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 +130012443
12444 ASSERT_NO_FATAL_FAILURE(InitState());
12445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012447 char const *vsSource = "#version 450\n"
12448 "\n"
12449 "out block { layout(location=1) float x; } outs;\n"
12450 "out gl_PerVertex {\n"
12451 " vec4 gl_Position;\n"
12452 "};\n"
12453 "void main(){\n"
12454 " outs.x = 0;\n"
12455 " gl_Position = vec4(1);\n"
12456 "}\n";
12457 char const *fsSource = "#version 450\n"
12458 "\n"
12459 "in block { layout(location=0) float x; } ins;\n"
12460 "layout(location=0) out vec4 color;\n"
12461 "void main(){\n"
12462 " color = vec4(ins.x);\n"
12463 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012464
12465 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12466 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12467
12468 VkPipelineObj pipe(m_device);
12469 pipe.AddColorAttachment();
12470 pipe.AddShader(&vs);
12471 pipe.AddShader(&fs);
12472
12473 VkDescriptorSetObj descriptorSet(m_device);
12474 descriptorSet.AppendDummy();
12475 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12476
12477 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12478
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012479 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012480}
12481
12482TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012483 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012484 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012485 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012486 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 +130012487
12488 ASSERT_NO_FATAL_FAILURE(InitState());
12489 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12490
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012491 char const *vsSource = "#version 450\n"
12492 "\n"
12493 "out block { layout(location=0, component=0) float x; } outs;\n"
12494 "out gl_PerVertex {\n"
12495 " vec4 gl_Position;\n"
12496 "};\n"
12497 "void main(){\n"
12498 " outs.x = 0;\n"
12499 " gl_Position = vec4(1);\n"
12500 "}\n";
12501 char const *fsSource = "#version 450\n"
12502 "\n"
12503 "in block { layout(location=0, component=1) float x; } ins;\n"
12504 "layout(location=0) out vec4 color;\n"
12505 "void main(){\n"
12506 " color = vec4(ins.x);\n"
12507 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012508
12509 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12510 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12511
12512 VkPipelineObj pipe(m_device);
12513 pipe.AddColorAttachment();
12514 pipe.AddShader(&vs);
12515 pipe.AddShader(&fs);
12516
12517 VkDescriptorSetObj descriptorSet(m_device);
12518 descriptorSet.AppendDummy();
12519 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12520
12521 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12522
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012523 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012524}
12525
Karl Schultz6addd812016-02-02 17:17:23 -070012526TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012527 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12528 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012530
Chris Forbesde136e02015-05-25 11:13:28 +120012531 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012533
12534 VkVertexInputBindingDescription input_binding;
12535 memset(&input_binding, 0, sizeof(input_binding));
12536
12537 VkVertexInputAttributeDescription input_attrib;
12538 memset(&input_attrib, 0, sizeof(input_attrib));
12539 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12540
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012541 char const *vsSource = "#version 450\n"
12542 "\n"
12543 "out gl_PerVertex {\n"
12544 " vec4 gl_Position;\n"
12545 "};\n"
12546 "void main(){\n"
12547 " gl_Position = vec4(1);\n"
12548 "}\n";
12549 char const *fsSource = "#version 450\n"
12550 "\n"
12551 "layout(location=0) out vec4 color;\n"
12552 "void main(){\n"
12553 " color = vec4(1);\n"
12554 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012555
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012556 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12557 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012558
12559 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012560 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012561 pipe.AddShader(&vs);
12562 pipe.AddShader(&fs);
12563
12564 pipe.AddVertexInputBindings(&input_binding, 1);
12565 pipe.AddVertexInputAttribs(&input_attrib, 1);
12566
Chris Forbesde136e02015-05-25 11:13:28 +120012567 VkDescriptorSetObj descriptorSet(m_device);
12568 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012569 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012570
Tony Barbour5781e8f2015-08-04 16:23:11 -060012571 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012572
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012573 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012574}
12575
Karl Schultz6addd812016-02-02 17:17:23 -070012576TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012577 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12578 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012580
12581 ASSERT_NO_FATAL_FAILURE(InitState());
12582 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12583
12584 VkVertexInputBindingDescription input_binding;
12585 memset(&input_binding, 0, sizeof(input_binding));
12586
12587 VkVertexInputAttributeDescription input_attrib;
12588 memset(&input_attrib, 0, sizeof(input_attrib));
12589 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12590
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012591 char const *vsSource = "#version 450\n"
12592 "\n"
12593 "layout(location=1) in float x;\n"
12594 "out gl_PerVertex {\n"
12595 " vec4 gl_Position;\n"
12596 "};\n"
12597 "void main(){\n"
12598 " gl_Position = vec4(x);\n"
12599 "}\n";
12600 char const *fsSource = "#version 450\n"
12601 "\n"
12602 "layout(location=0) out vec4 color;\n"
12603 "void main(){\n"
12604 " color = vec4(1);\n"
12605 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012606
12607 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12608 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12609
12610 VkPipelineObj pipe(m_device);
12611 pipe.AddColorAttachment();
12612 pipe.AddShader(&vs);
12613 pipe.AddShader(&fs);
12614
12615 pipe.AddVertexInputBindings(&input_binding, 1);
12616 pipe.AddVertexInputAttribs(&input_attrib, 1);
12617
12618 VkDescriptorSetObj descriptorSet(m_device);
12619 descriptorSet.AppendDummy();
12620 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12621
12622 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12623
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012624 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012625}
12626
Karl Schultz6addd812016-02-02 17:17:23 -070012627TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012628 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012629 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012630 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 -060012631
Chris Forbes62e8e502015-05-25 11:13:29 +120012632 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012633 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012634
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012635 char const *vsSource = "#version 450\n"
12636 "\n"
12637 "layout(location=0) in vec4 x;\n" /* not provided */
12638 "out gl_PerVertex {\n"
12639 " vec4 gl_Position;\n"
12640 "};\n"
12641 "void main(){\n"
12642 " gl_Position = x;\n"
12643 "}\n";
12644 char const *fsSource = "#version 450\n"
12645 "\n"
12646 "layout(location=0) out vec4 color;\n"
12647 "void main(){\n"
12648 " color = vec4(1);\n"
12649 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012650
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012651 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12652 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012653
12654 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012655 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012656 pipe.AddShader(&vs);
12657 pipe.AddShader(&fs);
12658
Chris Forbes62e8e502015-05-25 11:13:29 +120012659 VkDescriptorSetObj descriptorSet(m_device);
12660 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012661 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012662
Tony Barbour5781e8f2015-08-04 16:23:11 -060012663 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012664
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012665 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012666}
12667
Karl Schultz6addd812016-02-02 17:17:23 -070012668TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012669 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12670 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012671 "vertex shader input that consumes it");
12672 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 -060012673
Chris Forbesc97d98e2015-05-25 11:13:31 +120012674 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012675 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012676
12677 VkVertexInputBindingDescription input_binding;
12678 memset(&input_binding, 0, sizeof(input_binding));
12679
12680 VkVertexInputAttributeDescription input_attrib;
12681 memset(&input_attrib, 0, sizeof(input_attrib));
12682 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12683
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012684 char const *vsSource = "#version 450\n"
12685 "\n"
12686 "layout(location=0) in int x;\n" /* attrib provided float */
12687 "out gl_PerVertex {\n"
12688 " vec4 gl_Position;\n"
12689 "};\n"
12690 "void main(){\n"
12691 " gl_Position = vec4(x);\n"
12692 "}\n";
12693 char const *fsSource = "#version 450\n"
12694 "\n"
12695 "layout(location=0) out vec4 color;\n"
12696 "void main(){\n"
12697 " color = vec4(1);\n"
12698 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012699
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012700 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12701 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012702
12703 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012704 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012705 pipe.AddShader(&vs);
12706 pipe.AddShader(&fs);
12707
12708 pipe.AddVertexInputBindings(&input_binding, 1);
12709 pipe.AddVertexInputAttribs(&input_attrib, 1);
12710
Chris Forbesc97d98e2015-05-25 11:13:31 +120012711 VkDescriptorSetObj descriptorSet(m_device);
12712 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012713 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012714
Tony Barbour5781e8f2015-08-04 16:23:11 -060012715 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012716
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012717 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012718}
12719
Chris Forbesc68b43c2016-04-06 11:18:47 +120012720TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012721 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12722 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12724 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012725
12726 ASSERT_NO_FATAL_FAILURE(InitState());
12727 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12728
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012729 char const *vsSource = "#version 450\n"
12730 "\n"
12731 "out gl_PerVertex {\n"
12732 " vec4 gl_Position;\n"
12733 "};\n"
12734 "void main(){\n"
12735 " gl_Position = vec4(1);\n"
12736 "}\n";
12737 char const *fsSource = "#version 450\n"
12738 "\n"
12739 "layout(location=0) out vec4 color;\n"
12740 "void main(){\n"
12741 " color = vec4(1);\n"
12742 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012743
12744 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12745 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12746
12747 VkPipelineObj pipe(m_device);
12748 pipe.AddColorAttachment();
12749 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012750 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012751 pipe.AddShader(&fs);
12752
12753 VkDescriptorSetObj descriptorSet(m_device);
12754 descriptorSet.AppendDummy();
12755 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12756
12757 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12758
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012759 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012760}
12761
Chris Forbes82ff92a2016-09-09 10:50:24 +120012762TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12764 "No entrypoint found named `foo`");
12765
12766 ASSERT_NO_FATAL_FAILURE(InitState());
12767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12768
12769 char const *vsSource = "#version 450\n"
12770 "out gl_PerVertex {\n"
12771 " vec4 gl_Position;\n"
12772 "};\n"
12773 "void main(){\n"
12774 " gl_Position = vec4(0);\n"
12775 "}\n";
12776 char const *fsSource = "#version 450\n"
12777 "\n"
12778 "layout(location=0) out vec4 color;\n"
12779 "void main(){\n"
12780 " color = vec4(1);\n"
12781 "}\n";
12782
12783 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12784 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12785
12786 VkPipelineObj pipe(m_device);
12787 pipe.AddColorAttachment();
12788 pipe.AddShader(&vs);
12789 pipe.AddShader(&fs);
12790
12791 VkDescriptorSetObj descriptorSet(m_device);
12792 descriptorSet.AppendDummy();
12793 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12794
12795 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12796
12797 m_errorMonitor->VerifyFound();
12798}
12799
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012800TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12801 m_errorMonitor->SetDesiredFailureMsg(
12802 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12803 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12804 "uses a depth/stencil attachment");
12805
12806 ASSERT_NO_FATAL_FAILURE(InitState());
12807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12808
12809 char const *vsSource = "#version 450\n"
12810 "void main(){ gl_Position = vec4(0); }\n";
12811 char const *fsSource = "#version 450\n"
12812 "\n"
12813 "layout(location=0) out vec4 color;\n"
12814 "void main(){\n"
12815 " color = vec4(1);\n"
12816 "}\n";
12817
12818 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12819 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12820
12821 VkPipelineObj pipe(m_device);
12822 pipe.AddColorAttachment();
12823 pipe.AddShader(&vs);
12824 pipe.AddShader(&fs);
12825
12826 VkDescriptorSetObj descriptorSet(m_device);
12827 descriptorSet.AppendDummy();
12828 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12829
12830 VkAttachmentDescription attachments[] = {
12831 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12832 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12833 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12834 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12835 },
12836 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12837 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12838 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12839 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12840 },
12841 };
12842 VkAttachmentReference refs[] = {
12843 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12844 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12845 };
12846 VkSubpassDescription subpass = {
12847 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12848 1, &refs[0], nullptr, &refs[1],
12849 0, nullptr
12850 };
12851 VkRenderPassCreateInfo rpci = {
12852 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12853 0, 2, attachments, 1, &subpass, 0, nullptr
12854 };
12855 VkRenderPass rp;
12856 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12857 ASSERT_VK_SUCCESS(err);
12858
12859 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12860
12861 m_errorMonitor->VerifyFound();
12862
12863 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12864}
12865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012866TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012867 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12868 "the TCS without the patch decoration, but consumed in the TES "
12869 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12871 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012872
12873 ASSERT_NO_FATAL_FAILURE(InitState());
12874 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12875
Chris Forbesc1e852d2016-04-04 19:26:42 +120012876 if (!m_device->phy().features().tessellationShader) {
12877 printf("Device does not support tessellation shaders; skipped.\n");
12878 return;
12879 }
12880
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012881 char const *vsSource = "#version 450\n"
12882 "void main(){}\n";
12883 char const *tcsSource = "#version 450\n"
12884 "layout(location=0) out int x[];\n"
12885 "layout(vertices=3) out;\n"
12886 "void main(){\n"
12887 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12888 " gl_TessLevelInner[0] = 1;\n"
12889 " x[gl_InvocationID] = gl_InvocationID;\n"
12890 "}\n";
12891 char const *tesSource = "#version 450\n"
12892 "layout(triangles, equal_spacing, cw) in;\n"
12893 "layout(location=0) patch in int x;\n"
12894 "out gl_PerVertex { vec4 gl_Position; };\n"
12895 "void main(){\n"
12896 " gl_Position.xyz = gl_TessCoord;\n"
12897 " gl_Position.w = x;\n"
12898 "}\n";
12899 char const *fsSource = "#version 450\n"
12900 "layout(location=0) out vec4 color;\n"
12901 "void main(){\n"
12902 " color = vec4(1);\n"
12903 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012904
12905 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12906 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12907 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12908 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12909
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012910 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12911 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012912
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012913 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012914
12915 VkPipelineObj pipe(m_device);
12916 pipe.SetInputAssembly(&iasci);
12917 pipe.SetTessellation(&tsci);
12918 pipe.AddColorAttachment();
12919 pipe.AddShader(&vs);
12920 pipe.AddShader(&tcs);
12921 pipe.AddShader(&tes);
12922 pipe.AddShader(&fs);
12923
12924 VkDescriptorSetObj descriptorSet(m_device);
12925 descriptorSet.AppendDummy();
12926 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12927
12928 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12929
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012930 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012931}
12932
Karl Schultz6addd812016-02-02 17:17:23 -070012933TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012934 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12935 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12937 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012938
Chris Forbes280ba2c2015-06-12 11:16:41 +120012939 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012940 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012941
12942 /* Two binding descriptions for binding 0 */
12943 VkVertexInputBindingDescription input_bindings[2];
12944 memset(input_bindings, 0, sizeof(input_bindings));
12945
12946 VkVertexInputAttributeDescription input_attrib;
12947 memset(&input_attrib, 0, sizeof(input_attrib));
12948 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12949
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012950 char const *vsSource = "#version 450\n"
12951 "\n"
12952 "layout(location=0) in float x;\n" /* attrib provided float */
12953 "out gl_PerVertex {\n"
12954 " vec4 gl_Position;\n"
12955 "};\n"
12956 "void main(){\n"
12957 " gl_Position = vec4(x);\n"
12958 "}\n";
12959 char const *fsSource = "#version 450\n"
12960 "\n"
12961 "layout(location=0) out vec4 color;\n"
12962 "void main(){\n"
12963 " color = vec4(1);\n"
12964 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012965
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012966 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12967 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012968
12969 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012970 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012971 pipe.AddShader(&vs);
12972 pipe.AddShader(&fs);
12973
12974 pipe.AddVertexInputBindings(input_bindings, 2);
12975 pipe.AddVertexInputAttribs(&input_attrib, 1);
12976
Chris Forbes280ba2c2015-06-12 11:16:41 +120012977 VkDescriptorSetObj descriptorSet(m_device);
12978 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012979 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012980
Tony Barbour5781e8f2015-08-04 16:23:11 -060012981 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012982
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012983 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012984}
Chris Forbes8f68b562015-05-25 11:13:32 +120012985
Karl Schultz6addd812016-02-02 17:17:23 -070012986TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012987 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012988 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012990
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012991 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012992
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012993 char const *vsSource = "#version 450\n"
12994 "\n"
12995 "out gl_PerVertex {\n"
12996 " vec4 gl_Position;\n"
12997 "};\n"
12998 "void main(){\n"
12999 " gl_Position = vec4(1);\n"
13000 "}\n";
13001 char const *fsSource = "#version 450\n"
13002 "\n"
13003 "void main(){\n"
13004 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013005
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013006 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13007 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013008
13009 VkPipelineObj pipe(m_device);
13010 pipe.AddShader(&vs);
13011 pipe.AddShader(&fs);
13012
Chia-I Wu08accc62015-07-07 11:50:03 +080013013 /* set up CB 0, not written */
13014 pipe.AddColorAttachment();
13015 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013016
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013017 VkDescriptorSetObj descriptorSet(m_device);
13018 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013019 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013020
Tony Barbour5781e8f2015-08-04 16:23:11 -060013021 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013022
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013023 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013024}
13025
Karl Schultz6addd812016-02-02 17:17:23 -070013026TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013027 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013028 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013030 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013031
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013032 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013034 char const *vsSource = "#version 450\n"
13035 "\n"
13036 "out gl_PerVertex {\n"
13037 " vec4 gl_Position;\n"
13038 "};\n"
13039 "void main(){\n"
13040 " gl_Position = vec4(1);\n"
13041 "}\n";
13042 char const *fsSource = "#version 450\n"
13043 "\n"
13044 "layout(location=0) out vec4 x;\n"
13045 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13046 "void main(){\n"
13047 " x = vec4(1);\n"
13048 " y = vec4(1);\n"
13049 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013050
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013051 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13052 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013053
13054 VkPipelineObj pipe(m_device);
13055 pipe.AddShader(&vs);
13056 pipe.AddShader(&fs);
13057
Chia-I Wu08accc62015-07-07 11:50:03 +080013058 /* set up CB 0, not written */
13059 pipe.AddColorAttachment();
13060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013061 /* FS writes CB 1, but we don't configure it */
13062
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013063 VkDescriptorSetObj descriptorSet(m_device);
13064 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013065 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013066
Tony Barbour5781e8f2015-08-04 16:23:11 -060013067 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013068
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013069 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013070}
13071
Karl Schultz6addd812016-02-02 17:17:23 -070013072TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013073 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013074 "type of an fragment shader output variable, and the format of the corresponding attachment");
13075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013076
Chris Forbesa36d69e2015-05-25 11:13:44 +120013077 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013079 char const *vsSource = "#version 450\n"
13080 "\n"
13081 "out gl_PerVertex {\n"
13082 " vec4 gl_Position;\n"
13083 "};\n"
13084 "void main(){\n"
13085 " gl_Position = vec4(1);\n"
13086 "}\n";
13087 char const *fsSource = "#version 450\n"
13088 "\n"
13089 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13090 "void main(){\n"
13091 " x = ivec4(1);\n"
13092 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013093
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013094 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13095 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013096
13097 VkPipelineObj pipe(m_device);
13098 pipe.AddShader(&vs);
13099 pipe.AddShader(&fs);
13100
Chia-I Wu08accc62015-07-07 11:50:03 +080013101 /* set up CB 0; type is UNORM by default */
13102 pipe.AddColorAttachment();
13103 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013104
Chris Forbesa36d69e2015-05-25 11:13:44 +120013105 VkDescriptorSetObj descriptorSet(m_device);
13106 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013107 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013108
Tony Barbour5781e8f2015-08-04 16:23:11 -060013109 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013110
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013111 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013112}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013113
Karl Schultz6addd812016-02-02 17:17:23 -070013114TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013115 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13116 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013118
Chris Forbes556c76c2015-08-14 12:04:59 +120013119 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013121 char const *vsSource = "#version 450\n"
13122 "\n"
13123 "out gl_PerVertex {\n"
13124 " vec4 gl_Position;\n"
13125 "};\n"
13126 "void main(){\n"
13127 " gl_Position = vec4(1);\n"
13128 "}\n";
13129 char const *fsSource = "#version 450\n"
13130 "\n"
13131 "layout(location=0) out vec4 x;\n"
13132 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13133 "void main(){\n"
13134 " x = vec4(bar.y);\n"
13135 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013136
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013137 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13138 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013139
Chris Forbes556c76c2015-08-14 12:04:59 +120013140 VkPipelineObj pipe(m_device);
13141 pipe.AddShader(&vs);
13142 pipe.AddShader(&fs);
13143
13144 /* set up CB 0; type is UNORM by default */
13145 pipe.AddColorAttachment();
13146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13147
13148 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013149 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013150
13151 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13152
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013153 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013154}
13155
Chris Forbes5c59e902016-02-26 16:56:09 +130013156TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013157 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13158 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013160
13161 ASSERT_NO_FATAL_FAILURE(InitState());
13162
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013163 char const *vsSource = "#version 450\n"
13164 "\n"
13165 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13166 "out gl_PerVertex {\n"
13167 " vec4 gl_Position;\n"
13168 "};\n"
13169 "void main(){\n"
13170 " gl_Position = vec4(consts.x);\n"
13171 "}\n";
13172 char const *fsSource = "#version 450\n"
13173 "\n"
13174 "layout(location=0) out vec4 x;\n"
13175 "void main(){\n"
13176 " x = vec4(1);\n"
13177 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013178
13179 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13180 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13181
13182 VkPipelineObj pipe(m_device);
13183 pipe.AddShader(&vs);
13184 pipe.AddShader(&fs);
13185
13186 /* set up CB 0; type is UNORM by default */
13187 pipe.AddColorAttachment();
13188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13189
13190 VkDescriptorSetObj descriptorSet(m_device);
13191 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13192
13193 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13194
13195 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013196 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013197}
13198
Chris Forbes3fb17902016-08-22 14:57:55 +120013199TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13200 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13201 "which is not included in the subpass description");
13202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13203 "consumes input attachment index 0 but not provided in subpass");
13204
13205 ASSERT_NO_FATAL_FAILURE(InitState());
13206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013207 char const *vsSource = "#version 450\n"
13208 "\n"
13209 "out gl_PerVertex {\n"
13210 " vec4 gl_Position;\n"
13211 "};\n"
13212 "void main(){\n"
13213 " gl_Position = vec4(1);\n"
13214 "}\n";
13215 char const *fsSource = "#version 450\n"
13216 "\n"
13217 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13218 "layout(location=0) out vec4 color;\n"
13219 "void main() {\n"
13220 " color = subpassLoad(x);\n"
13221 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013222
13223 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13224 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13225
13226 VkPipelineObj pipe(m_device);
13227 pipe.AddShader(&vs);
13228 pipe.AddShader(&fs);
13229 pipe.AddColorAttachment();
13230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13231
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013232 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13233 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013234 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013235 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013236 ASSERT_VK_SUCCESS(err);
13237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013238 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013239 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013240 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013241 ASSERT_VK_SUCCESS(err);
13242
13243 // error here.
13244 pipe.CreateVKPipeline(pl, renderPass());
13245
13246 m_errorMonitor->VerifyFound();
13247
13248 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13249 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13250}
13251
Chris Forbes5a9a0472016-08-22 16:02:09 +120013252TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13253 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13254 "with a format having a different fundamental type");
13255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13256 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13257
13258 ASSERT_NO_FATAL_FAILURE(InitState());
13259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013260 char const *vsSource = "#version 450\n"
13261 "\n"
13262 "out gl_PerVertex {\n"
13263 " vec4 gl_Position;\n"
13264 "};\n"
13265 "void main(){\n"
13266 " gl_Position = vec4(1);\n"
13267 "}\n";
13268 char const *fsSource = "#version 450\n"
13269 "\n"
13270 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13271 "layout(location=0) out vec4 color;\n"
13272 "void main() {\n"
13273 " color = subpassLoad(x);\n"
13274 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013275
13276 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13277 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13278
13279 VkPipelineObj pipe(m_device);
13280 pipe.AddShader(&vs);
13281 pipe.AddShader(&fs);
13282 pipe.AddColorAttachment();
13283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013285 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13286 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013287 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013288 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013289 ASSERT_VK_SUCCESS(err);
13290
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013291 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013292 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013293 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013294 ASSERT_VK_SUCCESS(err);
13295
13296 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013297 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13298 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13299 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13300 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13301 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 +120013302 };
13303 VkAttachmentReference color = {
13304 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13305 };
13306 VkAttachmentReference input = {
13307 1, VK_IMAGE_LAYOUT_GENERAL,
13308 };
13309
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013310 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013311
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013312 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013313 VkRenderPass rp;
13314 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13315 ASSERT_VK_SUCCESS(err);
13316
13317 // error here.
13318 pipe.CreateVKPipeline(pl, rp);
13319
13320 m_errorMonitor->VerifyFound();
13321
13322 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13323 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13324 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13325}
13326
Chris Forbes541f7b02016-08-22 15:30:27 +120013327TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13328 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13329 "which is not included in the subpass description -- array case");
13330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13331 "consumes input attachment index 1 but not provided in subpass");
13332
13333 ASSERT_NO_FATAL_FAILURE(InitState());
13334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013335 char const *vsSource = "#version 450\n"
13336 "\n"
13337 "out gl_PerVertex {\n"
13338 " vec4 gl_Position;\n"
13339 "};\n"
13340 "void main(){\n"
13341 " gl_Position = vec4(1);\n"
13342 "}\n";
13343 char const *fsSource = "#version 450\n"
13344 "\n"
13345 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13346 "layout(location=0) out vec4 color;\n"
13347 "void main() {\n"
13348 " color = subpassLoad(xs[1]);\n"
13349 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013350
13351 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13352 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13353
13354 VkPipelineObj pipe(m_device);
13355 pipe.AddShader(&vs);
13356 pipe.AddShader(&fs);
13357 pipe.AddColorAttachment();
13358 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013360 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13361 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013362 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013363 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013364 ASSERT_VK_SUCCESS(err);
13365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013366 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013367 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013368 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013369 ASSERT_VK_SUCCESS(err);
13370
13371 // error here.
13372 pipe.CreateVKPipeline(pl, renderPass());
13373
13374 m_errorMonitor->VerifyFound();
13375
13376 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13377 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13378}
13379
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013380TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013381 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13382 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013384
13385 ASSERT_NO_FATAL_FAILURE(InitState());
13386
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013387 char const *csSource = "#version 450\n"
13388 "\n"
13389 "layout(local_size_x=1) in;\n"
13390 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13391 "void main(){\n"
13392 " x = vec4(1);\n"
13393 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013394
13395 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13396
13397 VkDescriptorSetObj descriptorSet(m_device);
13398 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13399
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013400 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13401 nullptr,
13402 0,
13403 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13404 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13405 descriptorSet.GetPipelineLayout(),
13406 VK_NULL_HANDLE,
13407 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013408
13409 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013410 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013411
13412 m_errorMonitor->VerifyFound();
13413
13414 if (err == VK_SUCCESS) {
13415 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13416 }
13417}
13418
Chris Forbes22a9b092016-07-19 14:34:05 +120013419TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013420 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13421 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13423 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013424
13425 ASSERT_NO_FATAL_FAILURE(InitState());
13426
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013427 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13428 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013429 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013430 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013431 ASSERT_VK_SUCCESS(err);
13432
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013433 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013434 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013435 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013436 ASSERT_VK_SUCCESS(err);
13437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013438 char const *csSource = "#version 450\n"
13439 "\n"
13440 "layout(local_size_x=1) in;\n"
13441 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13442 "void main() {\n"
13443 " x.x = 1.0f;\n"
13444 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013445 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013447 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13448 nullptr,
13449 0,
13450 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13451 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13452 pl,
13453 VK_NULL_HANDLE,
13454 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013455
13456 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013457 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013458
13459 m_errorMonitor->VerifyFound();
13460
13461 if (err == VK_SUCCESS) {
13462 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13463 }
13464
13465 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13466 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13467}
13468
Chris Forbes50020592016-07-27 13:52:41 +120013469TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13470 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13471 "does not match the dimensionality declared in the shader");
13472
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013473 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 +120013474
13475 ASSERT_NO_FATAL_FAILURE(InitState());
13476 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13477
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013478 char const *vsSource = "#version 450\n"
13479 "\n"
13480 "out gl_PerVertex { vec4 gl_Position; };\n"
13481 "void main() { gl_Position = vec4(0); }\n";
13482 char const *fsSource = "#version 450\n"
13483 "\n"
13484 "layout(set=0, binding=0) uniform sampler3D s;\n"
13485 "layout(location=0) out vec4 color;\n"
13486 "void main() {\n"
13487 " color = texture(s, vec3(0));\n"
13488 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013489 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13490 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13491
13492 VkPipelineObj pipe(m_device);
13493 pipe.AddShader(&vs);
13494 pipe.AddShader(&fs);
13495 pipe.AddColorAttachment();
13496
13497 VkTextureObj texture(m_device, nullptr);
13498 VkSamplerObj sampler(m_device);
13499
13500 VkDescriptorSetObj descriptorSet(m_device);
13501 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13502 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13503
13504 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13505 ASSERT_VK_SUCCESS(err);
13506
13507 BeginCommandBuffer();
13508
13509 m_commandBuffer->BindPipeline(pipe);
13510 m_commandBuffer->BindDescriptorSet(descriptorSet);
13511
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013512 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013513 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013514 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013515 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13516
13517 // error produced here.
13518 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13519
13520 m_errorMonitor->VerifyFound();
13521
13522 EndCommandBuffer();
13523}
13524
Chris Forbes5533bfc2016-07-27 14:12:34 +120013525TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13526 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13527 "are consumed via singlesample images types in the shader, or vice versa.");
13528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013530
13531 ASSERT_NO_FATAL_FAILURE(InitState());
13532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13533
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013534 char const *vsSource = "#version 450\n"
13535 "\n"
13536 "out gl_PerVertex { vec4 gl_Position; };\n"
13537 "void main() { gl_Position = vec4(0); }\n";
13538 char const *fsSource = "#version 450\n"
13539 "\n"
13540 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13541 "layout(location=0) out vec4 color;\n"
13542 "void main() {\n"
13543 " color = texelFetch(s, ivec2(0), 0);\n"
13544 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013545 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13546 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13547
13548 VkPipelineObj pipe(m_device);
13549 pipe.AddShader(&vs);
13550 pipe.AddShader(&fs);
13551 pipe.AddColorAttachment();
13552
13553 VkTextureObj texture(m_device, nullptr);
13554 VkSamplerObj sampler(m_device);
13555
13556 VkDescriptorSetObj descriptorSet(m_device);
13557 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13558 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13559
13560 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13561 ASSERT_VK_SUCCESS(err);
13562
13563 BeginCommandBuffer();
13564
13565 m_commandBuffer->BindPipeline(pipe);
13566 m_commandBuffer->BindDescriptorSet(descriptorSet);
13567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013568 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013569 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013570 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013571 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13572
13573 // error produced here.
13574 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13575
13576 m_errorMonitor->VerifyFound();
13577
13578 EndCommandBuffer();
13579}
13580
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013581#endif // SHADER_CHECKER_TESTS
13582
13583#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013584TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013586
13587 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013588
13589 // Create an image
13590 VkImage image;
13591
Karl Schultz6addd812016-02-02 17:17:23 -070013592 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13593 const int32_t tex_width = 32;
13594 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013595
13596 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013597 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13598 image_create_info.pNext = NULL;
13599 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13600 image_create_info.format = tex_format;
13601 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013602 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013603 image_create_info.extent.depth = 1;
13604 image_create_info.mipLevels = 1;
13605 image_create_info.arrayLayers = 1;
13606 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13607 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13608 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13609 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013610
13611 // Introduce error by sending down a bogus width extent
13612 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013613 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013614
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013615 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013616}
13617
Mark Youngc48c4c12016-04-11 14:26:49 -060013618TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13620 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013621
13622 ASSERT_NO_FATAL_FAILURE(InitState());
13623
13624 // Create an image
13625 VkImage image;
13626
13627 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13628 const int32_t tex_width = 32;
13629 const int32_t tex_height = 32;
13630
13631 VkImageCreateInfo image_create_info = {};
13632 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13633 image_create_info.pNext = NULL;
13634 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13635 image_create_info.format = tex_format;
13636 image_create_info.extent.width = tex_width;
13637 image_create_info.extent.height = tex_height;
13638 image_create_info.extent.depth = 1;
13639 image_create_info.mipLevels = 1;
13640 image_create_info.arrayLayers = 1;
13641 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13642 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13643 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13644 image_create_info.flags = 0;
13645
13646 // Introduce error by sending down a bogus width extent
13647 image_create_info.extent.width = 0;
13648 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13649
13650 m_errorMonitor->VerifyFound();
13651}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013652#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013653
Tobin Ehliscde08892015-09-22 10:11:37 -060013654#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013655
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013656TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13657 TEST_DESCRIPTION("Create a render pass with an attachment description "
13658 "format set to VK_FORMAT_UNDEFINED");
13659
13660 ASSERT_NO_FATAL_FAILURE(InitState());
13661 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013664
13665 VkAttachmentReference color_attach = {};
13666 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13667 color_attach.attachment = 0;
13668 VkSubpassDescription subpass = {};
13669 subpass.colorAttachmentCount = 1;
13670 subpass.pColorAttachments = &color_attach;
13671
13672 VkRenderPassCreateInfo rpci = {};
13673 rpci.subpassCount = 1;
13674 rpci.pSubpasses = &subpass;
13675 rpci.attachmentCount = 1;
13676 VkAttachmentDescription attach_desc = {};
13677 attach_desc.format = VK_FORMAT_UNDEFINED;
13678 rpci.pAttachments = &attach_desc;
13679 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13680 VkRenderPass rp;
13681 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13682
13683 m_errorMonitor->VerifyFound();
13684
13685 if (result == VK_SUCCESS) {
13686 vkDestroyRenderPass(m_device->device(), rp, NULL);
13687 }
13688}
13689
Karl Schultz6addd812016-02-02 17:17:23 -070013690TEST_F(VkLayerTest, InvalidImageView) {
13691 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013694
Tobin Ehliscde08892015-09-22 10:11:37 -060013695 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013696
Mike Stroyana3082432015-09-25 13:39:21 -060013697 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013698 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013699
Karl Schultz6addd812016-02-02 17:17:23 -070013700 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13701 const int32_t tex_width = 32;
13702 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013703
13704 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13706 image_create_info.pNext = NULL;
13707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13708 image_create_info.format = tex_format;
13709 image_create_info.extent.width = tex_width;
13710 image_create_info.extent.height = tex_height;
13711 image_create_info.extent.depth = 1;
13712 image_create_info.mipLevels = 1;
13713 image_create_info.arrayLayers = 1;
13714 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13715 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13716 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13717 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013718
Chia-I Wuf7458c52015-10-26 21:10:41 +080013719 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013720 ASSERT_VK_SUCCESS(err);
13721
13722 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013723 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13724 image_view_create_info.image = image;
13725 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13726 image_view_create_info.format = tex_format;
13727 image_view_create_info.subresourceRange.layerCount = 1;
13728 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13729 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013730 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013731
13732 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013733 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013734
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013735 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013736 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013737}
Mike Stroyana3082432015-09-25 13:39:21 -060013738
Mark Youngd339ba32016-05-30 13:28:35 -060013739TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13740 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013742 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013743
13744 ASSERT_NO_FATAL_FAILURE(InitState());
13745
13746 // Create an image and try to create a view with no memory backing the image
13747 VkImage image;
13748
13749 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13750 const int32_t tex_width = 32;
13751 const int32_t tex_height = 32;
13752
13753 VkImageCreateInfo image_create_info = {};
13754 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;
13759 image_create_info.extent.height = tex_height;
13760 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;
13767
13768 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13769 ASSERT_VK_SUCCESS(err);
13770
13771 VkImageViewCreateInfo image_view_create_info = {};
13772 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13773 image_view_create_info.image = image;
13774 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13775 image_view_create_info.format = tex_format;
13776 image_view_create_info.subresourceRange.layerCount = 1;
13777 image_view_create_info.subresourceRange.baseMipLevel = 0;
13778 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013779 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013780
13781 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013782 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013783
13784 m_errorMonitor->VerifyFound();
13785 vkDestroyImage(m_device->device(), image, NULL);
13786 // If last error is success, it still created the view, so delete it.
13787 if (err == VK_SUCCESS) {
13788 vkDestroyImageView(m_device->device(), view, NULL);
13789 }
Mark Youngd339ba32016-05-30 13:28:35 -060013790}
13791
Karl Schultz6addd812016-02-02 17:17:23 -070013792TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013793 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013795 "formats must have ONLY the "
13796 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13798 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013799
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013800 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013801
Karl Schultz6addd812016-02-02 17:17:23 -070013802 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013803 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013804 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013805 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013806
13807 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013808 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013809 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013810 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13811 image_view_create_info.format = tex_format;
13812 image_view_create_info.subresourceRange.baseMipLevel = 0;
13813 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013814 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013815 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013816 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013817
13818 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013819 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013820
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013821 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013822}
13823
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013824TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013825 VkResult err;
13826 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013827
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13829 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013830
Mike Stroyana3082432015-09-25 13:39:21 -060013831 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013832
13833 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013834 VkImage srcImage;
13835 VkImage dstImage;
13836 VkDeviceMemory srcMem;
13837 VkDeviceMemory destMem;
13838 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013839
13840 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013841 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13842 image_create_info.pNext = NULL;
13843 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13844 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13845 image_create_info.extent.width = 32;
13846 image_create_info.extent.height = 32;
13847 image_create_info.extent.depth = 1;
13848 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013849 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013850 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13851 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13852 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13853 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013854
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013855 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013856 ASSERT_VK_SUCCESS(err);
13857
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013858 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013859 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013860 ASSERT_VK_SUCCESS(err);
13861
13862 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013863 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013864 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13865 memAlloc.pNext = NULL;
13866 memAlloc.allocationSize = 0;
13867 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013868
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013869 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013870 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013871 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013872 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013873 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013874 ASSERT_VK_SUCCESS(err);
13875
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013876 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013877 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013878 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013879 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013880 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013881 ASSERT_VK_SUCCESS(err);
13882
13883 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13884 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013885 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013886 ASSERT_VK_SUCCESS(err);
13887
13888 BeginCommandBuffer();
13889 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013890 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013891 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013892 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013893 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013894 copyRegion.srcOffset.x = 0;
13895 copyRegion.srcOffset.y = 0;
13896 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013897 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013898 copyRegion.dstSubresource.mipLevel = 0;
13899 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013900 // Introduce failure by forcing the dst layerCount to differ from src
13901 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013902 copyRegion.dstOffset.x = 0;
13903 copyRegion.dstOffset.y = 0;
13904 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013905 copyRegion.extent.width = 1;
13906 copyRegion.extent.height = 1;
13907 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013908 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013909 EndCommandBuffer();
13910
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013911 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013912
Chia-I Wuf7458c52015-10-26 21:10:41 +080013913 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013914 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013915 vkFreeMemory(m_device->device(), srcMem, NULL);
13916 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013917}
13918
Tony Barbourd6673642016-05-05 14:46:39 -060013919TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13920
13921 TEST_DESCRIPTION("Creating images with unsuported formats ");
13922
13923 ASSERT_NO_FATAL_FAILURE(InitState());
13924 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13925 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013926 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 -060013927 VK_IMAGE_TILING_OPTIMAL, 0);
13928 ASSERT_TRUE(image.initialized());
13929
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013930 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13931 VkImageCreateInfo image_create_info;
13932 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13933 image_create_info.pNext = NULL;
13934 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13935 image_create_info.format = VK_FORMAT_UNDEFINED;
13936 image_create_info.extent.width = 32;
13937 image_create_info.extent.height = 32;
13938 image_create_info.extent.depth = 1;
13939 image_create_info.mipLevels = 1;
13940 image_create_info.arrayLayers = 1;
13941 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13942 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13943 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13944 image_create_info.flags = 0;
13945
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13947 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013948
13949 VkImage localImage;
13950 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13951 m_errorMonitor->VerifyFound();
13952
Tony Barbourd6673642016-05-05 14:46:39 -060013953 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013954 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013955 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13956 VkFormat format = static_cast<VkFormat>(f);
13957 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013958 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013959 unsupported = format;
13960 break;
13961 }
13962 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013963
Tony Barbourd6673642016-05-05 14:46:39 -060013964 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013965 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013967
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013968 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013969 m_errorMonitor->VerifyFound();
13970 }
13971}
13972
13973TEST_F(VkLayerTest, ImageLayerViewTests) {
13974 VkResult ret;
13975 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13976
13977 ASSERT_NO_FATAL_FAILURE(InitState());
13978
13979 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013980 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 -060013981 VK_IMAGE_TILING_OPTIMAL, 0);
13982 ASSERT_TRUE(image.initialized());
13983
13984 VkImageView imgView;
13985 VkImageViewCreateInfo imgViewInfo = {};
13986 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13987 imgViewInfo.image = image.handle();
13988 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13989 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13990 imgViewInfo.subresourceRange.layerCount = 1;
13991 imgViewInfo.subresourceRange.baseMipLevel = 0;
13992 imgViewInfo.subresourceRange.levelCount = 1;
13993 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13994
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013996 // View can't have baseMipLevel >= image's mipLevels - Expect
13997 // VIEW_CREATE_ERROR
13998 imgViewInfo.subresourceRange.baseMipLevel = 1;
13999 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14000 m_errorMonitor->VerifyFound();
14001 imgViewInfo.subresourceRange.baseMipLevel = 0;
14002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014004 // View can't have baseArrayLayer >= image's arraySize - Expect
14005 // VIEW_CREATE_ERROR
14006 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14007 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14008 m_errorMonitor->VerifyFound();
14009 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14012 "pCreateInfo->subresourceRange."
14013 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014014 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14015 imgViewInfo.subresourceRange.levelCount = 0;
14016 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14017 m_errorMonitor->VerifyFound();
14018 imgViewInfo.subresourceRange.levelCount = 1;
14019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14021 "pCreateInfo->subresourceRange."
14022 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014023 m_errorMonitor->SetDesiredFailureMsg(
14024 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14025 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014026 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14027 imgViewInfo.subresourceRange.layerCount = 0;
14028 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14029 m_errorMonitor->VerifyFound();
14030 imgViewInfo.subresourceRange.layerCount = 1;
14031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14034 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14035 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014036 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14037 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14038 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14039 m_errorMonitor->VerifyFound();
14040 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14043 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14044 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014045 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14046 // VIEW_CREATE_ERROR
14047 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14048 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14049 m_errorMonitor->VerifyFound();
14050 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14051
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14053 "differing formats but they must be "
14054 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014055 // TODO: Update framework to easily passing mutable flag into ImageObj init
14056 // For now just allowing image for this one test to not have memory bound
14057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14058 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014059 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14060 // VIEW_CREATE_ERROR
14061 VkImageCreateInfo mutImgInfo = image.create_info();
14062 VkImage mutImage;
14063 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014064 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014065 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14066 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14067 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14068 ASSERT_VK_SUCCESS(ret);
14069 imgViewInfo.image = mutImage;
14070 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14071 m_errorMonitor->VerifyFound();
14072 imgViewInfo.image = image.handle();
14073 vkDestroyImage(m_device->handle(), mutImage, NULL);
14074}
14075
14076TEST_F(VkLayerTest, MiscImageLayerTests) {
14077
14078 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14079
14080 ASSERT_NO_FATAL_FAILURE(InitState());
14081
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 Lobodzinskice751c62016-09-08 10:45:35 -060014087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060014088 vk_testing::Buffer buffer;
14089 VkMemoryPropertyFlags reqs = 0;
14090 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14091 VkBufferImageCopy region = {};
14092 region.bufferRowLength = 128;
14093 region.bufferImageHeight = 128;
14094 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14095 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14096 region.imageSubresource.layerCount = 0;
14097 region.imageExtent.height = 4;
14098 region.imageExtent.width = 4;
14099 region.imageExtent.depth = 1;
14100 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014101 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14102 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014103 m_errorMonitor->VerifyFound();
14104 region.imageSubresource.layerCount = 1;
14105
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014106 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14107 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14108 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
14110 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14111 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014112 m_errorMonitor->VerifyFound();
14113
14114 // BufferOffset must be a multiple of 4
14115 // Introduce failure by setting bufferOffset to a value not divisible by 4
14116 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
14118 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14119 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014120 m_errorMonitor->VerifyFound();
14121
14122 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14123 region.bufferOffset = 0;
14124 region.imageExtent.height = 128;
14125 region.imageExtent.width = 128;
14126 // Introduce failure by setting bufferRowLength > 0 but less than width
14127 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14129 "must be zero or greater-than-or-equal-to imageExtent.width");
14130 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14131 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014132 m_errorMonitor->VerifyFound();
14133
14134 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14135 region.bufferRowLength = 128;
14136 // Introduce failure by setting bufferRowHeight > 0 but less than height
14137 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14139 "must be zero or greater-than-or-equal-to imageExtent.height");
14140 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14141 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014142 m_errorMonitor->VerifyFound();
14143
14144 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
14146 "specify only COLOR or DEPTH or "
14147 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060014148 // Expect MISMATCHED_IMAGE_ASPECT
14149 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014150 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14151 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014152 m_errorMonitor->VerifyFound();
14153 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14154
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14156 "If the format of srcImage is a depth, stencil, depth stencil or "
14157 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014158 // Expect INVALID_FILTER
14159 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014160 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 -060014161 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014162 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 -060014163 VkImageBlit blitRegion = {};
14164 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14165 blitRegion.srcSubresource.baseArrayLayer = 0;
14166 blitRegion.srcSubresource.layerCount = 1;
14167 blitRegion.srcSubresource.mipLevel = 0;
14168 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14169 blitRegion.dstSubresource.baseArrayLayer = 0;
14170 blitRegion.dstSubresource.layerCount = 1;
14171 blitRegion.dstSubresource.mipLevel = 0;
14172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014173 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14174 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014175 m_errorMonitor->VerifyFound();
14176
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014177 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14179 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14180 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014181 m_errorMonitor->VerifyFound();
14182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014184 VkImageMemoryBarrier img_barrier;
14185 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14186 img_barrier.pNext = NULL;
14187 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14188 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14189 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14190 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14191 img_barrier.image = image.handle();
14192 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14193 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14194 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14195 img_barrier.subresourceRange.baseArrayLayer = 0;
14196 img_barrier.subresourceRange.baseMipLevel = 0;
14197 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14198 img_barrier.subresourceRange.layerCount = 0;
14199 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014200 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14201 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014202 m_errorMonitor->VerifyFound();
14203 img_barrier.subresourceRange.layerCount = 1;
14204}
14205
14206TEST_F(VkLayerTest, ImageFormatLimits) {
14207
14208 TEST_DESCRIPTION("Exceed the limits of image format ");
14209
Cody Northropc31a84f2016-08-22 10:41:47 -060014210 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014212 VkImageCreateInfo image_create_info = {};
14213 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14214 image_create_info.pNext = NULL;
14215 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14216 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14217 image_create_info.extent.width = 32;
14218 image_create_info.extent.height = 32;
14219 image_create_info.extent.depth = 1;
14220 image_create_info.mipLevels = 1;
14221 image_create_info.arrayLayers = 1;
14222 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14223 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14224 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14225 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14226 image_create_info.flags = 0;
14227
14228 VkImage nullImg;
14229 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014230 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14231 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014232 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14233 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14234 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14235 m_errorMonitor->VerifyFound();
14236 image_create_info.extent.depth = 1;
14237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014239 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14240 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14241 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14242 m_errorMonitor->VerifyFound();
14243 image_create_info.mipLevels = 1;
14244
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014246 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14247 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14248 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14249 m_errorMonitor->VerifyFound();
14250 image_create_info.arrayLayers = 1;
14251
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014253 int samples = imgFmtProps.sampleCounts >> 1;
14254 image_create_info.samples = (VkSampleCountFlagBits)samples;
14255 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14256 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14257 m_errorMonitor->VerifyFound();
14258 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14261 "VK_IMAGE_LAYOUT_UNDEFINED or "
14262 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014263 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14264 // Expect INVALID_LAYOUT
14265 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14266 m_errorMonitor->VerifyFound();
14267 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14268}
14269
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014270TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14271
14272 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014274
14275 ASSERT_NO_FATAL_FAILURE(InitState());
14276
14277 VkImageObj src_image(m_device);
14278 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14279 VkImageObj dst_image(m_device);
14280 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14281
14282 BeginCommandBuffer();
14283 VkImageCopy copy_region;
14284 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14285 copy_region.srcSubresource.mipLevel = 0;
14286 copy_region.srcSubresource.baseArrayLayer = 0;
14287 copy_region.srcSubresource.layerCount = 0;
14288 copy_region.srcOffset.x = 0;
14289 copy_region.srcOffset.y = 0;
14290 copy_region.srcOffset.z = 0;
14291 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14292 copy_region.dstSubresource.mipLevel = 0;
14293 copy_region.dstSubresource.baseArrayLayer = 0;
14294 copy_region.dstSubresource.layerCount = 0;
14295 copy_region.dstOffset.x = 0;
14296 copy_region.dstOffset.y = 0;
14297 copy_region.dstOffset.z = 0;
14298 copy_region.extent.width = 64;
14299 copy_region.extent.height = 64;
14300 copy_region.extent.depth = 1;
14301 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14302 &copy_region);
14303 EndCommandBuffer();
14304
14305 m_errorMonitor->VerifyFound();
14306}
14307
14308TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14309
14310 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014312
14313 ASSERT_NO_FATAL_FAILURE(InitState());
14314
14315 VkImageObj src_image(m_device);
14316 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14317 VkImageObj dst_image(m_device);
14318 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14319
14320 BeginCommandBuffer();
14321 VkImageCopy copy_region;
14322 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14323 copy_region.srcSubresource.mipLevel = 0;
14324 copy_region.srcSubresource.baseArrayLayer = 0;
14325 copy_region.srcSubresource.layerCount = 0;
14326 copy_region.srcOffset.x = 0;
14327 copy_region.srcOffset.y = 0;
14328 copy_region.srcOffset.z = 0;
14329 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14330 copy_region.dstSubresource.mipLevel = 0;
14331 copy_region.dstSubresource.baseArrayLayer = 0;
14332 copy_region.dstSubresource.layerCount = 0;
14333 copy_region.dstOffset.x = 0;
14334 copy_region.dstOffset.y = 0;
14335 copy_region.dstOffset.z = 0;
14336 copy_region.extent.width = 64;
14337 copy_region.extent.height = 64;
14338 copy_region.extent.depth = 1;
14339 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14340 &copy_region);
14341 EndCommandBuffer();
14342
14343 m_errorMonitor->VerifyFound();
14344}
14345
Karl Schultz6addd812016-02-02 17:17:23 -070014346TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014347 VkResult err;
14348 bool pass;
14349
14350 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14352 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014353
14354 ASSERT_NO_FATAL_FAILURE(InitState());
14355
14356 // Create two images of different types and try to copy between them
14357 VkImage srcImage;
14358 VkImage dstImage;
14359 VkDeviceMemory srcMem;
14360 VkDeviceMemory destMem;
14361 VkMemoryRequirements memReqs;
14362
14363 VkImageCreateInfo image_create_info = {};
14364 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14365 image_create_info.pNext = NULL;
14366 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14367 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14368 image_create_info.extent.width = 32;
14369 image_create_info.extent.height = 32;
14370 image_create_info.extent.depth = 1;
14371 image_create_info.mipLevels = 1;
14372 image_create_info.arrayLayers = 1;
14373 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14374 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14375 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14376 image_create_info.flags = 0;
14377
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014378 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014379 ASSERT_VK_SUCCESS(err);
14380
14381 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14382 // Introduce failure by creating second image with a different-sized format.
14383 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14384
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014385 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014386 ASSERT_VK_SUCCESS(err);
14387
14388 // Allocate memory
14389 VkMemoryAllocateInfo memAlloc = {};
14390 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14391 memAlloc.pNext = NULL;
14392 memAlloc.allocationSize = 0;
14393 memAlloc.memoryTypeIndex = 0;
14394
14395 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14396 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014397 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014398 ASSERT_TRUE(pass);
14399 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14400 ASSERT_VK_SUCCESS(err);
14401
14402 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14403 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014404 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014405 ASSERT_TRUE(pass);
14406 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14407 ASSERT_VK_SUCCESS(err);
14408
14409 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14410 ASSERT_VK_SUCCESS(err);
14411 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14412 ASSERT_VK_SUCCESS(err);
14413
14414 BeginCommandBuffer();
14415 VkImageCopy copyRegion;
14416 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14417 copyRegion.srcSubresource.mipLevel = 0;
14418 copyRegion.srcSubresource.baseArrayLayer = 0;
14419 copyRegion.srcSubresource.layerCount = 0;
14420 copyRegion.srcOffset.x = 0;
14421 copyRegion.srcOffset.y = 0;
14422 copyRegion.srcOffset.z = 0;
14423 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14424 copyRegion.dstSubresource.mipLevel = 0;
14425 copyRegion.dstSubresource.baseArrayLayer = 0;
14426 copyRegion.dstSubresource.layerCount = 0;
14427 copyRegion.dstOffset.x = 0;
14428 copyRegion.dstOffset.y = 0;
14429 copyRegion.dstOffset.z = 0;
14430 copyRegion.extent.width = 1;
14431 copyRegion.extent.height = 1;
14432 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014433 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014434 EndCommandBuffer();
14435
14436 m_errorMonitor->VerifyFound();
14437
14438 vkDestroyImage(m_device->device(), srcImage, NULL);
14439 vkDestroyImage(m_device->device(), dstImage, NULL);
14440 vkFreeMemory(m_device->device(), srcMem, NULL);
14441 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014442}
14443
Karl Schultz6addd812016-02-02 17:17:23 -070014444TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14445 VkResult err;
14446 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014447
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014448 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14450 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014451
Mike Stroyana3082432015-09-25 13:39:21 -060014452 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014453
14454 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014455 VkImage srcImage;
14456 VkImage dstImage;
14457 VkDeviceMemory srcMem;
14458 VkDeviceMemory destMem;
14459 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014460
14461 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014462 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14463 image_create_info.pNext = NULL;
14464 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14465 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14466 image_create_info.extent.width = 32;
14467 image_create_info.extent.height = 32;
14468 image_create_info.extent.depth = 1;
14469 image_create_info.mipLevels = 1;
14470 image_create_info.arrayLayers = 1;
14471 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14472 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14473 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14474 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014475
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014476 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014477 ASSERT_VK_SUCCESS(err);
14478
Karl Schultzbdb75952016-04-19 11:36:49 -060014479 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14480
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014481 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014482 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014483 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014484 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014486 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014487 ASSERT_VK_SUCCESS(err);
14488
14489 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014490 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014491 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14492 memAlloc.pNext = NULL;
14493 memAlloc.allocationSize = 0;
14494 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014495
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014496 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014497 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014498 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014499 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014500 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014501 ASSERT_VK_SUCCESS(err);
14502
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014503 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014504 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014505 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014506 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014507 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014508 ASSERT_VK_SUCCESS(err);
14509
14510 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14511 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014512 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014513 ASSERT_VK_SUCCESS(err);
14514
14515 BeginCommandBuffer();
14516 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014517 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014518 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014519 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014520 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014521 copyRegion.srcOffset.x = 0;
14522 copyRegion.srcOffset.y = 0;
14523 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014524 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014525 copyRegion.dstSubresource.mipLevel = 0;
14526 copyRegion.dstSubresource.baseArrayLayer = 0;
14527 copyRegion.dstSubresource.layerCount = 0;
14528 copyRegion.dstOffset.x = 0;
14529 copyRegion.dstOffset.y = 0;
14530 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014531 copyRegion.extent.width = 1;
14532 copyRegion.extent.height = 1;
14533 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014534 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014535 EndCommandBuffer();
14536
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014537 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014538
Chia-I Wuf7458c52015-10-26 21:10:41 +080014539 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014540 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014541 vkFreeMemory(m_device->device(), srcMem, NULL);
14542 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014543}
14544
Karl Schultz6addd812016-02-02 17:17:23 -070014545TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14546 VkResult err;
14547 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014548
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14550 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014551
Mike Stroyana3082432015-09-25 13:39:21 -060014552 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014553
14554 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014555 VkImage srcImage;
14556 VkImage dstImage;
14557 VkDeviceMemory srcMem;
14558 VkDeviceMemory destMem;
14559 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014560
14561 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014562 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14563 image_create_info.pNext = NULL;
14564 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14565 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14566 image_create_info.extent.width = 32;
14567 image_create_info.extent.height = 1;
14568 image_create_info.extent.depth = 1;
14569 image_create_info.mipLevels = 1;
14570 image_create_info.arrayLayers = 1;
14571 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14572 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14573 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14574 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014575
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014576 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014577 ASSERT_VK_SUCCESS(err);
14578
Karl Schultz6addd812016-02-02 17:17:23 -070014579 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014581 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014582 ASSERT_VK_SUCCESS(err);
14583
14584 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014585 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014586 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14587 memAlloc.pNext = NULL;
14588 memAlloc.allocationSize = 0;
14589 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014590
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014591 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014592 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014593 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014594 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014595 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014596 ASSERT_VK_SUCCESS(err);
14597
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014598 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014599 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014600 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014601 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014602 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014603 ASSERT_VK_SUCCESS(err);
14604
14605 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14606 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014607 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014608 ASSERT_VK_SUCCESS(err);
14609
14610 BeginCommandBuffer();
14611 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014612 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14613 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014614 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014615 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014616 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014617 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014618 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014619 resolveRegion.srcOffset.x = 0;
14620 resolveRegion.srcOffset.y = 0;
14621 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014622 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014623 resolveRegion.dstSubresource.mipLevel = 0;
14624 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014625 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014626 resolveRegion.dstOffset.x = 0;
14627 resolveRegion.dstOffset.y = 0;
14628 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014629 resolveRegion.extent.width = 1;
14630 resolveRegion.extent.height = 1;
14631 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014632 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014633 EndCommandBuffer();
14634
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014635 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014636
Chia-I Wuf7458c52015-10-26 21:10:41 +080014637 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014638 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014639 vkFreeMemory(m_device->device(), srcMem, NULL);
14640 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014641}
14642
Karl Schultz6addd812016-02-02 17:17:23 -070014643TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14644 VkResult err;
14645 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014646
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14648 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014649
Mike Stroyana3082432015-09-25 13:39:21 -060014650 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014651
Chris Forbesa7530692016-05-08 12:35:39 +120014652 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014653 VkImage srcImage;
14654 VkImage dstImage;
14655 VkDeviceMemory srcMem;
14656 VkDeviceMemory destMem;
14657 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014658
14659 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014660 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14661 image_create_info.pNext = NULL;
14662 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14663 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14664 image_create_info.extent.width = 32;
14665 image_create_info.extent.height = 1;
14666 image_create_info.extent.depth = 1;
14667 image_create_info.mipLevels = 1;
14668 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014669 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014670 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14671 // Note: Some implementations expect color attachment usage for any
14672 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014673 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014674 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014675
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014676 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014677 ASSERT_VK_SUCCESS(err);
14678
Karl Schultz6addd812016-02-02 17:17:23 -070014679 // Note: Some implementations expect color attachment usage for any
14680 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014681 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014682
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014683 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014684 ASSERT_VK_SUCCESS(err);
14685
14686 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014687 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014688 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14689 memAlloc.pNext = NULL;
14690 memAlloc.allocationSize = 0;
14691 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014692
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014693 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014694 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014695 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014696 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014697 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014698 ASSERT_VK_SUCCESS(err);
14699
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014700 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014701 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014702 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014703 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014704 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014705 ASSERT_VK_SUCCESS(err);
14706
14707 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14708 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014709 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014710 ASSERT_VK_SUCCESS(err);
14711
14712 BeginCommandBuffer();
14713 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014714 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14715 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014716 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014717 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014718 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014719 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014720 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014721 resolveRegion.srcOffset.x = 0;
14722 resolveRegion.srcOffset.y = 0;
14723 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014724 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014725 resolveRegion.dstSubresource.mipLevel = 0;
14726 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014727 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014728 resolveRegion.dstOffset.x = 0;
14729 resolveRegion.dstOffset.y = 0;
14730 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014731 resolveRegion.extent.width = 1;
14732 resolveRegion.extent.height = 1;
14733 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014734 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014735 EndCommandBuffer();
14736
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014737 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014738
Chia-I Wuf7458c52015-10-26 21:10:41 +080014739 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014740 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014741 vkFreeMemory(m_device->device(), srcMem, NULL);
14742 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014743}
14744
Karl Schultz6addd812016-02-02 17:17:23 -070014745TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14746 VkResult err;
14747 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14750 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014751
Mike Stroyana3082432015-09-25 13:39:21 -060014752 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014753
14754 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014755 VkImage srcImage;
14756 VkImage dstImage;
14757 VkDeviceMemory srcMem;
14758 VkDeviceMemory destMem;
14759 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014760
14761 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014762 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14763 image_create_info.pNext = NULL;
14764 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14765 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14766 image_create_info.extent.width = 32;
14767 image_create_info.extent.height = 1;
14768 image_create_info.extent.depth = 1;
14769 image_create_info.mipLevels = 1;
14770 image_create_info.arrayLayers = 1;
14771 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14772 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14773 // Note: Some implementations expect color attachment usage for any
14774 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014775 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014776 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014777
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014778 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014779 ASSERT_VK_SUCCESS(err);
14780
Karl Schultz6addd812016-02-02 17:17:23 -070014781 // Set format to something other than source image
14782 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14783 // Note: Some implementations expect color attachment usage for any
14784 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014785 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014786 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014788 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014789 ASSERT_VK_SUCCESS(err);
14790
14791 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014792 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014793 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14794 memAlloc.pNext = NULL;
14795 memAlloc.allocationSize = 0;
14796 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014797
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014798 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014799 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014800 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014801 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014802 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014803 ASSERT_VK_SUCCESS(err);
14804
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014805 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014806 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014807 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014808 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014809 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014810 ASSERT_VK_SUCCESS(err);
14811
14812 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14813 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014814 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014815 ASSERT_VK_SUCCESS(err);
14816
14817 BeginCommandBuffer();
14818 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014819 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14820 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014821 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014822 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014823 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014824 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014825 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014826 resolveRegion.srcOffset.x = 0;
14827 resolveRegion.srcOffset.y = 0;
14828 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014829 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014830 resolveRegion.dstSubresource.mipLevel = 0;
14831 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014832 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014833 resolveRegion.dstOffset.x = 0;
14834 resolveRegion.dstOffset.y = 0;
14835 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014836 resolveRegion.extent.width = 1;
14837 resolveRegion.extent.height = 1;
14838 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014839 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014840 EndCommandBuffer();
14841
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014842 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014843
Chia-I Wuf7458c52015-10-26 21:10:41 +080014844 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014845 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014846 vkFreeMemory(m_device->device(), srcMem, NULL);
14847 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014848}
14849
Karl Schultz6addd812016-02-02 17:17:23 -070014850TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14851 VkResult err;
14852 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014853
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14855 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014856
Mike Stroyana3082432015-09-25 13:39:21 -060014857 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014858
14859 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014860 VkImage srcImage;
14861 VkImage dstImage;
14862 VkDeviceMemory srcMem;
14863 VkDeviceMemory destMem;
14864 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014865
14866 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014867 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14868 image_create_info.pNext = NULL;
14869 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14870 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14871 image_create_info.extent.width = 32;
14872 image_create_info.extent.height = 1;
14873 image_create_info.extent.depth = 1;
14874 image_create_info.mipLevels = 1;
14875 image_create_info.arrayLayers = 1;
14876 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14877 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14878 // Note: Some implementations expect color attachment usage for any
14879 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014880 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014881 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014883 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014884 ASSERT_VK_SUCCESS(err);
14885
Karl Schultz6addd812016-02-02 17:17:23 -070014886 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14887 // Note: Some implementations expect color attachment usage for any
14888 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014889 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014890 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014891
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014892 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014893 ASSERT_VK_SUCCESS(err);
14894
14895 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014896 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014897 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14898 memAlloc.pNext = NULL;
14899 memAlloc.allocationSize = 0;
14900 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014901
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014902 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014903 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014904 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014905 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014906 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014907 ASSERT_VK_SUCCESS(err);
14908
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014909 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014910 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014911 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014912 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014913 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014914 ASSERT_VK_SUCCESS(err);
14915
14916 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14917 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014918 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014919 ASSERT_VK_SUCCESS(err);
14920
14921 BeginCommandBuffer();
14922 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014923 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14924 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014925 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014926 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014927 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014928 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014929 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014930 resolveRegion.srcOffset.x = 0;
14931 resolveRegion.srcOffset.y = 0;
14932 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014933 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014934 resolveRegion.dstSubresource.mipLevel = 0;
14935 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014936 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014937 resolveRegion.dstOffset.x = 0;
14938 resolveRegion.dstOffset.y = 0;
14939 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014940 resolveRegion.extent.width = 1;
14941 resolveRegion.extent.height = 1;
14942 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014943 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014944 EndCommandBuffer();
14945
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014946 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014947
Chia-I Wuf7458c52015-10-26 21:10:41 +080014948 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014949 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014950 vkFreeMemory(m_device->device(), srcMem, NULL);
14951 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014952}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014953
Karl Schultz6addd812016-02-02 17:17:23 -070014954TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014955 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014956 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14957 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014958 // The image format check comes 2nd in validation so we trigger it first,
14959 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014960 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014961
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14963 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014964
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014965 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014966
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014967 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014968 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14969 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014970
14971 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014972 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14973 ds_pool_ci.pNext = NULL;
14974 ds_pool_ci.maxSets = 1;
14975 ds_pool_ci.poolSizeCount = 1;
14976 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014977
14978 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014979 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014980 ASSERT_VK_SUCCESS(err);
14981
14982 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014983 dsl_binding.binding = 0;
14984 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14985 dsl_binding.descriptorCount = 1;
14986 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14987 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014988
14989 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014990 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14991 ds_layout_ci.pNext = NULL;
14992 ds_layout_ci.bindingCount = 1;
14993 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014994 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014995 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014996 ASSERT_VK_SUCCESS(err);
14997
14998 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014999 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015000 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015001 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015002 alloc_info.descriptorPool = ds_pool;
15003 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015004 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015005 ASSERT_VK_SUCCESS(err);
15006
Karl Schultz6addd812016-02-02 17:17:23 -070015007 VkImage image_bad;
15008 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015009 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015010 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015011 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015012 const int32_t tex_width = 32;
15013 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015014
15015 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015016 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15017 image_create_info.pNext = NULL;
15018 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15019 image_create_info.format = tex_format_bad;
15020 image_create_info.extent.width = tex_width;
15021 image_create_info.extent.height = tex_height;
15022 image_create_info.extent.depth = 1;
15023 image_create_info.mipLevels = 1;
15024 image_create_info.arrayLayers = 1;
15025 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15026 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015027 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015028 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015030 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015031 ASSERT_VK_SUCCESS(err);
15032 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015033 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15034 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015035 ASSERT_VK_SUCCESS(err);
15036
15037 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015038 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15039 image_view_create_info.image = image_bad;
15040 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15041 image_view_create_info.format = tex_format_bad;
15042 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15043 image_view_create_info.subresourceRange.baseMipLevel = 0;
15044 image_view_create_info.subresourceRange.layerCount = 1;
15045 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015046 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015047
15048 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015049 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015050
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015051 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015052
Chia-I Wuf7458c52015-10-26 21:10:41 +080015053 vkDestroyImage(m_device->device(), image_bad, NULL);
15054 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015055 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15056 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015057}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015058
15059TEST_F(VkLayerTest, ClearImageErrors) {
15060 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15061 "ClearDepthStencilImage with a color image.");
15062
15063 ASSERT_NO_FATAL_FAILURE(InitState());
15064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15065
15066 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15067 BeginCommandBuffer();
15068 m_commandBuffer->EndRenderPass();
15069
15070 // Color image
15071 VkClearColorValue clear_color;
15072 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15073 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15074 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15075 const int32_t img_width = 32;
15076 const int32_t img_height = 32;
15077 VkImageCreateInfo image_create_info = {};
15078 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15079 image_create_info.pNext = NULL;
15080 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15081 image_create_info.format = color_format;
15082 image_create_info.extent.width = img_width;
15083 image_create_info.extent.height = img_height;
15084 image_create_info.extent.depth = 1;
15085 image_create_info.mipLevels = 1;
15086 image_create_info.arrayLayers = 1;
15087 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15088 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15089 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15090
15091 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015092 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015094 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015095
15096 // Depth/Stencil image
15097 VkClearDepthStencilValue clear_value = {0};
15098 reqs = 0; // don't need HOST_VISIBLE DS image
15099 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15100 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15101 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15102 ds_image_create_info.extent.width = 64;
15103 ds_image_create_info.extent.height = 64;
15104 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15105 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15106
15107 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015108 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015110 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 -060015111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015114 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015115 &color_range);
15116
15117 m_errorMonitor->VerifyFound();
15118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15120 "image created without "
15121 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015123 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015124 &color_range);
15125
15126 m_errorMonitor->VerifyFound();
15127
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015128 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15130 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15133 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015134
15135 m_errorMonitor->VerifyFound();
15136}
Tobin Ehliscde08892015-09-22 10:11:37 -060015137#endif // IMAGE_TESTS
15138
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015139
15140// WSI Enabled Tests
15141//
Chris Forbes09368e42016-10-13 11:59:22 +130015142#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015143TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15144
15145#if defined(VK_USE_PLATFORM_XCB_KHR)
15146 VkSurfaceKHR surface = VK_NULL_HANDLE;
15147
15148 VkResult err;
15149 bool pass;
15150 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15151 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15152 // uint32_t swapchain_image_count = 0;
15153 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15154 // uint32_t image_index = 0;
15155 // VkPresentInfoKHR present_info = {};
15156
15157 ASSERT_NO_FATAL_FAILURE(InitState());
15158
15159 // Use the create function from one of the VK_KHR_*_surface extension in
15160 // order to create a surface, testing all known errors in the process,
15161 // before successfully creating a surface:
15162 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15164 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15165 pass = (err != VK_SUCCESS);
15166 ASSERT_TRUE(pass);
15167 m_errorMonitor->VerifyFound();
15168
15169 // Next, try to create a surface with the wrong
15170 // VkXcbSurfaceCreateInfoKHR::sType:
15171 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15172 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15174 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15175 pass = (err != VK_SUCCESS);
15176 ASSERT_TRUE(pass);
15177 m_errorMonitor->VerifyFound();
15178
15179 // Create a native window, and then correctly create a surface:
15180 xcb_connection_t *connection;
15181 xcb_screen_t *screen;
15182 xcb_window_t xcb_window;
15183 xcb_intern_atom_reply_t *atom_wm_delete_window;
15184
15185 const xcb_setup_t *setup;
15186 xcb_screen_iterator_t iter;
15187 int scr;
15188 uint32_t value_mask, value_list[32];
15189 int width = 1;
15190 int height = 1;
15191
15192 connection = xcb_connect(NULL, &scr);
15193 ASSERT_TRUE(connection != NULL);
15194 setup = xcb_get_setup(connection);
15195 iter = xcb_setup_roots_iterator(setup);
15196 while (scr-- > 0)
15197 xcb_screen_next(&iter);
15198 screen = iter.data;
15199
15200 xcb_window = xcb_generate_id(connection);
15201
15202 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15203 value_list[0] = screen->black_pixel;
15204 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15205
15206 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15207 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15208
15209 /* Magic code that will send notification when window is destroyed */
15210 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15211 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15212
15213 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15214 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15215 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15216 free(reply);
15217
15218 xcb_map_window(connection, xcb_window);
15219
15220 // Force the x/y coordinates to 100,100 results are identical in consecutive
15221 // runs
15222 const uint32_t coords[] = { 100, 100 };
15223 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15224
15225 // Finally, try to correctly create a surface:
15226 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15227 xcb_create_info.pNext = NULL;
15228 xcb_create_info.flags = 0;
15229 xcb_create_info.connection = connection;
15230 xcb_create_info.window = xcb_window;
15231 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15232 pass = (err == VK_SUCCESS);
15233 ASSERT_TRUE(pass);
15234
15235 // Check if surface supports presentation:
15236
15237 // 1st, do so without having queried the queue families:
15238 VkBool32 supported = false;
15239 // TODO: Get the following error to come out:
15240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15241 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15242 "function");
15243 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15244 pass = (err != VK_SUCCESS);
15245 // ASSERT_TRUE(pass);
15246 // m_errorMonitor->VerifyFound();
15247
15248 // Next, query a queue family index that's too large:
15249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15250 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15251 pass = (err != VK_SUCCESS);
15252 ASSERT_TRUE(pass);
15253 m_errorMonitor->VerifyFound();
15254
15255 // Finally, do so correctly:
15256 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15257 // SUPPORTED
15258 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15259 pass = (err == VK_SUCCESS);
15260 ASSERT_TRUE(pass);
15261
15262 // Before proceeding, try to create a swapchain without having called
15263 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15264 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15265 swapchain_create_info.pNext = NULL;
15266 swapchain_create_info.flags = 0;
15267 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15268 swapchain_create_info.surface = surface;
15269 swapchain_create_info.imageArrayLayers = 1;
15270 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15271 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15273 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15274 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15275 pass = (err != VK_SUCCESS);
15276 ASSERT_TRUE(pass);
15277 m_errorMonitor->VerifyFound();
15278
15279 // Get the surface capabilities:
15280 VkSurfaceCapabilitiesKHR surface_capabilities;
15281
15282 // Do so correctly (only error logged by this entrypoint is if the
15283 // extension isn't enabled):
15284 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15285 pass = (err == VK_SUCCESS);
15286 ASSERT_TRUE(pass);
15287
15288 // Get the surface formats:
15289 uint32_t surface_format_count;
15290
15291 // First, try without a pointer to surface_format_count:
15292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15293 "specified as NULL");
15294 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15295 pass = (err == VK_SUCCESS);
15296 ASSERT_TRUE(pass);
15297 m_errorMonitor->VerifyFound();
15298
15299 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15300 // correctly done a 1st try (to get the count):
15301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15302 surface_format_count = 0;
15303 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15304 pass = (err == VK_SUCCESS);
15305 ASSERT_TRUE(pass);
15306 m_errorMonitor->VerifyFound();
15307
15308 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15309 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15310 pass = (err == VK_SUCCESS);
15311 ASSERT_TRUE(pass);
15312
15313 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15314 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15315
15316 // Next, do a 2nd try with surface_format_count being set too high:
15317 surface_format_count += 5;
15318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15319 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15320 pass = (err == VK_SUCCESS);
15321 ASSERT_TRUE(pass);
15322 m_errorMonitor->VerifyFound();
15323
15324 // Finally, do a correct 1st and 2nd try:
15325 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15326 pass = (err == VK_SUCCESS);
15327 ASSERT_TRUE(pass);
15328 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15329 pass = (err == VK_SUCCESS);
15330 ASSERT_TRUE(pass);
15331
15332 // Get the surface present modes:
15333 uint32_t surface_present_mode_count;
15334
15335 // First, try without a pointer to surface_format_count:
15336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15337 "specified as NULL");
15338
15339 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15340 pass = (err == VK_SUCCESS);
15341 ASSERT_TRUE(pass);
15342 m_errorMonitor->VerifyFound();
15343
15344 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15345 // correctly done a 1st try (to get the count):
15346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15347 surface_present_mode_count = 0;
15348 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15349 (VkPresentModeKHR *)&surface_present_mode_count);
15350 pass = (err == VK_SUCCESS);
15351 ASSERT_TRUE(pass);
15352 m_errorMonitor->VerifyFound();
15353
15354 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15355 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15356 pass = (err == VK_SUCCESS);
15357 ASSERT_TRUE(pass);
15358
15359 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15360 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15361
15362 // Next, do a 2nd try with surface_format_count being set too high:
15363 surface_present_mode_count += 5;
15364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15365 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15366 pass = (err == VK_SUCCESS);
15367 ASSERT_TRUE(pass);
15368 m_errorMonitor->VerifyFound();
15369
15370 // Finally, do a correct 1st and 2nd try:
15371 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15372 pass = (err == VK_SUCCESS);
15373 ASSERT_TRUE(pass);
15374 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15375 pass = (err == VK_SUCCESS);
15376 ASSERT_TRUE(pass);
15377
15378 // Create a swapchain:
15379
15380 // First, try without a pointer to swapchain_create_info:
15381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15382 "specified as NULL");
15383
15384 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15385 pass = (err != VK_SUCCESS);
15386 ASSERT_TRUE(pass);
15387 m_errorMonitor->VerifyFound();
15388
15389 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15390 // sType:
15391 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15393
15394 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15395 pass = (err != VK_SUCCESS);
15396 ASSERT_TRUE(pass);
15397 m_errorMonitor->VerifyFound();
15398
15399 // Next, call with a NULL swapchain pointer:
15400 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15401 swapchain_create_info.pNext = NULL;
15402 swapchain_create_info.flags = 0;
15403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15404 "specified as NULL");
15405
15406 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15407 pass = (err != VK_SUCCESS);
15408 ASSERT_TRUE(pass);
15409 m_errorMonitor->VerifyFound();
15410
15411 // TODO: Enhance swapchain layer so that
15412 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15413
15414 // Next, call with a queue family index that's too large:
15415 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15416 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15417 swapchain_create_info.queueFamilyIndexCount = 2;
15418 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15420 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15421 pass = (err != VK_SUCCESS);
15422 ASSERT_TRUE(pass);
15423 m_errorMonitor->VerifyFound();
15424
15425 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15426 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15427 swapchain_create_info.queueFamilyIndexCount = 1;
15428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15429 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15430 "pCreateInfo->pQueueFamilyIndices).");
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 // Next, call with an invalid imageSharingMode:
15437 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15438 swapchain_create_info.queueFamilyIndexCount = 1;
15439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15440 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15441 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15442 pass = (err != VK_SUCCESS);
15443 ASSERT_TRUE(pass);
15444 m_errorMonitor->VerifyFound();
15445 // Fix for the future:
15446 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15447 // SUPPORTED
15448 swapchain_create_info.queueFamilyIndexCount = 0;
15449 queueFamilyIndex[0] = 0;
15450 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15451
15452 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15453 // Get the images from a swapchain:
15454 // Acquire an image from a swapchain:
15455 // Present an image to a swapchain:
15456 // Destroy the swapchain:
15457
15458 // TODOs:
15459 //
15460 // - Try destroying the device without first destroying the swapchain
15461 //
15462 // - Try destroying the device without first destroying the surface
15463 //
15464 // - Try destroying the surface without first destroying the swapchain
15465
15466 // Destroy the surface:
15467 vkDestroySurfaceKHR(instance(), surface, NULL);
15468
15469 // Tear down the window:
15470 xcb_destroy_window(connection, xcb_window);
15471 xcb_disconnect(connection);
15472
15473#else // VK_USE_PLATFORM_XCB_KHR
15474 return;
15475#endif // VK_USE_PLATFORM_XCB_KHR
15476}
Chris Forbes09368e42016-10-13 11:59:22 +130015477#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015478
15479//
15480// POSITIVE VALIDATION TESTS
15481//
15482// These tests do not expect to encounter ANY validation errors pass only if this is true
15483
Tobin Ehlise0006882016-11-03 10:14:28 -060015484TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15485 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15486 "by a transition in the primary.");
15487 VkResult err;
15488 m_errorMonitor->ExpectSuccess();
15489 ASSERT_NO_FATAL_FAILURE(InitState());
15490 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15491 // Allocate a secondary and primary cmd buffer
15492 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15493 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15494 command_buffer_allocate_info.commandPool = m_commandPool;
15495 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15496 command_buffer_allocate_info.commandBufferCount = 1;
15497
15498 VkCommandBuffer secondary_command_buffer;
15499 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15500 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15501 VkCommandBuffer primary_command_buffer;
15502 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15503 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15504 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15505 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15506 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15507 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15508 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15509
15510 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15511 ASSERT_VK_SUCCESS(err);
15512 VkImageObj image(m_device);
15513 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15514 ASSERT_TRUE(image.initialized());
15515 VkImageMemoryBarrier img_barrier = {};
15516 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15517 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15518 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15519 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15520 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15521 img_barrier.image = image.handle();
15522 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15523 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15524 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15525 img_barrier.subresourceRange.baseArrayLayer = 0;
15526 img_barrier.subresourceRange.baseMipLevel = 0;
15527 img_barrier.subresourceRange.layerCount = 1;
15528 img_barrier.subresourceRange.levelCount = 1;
15529 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15530 0, nullptr, 1, &img_barrier);
15531 err = vkEndCommandBuffer(secondary_command_buffer);
15532 ASSERT_VK_SUCCESS(err);
15533
15534 // Now update primary cmd buffer to execute secondary and transitions image
15535 command_buffer_begin_info.pInheritanceInfo = nullptr;
15536 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15537 ASSERT_VK_SUCCESS(err);
15538 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15539 VkImageMemoryBarrier img_barrier2 = {};
15540 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15541 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15542 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15543 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15544 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15545 img_barrier2.image = image.handle();
15546 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15547 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15548 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15549 img_barrier2.subresourceRange.baseArrayLayer = 0;
15550 img_barrier2.subresourceRange.baseMipLevel = 0;
15551 img_barrier2.subresourceRange.layerCount = 1;
15552 img_barrier2.subresourceRange.levelCount = 1;
15553 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15554 nullptr, 1, &img_barrier2);
15555 err = vkEndCommandBuffer(primary_command_buffer);
15556 ASSERT_VK_SUCCESS(err);
15557 VkSubmitInfo submit_info = {};
15558 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15559 submit_info.commandBufferCount = 1;
15560 submit_info.pCommandBuffers = &primary_command_buffer;
15561 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15562 ASSERT_VK_SUCCESS(err);
15563 m_errorMonitor->VerifyNotFound();
15564 err = vkDeviceWaitIdle(m_device->device());
15565 ASSERT_VK_SUCCESS(err);
15566 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15567 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15568}
15569
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015570// This is a positive test. No failures are expected.
15571TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15572 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15573 "is ignoring VkWriteDescriptorSet members that are not "
15574 "related to the descriptor type specified by "
15575 "VkWriteDescriptorSet::descriptorType. Correct "
15576 "validation behavior will result in the test running to "
15577 "completion without validation errors.");
15578
15579 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15580
15581 ASSERT_NO_FATAL_FAILURE(InitState());
15582
15583 // Image Case
15584 {
15585 m_errorMonitor->ExpectSuccess();
15586
15587 VkImage image;
15588 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15589 const int32_t tex_width = 32;
15590 const int32_t tex_height = 32;
15591 VkImageCreateInfo image_create_info = {};
15592 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15593 image_create_info.pNext = NULL;
15594 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15595 image_create_info.format = tex_format;
15596 image_create_info.extent.width = tex_width;
15597 image_create_info.extent.height = tex_height;
15598 image_create_info.extent.depth = 1;
15599 image_create_info.mipLevels = 1;
15600 image_create_info.arrayLayers = 1;
15601 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15602 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15603 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15604 image_create_info.flags = 0;
15605 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15606 ASSERT_VK_SUCCESS(err);
15607
15608 VkMemoryRequirements memory_reqs;
15609 VkDeviceMemory image_memory;
15610 bool pass;
15611 VkMemoryAllocateInfo memory_info = {};
15612 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15613 memory_info.pNext = NULL;
15614 memory_info.allocationSize = 0;
15615 memory_info.memoryTypeIndex = 0;
15616 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15617 memory_info.allocationSize = memory_reqs.size;
15618 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15619 ASSERT_TRUE(pass);
15620 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15621 ASSERT_VK_SUCCESS(err);
15622 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15623 ASSERT_VK_SUCCESS(err);
15624
15625 VkImageViewCreateInfo image_view_create_info = {};
15626 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15627 image_view_create_info.image = image;
15628 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15629 image_view_create_info.format = tex_format;
15630 image_view_create_info.subresourceRange.layerCount = 1;
15631 image_view_create_info.subresourceRange.baseMipLevel = 0;
15632 image_view_create_info.subresourceRange.levelCount = 1;
15633 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15634
15635 VkImageView view;
15636 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15637 ASSERT_VK_SUCCESS(err);
15638
15639 VkDescriptorPoolSize ds_type_count = {};
15640 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15641 ds_type_count.descriptorCount = 1;
15642
15643 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15644 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15645 ds_pool_ci.pNext = NULL;
15646 ds_pool_ci.maxSets = 1;
15647 ds_pool_ci.poolSizeCount = 1;
15648 ds_pool_ci.pPoolSizes = &ds_type_count;
15649
15650 VkDescriptorPool ds_pool;
15651 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15652 ASSERT_VK_SUCCESS(err);
15653
15654 VkDescriptorSetLayoutBinding dsl_binding = {};
15655 dsl_binding.binding = 0;
15656 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15657 dsl_binding.descriptorCount = 1;
15658 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15659 dsl_binding.pImmutableSamplers = NULL;
15660
15661 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15662 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15663 ds_layout_ci.pNext = NULL;
15664 ds_layout_ci.bindingCount = 1;
15665 ds_layout_ci.pBindings = &dsl_binding;
15666 VkDescriptorSetLayout ds_layout;
15667 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15668 ASSERT_VK_SUCCESS(err);
15669
15670 VkDescriptorSet descriptor_set;
15671 VkDescriptorSetAllocateInfo alloc_info = {};
15672 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15673 alloc_info.descriptorSetCount = 1;
15674 alloc_info.descriptorPool = ds_pool;
15675 alloc_info.pSetLayouts = &ds_layout;
15676 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15677 ASSERT_VK_SUCCESS(err);
15678
15679 VkDescriptorImageInfo image_info = {};
15680 image_info.imageView = view;
15681 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15682
15683 VkWriteDescriptorSet descriptor_write;
15684 memset(&descriptor_write, 0, sizeof(descriptor_write));
15685 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15686 descriptor_write.dstSet = descriptor_set;
15687 descriptor_write.dstBinding = 0;
15688 descriptor_write.descriptorCount = 1;
15689 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15690 descriptor_write.pImageInfo = &image_info;
15691
15692 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15693 // be
15694 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15695 // This will most likely produce a crash if the parameter_validation
15696 // layer
15697 // does not correctly ignore pBufferInfo.
15698 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15699 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15700
15701 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15702
15703 m_errorMonitor->VerifyNotFound();
15704
15705 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15706 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15707 vkDestroyImageView(m_device->device(), view, NULL);
15708 vkDestroyImage(m_device->device(), image, NULL);
15709 vkFreeMemory(m_device->device(), image_memory, NULL);
15710 }
15711
15712 // Buffer Case
15713 {
15714 m_errorMonitor->ExpectSuccess();
15715
15716 VkBuffer buffer;
15717 uint32_t queue_family_index = 0;
15718 VkBufferCreateInfo buffer_create_info = {};
15719 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15720 buffer_create_info.size = 1024;
15721 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15722 buffer_create_info.queueFamilyIndexCount = 1;
15723 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15724
15725 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15726 ASSERT_VK_SUCCESS(err);
15727
15728 VkMemoryRequirements memory_reqs;
15729 VkDeviceMemory buffer_memory;
15730 bool pass;
15731 VkMemoryAllocateInfo memory_info = {};
15732 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15733 memory_info.pNext = NULL;
15734 memory_info.allocationSize = 0;
15735 memory_info.memoryTypeIndex = 0;
15736
15737 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15738 memory_info.allocationSize = memory_reqs.size;
15739 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15740 ASSERT_TRUE(pass);
15741
15742 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15743 ASSERT_VK_SUCCESS(err);
15744 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15745 ASSERT_VK_SUCCESS(err);
15746
15747 VkDescriptorPoolSize ds_type_count = {};
15748 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15749 ds_type_count.descriptorCount = 1;
15750
15751 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15752 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15753 ds_pool_ci.pNext = NULL;
15754 ds_pool_ci.maxSets = 1;
15755 ds_pool_ci.poolSizeCount = 1;
15756 ds_pool_ci.pPoolSizes = &ds_type_count;
15757
15758 VkDescriptorPool ds_pool;
15759 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15760 ASSERT_VK_SUCCESS(err);
15761
15762 VkDescriptorSetLayoutBinding dsl_binding = {};
15763 dsl_binding.binding = 0;
15764 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15765 dsl_binding.descriptorCount = 1;
15766 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15767 dsl_binding.pImmutableSamplers = NULL;
15768
15769 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15770 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15771 ds_layout_ci.pNext = NULL;
15772 ds_layout_ci.bindingCount = 1;
15773 ds_layout_ci.pBindings = &dsl_binding;
15774 VkDescriptorSetLayout ds_layout;
15775 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15776 ASSERT_VK_SUCCESS(err);
15777
15778 VkDescriptorSet descriptor_set;
15779 VkDescriptorSetAllocateInfo alloc_info = {};
15780 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15781 alloc_info.descriptorSetCount = 1;
15782 alloc_info.descriptorPool = ds_pool;
15783 alloc_info.pSetLayouts = &ds_layout;
15784 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15785 ASSERT_VK_SUCCESS(err);
15786
15787 VkDescriptorBufferInfo buffer_info = {};
15788 buffer_info.buffer = buffer;
15789 buffer_info.offset = 0;
15790 buffer_info.range = 1024;
15791
15792 VkWriteDescriptorSet descriptor_write;
15793 memset(&descriptor_write, 0, sizeof(descriptor_write));
15794 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15795 descriptor_write.dstSet = descriptor_set;
15796 descriptor_write.dstBinding = 0;
15797 descriptor_write.descriptorCount = 1;
15798 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15799 descriptor_write.pBufferInfo = &buffer_info;
15800
15801 // Set pImageInfo and pTexelBufferView to invalid values, which should
15802 // be
15803 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15804 // This will most likely produce a crash if the parameter_validation
15805 // layer
15806 // does not correctly ignore pImageInfo.
15807 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15808 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15809
15810 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15811
15812 m_errorMonitor->VerifyNotFound();
15813
15814 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15815 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15816 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15817 vkDestroyBuffer(m_device->device(), buffer, NULL);
15818 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15819 }
15820
15821 // Texel Buffer Case
15822 {
15823 m_errorMonitor->ExpectSuccess();
15824
15825 VkBuffer buffer;
15826 uint32_t queue_family_index = 0;
15827 VkBufferCreateInfo buffer_create_info = {};
15828 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15829 buffer_create_info.size = 1024;
15830 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15831 buffer_create_info.queueFamilyIndexCount = 1;
15832 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15833
15834 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15835 ASSERT_VK_SUCCESS(err);
15836
15837 VkMemoryRequirements memory_reqs;
15838 VkDeviceMemory buffer_memory;
15839 bool pass;
15840 VkMemoryAllocateInfo memory_info = {};
15841 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15842 memory_info.pNext = NULL;
15843 memory_info.allocationSize = 0;
15844 memory_info.memoryTypeIndex = 0;
15845
15846 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15847 memory_info.allocationSize = memory_reqs.size;
15848 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15849 ASSERT_TRUE(pass);
15850
15851 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15852 ASSERT_VK_SUCCESS(err);
15853 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15854 ASSERT_VK_SUCCESS(err);
15855
15856 VkBufferViewCreateInfo buff_view_ci = {};
15857 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15858 buff_view_ci.buffer = buffer;
15859 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15860 buff_view_ci.range = VK_WHOLE_SIZE;
15861 VkBufferView buffer_view;
15862 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15863
15864 VkDescriptorPoolSize ds_type_count = {};
15865 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15866 ds_type_count.descriptorCount = 1;
15867
15868 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15869 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15870 ds_pool_ci.pNext = NULL;
15871 ds_pool_ci.maxSets = 1;
15872 ds_pool_ci.poolSizeCount = 1;
15873 ds_pool_ci.pPoolSizes = &ds_type_count;
15874
15875 VkDescriptorPool ds_pool;
15876 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15877 ASSERT_VK_SUCCESS(err);
15878
15879 VkDescriptorSetLayoutBinding dsl_binding = {};
15880 dsl_binding.binding = 0;
15881 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15882 dsl_binding.descriptorCount = 1;
15883 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15884 dsl_binding.pImmutableSamplers = NULL;
15885
15886 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15887 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15888 ds_layout_ci.pNext = NULL;
15889 ds_layout_ci.bindingCount = 1;
15890 ds_layout_ci.pBindings = &dsl_binding;
15891 VkDescriptorSetLayout ds_layout;
15892 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15893 ASSERT_VK_SUCCESS(err);
15894
15895 VkDescriptorSet descriptor_set;
15896 VkDescriptorSetAllocateInfo alloc_info = {};
15897 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15898 alloc_info.descriptorSetCount = 1;
15899 alloc_info.descriptorPool = ds_pool;
15900 alloc_info.pSetLayouts = &ds_layout;
15901 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15902 ASSERT_VK_SUCCESS(err);
15903
15904 VkWriteDescriptorSet descriptor_write;
15905 memset(&descriptor_write, 0, sizeof(descriptor_write));
15906 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15907 descriptor_write.dstSet = descriptor_set;
15908 descriptor_write.dstBinding = 0;
15909 descriptor_write.descriptorCount = 1;
15910 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15911 descriptor_write.pTexelBufferView = &buffer_view;
15912
15913 // Set pImageInfo and pBufferInfo to invalid values, which should be
15914 // ignored for descriptorType ==
15915 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15916 // This will most likely produce a crash if the parameter_validation
15917 // layer
15918 // does not correctly ignore pImageInfo and pBufferInfo.
15919 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15920 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15921
15922 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15923
15924 m_errorMonitor->VerifyNotFound();
15925
15926 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15927 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15928 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15929 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15930 vkDestroyBuffer(m_device->device(), buffer, NULL);
15931 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15932 }
15933}
15934
Tobin Ehlisf7428442016-10-25 07:58:24 -060015935TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
15936 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
15937
15938 ASSERT_NO_FATAL_FAILURE(InitState());
15939 // Create layout where two binding #s are "1"
15940 static const uint32_t NUM_BINDINGS = 3;
15941 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15942 dsl_binding[0].binding = 1;
15943 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15944 dsl_binding[0].descriptorCount = 1;
15945 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15946 dsl_binding[0].pImmutableSamplers = NULL;
15947 dsl_binding[1].binding = 0;
15948 dsl_binding[1].descriptorCount = 1;
15949 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15950 dsl_binding[1].descriptorCount = 1;
15951 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15952 dsl_binding[1].pImmutableSamplers = NULL;
15953 dsl_binding[2].binding = 1; // Duplicate binding should cause error
15954 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15955 dsl_binding[2].descriptorCount = 1;
15956 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15957 dsl_binding[2].pImmutableSamplers = NULL;
15958
15959 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15960 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15961 ds_layout_ci.pNext = NULL;
15962 ds_layout_ci.bindingCount = NUM_BINDINGS;
15963 ds_layout_ci.pBindings = dsl_binding;
15964 VkDescriptorSetLayout ds_layout;
15965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
15966 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15967 m_errorMonitor->VerifyFound();
15968}
15969
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015970TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015971 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
15972
15973 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015974
15975 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015976
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015977 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
15978
15979 {
15980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
15981 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
15982 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15983 m_errorMonitor->VerifyFound();
15984 }
15985
15986 {
15987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
15988 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
15989 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15990 m_errorMonitor->VerifyFound();
15991 }
15992
15993 {
15994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15995 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
15996 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15997 m_errorMonitor->VerifyFound();
15998 }
15999
16000 {
16001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16002 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16003 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16004 m_errorMonitor->VerifyFound();
16005 }
16006
16007 {
16008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16009 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16010 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16011 m_errorMonitor->VerifyFound();
16012 }
16013
16014 {
16015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16016 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16017 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16018 m_errorMonitor->VerifyFound();
16019 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016020
16021 {
16022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16023 VkRect2D scissor = {{-1, 0}, {16, 16}};
16024 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16025 m_errorMonitor->VerifyFound();
16026 }
16027
16028 {
16029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16030 VkRect2D scissor = {{0, -2}, {16, 16}};
16031 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16032 m_errorMonitor->VerifyFound();
16033 }
16034
16035 {
16036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16037 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16038 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16039 m_errorMonitor->VerifyFound();
16040 }
16041
16042 {
16043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16044 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16045 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16046 m_errorMonitor->VerifyFound();
16047 }
16048
16049 EndCommandBuffer();
16050}
16051
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016052// This is a positive test. No failures are expected.
16053TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16054 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16055 VkResult err;
16056
16057 ASSERT_NO_FATAL_FAILURE(InitState());
16058 m_errorMonitor->ExpectSuccess();
16059 VkDescriptorPoolSize ds_type_count = {};
16060 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16061 ds_type_count.descriptorCount = 2;
16062
16063 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16064 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16065 ds_pool_ci.pNext = NULL;
16066 ds_pool_ci.maxSets = 1;
16067 ds_pool_ci.poolSizeCount = 1;
16068 ds_pool_ci.pPoolSizes = &ds_type_count;
16069
16070 VkDescriptorPool ds_pool;
16071 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16072 ASSERT_VK_SUCCESS(err);
16073
16074 // Create layout with two uniform buffer descriptors w/ empty binding between them
16075 static const uint32_t NUM_BINDINGS = 3;
16076 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16077 dsl_binding[0].binding = 0;
16078 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16079 dsl_binding[0].descriptorCount = 1;
16080 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16081 dsl_binding[0].pImmutableSamplers = NULL;
16082 dsl_binding[1].binding = 1;
16083 dsl_binding[1].descriptorCount = 0; // empty binding
16084 dsl_binding[2].binding = 2;
16085 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16086 dsl_binding[2].descriptorCount = 1;
16087 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16088 dsl_binding[2].pImmutableSamplers = NULL;
16089
16090 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16091 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16092 ds_layout_ci.pNext = NULL;
16093 ds_layout_ci.bindingCount = NUM_BINDINGS;
16094 ds_layout_ci.pBindings = dsl_binding;
16095 VkDescriptorSetLayout ds_layout;
16096 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16097 ASSERT_VK_SUCCESS(err);
16098
16099 VkDescriptorSet descriptor_set = {};
16100 VkDescriptorSetAllocateInfo alloc_info = {};
16101 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16102 alloc_info.descriptorSetCount = 1;
16103 alloc_info.descriptorPool = ds_pool;
16104 alloc_info.pSetLayouts = &ds_layout;
16105 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16106 ASSERT_VK_SUCCESS(err);
16107
16108 // Create a buffer to be used for update
16109 VkBufferCreateInfo buff_ci = {};
16110 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16111 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16112 buff_ci.size = 256;
16113 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16114 VkBuffer buffer;
16115 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16116 ASSERT_VK_SUCCESS(err);
16117 // Have to bind memory to buffer before descriptor update
16118 VkMemoryAllocateInfo mem_alloc = {};
16119 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16120 mem_alloc.pNext = NULL;
16121 mem_alloc.allocationSize = 512; // one allocation for both buffers
16122 mem_alloc.memoryTypeIndex = 0;
16123
16124 VkMemoryRequirements mem_reqs;
16125 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16126 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16127 if (!pass) {
16128 vkDestroyBuffer(m_device->device(), buffer, NULL);
16129 return;
16130 }
16131
16132 VkDeviceMemory mem;
16133 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16134 ASSERT_VK_SUCCESS(err);
16135 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16136 ASSERT_VK_SUCCESS(err);
16137
16138 // Only update the descriptor at binding 2
16139 VkDescriptorBufferInfo buff_info = {};
16140 buff_info.buffer = buffer;
16141 buff_info.offset = 0;
16142 buff_info.range = VK_WHOLE_SIZE;
16143 VkWriteDescriptorSet descriptor_write = {};
16144 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16145 descriptor_write.dstBinding = 2;
16146 descriptor_write.descriptorCount = 1;
16147 descriptor_write.pTexelBufferView = nullptr;
16148 descriptor_write.pBufferInfo = &buff_info;
16149 descriptor_write.pImageInfo = nullptr;
16150 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16151 descriptor_write.dstSet = descriptor_set;
16152
16153 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16154
16155 m_errorMonitor->VerifyNotFound();
16156 // Cleanup
16157 vkFreeMemory(m_device->device(), mem, NULL);
16158 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16159 vkDestroyBuffer(m_device->device(), buffer, NULL);
16160 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16161}
16162
16163// This is a positive test. No failures are expected.
16164TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16165 VkResult err;
16166 bool pass;
16167
16168 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16169 "the buffer, create an image, and bind the same memory to "
16170 "it");
16171
16172 m_errorMonitor->ExpectSuccess();
16173
16174 ASSERT_NO_FATAL_FAILURE(InitState());
16175
16176 VkBuffer buffer;
16177 VkImage image;
16178 VkDeviceMemory mem;
16179 VkMemoryRequirements mem_reqs;
16180
16181 VkBufferCreateInfo buf_info = {};
16182 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16183 buf_info.pNext = NULL;
16184 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16185 buf_info.size = 256;
16186 buf_info.queueFamilyIndexCount = 0;
16187 buf_info.pQueueFamilyIndices = NULL;
16188 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16189 buf_info.flags = 0;
16190 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16191 ASSERT_VK_SUCCESS(err);
16192
16193 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16194
16195 VkMemoryAllocateInfo alloc_info = {};
16196 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16197 alloc_info.pNext = NULL;
16198 alloc_info.memoryTypeIndex = 0;
16199
16200 // Ensure memory is big enough for both bindings
16201 alloc_info.allocationSize = 0x10000;
16202
16203 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16204 if (!pass) {
16205 vkDestroyBuffer(m_device->device(), buffer, NULL);
16206 return;
16207 }
16208
16209 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16210 ASSERT_VK_SUCCESS(err);
16211
16212 uint8_t *pData;
16213 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16214 ASSERT_VK_SUCCESS(err);
16215
16216 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16217
16218 vkUnmapMemory(m_device->device(), mem);
16219
16220 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16221 ASSERT_VK_SUCCESS(err);
16222
16223 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16224 // memory. In fact, it was never used by the GPU.
16225 // Just be be sure, wait for idle.
16226 vkDestroyBuffer(m_device->device(), buffer, NULL);
16227 vkDeviceWaitIdle(m_device->device());
16228
16229 VkImageCreateInfo image_create_info = {};
16230 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16231 image_create_info.pNext = NULL;
16232 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16233 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16234 image_create_info.extent.width = 64;
16235 image_create_info.extent.height = 64;
16236 image_create_info.extent.depth = 1;
16237 image_create_info.mipLevels = 1;
16238 image_create_info.arrayLayers = 1;
16239 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16240 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16241 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16242 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16243 image_create_info.queueFamilyIndexCount = 0;
16244 image_create_info.pQueueFamilyIndices = NULL;
16245 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16246 image_create_info.flags = 0;
16247
16248 VkMemoryAllocateInfo mem_alloc = {};
16249 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16250 mem_alloc.pNext = NULL;
16251 mem_alloc.allocationSize = 0;
16252 mem_alloc.memoryTypeIndex = 0;
16253
16254 /* Create a mappable image. It will be the texture if linear images are ok
16255 * to be textures or it will be the staging image if they are not.
16256 */
16257 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16258 ASSERT_VK_SUCCESS(err);
16259
16260 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16261
16262 mem_alloc.allocationSize = mem_reqs.size;
16263
16264 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16265 if (!pass) {
16266 vkDestroyImage(m_device->device(), image, NULL);
16267 return;
16268 }
16269
16270 // VALIDATION FAILURE:
16271 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16272 ASSERT_VK_SUCCESS(err);
16273
16274 m_errorMonitor->VerifyNotFound();
16275
16276 vkFreeMemory(m_device->device(), mem, NULL);
16277 vkDestroyBuffer(m_device->device(), buffer, NULL);
16278 vkDestroyImage(m_device->device(), image, NULL);
16279}
16280
Tobin Ehlis953e8392016-11-17 10:54:13 -070016281TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16282 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16283 // We previously had a bug where dynamic offset of inactive bindings was still being used
16284 VkResult err;
16285 m_errorMonitor->ExpectSuccess();
16286
16287 ASSERT_NO_FATAL_FAILURE(InitState());
16288 ASSERT_NO_FATAL_FAILURE(InitViewport());
16289 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16290
16291 VkDescriptorPoolSize ds_type_count = {};
16292 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16293 ds_type_count.descriptorCount = 3;
16294
16295 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16296 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16297 ds_pool_ci.pNext = NULL;
16298 ds_pool_ci.maxSets = 1;
16299 ds_pool_ci.poolSizeCount = 1;
16300 ds_pool_ci.pPoolSizes = &ds_type_count;
16301
16302 VkDescriptorPool ds_pool;
16303 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16304 ASSERT_VK_SUCCESS(err);
16305
16306 const uint32_t BINDING_COUNT = 3;
16307 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
16308 dsl_binding[0].binding = 0;
16309 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16310 dsl_binding[0].descriptorCount = 1;
16311 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16312 dsl_binding[0].pImmutableSamplers = NULL;
16313 dsl_binding[1].binding = 1;
16314 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16315 dsl_binding[1].descriptorCount = 1;
16316 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16317 dsl_binding[1].pImmutableSamplers = NULL;
16318 dsl_binding[2].binding = 2;
16319 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16320 dsl_binding[2].descriptorCount = 1;
16321 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16322 dsl_binding[2].pImmutableSamplers = NULL;
16323
16324 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16325 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16326 ds_layout_ci.pNext = NULL;
16327 ds_layout_ci.bindingCount = BINDING_COUNT;
16328 ds_layout_ci.pBindings = dsl_binding;
16329 VkDescriptorSetLayout ds_layout;
16330 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16331 ASSERT_VK_SUCCESS(err);
16332
16333 VkDescriptorSet descriptor_set;
16334 VkDescriptorSetAllocateInfo alloc_info = {};
16335 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16336 alloc_info.descriptorSetCount = 1;
16337 alloc_info.descriptorPool = ds_pool;
16338 alloc_info.pSetLayouts = &ds_layout;
16339 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16340 ASSERT_VK_SUCCESS(err);
16341
16342 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16343 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16344 pipeline_layout_ci.pNext = NULL;
16345 pipeline_layout_ci.setLayoutCount = 1;
16346 pipeline_layout_ci.pSetLayouts = &ds_layout;
16347
16348 VkPipelineLayout pipeline_layout;
16349 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16350 ASSERT_VK_SUCCESS(err);
16351
16352 // Create two buffers to update the descriptors with
16353 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16354 uint32_t qfi = 0;
16355 VkBufferCreateInfo buffCI = {};
16356 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16357 buffCI.size = 2048;
16358 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16359 buffCI.queueFamilyIndexCount = 1;
16360 buffCI.pQueueFamilyIndices = &qfi;
16361
16362 VkBuffer dyub1;
16363 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16364 ASSERT_VK_SUCCESS(err);
16365 // buffer2
16366 buffCI.size = 1024;
16367 VkBuffer dyub2;
16368 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16369 ASSERT_VK_SUCCESS(err);
16370 // Allocate memory and bind to buffers
16371 VkMemoryAllocateInfo mem_alloc[2] = {};
16372 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16373 mem_alloc[0].pNext = NULL;
16374 mem_alloc[0].memoryTypeIndex = 0;
16375 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16376 mem_alloc[1].pNext = NULL;
16377 mem_alloc[1].memoryTypeIndex = 0;
16378
16379 VkMemoryRequirements mem_reqs1;
16380 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16381 VkMemoryRequirements mem_reqs2;
16382 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16383 mem_alloc[0].allocationSize = mem_reqs1.size;
16384 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16385 mem_alloc[1].allocationSize = mem_reqs2.size;
16386 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16387 if (!pass) {
16388 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16389 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16390 return;
16391 }
16392
16393 VkDeviceMemory mem1;
16394 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16395 ASSERT_VK_SUCCESS(err);
16396 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16397 ASSERT_VK_SUCCESS(err);
16398 VkDeviceMemory mem2;
16399 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16400 ASSERT_VK_SUCCESS(err);
16401 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16402 ASSERT_VK_SUCCESS(err);
16403 // Update descriptors
16404 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16405 buff_info[0].buffer = dyub1;
16406 buff_info[0].offset = 0;
16407 buff_info[0].range = 256;
16408 buff_info[1].buffer = dyub1;
16409 buff_info[1].offset = 256;
16410 buff_info[1].range = 512;
16411 buff_info[2].buffer = dyub2;
16412 buff_info[2].offset = 0;
16413 buff_info[2].range = 512;
16414
16415 VkWriteDescriptorSet descriptor_write;
16416 memset(&descriptor_write, 0, sizeof(descriptor_write));
16417 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16418 descriptor_write.dstSet = descriptor_set;
16419 descriptor_write.dstBinding = 0;
16420 descriptor_write.descriptorCount = BINDING_COUNT;
16421 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16422 descriptor_write.pBufferInfo = buff_info;
16423
16424 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16425
16426 BeginCommandBuffer();
16427
16428 // Create PSO to be used for draw-time errors below
16429 char const *vsSource = "#version 450\n"
16430 "\n"
16431 "out gl_PerVertex { \n"
16432 " vec4 gl_Position;\n"
16433 "};\n"
16434 "void main(){\n"
16435 " gl_Position = vec4(1);\n"
16436 "}\n";
16437 char const *fsSource = "#version 450\n"
16438 "\n"
16439 "layout(location=0) out vec4 x;\n"
16440 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16441 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16442 "void main(){\n"
16443 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16444 "}\n";
16445 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16446 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16447 VkPipelineObj pipe(m_device);
16448 pipe.SetViewport(m_viewports);
16449 pipe.SetScissor(m_scissors);
16450 pipe.AddShader(&vs);
16451 pipe.AddShader(&fs);
16452 pipe.AddColorAttachment();
16453 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16454
16455 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16456 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16457 // we used to have a bug in this case.
16458 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16459 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16460 &descriptor_set, BINDING_COUNT, dyn_off);
16461 Draw(1, 0, 0, 0);
16462 m_errorMonitor->VerifyNotFound();
16463
16464 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16465 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16466 vkFreeMemory(m_device->device(), mem1, NULL);
16467 vkFreeMemory(m_device->device(), mem2, NULL);
16468
16469 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16470 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16471 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16472}
16473
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016474TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16475
16476 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16477 "mapping while using VK_WHOLE_SIZE does not cause access "
16478 "violations");
16479 VkResult err;
16480 uint8_t *pData;
16481 ASSERT_NO_FATAL_FAILURE(InitState());
16482
16483 VkDeviceMemory mem;
16484 VkMemoryRequirements mem_reqs;
16485 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16486 VkMemoryAllocateInfo alloc_info = {};
16487 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16488 alloc_info.pNext = NULL;
16489 alloc_info.memoryTypeIndex = 0;
16490
16491 static const VkDeviceSize allocation_size = 0x1000;
16492 alloc_info.allocationSize = allocation_size;
16493
16494 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16495 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16496 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16497 if (!pass) {
16498 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16499 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16500 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16501 if (!pass) {
16502 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16503 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16504 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16505 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16506 if (!pass) {
16507 return;
16508 }
16509 }
16510 }
16511
16512 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16513 ASSERT_VK_SUCCESS(err);
16514
16515 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16516 // mapped range
16517 m_errorMonitor->ExpectSuccess();
16518 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16519 ASSERT_VK_SUCCESS(err);
16520 VkMappedMemoryRange mmr = {};
16521 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16522 mmr.memory = mem;
16523 mmr.offset = 0;
16524 mmr.size = VK_WHOLE_SIZE;
16525 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16526 ASSERT_VK_SUCCESS(err);
16527 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16528 ASSERT_VK_SUCCESS(err);
16529 m_errorMonitor->VerifyNotFound();
16530 vkUnmapMemory(m_device->device(), mem);
16531
16532 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16533 // mapped range
16534 m_errorMonitor->ExpectSuccess();
16535 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16536 ASSERT_VK_SUCCESS(err);
16537 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16538 mmr.memory = mem;
16539 mmr.offset = 13;
16540 mmr.size = VK_WHOLE_SIZE;
16541 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16542 ASSERT_VK_SUCCESS(err);
16543 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16544 ASSERT_VK_SUCCESS(err);
16545 m_errorMonitor->VerifyNotFound();
16546 vkUnmapMemory(m_device->device(), mem);
16547
16548 // Map with prime offset and size
16549 // Flush/Invalidate subrange of mapped area with prime offset and size
16550 m_errorMonitor->ExpectSuccess();
16551 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16552 ASSERT_VK_SUCCESS(err);
16553 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16554 mmr.memory = mem;
16555 mmr.offset = allocation_size - 107;
16556 mmr.size = 61;
16557 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16558 ASSERT_VK_SUCCESS(err);
16559 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16560 ASSERT_VK_SUCCESS(err);
16561 m_errorMonitor->VerifyNotFound();
16562 vkUnmapMemory(m_device->device(), mem);
16563
16564 // Map without offset and flush WHOLE_SIZE with two separate offsets
16565 m_errorMonitor->ExpectSuccess();
16566 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16567 ASSERT_VK_SUCCESS(err);
16568 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16569 mmr.memory = mem;
16570 mmr.offset = allocation_size - 100;
16571 mmr.size = VK_WHOLE_SIZE;
16572 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16573 ASSERT_VK_SUCCESS(err);
16574 mmr.offset = allocation_size - 200;
16575 mmr.size = VK_WHOLE_SIZE;
16576 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16577 ASSERT_VK_SUCCESS(err);
16578 m_errorMonitor->VerifyNotFound();
16579 vkUnmapMemory(m_device->device(), mem);
16580
16581 vkFreeMemory(m_device->device(), mem, NULL);
16582}
16583
16584// This is a positive test. We used to expect error in this case but spec now allows it
16585TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16586 m_errorMonitor->ExpectSuccess();
16587 vk_testing::Fence testFence;
16588 VkFenceCreateInfo fenceInfo = {};
16589 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16590 fenceInfo.pNext = NULL;
16591
16592 ASSERT_NO_FATAL_FAILURE(InitState());
16593 testFence.init(*m_device, fenceInfo);
16594 VkFence fences[1] = { testFence.handle() };
16595 VkResult result = vkResetFences(m_device->device(), 1, fences);
16596 ASSERT_VK_SUCCESS(result);
16597
16598 m_errorMonitor->VerifyNotFound();
16599}
16600
16601TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16602 m_errorMonitor->ExpectSuccess();
16603
16604 ASSERT_NO_FATAL_FAILURE(InitState());
16605 VkResult err;
16606
16607 // Record (empty!) command buffer that can be submitted multiple times
16608 // simultaneously.
16609 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16610 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16611 m_commandBuffer->BeginCommandBuffer(&cbbi);
16612 m_commandBuffer->EndCommandBuffer();
16613
16614 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16615 VkFence fence;
16616 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16617 ASSERT_VK_SUCCESS(err);
16618
16619 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16620 VkSemaphore s1, s2;
16621 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16622 ASSERT_VK_SUCCESS(err);
16623 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16624 ASSERT_VK_SUCCESS(err);
16625
16626 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16627 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16628 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16629 ASSERT_VK_SUCCESS(err);
16630
16631 // Submit CB again, signaling s2.
16632 si.pSignalSemaphores = &s2;
16633 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16634 ASSERT_VK_SUCCESS(err);
16635
16636 // Wait for fence.
16637 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16638 ASSERT_VK_SUCCESS(err);
16639
16640 // CB is still in flight from second submission, but semaphore s1 is no
16641 // longer in flight. delete it.
16642 vkDestroySemaphore(m_device->device(), s1, nullptr);
16643
16644 m_errorMonitor->VerifyNotFound();
16645
16646 // Force device idle and clean up remaining objects
16647 vkDeviceWaitIdle(m_device->device());
16648 vkDestroySemaphore(m_device->device(), s2, nullptr);
16649 vkDestroyFence(m_device->device(), fence, nullptr);
16650}
16651
16652TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16653 m_errorMonitor->ExpectSuccess();
16654
16655 ASSERT_NO_FATAL_FAILURE(InitState());
16656 VkResult err;
16657
16658 // A fence created signaled
16659 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16660 VkFence f1;
16661 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16662 ASSERT_VK_SUCCESS(err);
16663
16664 // A fence created not
16665 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16666 VkFence f2;
16667 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16668 ASSERT_VK_SUCCESS(err);
16669
16670 // Submit the unsignaled fence
16671 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16672 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16673
16674 // Wait on both fences, with signaled first.
16675 VkFence fences[] = { f1, f2 };
16676 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16677
16678 // Should have both retired!
16679 vkDestroyFence(m_device->device(), f1, nullptr);
16680 vkDestroyFence(m_device->device(), f2, nullptr);
16681
16682 m_errorMonitor->VerifyNotFound();
16683}
16684
16685TEST_F(VkPositiveLayerTest, ValidUsage) {
16686 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16687 "doesn't generate validation errors");
16688
16689 ASSERT_NO_FATAL_FAILURE(InitState());
16690
16691 m_errorMonitor->ExpectSuccess();
16692 // Verify that we can create a view with usage INPUT_ATTACHMENT
16693 VkImageObj image(m_device);
16694 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16695 ASSERT_TRUE(image.initialized());
16696 VkImageView imageView;
16697 VkImageViewCreateInfo ivci = {};
16698 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16699 ivci.image = image.handle();
16700 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16701 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16702 ivci.subresourceRange.layerCount = 1;
16703 ivci.subresourceRange.baseMipLevel = 0;
16704 ivci.subresourceRange.levelCount = 1;
16705 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16706
16707 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16708 m_errorMonitor->VerifyNotFound();
16709 vkDestroyImageView(m_device->device(), imageView, NULL);
16710}
16711
16712// This is a positive test. No failures are expected.
16713TEST_F(VkPositiveLayerTest, BindSparse) {
16714 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16715 "and then free the memory");
16716
16717 ASSERT_NO_FATAL_FAILURE(InitState());
16718
16719 auto index = m_device->graphics_queue_node_index_;
16720 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16721 return;
16722
16723 m_errorMonitor->ExpectSuccess();
16724
16725 VkImage image;
16726 VkImageCreateInfo image_create_info = {};
16727 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16728 image_create_info.pNext = NULL;
16729 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16730 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16731 image_create_info.extent.width = 64;
16732 image_create_info.extent.height = 64;
16733 image_create_info.extent.depth = 1;
16734 image_create_info.mipLevels = 1;
16735 image_create_info.arrayLayers = 1;
16736 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16737 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16738 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16739 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16740 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16741 ASSERT_VK_SUCCESS(err);
16742
16743 VkMemoryRequirements memory_reqs;
16744 VkDeviceMemory memory_one, memory_two;
16745 bool pass;
16746 VkMemoryAllocateInfo memory_info = {};
16747 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16748 memory_info.pNext = NULL;
16749 memory_info.allocationSize = 0;
16750 memory_info.memoryTypeIndex = 0;
16751 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16752 // Find an image big enough to allow sparse mapping of 2 memory regions
16753 // Increase the image size until it is at least twice the
16754 // size of the required alignment, to ensure we can bind both
16755 // allocated memory blocks to the image on aligned offsets.
16756 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16757 vkDestroyImage(m_device->device(), image, nullptr);
16758 image_create_info.extent.width *= 2;
16759 image_create_info.extent.height *= 2;
16760 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16761 ASSERT_VK_SUCCESS(err);
16762 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16763 }
16764 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16765 // at the end of the first
16766 memory_info.allocationSize = memory_reqs.alignment;
16767 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16768 ASSERT_TRUE(pass);
16769 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16770 ASSERT_VK_SUCCESS(err);
16771 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16772 ASSERT_VK_SUCCESS(err);
16773 VkSparseMemoryBind binds[2];
16774 binds[0].flags = 0;
16775 binds[0].memory = memory_one;
16776 binds[0].memoryOffset = 0;
16777 binds[0].resourceOffset = 0;
16778 binds[0].size = memory_info.allocationSize;
16779 binds[1].flags = 0;
16780 binds[1].memory = memory_two;
16781 binds[1].memoryOffset = 0;
16782 binds[1].resourceOffset = memory_info.allocationSize;
16783 binds[1].size = memory_info.allocationSize;
16784
16785 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16786 opaqueBindInfo.image = image;
16787 opaqueBindInfo.bindCount = 2;
16788 opaqueBindInfo.pBinds = binds;
16789
16790 VkFence fence = VK_NULL_HANDLE;
16791 VkBindSparseInfo bindSparseInfo = {};
16792 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16793 bindSparseInfo.imageOpaqueBindCount = 1;
16794 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16795
16796 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16797 vkQueueWaitIdle(m_device->m_queue);
16798 vkDestroyImage(m_device->device(), image, NULL);
16799 vkFreeMemory(m_device->device(), memory_one, NULL);
16800 vkFreeMemory(m_device->device(), memory_two, NULL);
16801 m_errorMonitor->VerifyNotFound();
16802}
16803
16804TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16805 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16806 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16807 "the command buffer has prior knowledge of that "
16808 "attachment's layout.");
16809
16810 m_errorMonitor->ExpectSuccess();
16811
16812 ASSERT_NO_FATAL_FAILURE(InitState());
16813
16814 // A renderpass with one color attachment.
16815 VkAttachmentDescription attachment = { 0,
16816 VK_FORMAT_R8G8B8A8_UNORM,
16817 VK_SAMPLE_COUNT_1_BIT,
16818 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16819 VK_ATTACHMENT_STORE_OP_STORE,
16820 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16821 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16822 VK_IMAGE_LAYOUT_UNDEFINED,
16823 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16824
16825 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16826
16827 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16828
16829 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16830
16831 VkRenderPass rp;
16832 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16833 ASSERT_VK_SUCCESS(err);
16834
16835 // A compatible framebuffer.
16836 VkImageObj image(m_device);
16837 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16838 ASSERT_TRUE(image.initialized());
16839
16840 VkImageViewCreateInfo ivci = {
16841 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16842 nullptr,
16843 0,
16844 image.handle(),
16845 VK_IMAGE_VIEW_TYPE_2D,
16846 VK_FORMAT_R8G8B8A8_UNORM,
16847 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16848 VK_COMPONENT_SWIZZLE_IDENTITY },
16849 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16850 };
16851 VkImageView view;
16852 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16853 ASSERT_VK_SUCCESS(err);
16854
16855 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16856 VkFramebuffer fb;
16857 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16858 ASSERT_VK_SUCCESS(err);
16859
16860 // Record a single command buffer which uses this renderpass twice. The
16861 // bug is triggered at the beginning of the second renderpass, when the
16862 // command buffer already has a layout recorded for the attachment.
16863 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16864 BeginCommandBuffer();
16865 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16866 vkCmdEndRenderPass(m_commandBuffer->handle());
16867 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16868
16869 m_errorMonitor->VerifyNotFound();
16870
16871 vkCmdEndRenderPass(m_commandBuffer->handle());
16872 EndCommandBuffer();
16873
16874 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16875 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16876 vkDestroyImageView(m_device->device(), view, nullptr);
16877}
16878
16879TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16880 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16881 "command buffer, bind them together, then destroy "
16882 "command pool and framebuffer and verify there are no "
16883 "errors.");
16884
16885 m_errorMonitor->ExpectSuccess();
16886
16887 ASSERT_NO_FATAL_FAILURE(InitState());
16888
16889 // A renderpass with one color attachment.
16890 VkAttachmentDescription attachment = { 0,
16891 VK_FORMAT_R8G8B8A8_UNORM,
16892 VK_SAMPLE_COUNT_1_BIT,
16893 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16894 VK_ATTACHMENT_STORE_OP_STORE,
16895 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16896 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16897 VK_IMAGE_LAYOUT_UNDEFINED,
16898 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16899
16900 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16901
16902 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16903
16904 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16905
16906 VkRenderPass rp;
16907 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16908 ASSERT_VK_SUCCESS(err);
16909
16910 // A compatible framebuffer.
16911 VkImageObj image(m_device);
16912 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16913 ASSERT_TRUE(image.initialized());
16914
16915 VkImageViewCreateInfo ivci = {
16916 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16917 nullptr,
16918 0,
16919 image.handle(),
16920 VK_IMAGE_VIEW_TYPE_2D,
16921 VK_FORMAT_R8G8B8A8_UNORM,
16922 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16923 VK_COMPONENT_SWIZZLE_IDENTITY },
16924 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16925 };
16926 VkImageView view;
16927 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16928 ASSERT_VK_SUCCESS(err);
16929
16930 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16931 VkFramebuffer fb;
16932 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16933 ASSERT_VK_SUCCESS(err);
16934
16935 // Explicitly create a command buffer to bind the FB to so that we can then
16936 // destroy the command pool in order to implicitly free command buffer
16937 VkCommandPool command_pool;
16938 VkCommandPoolCreateInfo pool_create_info{};
16939 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16940 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16941 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16942 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16943
16944 VkCommandBuffer command_buffer;
16945 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16946 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16947 command_buffer_allocate_info.commandPool = command_pool;
16948 command_buffer_allocate_info.commandBufferCount = 1;
16949 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16950 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16951
16952 // Begin our cmd buffer with renderpass using our framebuffer
16953 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16954 VkCommandBufferBeginInfo begin_info{};
16955 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16956 vkBeginCommandBuffer(command_buffer, &begin_info);
16957
16958 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16959 vkCmdEndRenderPass(command_buffer);
16960 vkEndCommandBuffer(command_buffer);
16961 vkDestroyImageView(m_device->device(), view, nullptr);
16962 // Destroy command pool to implicitly free command buffer
16963 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16964 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16965 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16966 m_errorMonitor->VerifyNotFound();
16967}
16968
16969TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16970 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16971 "transitions for the first subpass");
16972
16973 m_errorMonitor->ExpectSuccess();
16974
16975 ASSERT_NO_FATAL_FAILURE(InitState());
16976
16977 // A renderpass with one color attachment.
16978 VkAttachmentDescription attachment = { 0,
16979 VK_FORMAT_R8G8B8A8_UNORM,
16980 VK_SAMPLE_COUNT_1_BIT,
16981 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16982 VK_ATTACHMENT_STORE_OP_STORE,
16983 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16984 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16985 VK_IMAGE_LAYOUT_UNDEFINED,
16986 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16987
16988 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16989
16990 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16991
16992 VkSubpassDependency dep = { 0,
16993 0,
16994 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16995 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16996 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16997 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16998 VK_DEPENDENCY_BY_REGION_BIT };
16999
17000 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17001
17002 VkResult err;
17003 VkRenderPass rp;
17004 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17005 ASSERT_VK_SUCCESS(err);
17006
17007 // A compatible framebuffer.
17008 VkImageObj image(m_device);
17009 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17010 ASSERT_TRUE(image.initialized());
17011
17012 VkImageViewCreateInfo ivci = {
17013 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17014 nullptr,
17015 0,
17016 image.handle(),
17017 VK_IMAGE_VIEW_TYPE_2D,
17018 VK_FORMAT_R8G8B8A8_UNORM,
17019 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17020 VK_COMPONENT_SWIZZLE_IDENTITY },
17021 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17022 };
17023 VkImageView view;
17024 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17025 ASSERT_VK_SUCCESS(err);
17026
17027 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17028 VkFramebuffer fb;
17029 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17030 ASSERT_VK_SUCCESS(err);
17031
17032 // Record a single command buffer which issues a pipeline barrier w/
17033 // image memory barrier for the attachment. This detects the previously
17034 // missing tracking of the subpass layout by throwing a validation error
17035 // if it doesn't occur.
17036 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17037 BeginCommandBuffer();
17038 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17039
17040 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17041 nullptr,
17042 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17043 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17044 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17045 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17046 VK_QUEUE_FAMILY_IGNORED,
17047 VK_QUEUE_FAMILY_IGNORED,
17048 image.handle(),
17049 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17050 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17051 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17052 &imb);
17053
17054 vkCmdEndRenderPass(m_commandBuffer->handle());
17055 m_errorMonitor->VerifyNotFound();
17056 EndCommandBuffer();
17057
17058 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17059 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17060 vkDestroyImageView(m_device->device(), view, nullptr);
17061}
17062
17063TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17064 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17065 "is used as a depth/stencil framebuffer attachment, the "
17066 "aspectMask is ignored and both depth and stencil image "
17067 "subresources are used.");
17068
17069 VkFormatProperties format_properties;
17070 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17071 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17072 return;
17073 }
17074
17075 m_errorMonitor->ExpectSuccess();
17076
17077 ASSERT_NO_FATAL_FAILURE(InitState());
17078
17079 VkAttachmentDescription attachment = { 0,
17080 VK_FORMAT_D32_SFLOAT_S8_UINT,
17081 VK_SAMPLE_COUNT_1_BIT,
17082 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17083 VK_ATTACHMENT_STORE_OP_STORE,
17084 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17085 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17086 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17087 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17088
17089 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17090
17091 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17092
17093 VkSubpassDependency dep = { 0,
17094 0,
17095 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17096 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17097 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17098 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17099 VK_DEPENDENCY_BY_REGION_BIT};
17100
17101 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17102
17103 VkResult err;
17104 VkRenderPass rp;
17105 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17106 ASSERT_VK_SUCCESS(err);
17107
17108 VkImageObj image(m_device);
17109 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17110 0x26, // usage
17111 VK_IMAGE_TILING_OPTIMAL, 0);
17112 ASSERT_TRUE(image.initialized());
17113 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17114
17115 VkImageViewCreateInfo ivci = {
17116 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17117 nullptr,
17118 0,
17119 image.handle(),
17120 VK_IMAGE_VIEW_TYPE_2D,
17121 VK_FORMAT_D32_SFLOAT_S8_UINT,
17122 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17123 { 0x2, 0, 1, 0, 1 },
17124 };
17125 VkImageView view;
17126 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17127 ASSERT_VK_SUCCESS(err);
17128
17129 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17130 VkFramebuffer fb;
17131 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17132 ASSERT_VK_SUCCESS(err);
17133
17134 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17135 BeginCommandBuffer();
17136 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17137
17138 VkImageMemoryBarrier imb = {};
17139 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17140 imb.pNext = nullptr;
17141 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17142 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17143 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17144 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17145 imb.srcQueueFamilyIndex = 0;
17146 imb.dstQueueFamilyIndex = 0;
17147 imb.image = image.handle();
17148 imb.subresourceRange.aspectMask = 0x6;
17149 imb.subresourceRange.baseMipLevel = 0;
17150 imb.subresourceRange.levelCount = 0x1;
17151 imb.subresourceRange.baseArrayLayer = 0;
17152 imb.subresourceRange.layerCount = 0x1;
17153
17154 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17155 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17156 &imb);
17157
17158 vkCmdEndRenderPass(m_commandBuffer->handle());
17159 EndCommandBuffer();
17160 QueueCommandBuffer(false);
17161 m_errorMonitor->VerifyNotFound();
17162
17163 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17164 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17165 vkDestroyImageView(m_device->device(), view, nullptr);
17166}
17167
17168TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17169 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17170 "errors, when an attachment reference is "
17171 "VK_ATTACHMENT_UNUSED");
17172
17173 m_errorMonitor->ExpectSuccess();
17174
17175 ASSERT_NO_FATAL_FAILURE(InitState());
17176
17177 // A renderpass with no attachments
17178 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17179
17180 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17181
17182 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17183
17184 VkRenderPass rp;
17185 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17186 ASSERT_VK_SUCCESS(err);
17187
17188 // A compatible framebuffer.
17189 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17190 VkFramebuffer fb;
17191 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17192 ASSERT_VK_SUCCESS(err);
17193
17194 // Record a command buffer which just begins and ends the renderpass. The
17195 // bug manifests in BeginRenderPass.
17196 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17197 BeginCommandBuffer();
17198 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17199 vkCmdEndRenderPass(m_commandBuffer->handle());
17200 m_errorMonitor->VerifyNotFound();
17201 EndCommandBuffer();
17202
17203 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17204 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17205}
17206
17207// This is a positive test. No errors are expected.
17208TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17209 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17210 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17211 VkResult result = VK_SUCCESS;
17212 VkImageFormatProperties formatProps;
17213 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17214 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17215 &formatProps);
17216 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17217 return;
17218 }
17219
17220 ASSERT_NO_FATAL_FAILURE(InitState());
17221 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17222 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17223 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17224 VkAttachmentDescription att = {};
17225 VkAttachmentReference ref = {};
17226 att.format = depth_stencil_fmt;
17227 att.samples = VK_SAMPLE_COUNT_1_BIT;
17228 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17229 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17230 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17231 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17232 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17233 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17234
17235 VkClearValue clear;
17236 clear.depthStencil.depth = 1.0;
17237 clear.depthStencil.stencil = 0;
17238 ref.attachment = 0;
17239 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17240
17241 VkSubpassDescription subpass = {};
17242 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17243 subpass.flags = 0;
17244 subpass.inputAttachmentCount = 0;
17245 subpass.pInputAttachments = NULL;
17246 subpass.colorAttachmentCount = 0;
17247 subpass.pColorAttachments = NULL;
17248 subpass.pResolveAttachments = NULL;
17249 subpass.pDepthStencilAttachment = &ref;
17250 subpass.preserveAttachmentCount = 0;
17251 subpass.pPreserveAttachments = NULL;
17252
17253 VkRenderPass rp;
17254 VkRenderPassCreateInfo rp_info = {};
17255 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17256 rp_info.attachmentCount = 1;
17257 rp_info.pAttachments = &att;
17258 rp_info.subpassCount = 1;
17259 rp_info.pSubpasses = &subpass;
17260 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17261 ASSERT_VK_SUCCESS(result);
17262
17263 VkImageView *depthView = m_depthStencil->BindInfo();
17264 VkFramebufferCreateInfo fb_info = {};
17265 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17266 fb_info.pNext = NULL;
17267 fb_info.renderPass = rp;
17268 fb_info.attachmentCount = 1;
17269 fb_info.pAttachments = depthView;
17270 fb_info.width = 100;
17271 fb_info.height = 100;
17272 fb_info.layers = 1;
17273 VkFramebuffer fb;
17274 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17275 ASSERT_VK_SUCCESS(result);
17276
17277 VkRenderPassBeginInfo rpbinfo = {};
17278 rpbinfo.clearValueCount = 1;
17279 rpbinfo.pClearValues = &clear;
17280 rpbinfo.pNext = NULL;
17281 rpbinfo.renderPass = rp;
17282 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17283 rpbinfo.renderArea.extent.width = 100;
17284 rpbinfo.renderArea.extent.height = 100;
17285 rpbinfo.renderArea.offset.x = 0;
17286 rpbinfo.renderArea.offset.y = 0;
17287 rpbinfo.framebuffer = fb;
17288
17289 VkFence fence = {};
17290 VkFenceCreateInfo fence_ci = {};
17291 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17292 fence_ci.pNext = nullptr;
17293 fence_ci.flags = 0;
17294 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17295 ASSERT_VK_SUCCESS(result);
17296
17297 m_commandBuffer->BeginCommandBuffer();
17298 m_commandBuffer->BeginRenderPass(rpbinfo);
17299 m_commandBuffer->EndRenderPass();
17300 m_commandBuffer->EndCommandBuffer();
17301 m_commandBuffer->QueueCommandBuffer(fence);
17302
17303 VkImageObj destImage(m_device);
17304 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17305 VK_IMAGE_TILING_OPTIMAL, 0);
17306 VkImageMemoryBarrier barrier = {};
17307 VkImageSubresourceRange range;
17308 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17309 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17310 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17311 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17312 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17313 barrier.image = m_depthStencil->handle();
17314 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17315 range.baseMipLevel = 0;
17316 range.levelCount = 1;
17317 range.baseArrayLayer = 0;
17318 range.layerCount = 1;
17319 barrier.subresourceRange = range;
17320 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17321 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17322 cmdbuf.BeginCommandBuffer();
17323 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17324 &barrier);
17325 barrier.srcAccessMask = 0;
17326 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17327 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17328 barrier.image = destImage.handle();
17329 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17330 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17331 &barrier);
17332 VkImageCopy cregion;
17333 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17334 cregion.srcSubresource.mipLevel = 0;
17335 cregion.srcSubresource.baseArrayLayer = 0;
17336 cregion.srcSubresource.layerCount = 1;
17337 cregion.srcOffset.x = 0;
17338 cregion.srcOffset.y = 0;
17339 cregion.srcOffset.z = 0;
17340 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17341 cregion.dstSubresource.mipLevel = 0;
17342 cregion.dstSubresource.baseArrayLayer = 0;
17343 cregion.dstSubresource.layerCount = 1;
17344 cregion.dstOffset.x = 0;
17345 cregion.dstOffset.y = 0;
17346 cregion.dstOffset.z = 0;
17347 cregion.extent.width = 100;
17348 cregion.extent.height = 100;
17349 cregion.extent.depth = 1;
17350 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17351 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17352 cmdbuf.EndCommandBuffer();
17353
17354 VkSubmitInfo submit_info;
17355 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17356 submit_info.pNext = NULL;
17357 submit_info.waitSemaphoreCount = 0;
17358 submit_info.pWaitSemaphores = NULL;
17359 submit_info.pWaitDstStageMask = NULL;
17360 submit_info.commandBufferCount = 1;
17361 submit_info.pCommandBuffers = &cmdbuf.handle();
17362 submit_info.signalSemaphoreCount = 0;
17363 submit_info.pSignalSemaphores = NULL;
17364
17365 m_errorMonitor->ExpectSuccess();
17366 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17367 m_errorMonitor->VerifyNotFound();
17368
17369 vkQueueWaitIdle(m_device->m_queue);
17370 vkDestroyFence(m_device->device(), fence, nullptr);
17371 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17372 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17373}
17374
17375// This is a positive test. No errors should be generated.
17376TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17377 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17378
17379 m_errorMonitor->ExpectSuccess();
17380 ASSERT_NO_FATAL_FAILURE(InitState());
17381
17382 VkEvent event;
17383 VkEventCreateInfo event_create_info{};
17384 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17385 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17386
17387 VkCommandPool command_pool;
17388 VkCommandPoolCreateInfo pool_create_info{};
17389 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17390 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17391 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17392 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17393
17394 VkCommandBuffer command_buffer;
17395 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17396 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17397 command_buffer_allocate_info.commandPool = command_pool;
17398 command_buffer_allocate_info.commandBufferCount = 1;
17399 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17400 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17401
17402 VkQueue queue = VK_NULL_HANDLE;
17403 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17404
17405 {
17406 VkCommandBufferBeginInfo begin_info{};
17407 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17408 vkBeginCommandBuffer(command_buffer, &begin_info);
17409
17410 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17411 nullptr, 0, nullptr);
17412 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17413 vkEndCommandBuffer(command_buffer);
17414 }
17415 {
17416 VkSubmitInfo submit_info{};
17417 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17418 submit_info.commandBufferCount = 1;
17419 submit_info.pCommandBuffers = &command_buffer;
17420 submit_info.signalSemaphoreCount = 0;
17421 submit_info.pSignalSemaphores = nullptr;
17422 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17423 }
17424 { vkSetEvent(m_device->device(), event); }
17425
17426 vkQueueWaitIdle(queue);
17427
17428 vkDestroyEvent(m_device->device(), event, nullptr);
17429 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17430 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17431
17432 m_errorMonitor->VerifyNotFound();
17433}
17434// This is a positive test. No errors should be generated.
17435TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17436 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17437
17438 ASSERT_NO_FATAL_FAILURE(InitState());
17439 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17440 return;
17441
17442 m_errorMonitor->ExpectSuccess();
17443
17444 VkQueryPool query_pool;
17445 VkQueryPoolCreateInfo query_pool_create_info{};
17446 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17447 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17448 query_pool_create_info.queryCount = 1;
17449 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17450
17451 VkCommandPool command_pool;
17452 VkCommandPoolCreateInfo pool_create_info{};
17453 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17454 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17455 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17456 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17457
17458 VkCommandBuffer command_buffer;
17459 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17460 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17461 command_buffer_allocate_info.commandPool = command_pool;
17462 command_buffer_allocate_info.commandBufferCount = 1;
17463 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17464 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17465
17466 VkCommandBuffer secondary_command_buffer;
17467 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17468 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17469
17470 VkQueue queue = VK_NULL_HANDLE;
17471 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17472
17473 uint32_t qfi = 0;
17474 VkBufferCreateInfo buff_create_info = {};
17475 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17476 buff_create_info.size = 1024;
17477 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17478 buff_create_info.queueFamilyIndexCount = 1;
17479 buff_create_info.pQueueFamilyIndices = &qfi;
17480
17481 VkResult err;
17482 VkBuffer buffer;
17483 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17484 ASSERT_VK_SUCCESS(err);
17485 VkMemoryAllocateInfo mem_alloc = {};
17486 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17487 mem_alloc.pNext = NULL;
17488 mem_alloc.allocationSize = 1024;
17489 mem_alloc.memoryTypeIndex = 0;
17490
17491 VkMemoryRequirements memReqs;
17492 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17493 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17494 if (!pass) {
17495 vkDestroyBuffer(m_device->device(), buffer, NULL);
17496 return;
17497 }
17498
17499 VkDeviceMemory mem;
17500 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17501 ASSERT_VK_SUCCESS(err);
17502 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17503 ASSERT_VK_SUCCESS(err);
17504
17505 VkCommandBufferInheritanceInfo hinfo = {};
17506 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17507 hinfo.renderPass = VK_NULL_HANDLE;
17508 hinfo.subpass = 0;
17509 hinfo.framebuffer = VK_NULL_HANDLE;
17510 hinfo.occlusionQueryEnable = VK_FALSE;
17511 hinfo.queryFlags = 0;
17512 hinfo.pipelineStatistics = 0;
17513
17514 {
17515 VkCommandBufferBeginInfo begin_info{};
17516 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17517 begin_info.pInheritanceInfo = &hinfo;
17518 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17519
17520 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17521 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17522
17523 vkEndCommandBuffer(secondary_command_buffer);
17524
17525 begin_info.pInheritanceInfo = nullptr;
17526 vkBeginCommandBuffer(command_buffer, &begin_info);
17527
17528 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17529 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17530
17531 vkEndCommandBuffer(command_buffer);
17532 }
17533 {
17534 VkSubmitInfo submit_info{};
17535 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17536 submit_info.commandBufferCount = 1;
17537 submit_info.pCommandBuffers = &command_buffer;
17538 submit_info.signalSemaphoreCount = 0;
17539 submit_info.pSignalSemaphores = nullptr;
17540 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17541 }
17542
17543 vkQueueWaitIdle(queue);
17544
17545 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17546 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17547 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17548 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17549 vkDestroyBuffer(m_device->device(), buffer, NULL);
17550 vkFreeMemory(m_device->device(), mem, NULL);
17551
17552 m_errorMonitor->VerifyNotFound();
17553}
17554
17555// This is a positive test. No errors should be generated.
17556TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17557 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17558
17559 ASSERT_NO_FATAL_FAILURE(InitState());
17560 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17561 return;
17562
17563 m_errorMonitor->ExpectSuccess();
17564
17565 VkQueryPool query_pool;
17566 VkQueryPoolCreateInfo query_pool_create_info{};
17567 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17568 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17569 query_pool_create_info.queryCount = 1;
17570 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17571
17572 VkCommandPool command_pool;
17573 VkCommandPoolCreateInfo pool_create_info{};
17574 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17575 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17576 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17577 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17578
17579 VkCommandBuffer command_buffer[2];
17580 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17581 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17582 command_buffer_allocate_info.commandPool = command_pool;
17583 command_buffer_allocate_info.commandBufferCount = 2;
17584 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17585 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17586
17587 VkQueue queue = VK_NULL_HANDLE;
17588 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17589
17590 uint32_t qfi = 0;
17591 VkBufferCreateInfo buff_create_info = {};
17592 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17593 buff_create_info.size = 1024;
17594 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17595 buff_create_info.queueFamilyIndexCount = 1;
17596 buff_create_info.pQueueFamilyIndices = &qfi;
17597
17598 VkResult err;
17599 VkBuffer buffer;
17600 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17601 ASSERT_VK_SUCCESS(err);
17602 VkMemoryAllocateInfo mem_alloc = {};
17603 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17604 mem_alloc.pNext = NULL;
17605 mem_alloc.allocationSize = 1024;
17606 mem_alloc.memoryTypeIndex = 0;
17607
17608 VkMemoryRequirements memReqs;
17609 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17610 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17611 if (!pass) {
17612 vkDestroyBuffer(m_device->device(), buffer, NULL);
17613 return;
17614 }
17615
17616 VkDeviceMemory mem;
17617 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17618 ASSERT_VK_SUCCESS(err);
17619 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17620 ASSERT_VK_SUCCESS(err);
17621
17622 {
17623 VkCommandBufferBeginInfo begin_info{};
17624 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17625 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17626
17627 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17628 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17629
17630 vkEndCommandBuffer(command_buffer[0]);
17631
17632 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17633
17634 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17635
17636 vkEndCommandBuffer(command_buffer[1]);
17637 }
17638 {
17639 VkSubmitInfo submit_info{};
17640 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17641 submit_info.commandBufferCount = 2;
17642 submit_info.pCommandBuffers = command_buffer;
17643 submit_info.signalSemaphoreCount = 0;
17644 submit_info.pSignalSemaphores = nullptr;
17645 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17646 }
17647
17648 vkQueueWaitIdle(queue);
17649
17650 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17651 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17652 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17653 vkDestroyBuffer(m_device->device(), buffer, NULL);
17654 vkFreeMemory(m_device->device(), mem, NULL);
17655
17656 m_errorMonitor->VerifyNotFound();
17657}
17658
Tony Barbourc46924f2016-11-04 11:49:52 -060017659TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017660 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17661
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017662 ASSERT_NO_FATAL_FAILURE(InitState());
17663 VkEvent event;
17664 VkEventCreateInfo event_create_info{};
17665 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17666 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17667
17668 VkCommandPool command_pool;
17669 VkCommandPoolCreateInfo pool_create_info{};
17670 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17671 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17672 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17673 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17674
17675 VkCommandBuffer command_buffer;
17676 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17677 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17678 command_buffer_allocate_info.commandPool = command_pool;
17679 command_buffer_allocate_info.commandBufferCount = 1;
17680 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17681 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17682
17683 VkQueue queue = VK_NULL_HANDLE;
17684 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17685
17686 {
17687 VkCommandBufferBeginInfo begin_info{};
17688 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17689 vkBeginCommandBuffer(command_buffer, &begin_info);
17690
17691 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017692 vkEndCommandBuffer(command_buffer);
17693 }
17694 {
17695 VkSubmitInfo submit_info{};
17696 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17697 submit_info.commandBufferCount = 1;
17698 submit_info.pCommandBuffers = &command_buffer;
17699 submit_info.signalSemaphoreCount = 0;
17700 submit_info.pSignalSemaphores = nullptr;
17701 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17702 }
17703 {
17704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17705 "command buffer.");
17706 vkSetEvent(m_device->device(), event);
17707 m_errorMonitor->VerifyFound();
17708 }
17709
17710 vkQueueWaitIdle(queue);
17711
17712 vkDestroyEvent(m_device->device(), event, nullptr);
17713 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17714 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17715}
17716
17717// This is a positive test. No errors should be generated.
17718TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17719 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17720 "run through a Submit & WaitForFences cycle 3 times. This "
17721 "previously revealed a bug so running this positive test "
17722 "to prevent a regression.");
17723 m_errorMonitor->ExpectSuccess();
17724
17725 ASSERT_NO_FATAL_FAILURE(InitState());
17726 VkQueue queue = VK_NULL_HANDLE;
17727 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17728
17729 static const uint32_t NUM_OBJECTS = 2;
17730 static const uint32_t NUM_FRAMES = 3;
17731 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17732 VkFence fences[NUM_OBJECTS] = {};
17733
17734 VkCommandPool cmd_pool;
17735 VkCommandPoolCreateInfo cmd_pool_ci = {};
17736 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17737 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17738 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17739 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17740 ASSERT_VK_SUCCESS(err);
17741
17742 VkCommandBufferAllocateInfo cmd_buf_info = {};
17743 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17744 cmd_buf_info.commandPool = cmd_pool;
17745 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17746 cmd_buf_info.commandBufferCount = 1;
17747
17748 VkFenceCreateInfo fence_ci = {};
17749 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17750 fence_ci.pNext = nullptr;
17751 fence_ci.flags = 0;
17752
17753 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17754 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17755 ASSERT_VK_SUCCESS(err);
17756 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17757 ASSERT_VK_SUCCESS(err);
17758 }
17759
17760 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17761 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17762 // Create empty cmd buffer
17763 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17764 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17765
17766 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17767 ASSERT_VK_SUCCESS(err);
17768 err = vkEndCommandBuffer(cmd_buffers[obj]);
17769 ASSERT_VK_SUCCESS(err);
17770
17771 VkSubmitInfo submit_info = {};
17772 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17773 submit_info.commandBufferCount = 1;
17774 submit_info.pCommandBuffers = &cmd_buffers[obj];
17775 // Submit cmd buffer and wait for fence
17776 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17777 ASSERT_VK_SUCCESS(err);
17778 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17779 ASSERT_VK_SUCCESS(err);
17780 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17781 ASSERT_VK_SUCCESS(err);
17782 }
17783 }
17784 m_errorMonitor->VerifyNotFound();
17785 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17786 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17787 vkDestroyFence(m_device->device(), fences[i], nullptr);
17788 }
17789}
17790// This is a positive test. No errors should be generated.
17791TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17792
17793 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17794 "submitted on separate queues followed by a QueueWaitIdle.");
17795
17796 ASSERT_NO_FATAL_FAILURE(InitState());
17797 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17798 return;
17799
17800 m_errorMonitor->ExpectSuccess();
17801
17802 VkSemaphore semaphore;
17803 VkSemaphoreCreateInfo semaphore_create_info{};
17804 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17805 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17806
17807 VkCommandPool command_pool;
17808 VkCommandPoolCreateInfo pool_create_info{};
17809 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17810 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17811 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17812 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17813
17814 VkCommandBuffer command_buffer[2];
17815 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17816 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17817 command_buffer_allocate_info.commandPool = command_pool;
17818 command_buffer_allocate_info.commandBufferCount = 2;
17819 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17820 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17821
17822 VkQueue queue = VK_NULL_HANDLE;
17823 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17824
17825 {
17826 VkCommandBufferBeginInfo begin_info{};
17827 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17828 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17829
17830 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17831 nullptr, 0, nullptr, 0, nullptr);
17832
17833 VkViewport viewport{};
17834 viewport.maxDepth = 1.0f;
17835 viewport.minDepth = 0.0f;
17836 viewport.width = 512;
17837 viewport.height = 512;
17838 viewport.x = 0;
17839 viewport.y = 0;
17840 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17841 vkEndCommandBuffer(command_buffer[0]);
17842 }
17843 {
17844 VkCommandBufferBeginInfo begin_info{};
17845 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17846 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17847
17848 VkViewport viewport{};
17849 viewport.maxDepth = 1.0f;
17850 viewport.minDepth = 0.0f;
17851 viewport.width = 512;
17852 viewport.height = 512;
17853 viewport.x = 0;
17854 viewport.y = 0;
17855 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17856 vkEndCommandBuffer(command_buffer[1]);
17857 }
17858 {
17859 VkSubmitInfo submit_info{};
17860 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17861 submit_info.commandBufferCount = 1;
17862 submit_info.pCommandBuffers = &command_buffer[0];
17863 submit_info.signalSemaphoreCount = 1;
17864 submit_info.pSignalSemaphores = &semaphore;
17865 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17866 }
17867 {
17868 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17869 VkSubmitInfo submit_info{};
17870 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17871 submit_info.commandBufferCount = 1;
17872 submit_info.pCommandBuffers = &command_buffer[1];
17873 submit_info.waitSemaphoreCount = 1;
17874 submit_info.pWaitSemaphores = &semaphore;
17875 submit_info.pWaitDstStageMask = flags;
17876 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17877 }
17878
17879 vkQueueWaitIdle(m_device->m_queue);
17880
17881 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17882 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17883 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17884
17885 m_errorMonitor->VerifyNotFound();
17886}
17887
17888// This is a positive test. No errors should be generated.
17889TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17890
17891 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17892 "submitted on separate queues, the second having a fence"
17893 "followed by a QueueWaitIdle.");
17894
17895 ASSERT_NO_FATAL_FAILURE(InitState());
17896 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17897 return;
17898
17899 m_errorMonitor->ExpectSuccess();
17900
17901 VkFence fence;
17902 VkFenceCreateInfo fence_create_info{};
17903 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17904 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17905
17906 VkSemaphore semaphore;
17907 VkSemaphoreCreateInfo semaphore_create_info{};
17908 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17909 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17910
17911 VkCommandPool command_pool;
17912 VkCommandPoolCreateInfo pool_create_info{};
17913 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17914 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17915 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17916 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17917
17918 VkCommandBuffer command_buffer[2];
17919 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17920 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17921 command_buffer_allocate_info.commandPool = command_pool;
17922 command_buffer_allocate_info.commandBufferCount = 2;
17923 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17924 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17925
17926 VkQueue queue = VK_NULL_HANDLE;
17927 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17928
17929 {
17930 VkCommandBufferBeginInfo begin_info{};
17931 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17932 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17933
17934 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17935 nullptr, 0, nullptr, 0, nullptr);
17936
17937 VkViewport viewport{};
17938 viewport.maxDepth = 1.0f;
17939 viewport.minDepth = 0.0f;
17940 viewport.width = 512;
17941 viewport.height = 512;
17942 viewport.x = 0;
17943 viewport.y = 0;
17944 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17945 vkEndCommandBuffer(command_buffer[0]);
17946 }
17947 {
17948 VkCommandBufferBeginInfo begin_info{};
17949 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17950 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17951
17952 VkViewport viewport{};
17953 viewport.maxDepth = 1.0f;
17954 viewport.minDepth = 0.0f;
17955 viewport.width = 512;
17956 viewport.height = 512;
17957 viewport.x = 0;
17958 viewport.y = 0;
17959 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17960 vkEndCommandBuffer(command_buffer[1]);
17961 }
17962 {
17963 VkSubmitInfo submit_info{};
17964 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17965 submit_info.commandBufferCount = 1;
17966 submit_info.pCommandBuffers = &command_buffer[0];
17967 submit_info.signalSemaphoreCount = 1;
17968 submit_info.pSignalSemaphores = &semaphore;
17969 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17970 }
17971 {
17972 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17973 VkSubmitInfo submit_info{};
17974 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17975 submit_info.commandBufferCount = 1;
17976 submit_info.pCommandBuffers = &command_buffer[1];
17977 submit_info.waitSemaphoreCount = 1;
17978 submit_info.pWaitSemaphores = &semaphore;
17979 submit_info.pWaitDstStageMask = flags;
17980 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17981 }
17982
17983 vkQueueWaitIdle(m_device->m_queue);
17984
17985 vkDestroyFence(m_device->device(), fence, nullptr);
17986 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17987 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17988 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17989
17990 m_errorMonitor->VerifyNotFound();
17991}
17992
17993// This is a positive test. No errors should be generated.
17994TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17995
17996 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17997 "submitted on separate queues, the second having a fence"
17998 "followed by two consecutive WaitForFences calls on the same fence.");
17999
18000 ASSERT_NO_FATAL_FAILURE(InitState());
18001 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18002 return;
18003
18004 m_errorMonitor->ExpectSuccess();
18005
18006 VkFence fence;
18007 VkFenceCreateInfo fence_create_info{};
18008 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18009 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18010
18011 VkSemaphore semaphore;
18012 VkSemaphoreCreateInfo semaphore_create_info{};
18013 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18014 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18015
18016 VkCommandPool command_pool;
18017 VkCommandPoolCreateInfo pool_create_info{};
18018 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18019 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18020 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18021 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18022
18023 VkCommandBuffer command_buffer[2];
18024 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18025 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18026 command_buffer_allocate_info.commandPool = command_pool;
18027 command_buffer_allocate_info.commandBufferCount = 2;
18028 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18029 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18030
18031 VkQueue queue = VK_NULL_HANDLE;
18032 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18033
18034 {
18035 VkCommandBufferBeginInfo begin_info{};
18036 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18037 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18038
18039 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18040 nullptr, 0, nullptr, 0, nullptr);
18041
18042 VkViewport viewport{};
18043 viewport.maxDepth = 1.0f;
18044 viewport.minDepth = 0.0f;
18045 viewport.width = 512;
18046 viewport.height = 512;
18047 viewport.x = 0;
18048 viewport.y = 0;
18049 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18050 vkEndCommandBuffer(command_buffer[0]);
18051 }
18052 {
18053 VkCommandBufferBeginInfo begin_info{};
18054 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18055 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18056
18057 VkViewport viewport{};
18058 viewport.maxDepth = 1.0f;
18059 viewport.minDepth = 0.0f;
18060 viewport.width = 512;
18061 viewport.height = 512;
18062 viewport.x = 0;
18063 viewport.y = 0;
18064 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18065 vkEndCommandBuffer(command_buffer[1]);
18066 }
18067 {
18068 VkSubmitInfo submit_info{};
18069 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18070 submit_info.commandBufferCount = 1;
18071 submit_info.pCommandBuffers = &command_buffer[0];
18072 submit_info.signalSemaphoreCount = 1;
18073 submit_info.pSignalSemaphores = &semaphore;
18074 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18075 }
18076 {
18077 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18078 VkSubmitInfo submit_info{};
18079 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18080 submit_info.commandBufferCount = 1;
18081 submit_info.pCommandBuffers = &command_buffer[1];
18082 submit_info.waitSemaphoreCount = 1;
18083 submit_info.pWaitSemaphores = &semaphore;
18084 submit_info.pWaitDstStageMask = flags;
18085 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18086 }
18087
18088 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18089 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18090
18091 vkDestroyFence(m_device->device(), fence, nullptr);
18092 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18093 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18094 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18095
18096 m_errorMonitor->VerifyNotFound();
18097}
18098
18099TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18100
18101 ASSERT_NO_FATAL_FAILURE(InitState());
18102 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18103 printf("Test requires two queues, skipping\n");
18104 return;
18105 }
18106
18107 VkResult err;
18108
18109 m_errorMonitor->ExpectSuccess();
18110
18111 VkQueue q0 = m_device->m_queue;
18112 VkQueue q1 = nullptr;
18113 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18114 ASSERT_NE(q1, nullptr);
18115
18116 // An (empty) command buffer. We must have work in the first submission --
18117 // the layer treats unfenced work differently from fenced work.
18118 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18119 VkCommandPool pool;
18120 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18121 ASSERT_VK_SUCCESS(err);
18122 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18123 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18124 VkCommandBuffer cb;
18125 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18126 ASSERT_VK_SUCCESS(err);
18127 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18128 err = vkBeginCommandBuffer(cb, &cbbi);
18129 ASSERT_VK_SUCCESS(err);
18130 err = vkEndCommandBuffer(cb);
18131 ASSERT_VK_SUCCESS(err);
18132
18133 // A semaphore
18134 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18135 VkSemaphore s;
18136 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18137 ASSERT_VK_SUCCESS(err);
18138
18139 // First submission, to q0
18140 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18141
18142 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18143 ASSERT_VK_SUCCESS(err);
18144
18145 // Second submission, to q1, waiting on s
18146 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18147 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18148
18149 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18150 ASSERT_VK_SUCCESS(err);
18151
18152 // Wait for q0 idle
18153 err = vkQueueWaitIdle(q0);
18154 ASSERT_VK_SUCCESS(err);
18155
18156 // Command buffer should have been completed (it was on q0); reset the pool.
18157 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18158
18159 m_errorMonitor->VerifyNotFound();
18160
18161 // Force device completely idle and clean up resources
18162 vkDeviceWaitIdle(m_device->device());
18163 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18164 vkDestroySemaphore(m_device->device(), s, nullptr);
18165}
18166
18167// This is a positive test. No errors should be generated.
18168TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18169
18170 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18171 "submitted on separate queues, the second having a fence, "
18172 "followed by a WaitForFences call.");
18173
18174 ASSERT_NO_FATAL_FAILURE(InitState());
18175 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18176 return;
18177
18178 m_errorMonitor->ExpectSuccess();
18179
18180 ASSERT_NO_FATAL_FAILURE(InitState());
18181 VkFence fence;
18182 VkFenceCreateInfo fence_create_info{};
18183 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18184 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18185
18186 VkSemaphore semaphore;
18187 VkSemaphoreCreateInfo semaphore_create_info{};
18188 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18189 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18190
18191 VkCommandPool command_pool;
18192 VkCommandPoolCreateInfo pool_create_info{};
18193 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18194 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18195 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18196 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18197
18198 VkCommandBuffer command_buffer[2];
18199 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18200 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18201 command_buffer_allocate_info.commandPool = command_pool;
18202 command_buffer_allocate_info.commandBufferCount = 2;
18203 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18204 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18205
18206 VkQueue queue = VK_NULL_HANDLE;
18207 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18208
18209 {
18210 VkCommandBufferBeginInfo begin_info{};
18211 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18212 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18213
18214 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18215 nullptr, 0, nullptr, 0, nullptr);
18216
18217 VkViewport viewport{};
18218 viewport.maxDepth = 1.0f;
18219 viewport.minDepth = 0.0f;
18220 viewport.width = 512;
18221 viewport.height = 512;
18222 viewport.x = 0;
18223 viewport.y = 0;
18224 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18225 vkEndCommandBuffer(command_buffer[0]);
18226 }
18227 {
18228 VkCommandBufferBeginInfo begin_info{};
18229 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18230 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18231
18232 VkViewport viewport{};
18233 viewport.maxDepth = 1.0f;
18234 viewport.minDepth = 0.0f;
18235 viewport.width = 512;
18236 viewport.height = 512;
18237 viewport.x = 0;
18238 viewport.y = 0;
18239 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18240 vkEndCommandBuffer(command_buffer[1]);
18241 }
18242 {
18243 VkSubmitInfo submit_info{};
18244 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18245 submit_info.commandBufferCount = 1;
18246 submit_info.pCommandBuffers = &command_buffer[0];
18247 submit_info.signalSemaphoreCount = 1;
18248 submit_info.pSignalSemaphores = &semaphore;
18249 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18250 }
18251 {
18252 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18253 VkSubmitInfo submit_info{};
18254 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18255 submit_info.commandBufferCount = 1;
18256 submit_info.pCommandBuffers = &command_buffer[1];
18257 submit_info.waitSemaphoreCount = 1;
18258 submit_info.pWaitSemaphores = &semaphore;
18259 submit_info.pWaitDstStageMask = flags;
18260 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18261 }
18262
18263 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18264
18265 vkDestroyFence(m_device->device(), fence, nullptr);
18266 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18267 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18268 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18269
18270 m_errorMonitor->VerifyNotFound();
18271}
18272
18273// This is a positive test. No errors should be generated.
18274TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18275
18276 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18277 "on the same queue, sharing a signal/wait semaphore, the "
18278 "second having a fence, "
18279 "followed by a WaitForFences call.");
18280
18281 m_errorMonitor->ExpectSuccess();
18282
18283 ASSERT_NO_FATAL_FAILURE(InitState());
18284 VkFence fence;
18285 VkFenceCreateInfo fence_create_info{};
18286 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18287 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18288
18289 VkSemaphore semaphore;
18290 VkSemaphoreCreateInfo semaphore_create_info{};
18291 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18292 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18293
18294 VkCommandPool command_pool;
18295 VkCommandPoolCreateInfo pool_create_info{};
18296 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18297 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18298 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18299 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18300
18301 VkCommandBuffer command_buffer[2];
18302 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18303 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18304 command_buffer_allocate_info.commandPool = command_pool;
18305 command_buffer_allocate_info.commandBufferCount = 2;
18306 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18307 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18308
18309 {
18310 VkCommandBufferBeginInfo begin_info{};
18311 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18312 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18313
18314 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18315 nullptr, 0, nullptr, 0, nullptr);
18316
18317 VkViewport viewport{};
18318 viewport.maxDepth = 1.0f;
18319 viewport.minDepth = 0.0f;
18320 viewport.width = 512;
18321 viewport.height = 512;
18322 viewport.x = 0;
18323 viewport.y = 0;
18324 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18325 vkEndCommandBuffer(command_buffer[0]);
18326 }
18327 {
18328 VkCommandBufferBeginInfo begin_info{};
18329 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18330 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18331
18332 VkViewport viewport{};
18333 viewport.maxDepth = 1.0f;
18334 viewport.minDepth = 0.0f;
18335 viewport.width = 512;
18336 viewport.height = 512;
18337 viewport.x = 0;
18338 viewport.y = 0;
18339 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18340 vkEndCommandBuffer(command_buffer[1]);
18341 }
18342 {
18343 VkSubmitInfo submit_info{};
18344 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18345 submit_info.commandBufferCount = 1;
18346 submit_info.pCommandBuffers = &command_buffer[0];
18347 submit_info.signalSemaphoreCount = 1;
18348 submit_info.pSignalSemaphores = &semaphore;
18349 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18350 }
18351 {
18352 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18353 VkSubmitInfo submit_info{};
18354 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18355 submit_info.commandBufferCount = 1;
18356 submit_info.pCommandBuffers = &command_buffer[1];
18357 submit_info.waitSemaphoreCount = 1;
18358 submit_info.pWaitSemaphores = &semaphore;
18359 submit_info.pWaitDstStageMask = flags;
18360 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18361 }
18362
18363 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18364
18365 vkDestroyFence(m_device->device(), fence, nullptr);
18366 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18367 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18368 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18369
18370 m_errorMonitor->VerifyNotFound();
18371}
18372
18373// This is a positive test. No errors should be generated.
18374TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18375
18376 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18377 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18378 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18379
18380 m_errorMonitor->ExpectSuccess();
18381
18382 ASSERT_NO_FATAL_FAILURE(InitState());
18383 VkFence fence;
18384 VkFenceCreateInfo fence_create_info{};
18385 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18386 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18387
18388 VkCommandPool command_pool;
18389 VkCommandPoolCreateInfo pool_create_info{};
18390 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18391 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18392 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18393 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18394
18395 VkCommandBuffer command_buffer[2];
18396 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18397 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18398 command_buffer_allocate_info.commandPool = command_pool;
18399 command_buffer_allocate_info.commandBufferCount = 2;
18400 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18401 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18402
18403 {
18404 VkCommandBufferBeginInfo begin_info{};
18405 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18406 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18407
18408 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18409 nullptr, 0, nullptr, 0, nullptr);
18410
18411 VkViewport viewport{};
18412 viewport.maxDepth = 1.0f;
18413 viewport.minDepth = 0.0f;
18414 viewport.width = 512;
18415 viewport.height = 512;
18416 viewport.x = 0;
18417 viewport.y = 0;
18418 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18419 vkEndCommandBuffer(command_buffer[0]);
18420 }
18421 {
18422 VkCommandBufferBeginInfo begin_info{};
18423 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18424 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18425
18426 VkViewport viewport{};
18427 viewport.maxDepth = 1.0f;
18428 viewport.minDepth = 0.0f;
18429 viewport.width = 512;
18430 viewport.height = 512;
18431 viewport.x = 0;
18432 viewport.y = 0;
18433 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18434 vkEndCommandBuffer(command_buffer[1]);
18435 }
18436 {
18437 VkSubmitInfo submit_info{};
18438 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18439 submit_info.commandBufferCount = 1;
18440 submit_info.pCommandBuffers = &command_buffer[0];
18441 submit_info.signalSemaphoreCount = 0;
18442 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18443 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18444 }
18445 {
18446 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18447 VkSubmitInfo submit_info{};
18448 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18449 submit_info.commandBufferCount = 1;
18450 submit_info.pCommandBuffers = &command_buffer[1];
18451 submit_info.waitSemaphoreCount = 0;
18452 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18453 submit_info.pWaitDstStageMask = flags;
18454 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18455 }
18456
18457 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18458
18459 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18460 ASSERT_VK_SUCCESS(err);
18461
18462 vkDestroyFence(m_device->device(), fence, nullptr);
18463 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18464 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18465
18466 m_errorMonitor->VerifyNotFound();
18467}
18468
18469// This is a positive test. No errors should be generated.
18470TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18471
18472 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18473 "on the same queue, the second having a fence, followed "
18474 "by a WaitForFences call.");
18475
18476 m_errorMonitor->ExpectSuccess();
18477
18478 ASSERT_NO_FATAL_FAILURE(InitState());
18479 VkFence fence;
18480 VkFenceCreateInfo fence_create_info{};
18481 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18482 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18483
18484 VkCommandPool command_pool;
18485 VkCommandPoolCreateInfo pool_create_info{};
18486 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18487 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18488 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18489 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18490
18491 VkCommandBuffer command_buffer[2];
18492 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18493 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18494 command_buffer_allocate_info.commandPool = command_pool;
18495 command_buffer_allocate_info.commandBufferCount = 2;
18496 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18497 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18498
18499 {
18500 VkCommandBufferBeginInfo begin_info{};
18501 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18502 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18503
18504 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18505 nullptr, 0, nullptr, 0, nullptr);
18506
18507 VkViewport viewport{};
18508 viewport.maxDepth = 1.0f;
18509 viewport.minDepth = 0.0f;
18510 viewport.width = 512;
18511 viewport.height = 512;
18512 viewport.x = 0;
18513 viewport.y = 0;
18514 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18515 vkEndCommandBuffer(command_buffer[0]);
18516 }
18517 {
18518 VkCommandBufferBeginInfo begin_info{};
18519 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18520 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18521
18522 VkViewport viewport{};
18523 viewport.maxDepth = 1.0f;
18524 viewport.minDepth = 0.0f;
18525 viewport.width = 512;
18526 viewport.height = 512;
18527 viewport.x = 0;
18528 viewport.y = 0;
18529 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18530 vkEndCommandBuffer(command_buffer[1]);
18531 }
18532 {
18533 VkSubmitInfo submit_info{};
18534 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18535 submit_info.commandBufferCount = 1;
18536 submit_info.pCommandBuffers = &command_buffer[0];
18537 submit_info.signalSemaphoreCount = 0;
18538 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18539 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18540 }
18541 {
18542 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18543 VkSubmitInfo submit_info{};
18544 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18545 submit_info.commandBufferCount = 1;
18546 submit_info.pCommandBuffers = &command_buffer[1];
18547 submit_info.waitSemaphoreCount = 0;
18548 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18549 submit_info.pWaitDstStageMask = flags;
18550 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18551 }
18552
18553 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18554
18555 vkDestroyFence(m_device->device(), fence, nullptr);
18556 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18557 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18558
18559 m_errorMonitor->VerifyNotFound();
18560}
18561
18562// This is a positive test. No errors should be generated.
18563TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18564
18565 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18566 "QueueSubmit call followed by a WaitForFences call.");
18567 ASSERT_NO_FATAL_FAILURE(InitState());
18568
18569 m_errorMonitor->ExpectSuccess();
18570
18571 VkFence fence;
18572 VkFenceCreateInfo fence_create_info{};
18573 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18574 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18575
18576 VkSemaphore semaphore;
18577 VkSemaphoreCreateInfo semaphore_create_info{};
18578 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18579 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18580
18581 VkCommandPool command_pool;
18582 VkCommandPoolCreateInfo pool_create_info{};
18583 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18584 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18585 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18586 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18587
18588 VkCommandBuffer command_buffer[2];
18589 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18590 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18591 command_buffer_allocate_info.commandPool = command_pool;
18592 command_buffer_allocate_info.commandBufferCount = 2;
18593 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18594 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18595
18596 {
18597 VkCommandBufferBeginInfo begin_info{};
18598 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18599 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18600
18601 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18602 nullptr, 0, nullptr, 0, nullptr);
18603
18604 VkViewport viewport{};
18605 viewport.maxDepth = 1.0f;
18606 viewport.minDepth = 0.0f;
18607 viewport.width = 512;
18608 viewport.height = 512;
18609 viewport.x = 0;
18610 viewport.y = 0;
18611 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18612 vkEndCommandBuffer(command_buffer[0]);
18613 }
18614 {
18615 VkCommandBufferBeginInfo begin_info{};
18616 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18617 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18618
18619 VkViewport viewport{};
18620 viewport.maxDepth = 1.0f;
18621 viewport.minDepth = 0.0f;
18622 viewport.width = 512;
18623 viewport.height = 512;
18624 viewport.x = 0;
18625 viewport.y = 0;
18626 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18627 vkEndCommandBuffer(command_buffer[1]);
18628 }
18629 {
18630 VkSubmitInfo submit_info[2];
18631 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18632
18633 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18634 submit_info[0].pNext = NULL;
18635 submit_info[0].commandBufferCount = 1;
18636 submit_info[0].pCommandBuffers = &command_buffer[0];
18637 submit_info[0].signalSemaphoreCount = 1;
18638 submit_info[0].pSignalSemaphores = &semaphore;
18639 submit_info[0].waitSemaphoreCount = 0;
18640 submit_info[0].pWaitSemaphores = NULL;
18641 submit_info[0].pWaitDstStageMask = 0;
18642
18643 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18644 submit_info[1].pNext = NULL;
18645 submit_info[1].commandBufferCount = 1;
18646 submit_info[1].pCommandBuffers = &command_buffer[1];
18647 submit_info[1].waitSemaphoreCount = 1;
18648 submit_info[1].pWaitSemaphores = &semaphore;
18649 submit_info[1].pWaitDstStageMask = flags;
18650 submit_info[1].signalSemaphoreCount = 0;
18651 submit_info[1].pSignalSemaphores = NULL;
18652 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18653 }
18654
18655 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18656
18657 vkDestroyFence(m_device->device(), fence, nullptr);
18658 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18659 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18660 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18661
18662 m_errorMonitor->VerifyNotFound();
18663}
18664
18665TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18666 m_errorMonitor->ExpectSuccess();
18667
18668 ASSERT_NO_FATAL_FAILURE(InitState());
18669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18670
18671 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18672 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18673
18674 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18675 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18676 m_errorMonitor->VerifyNotFound();
18677 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18678 m_errorMonitor->VerifyNotFound();
18679 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18680 m_errorMonitor->VerifyNotFound();
18681
18682 m_commandBuffer->EndCommandBuffer();
18683 m_errorMonitor->VerifyNotFound();
18684}
18685
18686TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18687 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18688 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18689 "has a valid layout, and a second subpass then uses a "
18690 "valid *READ_ONLY* layout.");
18691 m_errorMonitor->ExpectSuccess();
18692 ASSERT_NO_FATAL_FAILURE(InitState());
18693
18694 VkAttachmentReference attach[2] = {};
18695 attach[0].attachment = 0;
18696 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18697 attach[1].attachment = 0;
18698 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18699 VkSubpassDescription subpasses[2] = {};
18700 // First subpass clears DS attach on load
18701 subpasses[0].pDepthStencilAttachment = &attach[0];
18702 // 2nd subpass reads in DS as input attachment
18703 subpasses[1].inputAttachmentCount = 1;
18704 subpasses[1].pInputAttachments = &attach[1];
18705 VkAttachmentDescription attach_desc = {};
18706 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18707 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18708 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18709 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18710 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18711 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18712 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18713 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18714 VkRenderPassCreateInfo rpci = {};
18715 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18716 rpci.attachmentCount = 1;
18717 rpci.pAttachments = &attach_desc;
18718 rpci.subpassCount = 2;
18719 rpci.pSubpasses = subpasses;
18720
18721 // Now create RenderPass and verify no errors
18722 VkRenderPass rp;
18723 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18724 m_errorMonitor->VerifyNotFound();
18725
18726 vkDestroyRenderPass(m_device->device(), rp, NULL);
18727}
18728
18729TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18730 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18731 "as vertex attributes");
18732 m_errorMonitor->ExpectSuccess();
18733
18734 ASSERT_NO_FATAL_FAILURE(InitState());
18735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18736
18737 VkVertexInputBindingDescription input_binding;
18738 memset(&input_binding, 0, sizeof(input_binding));
18739
18740 VkVertexInputAttributeDescription input_attribs[2];
18741 memset(input_attribs, 0, sizeof(input_attribs));
18742
18743 for (int i = 0; i < 2; i++) {
18744 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18745 input_attribs[i].location = i;
18746 }
18747
18748 char const *vsSource = "#version 450\n"
18749 "\n"
18750 "layout(location=0) in mat2x4 x;\n"
18751 "out gl_PerVertex {\n"
18752 " vec4 gl_Position;\n"
18753 "};\n"
18754 "void main(){\n"
18755 " gl_Position = x[0] + x[1];\n"
18756 "}\n";
18757 char const *fsSource = "#version 450\n"
18758 "\n"
18759 "layout(location=0) out vec4 color;\n"
18760 "void main(){\n"
18761 " color = vec4(1);\n"
18762 "}\n";
18763
18764 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18765 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18766
18767 VkPipelineObj pipe(m_device);
18768 pipe.AddColorAttachment();
18769 pipe.AddShader(&vs);
18770 pipe.AddShader(&fs);
18771
18772 pipe.AddVertexInputBindings(&input_binding, 1);
18773 pipe.AddVertexInputAttribs(input_attribs, 2);
18774
18775 VkDescriptorSetObj descriptorSet(m_device);
18776 descriptorSet.AppendDummy();
18777 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18778
18779 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18780
18781 /* expect success */
18782 m_errorMonitor->VerifyNotFound();
18783}
18784
18785TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18786 m_errorMonitor->ExpectSuccess();
18787
18788 ASSERT_NO_FATAL_FAILURE(InitState());
18789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18790
18791 VkVertexInputBindingDescription input_binding;
18792 memset(&input_binding, 0, sizeof(input_binding));
18793
18794 VkVertexInputAttributeDescription input_attribs[2];
18795 memset(input_attribs, 0, sizeof(input_attribs));
18796
18797 for (int i = 0; i < 2; i++) {
18798 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18799 input_attribs[i].location = i;
18800 }
18801
18802 char const *vsSource = "#version 450\n"
18803 "\n"
18804 "layout(location=0) in vec4 x[2];\n"
18805 "out gl_PerVertex {\n"
18806 " vec4 gl_Position;\n"
18807 "};\n"
18808 "void main(){\n"
18809 " gl_Position = x[0] + x[1];\n"
18810 "}\n";
18811 char const *fsSource = "#version 450\n"
18812 "\n"
18813 "layout(location=0) out vec4 color;\n"
18814 "void main(){\n"
18815 " color = vec4(1);\n"
18816 "}\n";
18817
18818 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18819 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18820
18821 VkPipelineObj pipe(m_device);
18822 pipe.AddColorAttachment();
18823 pipe.AddShader(&vs);
18824 pipe.AddShader(&fs);
18825
18826 pipe.AddVertexInputBindings(&input_binding, 1);
18827 pipe.AddVertexInputAttribs(input_attribs, 2);
18828
18829 VkDescriptorSetObj descriptorSet(m_device);
18830 descriptorSet.AppendDummy();
18831 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18832
18833 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18834
18835 m_errorMonitor->VerifyNotFound();
18836}
18837
18838TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18839 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18840 "through multiple vertex shader inputs, each consuming a different "
18841 "subset of the components.");
18842 m_errorMonitor->ExpectSuccess();
18843
18844 ASSERT_NO_FATAL_FAILURE(InitState());
18845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18846
18847 VkVertexInputBindingDescription input_binding;
18848 memset(&input_binding, 0, sizeof(input_binding));
18849
18850 VkVertexInputAttributeDescription input_attribs[3];
18851 memset(input_attribs, 0, sizeof(input_attribs));
18852
18853 for (int i = 0; i < 3; i++) {
18854 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18855 input_attribs[i].location = i;
18856 }
18857
18858 char const *vsSource = "#version 450\n"
18859 "\n"
18860 "layout(location=0) in vec4 x;\n"
18861 "layout(location=1) in vec3 y1;\n"
18862 "layout(location=1, component=3) in float y2;\n"
18863 "layout(location=2) in vec4 z;\n"
18864 "out gl_PerVertex {\n"
18865 " vec4 gl_Position;\n"
18866 "};\n"
18867 "void main(){\n"
18868 " gl_Position = x + vec4(y1, y2) + z;\n"
18869 "}\n";
18870 char const *fsSource = "#version 450\n"
18871 "\n"
18872 "layout(location=0) out vec4 color;\n"
18873 "void main(){\n"
18874 " color = vec4(1);\n"
18875 "}\n";
18876
18877 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18878 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18879
18880 VkPipelineObj pipe(m_device);
18881 pipe.AddColorAttachment();
18882 pipe.AddShader(&vs);
18883 pipe.AddShader(&fs);
18884
18885 pipe.AddVertexInputBindings(&input_binding, 1);
18886 pipe.AddVertexInputAttribs(input_attribs, 3);
18887
18888 VkDescriptorSetObj descriptorSet(m_device);
18889 descriptorSet.AppendDummy();
18890 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18891
18892 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18893
18894 m_errorMonitor->VerifyNotFound();
18895}
18896
18897TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18898 m_errorMonitor->ExpectSuccess();
18899
18900 ASSERT_NO_FATAL_FAILURE(InitState());
18901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18902
18903 char const *vsSource = "#version 450\n"
18904 "out gl_PerVertex {\n"
18905 " vec4 gl_Position;\n"
18906 "};\n"
18907 "void main(){\n"
18908 " gl_Position = vec4(0);\n"
18909 "}\n";
18910 char const *fsSource = "#version 450\n"
18911 "\n"
18912 "layout(location=0) out vec4 color;\n"
18913 "void main(){\n"
18914 " color = vec4(1);\n"
18915 "}\n";
18916
18917 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18918 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18919
18920 VkPipelineObj pipe(m_device);
18921 pipe.AddColorAttachment();
18922 pipe.AddShader(&vs);
18923 pipe.AddShader(&fs);
18924
18925 VkDescriptorSetObj descriptorSet(m_device);
18926 descriptorSet.AppendDummy();
18927 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18928
18929 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18930
18931 m_errorMonitor->VerifyNotFound();
18932}
18933
18934TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18935 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18936 "set out in 14.1.3: fundamental type must match, and producer side must "
18937 "have at least as many components");
18938 m_errorMonitor->ExpectSuccess();
18939
18940 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18941
18942 ASSERT_NO_FATAL_FAILURE(InitState());
18943 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18944
18945 char const *vsSource = "#version 450\n"
18946 "out gl_PerVertex {\n"
18947 " vec4 gl_Position;\n"
18948 "};\n"
18949 "layout(location=0) out vec3 x;\n"
18950 "layout(location=1) out ivec3 y;\n"
18951 "layout(location=2) out vec3 z;\n"
18952 "void main(){\n"
18953 " gl_Position = vec4(0);\n"
18954 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18955 "}\n";
18956 char const *fsSource = "#version 450\n"
18957 "\n"
18958 "layout(location=0) out vec4 color;\n"
18959 "layout(location=0) in float x;\n"
18960 "layout(location=1) flat in int y;\n"
18961 "layout(location=2) in vec2 z;\n"
18962 "void main(){\n"
18963 " color = vec4(1 + x + y + z.x);\n"
18964 "}\n";
18965
18966 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18967 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18968
18969 VkPipelineObj pipe(m_device);
18970 pipe.AddColorAttachment();
18971 pipe.AddShader(&vs);
18972 pipe.AddShader(&fs);
18973
18974 VkDescriptorSetObj descriptorSet(m_device);
18975 descriptorSet.AppendDummy();
18976 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18977
18978 VkResult err = VK_SUCCESS;
18979 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18980 ASSERT_VK_SUCCESS(err);
18981
18982 m_errorMonitor->VerifyNotFound();
18983}
18984
18985TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18986 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18987 "passed between the TCS and TES stages");
18988 m_errorMonitor->ExpectSuccess();
18989
18990 ASSERT_NO_FATAL_FAILURE(InitState());
18991 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18992
18993 if (!m_device->phy().features().tessellationShader) {
18994 printf("Device does not support tessellation shaders; skipped.\n");
18995 return;
18996 }
18997
18998 char const *vsSource = "#version 450\n"
18999 "void main(){}\n";
19000 char const *tcsSource = "#version 450\n"
19001 "layout(location=0) out int x[];\n"
19002 "layout(vertices=3) out;\n"
19003 "void main(){\n"
19004 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19005 " gl_TessLevelInner[0] = 1;\n"
19006 " x[gl_InvocationID] = gl_InvocationID;\n"
19007 "}\n";
19008 char const *tesSource = "#version 450\n"
19009 "layout(triangles, equal_spacing, cw) in;\n"
19010 "layout(location=0) in int x[];\n"
19011 "out gl_PerVertex { vec4 gl_Position; };\n"
19012 "void main(){\n"
19013 " gl_Position.xyz = gl_TessCoord;\n"
19014 " gl_Position.w = x[0] + x[1] + x[2];\n"
19015 "}\n";
19016 char const *fsSource = "#version 450\n"
19017 "layout(location=0) out vec4 color;\n"
19018 "void main(){\n"
19019 " color = vec4(1);\n"
19020 "}\n";
19021
19022 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19023 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19024 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19025 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19026
19027 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19028 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19029
19030 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19031
19032 VkPipelineObj pipe(m_device);
19033 pipe.SetInputAssembly(&iasci);
19034 pipe.SetTessellation(&tsci);
19035 pipe.AddColorAttachment();
19036 pipe.AddShader(&vs);
19037 pipe.AddShader(&tcs);
19038 pipe.AddShader(&tes);
19039 pipe.AddShader(&fs);
19040
19041 VkDescriptorSetObj descriptorSet(m_device);
19042 descriptorSet.AppendDummy();
19043 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19044
19045 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19046
19047 m_errorMonitor->VerifyNotFound();
19048}
19049
19050TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19051 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19052 "interface block passed into the geometry shader. This "
19053 "is interesting because the 'extra' array level is not "
19054 "present on the member type, but on the block instance.");
19055 m_errorMonitor->ExpectSuccess();
19056
19057 ASSERT_NO_FATAL_FAILURE(InitState());
19058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19059
19060 if (!m_device->phy().features().geometryShader) {
19061 printf("Device does not support geometry shaders; skipped.\n");
19062 return;
19063 }
19064
19065 char const *vsSource = "#version 450\n"
19066 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19067 "void main(){\n"
19068 " vs_out.x = vec4(1);\n"
19069 "}\n";
19070 char const *gsSource = "#version 450\n"
19071 "layout(triangles) in;\n"
19072 "layout(triangle_strip, max_vertices=3) out;\n"
19073 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19074 "out gl_PerVertex { vec4 gl_Position; };\n"
19075 "void main() {\n"
19076 " gl_Position = gs_in[0].x;\n"
19077 " EmitVertex();\n"
19078 "}\n";
19079 char const *fsSource = "#version 450\n"
19080 "layout(location=0) out vec4 color;\n"
19081 "void main(){\n"
19082 " color = vec4(1);\n"
19083 "}\n";
19084
19085 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19086 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19087 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19088
19089 VkPipelineObj pipe(m_device);
19090 pipe.AddColorAttachment();
19091 pipe.AddShader(&vs);
19092 pipe.AddShader(&gs);
19093 pipe.AddShader(&fs);
19094
19095 VkDescriptorSetObj descriptorSet(m_device);
19096 descriptorSet.AppendDummy();
19097 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19098
19099 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19100
19101 m_errorMonitor->VerifyNotFound();
19102}
19103
19104TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19105 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19106 "attributes. This is interesting because they consume multiple "
19107 "locations.");
19108 m_errorMonitor->ExpectSuccess();
19109
19110 ASSERT_NO_FATAL_FAILURE(InitState());
19111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19112
19113 if (!m_device->phy().features().shaderFloat64) {
19114 printf("Device does not support 64bit vertex attributes; skipped.\n");
19115 return;
19116 }
19117
19118 VkVertexInputBindingDescription input_bindings[1];
19119 memset(input_bindings, 0, sizeof(input_bindings));
19120
19121 VkVertexInputAttributeDescription input_attribs[4];
19122 memset(input_attribs, 0, sizeof(input_attribs));
19123 input_attribs[0].location = 0;
19124 input_attribs[0].offset = 0;
19125 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19126 input_attribs[1].location = 2;
19127 input_attribs[1].offset = 32;
19128 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19129 input_attribs[2].location = 4;
19130 input_attribs[2].offset = 64;
19131 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19132 input_attribs[3].location = 6;
19133 input_attribs[3].offset = 96;
19134 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19135
19136 char const *vsSource = "#version 450\n"
19137 "\n"
19138 "layout(location=0) in dmat4 x;\n"
19139 "out gl_PerVertex {\n"
19140 " vec4 gl_Position;\n"
19141 "};\n"
19142 "void main(){\n"
19143 " gl_Position = vec4(x[0][0]);\n"
19144 "}\n";
19145 char const *fsSource = "#version 450\n"
19146 "\n"
19147 "layout(location=0) out vec4 color;\n"
19148 "void main(){\n"
19149 " color = vec4(1);\n"
19150 "}\n";
19151
19152 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19153 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19154
19155 VkPipelineObj pipe(m_device);
19156 pipe.AddColorAttachment();
19157 pipe.AddShader(&vs);
19158 pipe.AddShader(&fs);
19159
19160 pipe.AddVertexInputBindings(input_bindings, 1);
19161 pipe.AddVertexInputAttribs(input_attribs, 4);
19162
19163 VkDescriptorSetObj descriptorSet(m_device);
19164 descriptorSet.AppendDummy();
19165 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19166
19167 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19168
19169 m_errorMonitor->VerifyNotFound();
19170}
19171
19172TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19173 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19174 m_errorMonitor->ExpectSuccess();
19175
19176 ASSERT_NO_FATAL_FAILURE(InitState());
19177
19178 char const *vsSource = "#version 450\n"
19179 "\n"
19180 "out gl_PerVertex {\n"
19181 " vec4 gl_Position;\n"
19182 "};\n"
19183 "void main(){\n"
19184 " gl_Position = vec4(1);\n"
19185 "}\n";
19186 char const *fsSource = "#version 450\n"
19187 "\n"
19188 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19189 "layout(location=0) out vec4 color;\n"
19190 "void main() {\n"
19191 " color = subpassLoad(x);\n"
19192 "}\n";
19193
19194 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19195 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19196
19197 VkPipelineObj pipe(m_device);
19198 pipe.AddShader(&vs);
19199 pipe.AddShader(&fs);
19200 pipe.AddColorAttachment();
19201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19202
19203 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19204 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19205 VkDescriptorSetLayout dsl;
19206 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19207 ASSERT_VK_SUCCESS(err);
19208
19209 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19210 VkPipelineLayout pl;
19211 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19212 ASSERT_VK_SUCCESS(err);
19213
19214 VkAttachmentDescription descs[2] = {
19215 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19216 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19217 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19218 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19219 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19220 };
19221 VkAttachmentReference color = {
19222 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19223 };
19224 VkAttachmentReference input = {
19225 1, VK_IMAGE_LAYOUT_GENERAL,
19226 };
19227
19228 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19229
19230 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19231 VkRenderPass rp;
19232 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19233 ASSERT_VK_SUCCESS(err);
19234
19235 // should be OK. would go wrong here if it's going to...
19236 pipe.CreateVKPipeline(pl, rp);
19237
19238 m_errorMonitor->VerifyNotFound();
19239
19240 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19241 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19242 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19243}
19244
19245TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19246 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19247 "descriptor-backed resource which is not provided, but the shader does not "
19248 "statically use it. This is interesting because it requires compute pipelines "
19249 "to have a proper descriptor use walk, which they didn't for some time.");
19250 m_errorMonitor->ExpectSuccess();
19251
19252 ASSERT_NO_FATAL_FAILURE(InitState());
19253
19254 char const *csSource = "#version 450\n"
19255 "\n"
19256 "layout(local_size_x=1) in;\n"
19257 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19258 "void main(){\n"
19259 " // x is not used.\n"
19260 "}\n";
19261
19262 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19263
19264 VkDescriptorSetObj descriptorSet(m_device);
19265 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19266
19267 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19268 nullptr,
19269 0,
19270 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19271 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19272 descriptorSet.GetPipelineLayout(),
19273 VK_NULL_HANDLE,
19274 -1 };
19275
19276 VkPipeline pipe;
19277 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19278
19279 m_errorMonitor->VerifyNotFound();
19280
19281 if (err == VK_SUCCESS) {
19282 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19283 }
19284}
19285
19286TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19287 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19288 "sampler portion of a combined image + sampler");
19289 m_errorMonitor->ExpectSuccess();
19290
19291 ASSERT_NO_FATAL_FAILURE(InitState());
19292
19293 VkDescriptorSetLayoutBinding bindings[] = {
19294 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19295 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19296 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19297 };
19298 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19299 VkDescriptorSetLayout dsl;
19300 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19301 ASSERT_VK_SUCCESS(err);
19302
19303 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19304 VkPipelineLayout pl;
19305 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19306 ASSERT_VK_SUCCESS(err);
19307
19308 char const *csSource = "#version 450\n"
19309 "\n"
19310 "layout(local_size_x=1) in;\n"
19311 "layout(set=0, binding=0) uniform sampler s;\n"
19312 "layout(set=0, binding=1) uniform texture2D t;\n"
19313 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19314 "void main() {\n"
19315 " x = texture(sampler2D(t, s), vec2(0));\n"
19316 "}\n";
19317 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19318
19319 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19320 nullptr,
19321 0,
19322 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19323 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19324 pl,
19325 VK_NULL_HANDLE,
19326 -1 };
19327
19328 VkPipeline pipe;
19329 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19330
19331 m_errorMonitor->VerifyNotFound();
19332
19333 if (err == VK_SUCCESS) {
19334 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19335 }
19336
19337 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19338 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19339}
19340
19341TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19342 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19343 "image portion of a combined image + sampler");
19344 m_errorMonitor->ExpectSuccess();
19345
19346 ASSERT_NO_FATAL_FAILURE(InitState());
19347
19348 VkDescriptorSetLayoutBinding bindings[] = {
19349 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19350 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19351 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19352 };
19353 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19354 VkDescriptorSetLayout dsl;
19355 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19356 ASSERT_VK_SUCCESS(err);
19357
19358 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19359 VkPipelineLayout pl;
19360 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19361 ASSERT_VK_SUCCESS(err);
19362
19363 char const *csSource = "#version 450\n"
19364 "\n"
19365 "layout(local_size_x=1) in;\n"
19366 "layout(set=0, binding=0) uniform texture2D t;\n"
19367 "layout(set=0, binding=1) uniform sampler s;\n"
19368 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19369 "void main() {\n"
19370 " x = texture(sampler2D(t, s), vec2(0));\n"
19371 "}\n";
19372 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19373
19374 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19375 nullptr,
19376 0,
19377 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19378 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19379 pl,
19380 VK_NULL_HANDLE,
19381 -1 };
19382
19383 VkPipeline pipe;
19384 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19385
19386 m_errorMonitor->VerifyNotFound();
19387
19388 if (err == VK_SUCCESS) {
19389 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19390 }
19391
19392 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19393 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19394}
19395
19396TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19397 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19398 "both the sampler and the image of a combined image+sampler "
19399 "but via separate variables");
19400 m_errorMonitor->ExpectSuccess();
19401
19402 ASSERT_NO_FATAL_FAILURE(InitState());
19403
19404 VkDescriptorSetLayoutBinding bindings[] = {
19405 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19406 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19407 };
19408 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19409 VkDescriptorSetLayout dsl;
19410 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19411 ASSERT_VK_SUCCESS(err);
19412
19413 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19414 VkPipelineLayout pl;
19415 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19416 ASSERT_VK_SUCCESS(err);
19417
19418 char const *csSource = "#version 450\n"
19419 "\n"
19420 "layout(local_size_x=1) in;\n"
19421 "layout(set=0, binding=0) uniform texture2D t;\n"
19422 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19423 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19424 "void main() {\n"
19425 " x = texture(sampler2D(t, s), vec2(0));\n"
19426 "}\n";
19427 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19428
19429 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19430 nullptr,
19431 0,
19432 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19433 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19434 pl,
19435 VK_NULL_HANDLE,
19436 -1 };
19437
19438 VkPipeline pipe;
19439 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19440
19441 m_errorMonitor->VerifyNotFound();
19442
19443 if (err == VK_SUCCESS) {
19444 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19445 }
19446
19447 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19448 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19449}
19450
19451TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19452 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19453
19454 ASSERT_NO_FATAL_FAILURE(InitState());
19455
19456 // Positive test to check parameter_validation and unique_objects support
19457 // for NV_dedicated_allocation
19458 uint32_t extension_count = 0;
19459 bool supports_nv_dedicated_allocation = false;
19460 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19461 ASSERT_VK_SUCCESS(err);
19462
19463 if (extension_count > 0) {
19464 std::vector<VkExtensionProperties> available_extensions(extension_count);
19465
19466 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19467 ASSERT_VK_SUCCESS(err);
19468
19469 for (const auto &extension_props : available_extensions) {
19470 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19471 supports_nv_dedicated_allocation = true;
19472 }
19473 }
19474 }
19475
19476 if (supports_nv_dedicated_allocation) {
19477 m_errorMonitor->ExpectSuccess();
19478
19479 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19480 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19481 dedicated_buffer_create_info.pNext = nullptr;
19482 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19483
19484 uint32_t queue_family_index = 0;
19485 VkBufferCreateInfo buffer_create_info = {};
19486 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19487 buffer_create_info.pNext = &dedicated_buffer_create_info;
19488 buffer_create_info.size = 1024;
19489 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19490 buffer_create_info.queueFamilyIndexCount = 1;
19491 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19492
19493 VkBuffer buffer;
19494 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19495 ASSERT_VK_SUCCESS(err);
19496
19497 VkMemoryRequirements memory_reqs;
19498 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19499
19500 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19501 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19502 dedicated_memory_info.pNext = nullptr;
19503 dedicated_memory_info.buffer = buffer;
19504 dedicated_memory_info.image = VK_NULL_HANDLE;
19505
19506 VkMemoryAllocateInfo memory_info = {};
19507 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19508 memory_info.pNext = &dedicated_memory_info;
19509 memory_info.allocationSize = memory_reqs.size;
19510
19511 bool pass;
19512 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19513 ASSERT_TRUE(pass);
19514
19515 VkDeviceMemory buffer_memory;
19516 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19517 ASSERT_VK_SUCCESS(err);
19518
19519 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19520 ASSERT_VK_SUCCESS(err);
19521
19522 vkDestroyBuffer(m_device->device(), buffer, NULL);
19523 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19524
19525 m_errorMonitor->VerifyNotFound();
19526 }
19527}
19528
19529TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19530 VkResult err;
19531
19532 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19533
19534 ASSERT_NO_FATAL_FAILURE(InitState());
19535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19536
19537 std::vector<const char *> device_extension_names;
19538 auto features = m_device->phy().features();
19539 // Artificially disable support for non-solid fill modes
19540 features.fillModeNonSolid = false;
19541 // The sacrificial device object
19542 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19543
19544 VkRenderpassObj render_pass(&test_device);
19545
19546 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19547 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19548 pipeline_layout_ci.setLayoutCount = 0;
19549 pipeline_layout_ci.pSetLayouts = NULL;
19550
19551 VkPipelineLayout pipeline_layout;
19552 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19553 ASSERT_VK_SUCCESS(err);
19554
19555 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19556 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19557 rs_ci.pNext = nullptr;
19558 rs_ci.lineWidth = 1.0f;
19559 rs_ci.rasterizerDiscardEnable = true;
19560
19561 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19562 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19563
19564 // Set polygonMode=FILL. No error is expected
19565 m_errorMonitor->ExpectSuccess();
19566 {
19567 VkPipelineObj pipe(&test_device);
19568 pipe.AddShader(&vs);
19569 pipe.AddShader(&fs);
19570 pipe.AddColorAttachment();
19571 // Set polygonMode to a good value
19572 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19573 pipe.SetRasterization(&rs_ci);
19574 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19575 }
19576 m_errorMonitor->VerifyNotFound();
19577
19578 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19579}
19580
19581TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19582 VkResult err;
19583 ASSERT_NO_FATAL_FAILURE(InitState());
19584 ASSERT_NO_FATAL_FAILURE(InitViewport());
19585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19586
19587 VkPipelineLayout pipeline_layout;
19588 VkPushConstantRange pc_range = {};
19589 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19590 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19591 pipeline_layout_ci.pushConstantRangeCount = 1;
19592 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19593
19594 //
19595 // Check for invalid push constant ranges in pipeline layouts.
19596 //
19597 struct PipelineLayoutTestCase {
19598 VkPushConstantRange const range;
19599 char const *msg;
19600 };
19601
19602 // Check for overlapping ranges
19603 const uint32_t ranges_per_test = 5;
19604 struct OverlappingRangeTestCase {
19605 VkPushConstantRange const ranges[ranges_per_test];
19606 char const *msg;
19607 };
19608
19609 // Run some positive tests to make sure overlap checking in the layer is OK
19610 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19611 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19612 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19613 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19614 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19615 "" },
19616 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19617 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19618 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19619 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19620 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19621 "" } } };
19622 for (const auto &iter : overlapping_range_tests_pos) {
19623 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19624 m_errorMonitor->ExpectSuccess();
19625 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19626 m_errorMonitor->VerifyNotFound();
19627 if (VK_SUCCESS == err) {
19628 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19629 }
19630 }
19631
19632 //
19633 // CmdPushConstants tests
19634 //
19635 const uint8_t dummy_values[100] = {};
19636
19637 BeginCommandBuffer();
19638
19639 // positive overlapping range tests with cmd
19640 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19641 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19642 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19643 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19644 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19645 } };
19646
19647 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19648 const VkPushConstantRange pc_range4[] = {
19649 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19650 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19651 };
19652
19653 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19654 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19655 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19656 ASSERT_VK_SUCCESS(err);
19657 for (const auto &iter : cmd_overlap_tests_pos) {
19658 m_errorMonitor->ExpectSuccess();
19659 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19660 iter.range.size, dummy_values);
19661 m_errorMonitor->VerifyNotFound();
19662 }
19663 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19664
19665 EndCommandBuffer();
19666}
19667
19668
19669
19670
19671
19672
19673
19674#if 0 // A few devices have issues with this test so disabling for now
19675TEST_F(VkPositiveLayerTest, LongFenceChain)
19676{
19677 m_errorMonitor->ExpectSuccess();
19678
19679 ASSERT_NO_FATAL_FAILURE(InitState());
19680 VkResult err;
19681
19682 std::vector<VkFence> fences;
19683
19684 const int chainLength = 32768;
19685
19686 for (int i = 0; i < chainLength; i++) {
19687 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19688 VkFence fence;
19689 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19690 ASSERT_VK_SUCCESS(err);
19691
19692 fences.push_back(fence);
19693
19694 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19695 0, nullptr, 0, nullptr };
19696 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19697 ASSERT_VK_SUCCESS(err);
19698
19699 }
19700
19701 // BOOM, stack overflow.
19702 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19703
19704 for (auto fence : fences)
19705 vkDestroyFence(m_device->device(), fence, nullptr);
19706
19707 m_errorMonitor->VerifyNotFound();
19708}
19709#endif
19710
19711
Cody Northrop1242dfd2016-07-13 17:24:59 -060019712#if defined(ANDROID) && defined(VALIDATION_APK)
19713static bool initialized = false;
19714static bool active = false;
19715
19716// Convert Intents to argv
19717// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019718std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019719 std::vector<std::string> args;
19720 JavaVM &vm = *app.activity->vm;
19721 JNIEnv *p_env;
19722 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19723 return args;
19724
19725 JNIEnv &env = *p_env;
19726 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019727 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019728 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019729 jmethodID get_string_extra_method =
19730 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019731 jvalue get_string_extra_args;
19732 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019733 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019734
19735 std::string args_str;
19736 if (extra_str) {
19737 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19738 args_str = extra_utf;
19739 env.ReleaseStringUTFChars(extra_str, extra_utf);
19740 env.DeleteLocalRef(extra_str);
19741 }
19742
19743 env.DeleteLocalRef(get_string_extra_args.l);
19744 env.DeleteLocalRef(intent);
19745 vm.DetachCurrentThread();
19746
19747 // split args_str
19748 std::stringstream ss(args_str);
19749 std::string arg;
19750 while (std::getline(ss, arg, ' ')) {
19751 if (!arg.empty())
19752 args.push_back(arg);
19753 }
19754
19755 return args;
19756}
19757
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019758static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019760static void processCommand(struct android_app *app, int32_t cmd) {
19761 switch (cmd) {
19762 case APP_CMD_INIT_WINDOW: {
19763 if (app->window) {
19764 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019765 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019766 break;
19767 }
19768 case APP_CMD_GAINED_FOCUS: {
19769 active = true;
19770 break;
19771 }
19772 case APP_CMD_LOST_FOCUS: {
19773 active = false;
19774 break;
19775 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019776 }
19777}
19778
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019779void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019780 app_dummy();
19781
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019782 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019783
19784 int vulkanSupport = InitVulkan();
19785 if (vulkanSupport == 0) {
19786 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19787 return;
19788 }
19789
19790 app->onAppCmd = processCommand;
19791 app->onInputEvent = processInput;
19792
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019793 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019794 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019795 struct android_poll_source *source;
19796 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019797 if (source) {
19798 source->process(app, source);
19799 }
19800
19801 if (app->destroyRequested != 0) {
19802 VkTestFramework::Finish();
19803 return;
19804 }
19805 }
19806
19807 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019808 // Use the following key to send arguments to gtest, i.e.
19809 // --es args "--gtest_filter=-VkLayerTest.foo"
19810 const char key[] = "args";
19811 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019813 std::string filter = "";
19814 if (args.size() > 0) {
19815 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19816 filter += args[0];
19817 } else {
19818 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19819 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019821 int argc = 2;
19822 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19823 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019825 // Route output to files until we can override the gtest output
19826 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19827 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019829 ::testing::InitGoogleTest(&argc, argv);
19830 VkTestFramework::InitArgs(&argc, argv);
19831 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019832
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019833 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019835 if (result != 0) {
19836 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19837 } else {
19838 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19839 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019840
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019841 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019842
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019843 fclose(stdout);
19844 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019846 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019847
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019848 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019849 }
19850 }
19851}
19852#endif
19853
Tony Barbour300a6082015-04-07 13:44:53 -060019854int main(int argc, char **argv) {
19855 int result;
19856
Cody Northrop8e54a402016-03-08 22:25:52 -070019857#ifdef ANDROID
19858 int vulkanSupport = InitVulkan();
19859 if (vulkanSupport == 0)
19860 return 1;
19861#endif
19862
Tony Barbour300a6082015-04-07 13:44:53 -060019863 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019864 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019865
19866 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19867
19868 result = RUN_ALL_TESTS();
19869
Tony Barbour6918cd52015-04-09 12:58:51 -060019870 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019871 return result;
19872}