blob: 8c717132b34527a6554e92edadb3f112ed733829 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
Tony Barbourae58dba2016-12-13 16:30:36 -0700175 found_expected = true;
176 m_msgFound = VK_TRUE;
177 m_failure_message_strings.insert(errorString);
Karl Schultz05cc4e32016-10-12 13:25:23 -0600178 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600179 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600180 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600181 m_msgFound = VK_TRUE;
182 result = VK_TRUE;
183 // We only want one match for each expected error so remove from set here
184 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600185 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600186 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600187 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600188 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600189 for (auto desired_id : m_desired_message_ids) {
190 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
191 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
192 // Return true to avoid calling layers/driver with this error.
193 result = VK_TRUE;
194 } else if (desired_id == message_code) {
195 // Double-check that the string matches the error enum
196 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
197 found_expected = true;
198 result = VK_TRUE;
199 m_msgFound = VK_TRUE;
200 m_desired_message_ids.erase(desired_id);
201 break;
202 } else {
203 // Treat this message as a regular unexpected error, but print a warning jic
204 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
205 errorString.c_str(), desired_id, validation_error_map[desired_id]);
206 }
207 }
208 }
209
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600210 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200211 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600212 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600213 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600214 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600215 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600216 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217
Karl Schultz6addd812016-02-02 17:17:23 -0700218 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600219
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600220 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
221
Karl Schultz6addd812016-02-02 17:17:23 -0700222 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600223
Karl Schultz6addd812016-02-02 17:17:23 -0700224 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600225
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600227 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600228 if (otherMsgs.size()) {
229 cout << "Other error messages logged for this test were:" << endl;
230 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
231 cout << " " << *iter << endl;
232 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600233 }
234 }
235
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600236 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200237
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600238 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
239 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
240 m_msgFlags = message_flag_mask;
241 // Match ANY message matching specified type
242 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200243 }
244
245 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600246 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200247 if (!DesiredMsgFound()) {
248 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600249 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600250 FAIL() << "Did not receive expected error '" << desired_msg << "'";
251 }
Tony Barbour59b42282016-11-03 13:31:28 -0600252 for (auto desired_id : m_desired_message_ids) {
253 FAIL() << "Did not receive expected error '" << desired_id << "'";
254 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200255 }
256 }
257
258 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600259 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200260 if (DesiredMsgFound()) {
261 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600262 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600263 FAIL() << "Expected to succeed but got error: " << msg;
264 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200265 }
266 }
267
Karl Schultz6addd812016-02-02 17:17:23 -0700268 private:
269 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600270 std::unordered_set<uint32_t>m_desired_message_ids;
271 std::unordered_set<string> m_desired_message_strings;
272 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700273 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600274 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700275 bool *m_bailout;
276 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600277};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500278
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600279static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
280 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
281 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600282 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
283 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600284 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600285 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600286 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600287}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500288
Karl Schultz6addd812016-02-02 17:17:23 -0700289class VkLayerTest : public VkRenderFramework {
290 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800291 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
292 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
294 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700295 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600296 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
297 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700298 }
Tony Barbour300a6082015-04-07 13:44:53 -0600299
Tony Barbourfe3351b2015-07-28 10:17:20 -0600300 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600301 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800302 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
304 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700305 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600306 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700307 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600308 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700309 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600310 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
311 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
312 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700313 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
314 }
315 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
316 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
317 }
318
319 protected:
320 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600321 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600322
323 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600324 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600325 std::vector<const char *> instance_extension_names;
326 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600327
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700328 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600329 /*
330 * Since CreateDbgMsgCallback is an instance level extension call
331 * any extension / layer that utilizes that feature also needs
332 * to be enabled at create instance time.
333 */
Karl Schultz6addd812016-02-02 17:17:23 -0700334 // Use Threading layer first to protect others from
335 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700336 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600337 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800338 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700339 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800340 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600341 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700342 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600343
Ian Elliott2c1daf52016-05-12 09:41:46 -0600344 if (m_enableWSI) {
345 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
346 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
347#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
348#if defined(VK_USE_PLATFORM_ANDROID_KHR)
349 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_ANDROID_KHR
351#if defined(VK_USE_PLATFORM_MIR_KHR)
352 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_MIR_KHR
354#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
355 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WAYLAND_KHR
357#if defined(VK_USE_PLATFORM_WIN32_KHR)
358 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
359#endif // VK_USE_PLATFORM_WIN32_KHR
360#endif // NEED_TO_TEST_THIS_ON_PLATFORM
361#if defined(VK_USE_PLATFORM_XCB_KHR)
362 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
363#elif defined(VK_USE_PLATFORM_XLIB_KHR)
364 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
365#endif // VK_USE_PLATFORM_XLIB_KHR
366 }
367
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600368 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800370 this->app_info.pApplicationName = "layer_tests";
371 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600372 this->app_info.pEngineName = "unittest";
373 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600374 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600375
Tony Barbour15524c32015-04-29 17:34:29 -0600376 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600377 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600378 }
379
380 virtual void TearDown() {
381 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600382 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600383 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600384 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600385
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600386 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600387};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500388
Karl Schultz6addd812016-02-02 17:17:23 -0700389VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600390 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600391
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800392 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600393
394 /*
395 * For render test all drawing happens in a single render pass
396 * on a single command buffer.
397 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200398 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800399 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600400 }
401
402 return result;
403}
404
Karl Schultz6addd812016-02-02 17:17:23 -0700405VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600406 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600407
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200408 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200410 }
Tony Barbour300a6082015-04-07 13:44:53 -0600411
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800412 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600413
414 return result;
415}
416
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600417void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418 // Create identity matrix
419 int i;
420 struct vktriangle_vs_uniform data;
421
422 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700423 glm::mat4 View = glm::mat4(1.0f);
424 glm::mat4 Model = glm::mat4(1.0f);
425 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500426 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700427 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500428
429 memcpy(&data.mvp, &MVP[0][0], matrixSize);
430
Karl Schultz6addd812016-02-02 17:17:23 -0700431 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600432 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 };
434
Karl Schultz6addd812016-02-02 17:17:23 -0700435 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500436 data.position[i][0] = tri_data[i].posX;
437 data.position[i][1] = tri_data[i].posY;
438 data.position[i][2] = tri_data[i].posZ;
439 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700440 data.color[i][0] = tri_data[i].r;
441 data.color[i][1] = tri_data[i].g;
442 data.color[i][2] = tri_data[i].b;
443 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444 }
445
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500446 ASSERT_NO_FATAL_FAILURE(InitViewport());
447
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200448 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
449 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
Karl Schultz6addd812016-02-02 17:17:23 -0700451 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600452 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453
454 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800455 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500456 pipelineobj.AddShader(&vs);
457 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600458 if (failMask & BsoFailLineWidth) {
459 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600460 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600461 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600462 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
463 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600464 }
465 if (failMask & BsoFailDepthBias) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600470 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600471 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700473 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700474 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600475 if (failMask & BsoFailViewport) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
477 }
478 if (failMask & BsoFailScissor) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
480 }
481 if (failMask & BsoFailBlend) {
482 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600483 VkPipelineColorBlendAttachmentState att_state = {};
484 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
485 att_state.blendEnable = VK_TRUE;
486 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600487 }
488 if (failMask & BsoFailDepthBounds) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
490 }
491 if (failMask & BsoFailStencilReadMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
493 }
494 if (failMask & BsoFailStencilWriteMask) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
496 }
497 if (failMask & BsoFailStencilReference) {
498 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
499 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600502 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600505 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500506
Tony Barbourfe3351b2015-07-28 10:17:20 -0600507 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508
509 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600510 if (failMask & BsoFailIndexBuffer) {
511 // Use DrawIndexed w/o an index buffer bound
512 DrawIndexed(3, 1, 0, 0, 0);
513 } else {
514 Draw(3, 1, 0, 0);
515 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
Mark Muellerd4914412016-06-13 17:52:06 -0600517 if (failMask & BsoFailCmdClearAttachments) {
518 VkClearAttachment color_attachment = {};
519 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
520 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
521 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
522
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600523 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600524 }
525
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500526 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600527 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500528
Tony Barbourfe3351b2015-07-28 10:17:20 -0600529 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500530}
531
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
533 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500536 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600537 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538 }
539
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800540 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700541 // Make sure depthWriteEnable is set so that Depth fail test will work
542 // correctly
543 // Make sure stencilTestEnable is set so that Stencil fail test will work
544 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600545 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800546 stencil.failOp = VK_STENCIL_OP_KEEP;
547 stencil.passOp = VK_STENCIL_OP_KEEP;
548 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
549 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600550
551 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
552 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600553 ds_ci.pNext = NULL;
554 ds_ci.depthTestEnable = VK_FALSE;
555 ds_ci.depthWriteEnable = VK_TRUE;
556 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
557 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600558 if (failMask & BsoFailDepthBounds) {
559 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600560 ds_ci.maxDepthBounds = 0.0f;
561 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600562 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600563 ds_ci.stencilTestEnable = VK_TRUE;
564 ds_ci.front = stencil;
565 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600566
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600567 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600568 pipelineobj.SetViewport(m_viewports);
569 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600571 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600572 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800573 commandBuffer->BindPipeline(pipelineobj);
574 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500575}
576
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600577class VkPositiveLayerTest : public VkLayerTest {
578 public:
579 protected:
580};
581
Ian Elliott2c1daf52016-05-12 09:41:46 -0600582class VkWsiEnabledLayerTest : public VkLayerTest {
583 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600584 protected:
585 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600586};
587
Mark Muellerdfe37552016-07-07 14:47:42 -0600588class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600589 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600590 enum eTestEnFlags {
591 eDoubleDelete,
592 eInvalidDeviceOffset,
593 eInvalidMemoryOffset,
594 eBindNullBuffer,
595 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600596 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600597 };
598
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600599 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600600
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
602 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600603 return true;
604 }
605 VkDeviceSize offset_limit = 0;
606 if (eInvalidMemoryOffset == aTestFlag) {
607 VkBuffer vulkanBuffer;
608 VkBufferCreateInfo buffer_create_info = {};
609 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
610 buffer_create_info.size = 32;
611 buffer_create_info.usage = aBufferUsage;
612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600614 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600615
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600617 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
618 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
620 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600621 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600622 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600623 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 }
626 if (eOffsetAlignment < offset_limit) {
627 return true;
628 }
629 return false;
630 }
631
632 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
634 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600635
636 if (eBindNullBuffer == aTestFlag) {
637 VulkanMemory = 0;
638 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
639 } else {
640 VkBufferCreateInfo buffer_create_info = {};
641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
642 buffer_create_info.size = 32;
643 buffer_create_info.usage = aBufferUsage;
644
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600645 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600646
647 CreateCurrent = true;
648
649 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600650 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600651
652 VkMemoryAllocateInfo memory_allocate_info = {};
653 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
654 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600655 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
656 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 if (!pass) {
658 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
659 return;
660 }
661
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600663 AllocateCurrent = true;
664 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600665 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
666 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600667 BoundCurrent = true;
668
669 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
670 }
671 }
672
673 ~VkBufferTest() {
674 if (CreateCurrent) {
675 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
676 }
677 if (AllocateCurrent) {
678 if (InvalidDeleteEn) {
679 union {
680 VkDeviceMemory device_memory;
681 unsigned long long index_access;
682 } bad_index;
683
684 bad_index.device_memory = VulkanMemory;
685 bad_index.index_access++;
686
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600687 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600688 }
689 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
690 }
691 }
692
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600693 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600694
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600695 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600696
697 void TestDoubleDestroy() {
698 // Destroy the buffer but leave the flag set, which will cause
699 // the buffer to be destroyed again in the destructor.
700 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
701 }
702
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600703 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600704 bool AllocateCurrent;
705 bool BoundCurrent;
706 bool CreateCurrent;
707 bool InvalidDeleteEn;
708
709 VkBuffer VulkanBuffer;
710 VkDevice VulkanDevice;
711 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600712};
713
714class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 public:
716 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600717 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600720 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
721 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600722 BindIdGenerator++; // NB: This can wrap w/misuse
723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
725 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600726
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600727 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
728 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
729 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
730 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
731 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600732
733 unsigned i = 0;
734 do {
735 VertexInputAttributeDescription[i].binding = BindId;
736 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
738 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600739 i++;
740 } while (AttributeCount < i);
741
742 i = 0;
743 do {
744 VertexInputBindingDescription[i].binding = BindId;
745 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600746 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600747 i++;
748 } while (BindingCount < i);
749 }
750
751 ~VkVerticesObj() {
752 if (VertexInputAttributeDescription) {
753 delete[] VertexInputAttributeDescription;
754 }
755 if (VertexInputBindingDescription) {
756 delete[] VertexInputBindingDescription;
757 }
758 }
759
760 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600761 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
762 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600763 return true;
764 }
765
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600766 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600767 VkDeviceSize *offsetList;
768 unsigned offsetCount;
769
770 if (aOffsetCount) {
771 offsetList = aOffsetList;
772 offsetCount = aOffsetCount;
773 } else {
774 offsetList = new VkDeviceSize[1]();
775 offsetCount = 1;
776 }
777
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600778 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600779 BoundCurrent = true;
780
781 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600782 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600783 }
784 }
785
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600786 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600787 static uint32_t BindIdGenerator;
788
789 bool BoundCurrent;
790 unsigned AttributeCount;
791 unsigned BindingCount;
792 uint32_t BindId;
793
794 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
795 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
796 VkVertexInputBindingDescription *VertexInputBindingDescription;
797 VkConstantBufferObj VulkanMemoryBuffer;
798};
799
800uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500801// ********************************************************************************************************************
802// ********************************************************************************************************************
803// ********************************************************************************************************************
804// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600805#if PARAMETER_VALIDATION_TESTS
806TEST_F(VkLayerTest, RequiredParameter) {
807 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
808 "pointer, array, and array count parameters");
809
810 ASSERT_NO_FATAL_FAILURE(InitState());
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600813 // Specify NULL for a pointer to a handle
814 // Expected to trigger an error with
815 // parameter_validation::validate_required_pointer
816 vkGetPhysicalDeviceFeatures(gpu(), NULL);
817 m_errorMonitor->VerifyFound();
818
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
820 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 // Specify NULL for pointer to array count
822 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600823 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 m_errorMonitor->VerifyFound();
825
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600827 // Specify 0 for a required array count
828 // Expected to trigger an error with parameter_validation::validate_array
829 VkViewport view_port = {};
830 m_commandBuffer->SetViewport(0, 0, &view_port);
831 m_errorMonitor->VerifyFound();
832
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 // Specify NULL for a required array
835 // Expected to trigger an error with parameter_validation::validate_array
836 m_commandBuffer->SetViewport(0, 1, NULL);
837 m_errorMonitor->VerifyFound();
838
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600840 // Specify VK_NULL_HANDLE for a required handle
841 // Expected to trigger an error with
842 // parameter_validation::validate_required_handle
843 vkUnmapMemory(device(), VK_NULL_HANDLE);
844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
847 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600848 // Specify VK_NULL_HANDLE for a required handle array entry
849 // Expected to trigger an error with
850 // parameter_validation::validate_required_handle_array
851 VkFence fence = VK_NULL_HANDLE;
852 vkResetFences(device(), 1, &fence);
853 m_errorMonitor->VerifyFound();
854
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600856 // Specify NULL for a required struct pointer
857 // Expected to trigger an error with
858 // parameter_validation::validate_struct_type
859 VkDeviceMemory memory = VK_NULL_HANDLE;
860 vkAllocateMemory(device(), NULL, NULL, &memory);
861 m_errorMonitor->VerifyFound();
862
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600864 // Specify 0 for a required VkFlags parameter
865 // Expected to trigger an error with parameter_validation::validate_flags
866 m_commandBuffer->SetStencilReference(0, 0);
867 m_errorMonitor->VerifyFound();
868
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600870 // Specify 0 for a required VkFlags array entry
871 // Expected to trigger an error with
872 // parameter_validation::validate_flags_array
873 VkSemaphore semaphore = VK_NULL_HANDLE;
874 VkPipelineStageFlags stageFlags = 0;
875 VkSubmitInfo submitInfo = {};
876 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
877 submitInfo.waitSemaphoreCount = 1;
878 submitInfo.pWaitSemaphores = &semaphore;
879 submitInfo.pWaitDstStageMask = &stageFlags;
880 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
881 m_errorMonitor->VerifyFound();
882}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600883
Dustin Gravesfce74c02016-05-10 11:42:58 -0600884TEST_F(VkLayerTest, ReservedParameter) {
885 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
886
887 ASSERT_NO_FATAL_FAILURE(InitState());
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600890 // Specify 0 for a reserved VkFlags parameter
891 // Expected to trigger an error with
892 // parameter_validation::validate_reserved_flags
893 VkEvent event_handle = VK_NULL_HANDLE;
894 VkEventCreateInfo event_info = {};
895 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
896 event_info.flags = 1;
897 vkCreateEvent(device(), &event_info, NULL, &event_handle);
898 m_errorMonitor->VerifyFound();
899}
900
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600901TEST_F(VkLayerTest, InvalidStructSType) {
902 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
903 "structure's sType field");
904
905 ASSERT_NO_FATAL_FAILURE(InitState());
906
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600908 // Zero struct memory, effectively setting sType to
909 // VK_STRUCTURE_TYPE_APPLICATION_INFO
910 // Expected to trigger an error with
911 // parameter_validation::validate_struct_type
912 VkMemoryAllocateInfo alloc_info = {};
913 VkDeviceMemory memory = VK_NULL_HANDLE;
914 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
915 m_errorMonitor->VerifyFound();
916
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600918 // Zero struct memory, effectively setting sType to
919 // VK_STRUCTURE_TYPE_APPLICATION_INFO
920 // Expected to trigger an error with
921 // parameter_validation::validate_struct_type_array
922 VkSubmitInfo submit_info = {};
923 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
924 m_errorMonitor->VerifyFound();
925}
926
927TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929
930 ASSERT_NO_FATAL_FAILURE(InitState());
931
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600933 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600934 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600935 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600936 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600937 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600938 // Zero-initialization will provide the correct sType
939 VkApplicationInfo app_info = {};
940 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
941 event_alloc_info.pNext = &app_info;
942 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
943 m_errorMonitor->VerifyFound();
944
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
946 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600947 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
948 // a function that has allowed pNext structure types and specify
949 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600950 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600951 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600952 VkMemoryAllocateInfo memory_alloc_info = {};
953 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
954 memory_alloc_info.pNext = &app_info;
955 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600956 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600957}
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600960 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600961
962 ASSERT_NO_FATAL_FAILURE(InitState());
963
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
965 "range of the core VkFormat "
966 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600967 // Specify an invalid VkFormat value
968 // Expected to trigger an error with
969 // parameter_validation::validate_ranged_enum
970 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 m_errorMonitor->VerifyFound();
973
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600975 // Specify an invalid VkFlags bitmask value
976 // Expected to trigger an error with parameter_validation::validate_flags
977 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600978 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
979 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 m_errorMonitor->VerifyFound();
981
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600983 // Specify an invalid VkFlags array entry
984 // Expected to trigger an error with
985 // parameter_validation::validate_flags_array
986 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600987 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600988 VkSubmitInfo submit_info = {};
989 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
990 submit_info.waitSemaphoreCount = 1;
991 submit_info.pWaitSemaphores = &semaphore;
992 submit_info.pWaitDstStageMask = &stage_flags;
993 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
994 m_errorMonitor->VerifyFound();
995
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600997 // Specify an invalid VkBool32 value
998 // Expected to trigger a warning with
999 // parameter_validation::validate_bool32
1000 VkSampler sampler = VK_NULL_HANDLE;
1001 VkSamplerCreateInfo sampler_info = {};
1002 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1003 sampler_info.pNext = NULL;
1004 sampler_info.magFilter = VK_FILTER_NEAREST;
1005 sampler_info.minFilter = VK_FILTER_NEAREST;
1006 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1007 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1008 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1009 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1010 sampler_info.mipLodBias = 1.0;
1011 sampler_info.maxAnisotropy = 1;
1012 sampler_info.compareEnable = VK_FALSE;
1013 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1014 sampler_info.minLod = 1.0;
1015 sampler_info.maxLod = 1.0;
1016 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1017 sampler_info.unnormalizedCoordinates = VK_FALSE;
1018 // Not VK_TRUE or VK_FALSE
1019 sampler_info.anisotropyEnable = 3;
1020 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1021 m_errorMonitor->VerifyFound();
1022}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001023
1024TEST_F(VkLayerTest, FailedReturnValue) {
1025 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1026
1027 ASSERT_NO_FATAL_FAILURE(InitState());
1028
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001029 // Find an unsupported image format
1030 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1031 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1032 VkFormat format = static_cast<VkFormat>(f);
1033 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001034 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001035 unsupported = format;
1036 break;
1037 }
1038 }
1039
1040 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1042 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001043 // Specify an unsupported VkFormat value to generate a
1044 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1045 // Expected to trigger a warning from
1046 // parameter_validation::validate_result
1047 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001048 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1049 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001050 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1051 m_errorMonitor->VerifyFound();
1052 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001053}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001054
1055TEST_F(VkLayerTest, UpdateBufferAlignment) {
1056 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001057 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001058
1059 ASSERT_NO_FATAL_FAILURE(InitState());
1060
1061 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1062 vk_testing::Buffer buffer;
1063 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1064
1065 BeginCommandBuffer();
1066 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001068 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1069 m_errorMonitor->VerifyFound();
1070
1071 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001073 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1074 m_errorMonitor->VerifyFound();
1075
1076 // Introduce failure by using dataSize that is < 0
1077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001078 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001079 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1080 m_errorMonitor->VerifyFound();
1081
1082 // Introduce failure by using dataSize that is > 65536
1083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 EndCommandBuffer();
1089}
1090
1091TEST_F(VkLayerTest, FillBufferAlignment) {
1092 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1093
1094 ASSERT_NO_FATAL_FAILURE(InitState());
1095
1096 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1097 vk_testing::Buffer buffer;
1098 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1099
1100 BeginCommandBuffer();
1101
1102 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001104 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1105 m_errorMonitor->VerifyFound();
1106
1107 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001109 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1110 m_errorMonitor->VerifyFound();
1111
1112 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001114 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1115 m_errorMonitor->VerifyFound();
1116
1117 EndCommandBuffer();
1118}
Dustin Graves40f35822016-06-23 11:12:53 -06001119
Cortd889ff92016-07-27 09:51:27 -07001120TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1121 VkResult err;
1122
1123 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001124 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001125
1126 ASSERT_NO_FATAL_FAILURE(InitState());
1127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1128
1129 std::vector<const char *> device_extension_names;
1130 auto features = m_device->phy().features();
1131 // Artificially disable support for non-solid fill modes
1132 features.fillModeNonSolid = false;
1133 // The sacrificial device object
1134 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1135
1136 VkRenderpassObj render_pass(&test_device);
1137
1138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1140 pipeline_layout_ci.setLayoutCount = 0;
1141 pipeline_layout_ci.pSetLayouts = NULL;
1142
1143 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001144 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001145 ASSERT_VK_SUCCESS(err);
1146
1147 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1148 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1149 rs_ci.pNext = nullptr;
1150 rs_ci.lineWidth = 1.0f;
1151 rs_ci.rasterizerDiscardEnable = true;
1152
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001153 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1154 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001155
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001156 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1158 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001159 {
1160 VkPipelineObj pipe(&test_device);
1161 pipe.AddShader(&vs);
1162 pipe.AddShader(&fs);
1163 pipe.AddColorAttachment();
1164 // Introduce failure by setting unsupported polygon mode
1165 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1166 pipe.SetRasterization(&rs_ci);
1167 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1168 }
1169 m_errorMonitor->VerifyFound();
1170
1171 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1173 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001174 {
1175 VkPipelineObj pipe(&test_device);
1176 pipe.AddShader(&vs);
1177 pipe.AddShader(&fs);
1178 pipe.AddColorAttachment();
1179 // Introduce failure by setting unsupported polygon mode
1180 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1181 pipe.SetRasterization(&rs_ci);
1182 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1183 }
1184 m_errorMonitor->VerifyFound();
1185
Cortd889ff92016-07-27 09:51:27 -07001186 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1187}
1188
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001189#endif // PARAMETER_VALIDATION_TESTS
1190
Tobin Ehlis0788f522015-05-26 16:11:58 -06001191#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001192#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001193TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001194{
1195 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001196 VkFenceCreateInfo fenceInfo = {};
1197 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1198 fenceInfo.pNext = NULL;
1199 fenceInfo.flags = 0;
1200
Mike Weiblencce7ec72016-10-17 19:33:05 -06001201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001202
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001203 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001204
1205 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1206 vk_testing::Buffer buffer;
1207 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001208
Tony Barbourfe3351b2015-07-28 10:17:20 -06001209 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001210 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001211 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001212
1213 testFence.init(*m_device, fenceInfo);
1214
1215 // Bypass framework since it does the waits automatically
1216 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001217 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001218 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1219 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001221 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001222 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001223 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001224 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001225 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001226 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001227
1228 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001229 ASSERT_VK_SUCCESS( err );
1230
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001231 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001232 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001233
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001234 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235}
1236
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001237TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001238{
1239 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001240 VkFenceCreateInfo fenceInfo = {};
1241 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1242 fenceInfo.pNext = NULL;
1243 fenceInfo.flags = 0;
1244
Mike Weiblencce7ec72016-10-17 19:33:05 -06001245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001246
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001247 ASSERT_NO_FATAL_FAILURE(InitState());
1248 ASSERT_NO_FATAL_FAILURE(InitViewport());
1249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1250
Tony Barbourfe3351b2015-07-28 10:17:20 -06001251 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001252 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001253 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001254
1255 testFence.init(*m_device, fenceInfo);
1256
1257 // Bypass framework since it does the waits automatically
1258 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001259 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001260 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1261 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001263 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001264 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001265 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001266 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001267 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001268 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001269
1270 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001271 ASSERT_VK_SUCCESS( err );
1272
Jon Ashburnf19916e2016-01-11 13:12:43 -07001273 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001274 VkCommandBufferBeginInfo info = {};
1275 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1276 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001277 info.renderPass = VK_NULL_HANDLE;
1278 info.subpass = 0;
1279 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001280 info.occlusionQueryEnable = VK_FALSE;
1281 info.queryFlags = 0;
1282 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001283
1284 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001285 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001286
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001288}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001289#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001290
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001291TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1292 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1293
1294 ASSERT_NO_FATAL_FAILURE(InitState());
1295
1296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1297 VkBuffer buffer;
1298 VkBufferCreateInfo buf_info = {};
1299 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1300 buf_info.pNext = NULL;
1301 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1302 buf_info.size = 2048;
1303 buf_info.queueFamilyIndexCount = 0;
1304 buf_info.pQueueFamilyIndices = NULL;
1305 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1306 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1307 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1308 m_errorMonitor->VerifyFound();
1309
1310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1311 VkImage image;
1312 VkImageCreateInfo image_create_info = {};
1313 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1314 image_create_info.pNext = NULL;
1315 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1316 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1317 image_create_info.extent.width = 512;
1318 image_create_info.extent.height = 64;
1319 image_create_info.extent.depth = 1;
1320 image_create_info.mipLevels = 1;
1321 image_create_info.arrayLayers = 1;
1322 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1323 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1324 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1325 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1326 image_create_info.queueFamilyIndexCount = 0;
1327 image_create_info.pQueueFamilyIndices = NULL;
1328 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1329 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1330 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1331 m_errorMonitor->VerifyFound();
1332}
1333
Tobin Ehlisf11be982016-05-11 13:52:53 -06001334TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1335 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1336 "buffer and image to memory such that they will alias.");
1337 VkResult err;
1338 bool pass;
1339 ASSERT_NO_FATAL_FAILURE(InitState());
1340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001342 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001343 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001344 VkDeviceMemory mem; // buffer will be bound first
1345 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001346 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001347
1348 VkBufferCreateInfo buf_info = {};
1349 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1350 buf_info.pNext = NULL;
1351 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1352 buf_info.size = 256;
1353 buf_info.queueFamilyIndexCount = 0;
1354 buf_info.pQueueFamilyIndices = NULL;
1355 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1356 buf_info.flags = 0;
1357 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1358 ASSERT_VK_SUCCESS(err);
1359
Tobin Ehlis077ded32016-05-12 17:39:13 -06001360 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001361
1362 VkImageCreateInfo image_create_info = {};
1363 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1364 image_create_info.pNext = NULL;
1365 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1366 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1367 image_create_info.extent.width = 64;
1368 image_create_info.extent.height = 64;
1369 image_create_info.extent.depth = 1;
1370 image_create_info.mipLevels = 1;
1371 image_create_info.arrayLayers = 1;
1372 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001373 // Image tiling must be optimal to trigger error when aliasing linear buffer
1374 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001375 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1376 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1377 image_create_info.queueFamilyIndexCount = 0;
1378 image_create_info.pQueueFamilyIndices = NULL;
1379 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1380 image_create_info.flags = 0;
1381
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1383 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001384 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1385 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001386
Tobin Ehlis077ded32016-05-12 17:39:13 -06001387 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1388
1389 VkMemoryAllocateInfo alloc_info = {};
1390 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1391 alloc_info.pNext = NULL;
1392 alloc_info.memoryTypeIndex = 0;
1393 // Ensure memory is big enough for both bindings
1394 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001395 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1396 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001397 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001398 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001399 vkDestroyImage(m_device->device(), image, NULL);
1400 return;
1401 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001402 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1403 ASSERT_VK_SUCCESS(err);
1404 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1405 ASSERT_VK_SUCCESS(err);
1406
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001408 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001409 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1410 m_errorMonitor->VerifyFound();
1411
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001412 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001413 // aliasing buffer2
1414 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1415 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001416 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1417 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001418 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001419 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001421 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001422 m_errorMonitor->VerifyFound();
1423
1424 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001425 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001426 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001427 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001428 vkFreeMemory(m_device->device(), mem, NULL);
1429 vkFreeMemory(m_device->device(), mem_img, NULL);
1430}
1431
Tobin Ehlis35372522016-05-12 08:32:31 -06001432TEST_F(VkLayerTest, InvalidMemoryMapping) {
1433 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1434 VkResult err;
1435 bool pass;
1436 ASSERT_NO_FATAL_FAILURE(InitState());
1437
1438 VkBuffer buffer;
1439 VkDeviceMemory mem;
1440 VkMemoryRequirements mem_reqs;
1441
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001442 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1443
Tobin Ehlis35372522016-05-12 08:32:31 -06001444 VkBufferCreateInfo buf_info = {};
1445 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1446 buf_info.pNext = NULL;
1447 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1448 buf_info.size = 256;
1449 buf_info.queueFamilyIndexCount = 0;
1450 buf_info.pQueueFamilyIndices = NULL;
1451 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1452 buf_info.flags = 0;
1453 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1454 ASSERT_VK_SUCCESS(err);
1455
1456 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1457 VkMemoryAllocateInfo alloc_info = {};
1458 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1459 alloc_info.pNext = NULL;
1460 alloc_info.memoryTypeIndex = 0;
1461
1462 // Ensure memory is big enough for both bindings
1463 static const VkDeviceSize allocation_size = 0x10000;
1464 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001465 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 -06001466 if (!pass) {
1467 vkDestroyBuffer(m_device->device(), buffer, NULL);
1468 return;
1469 }
1470 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1471 ASSERT_VK_SUCCESS(err);
1472
1473 uint8_t *pData;
1474 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001475 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 -06001476 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1477 m_errorMonitor->VerifyFound();
1478 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001479 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1482 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1483 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 m_errorMonitor->VerifyFound();
1485
1486 // Unmap the memory to avoid re-map error
1487 vkUnmapMemory(m_device->device(), mem);
1488 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1490 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1491 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001492 m_errorMonitor->VerifyFound();
1493 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1495 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001496 m_errorMonitor->VerifyFound();
1497 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001499 vkUnmapMemory(m_device->device(), mem);
1500 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001501
Tobin Ehlis35372522016-05-12 08:32:31 -06001502 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001503 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001504 ASSERT_VK_SUCCESS(err);
1505 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001506 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001507 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001508 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001510 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1511 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001512
Tobin Ehlis35372522016-05-12 08:32:31 -06001513 // Now flush range that oversteps mapped range
1514 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001515 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001516 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001517 mmr.offset = atom_size;
1518 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1520 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1521 m_errorMonitor->VerifyFound();
1522
1523 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1524 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001525 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001526 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001527 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001528 mmr.size = VK_WHOLE_SIZE;
1529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001530 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1531 m_errorMonitor->VerifyFound();
1532
Tony Barboure3975eb2016-12-15 14:52:44 -07001533#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001534 // Some platforms have an atomsize of 1 which makes the test meaningless
1535 if (atom_size > 3) {
1536 // Now with an offset NOT a multiple of the device limit
1537 vkUnmapMemory(m_device->device(), mem);
1538 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1539 ASSERT_VK_SUCCESS(err);
1540 mmr.offset = 3; // Not a multiple of atom_size
1541 mmr.size = VK_WHOLE_SIZE;
1542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1543 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1544 m_errorMonitor->VerifyFound();
1545
1546 // Now with a size NOT a multiple of the device limit
1547 vkUnmapMemory(m_device->device(), mem);
1548 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1549 ASSERT_VK_SUCCESS(err);
1550 mmr.offset = atom_size;
1551 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1553 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1554 m_errorMonitor->VerifyFound();
1555 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001556#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001557 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1558 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001559 if (!pass) {
1560 vkFreeMemory(m_device->device(), mem, NULL);
1561 vkDestroyBuffer(m_device->device(), buffer, NULL);
1562 return;
1563 }
1564 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1565 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1566
1567 vkDestroyBuffer(m_device->device(), buffer, NULL);
1568 vkFreeMemory(m_device->device(), mem, NULL);
1569}
1570
Chris Forbes09368e42016-10-13 11:59:22 +13001571#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001572TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1573 VkResult err;
1574 bool pass;
1575
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001576 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1577 // following declaration (which is temporarily being moved below):
1578 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001579 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001580 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001581 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001582 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001584 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001585
1586 ASSERT_NO_FATAL_FAILURE(InitState());
1587
Ian Elliott3f06ce52016-04-29 14:46:21 -06001588#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1589#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1590 // Use the functions from the VK_KHR_android_surface extension without
1591 // enabling that extension:
1592
1593 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001594 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1596 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001597 pass = (err != VK_SUCCESS);
1598 ASSERT_TRUE(pass);
1599 m_errorMonitor->VerifyFound();
1600#endif // VK_USE_PLATFORM_ANDROID_KHR
1601
Ian Elliott3f06ce52016-04-29 14:46:21 -06001602#if defined(VK_USE_PLATFORM_MIR_KHR)
1603 // Use the functions from the VK_KHR_mir_surface extension without enabling
1604 // that extension:
1605
1606 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001607 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001609 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1610 pass = (err != VK_SUCCESS);
1611 ASSERT_TRUE(pass);
1612 m_errorMonitor->VerifyFound();
1613
1614 // Tell whether an mir_connection supports presentation:
1615 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1617 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001618 m_errorMonitor->VerifyFound();
1619#endif // VK_USE_PLATFORM_MIR_KHR
1620
Ian Elliott3f06ce52016-04-29 14:46:21 -06001621#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1622 // Use the functions from the VK_KHR_wayland_surface extension without
1623 // enabling that extension:
1624
1625 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001626 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_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");
1628 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001629 pass = (err != VK_SUCCESS);
1630 ASSERT_TRUE(pass);
1631 m_errorMonitor->VerifyFound();
1632
1633 // Tell whether an wayland_display supports presentation:
1634 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1636 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001637 m_errorMonitor->VerifyFound();
1638#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001639#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001640
Ian Elliott3f06ce52016-04-29 14:46:21 -06001641#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001642 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1643 // TO NON-LINUX PLATFORMS:
1644 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001645 // Use the functions from the VK_KHR_win32_surface extension without
1646 // enabling that extension:
1647
1648 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001649 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1651 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001652 pass = (err != VK_SUCCESS);
1653 ASSERT_TRUE(pass);
1654 m_errorMonitor->VerifyFound();
1655
1656 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001658 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001659 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001660// Set this (for now, until all platforms are supported and tested):
1661#define NEED_TO_TEST_THIS_ON_PLATFORM
1662#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001663#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1665 // TO NON-LINUX PLATFORMS:
1666 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001667#endif
1668#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001669 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1670 // that extension:
1671
1672 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001673 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001675 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1676 pass = (err != VK_SUCCESS);
1677 ASSERT_TRUE(pass);
1678 m_errorMonitor->VerifyFound();
1679
1680 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001681 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001682 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1684 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001685 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001686// Set this (for now, until all platforms are supported and tested):
1687#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001688#endif // VK_USE_PLATFORM_XCB_KHR
1689
Ian Elliott12630812016-04-29 14:35:43 -06001690#if defined(VK_USE_PLATFORM_XLIB_KHR)
1691 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1692 // that extension:
1693
1694 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001695 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001697 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1698 pass = (err != VK_SUCCESS);
1699 ASSERT_TRUE(pass);
1700 m_errorMonitor->VerifyFound();
1701
1702 // Tell whether an Xlib VisualID supports presentation:
1703 Display *dpy = NULL;
1704 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001706 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1707 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001708// Set this (for now, until all platforms are supported and tested):
1709#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001710#endif // VK_USE_PLATFORM_XLIB_KHR
1711
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001712// Use the functions from the VK_KHR_surface extension without enabling
1713// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001714
Ian Elliott489eec02016-05-05 14:12:44 -06001715#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001716 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001718 vkDestroySurfaceKHR(instance(), surface, NULL);
1719 m_errorMonitor->VerifyFound();
1720
1721 // Check if surface supports presentation:
1722 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001724 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1725 pass = (err != VK_SUCCESS);
1726 ASSERT_TRUE(pass);
1727 m_errorMonitor->VerifyFound();
1728
1729 // Check surface capabilities:
1730 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1732 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001733 pass = (err != VK_SUCCESS);
1734 ASSERT_TRUE(pass);
1735 m_errorMonitor->VerifyFound();
1736
1737 // Check surface formats:
1738 uint32_t format_count = 0;
1739 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1741 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001742 pass = (err != VK_SUCCESS);
1743 ASSERT_TRUE(pass);
1744 m_errorMonitor->VerifyFound();
1745
1746 // Check surface present modes:
1747 uint32_t present_mode_count = 0;
1748 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1750 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001751 pass = (err != VK_SUCCESS);
1752 ASSERT_TRUE(pass);
1753 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001754#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001755
Ian Elliott1c32c772016-04-28 14:47:13 -06001756 // Use the functions from the VK_KHR_swapchain extension without enabling
1757 // that extension:
1758
1759 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001761 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1762 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001763 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001764 pass = (err != VK_SUCCESS);
1765 ASSERT_TRUE(pass);
1766 m_errorMonitor->VerifyFound();
1767
1768 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1770 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001771 pass = (err != VK_SUCCESS);
1772 ASSERT_TRUE(pass);
1773 m_errorMonitor->VerifyFound();
1774
Chris Forbeseb7d5502016-09-13 18:19:21 +12001775 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1776 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1777 VkFence fence;
1778 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1779
Ian Elliott1c32c772016-04-28 14:47:13 -06001780 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001782 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001783 pass = (err != VK_SUCCESS);
1784 ASSERT_TRUE(pass);
1785 m_errorMonitor->VerifyFound();
1786
Chris Forbeseb7d5502016-09-13 18:19:21 +12001787 vkDestroyFence(m_device->device(), fence, nullptr);
1788
Ian Elliott1c32c772016-04-28 14:47:13 -06001789 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001790 //
1791 // NOTE: Currently can't test this because a real swapchain is needed (as
1792 // opposed to the fake one we created) in order for the layer to lookup the
1793 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001794
1795 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001797 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1798 m_errorMonitor->VerifyFound();
1799}
Chris Forbes09368e42016-10-13 11:59:22 +13001800#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001801
Karl Schultz6addd812016-02-02 17:17:23 -07001802TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1803 VkResult err;
1804 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001805
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1807 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001808
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001809 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001810
1811 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001812 VkImage image;
1813 VkDeviceMemory mem;
1814 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001815
Karl Schultz6addd812016-02-02 17:17:23 -07001816 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1817 const int32_t tex_width = 32;
1818 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001819
Tony Barboureb254902015-07-15 12:50:33 -06001820 VkImageCreateInfo image_create_info = {};
1821 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001822 image_create_info.pNext = NULL;
1823 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1824 image_create_info.format = tex_format;
1825 image_create_info.extent.width = tex_width;
1826 image_create_info.extent.height = tex_height;
1827 image_create_info.extent.depth = 1;
1828 image_create_info.mipLevels = 1;
1829 image_create_info.arrayLayers = 1;
1830 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1831 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1832 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1833 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001834 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001835
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001836 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001837 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001838 mem_alloc.pNext = NULL;
1839 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001840
Chia-I Wuf7458c52015-10-26 21:10:41 +08001841 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001842 ASSERT_VK_SUCCESS(err);
1843
Karl Schultz6addd812016-02-02 17:17:23 -07001844 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001845
Mark Lobodzinski23065352015-05-29 09:32:35 -05001846 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001847
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001848 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 -07001849 if (!pass) { // If we can't find any unmappable memory this test doesn't
1850 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001851 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001852 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001853 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001854
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001855 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001856 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001857 ASSERT_VK_SUCCESS(err);
1858
1859 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001860 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001861 ASSERT_VK_SUCCESS(err);
1862
1863 // Map memory as if to initialize the image
1864 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001865 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001866
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001867 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001868
Chia-I Wuf7458c52015-10-26 21:10:41 +08001869 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001870 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001871}
1872
Karl Schultz6addd812016-02-02 17:17:23 -07001873TEST_F(VkLayerTest, RebindMemory) {
1874 VkResult err;
1875 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001876
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001878
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001879 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001880
1881 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001882 VkImage image;
1883 VkDeviceMemory mem1;
1884 VkDeviceMemory mem2;
1885 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001886
Karl Schultz6addd812016-02-02 17:17:23 -07001887 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1888 const int32_t tex_width = 32;
1889 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001890
Tony Barboureb254902015-07-15 12:50:33 -06001891 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001892 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1893 image_create_info.pNext = NULL;
1894 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1895 image_create_info.format = tex_format;
1896 image_create_info.extent.width = tex_width;
1897 image_create_info.extent.height = tex_height;
1898 image_create_info.extent.depth = 1;
1899 image_create_info.mipLevels = 1;
1900 image_create_info.arrayLayers = 1;
1901 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1902 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1903 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1904 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001905
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001906 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001907 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1908 mem_alloc.pNext = NULL;
1909 mem_alloc.allocationSize = 0;
1910 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001911
Karl Schultz6addd812016-02-02 17:17:23 -07001912 // Introduce failure, do NOT set memProps to
1913 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001914 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001915 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001916 ASSERT_VK_SUCCESS(err);
1917
Karl Schultz6addd812016-02-02 17:17:23 -07001918 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001919
1920 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001921 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001922 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001923
1924 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001925 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001926 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001927 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001928 ASSERT_VK_SUCCESS(err);
1929
1930 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001931 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001932 ASSERT_VK_SUCCESS(err);
1933
Karl Schultz6addd812016-02-02 17:17:23 -07001934 // Introduce validation failure, try to bind a different memory object to
1935 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001936 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001937
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001938 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001939
Chia-I Wuf7458c52015-10-26 21:10:41 +08001940 vkDestroyImage(m_device->device(), image, NULL);
1941 vkFreeMemory(m_device->device(), mem1, NULL);
1942 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001943}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001944
Karl Schultz6addd812016-02-02 17:17:23 -07001945TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001946 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001947
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1949 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001950
1951 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001952 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1953 fenceInfo.pNext = NULL;
1954 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001955
Tony Barbour300a6082015-04-07 13:44:53 -06001956 ASSERT_NO_FATAL_FAILURE(InitState());
1957 ASSERT_NO_FATAL_FAILURE(InitViewport());
1958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1959
Tony Barbourfe3351b2015-07-28 10:17:20 -06001960 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001961 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001962 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001963
1964 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001965
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001966 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001967 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1968 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001969 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001970 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001971 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001972 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001973 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001974 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001975 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001976
1977 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001978 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001979
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001980 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001981}
Chris Forbes4e44c912016-06-16 10:20:00 +12001982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001983TEST_F(VkLayerTest, InvalidUsageBits) {
1984 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1985 "Initialize buffer with wrong usage then perform copy expecting errors "
1986 "from both the image and the buffer (2 calls)");
1987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001988
1989 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001990
1991 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1992
Tony Barbourf92621a2016-05-02 14:28:12 -06001993 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001994 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001995 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001996 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001997
Tony Barbourf92621a2016-05-02 14:28:12 -06001998 VkImageView dsv;
1999 VkImageViewCreateInfo dsvci = {};
2000 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2001 dsvci.image = image.handle();
2002 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002003 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002004 dsvci.subresourceRange.layerCount = 1;
2005 dsvci.subresourceRange.baseMipLevel = 0;
2006 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002007 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002008
Tony Barbourf92621a2016-05-02 14:28:12 -06002009 // Create a view with depth / stencil aspect for image with different usage
2010 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002011
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002012 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002013
2014 // Initialize buffer with TRANSFER_DST usage
2015 vk_testing::Buffer buffer;
2016 VkMemoryPropertyFlags reqs = 0;
2017 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2018 VkBufferImageCopy region = {};
2019 region.bufferRowLength = 128;
2020 region.bufferImageHeight = 128;
2021 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2022 region.imageSubresource.layerCount = 1;
2023 region.imageExtent.height = 16;
2024 region.imageExtent.width = 16;
2025 region.imageExtent.depth = 1;
2026
Tony Barbourf92621a2016-05-02 14:28:12 -06002027 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2028 // TRANSFER_DST
2029 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002030
Chris Forbesda581202016-10-06 18:25:26 +13002031 // two separate errors from this call:
2032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2034
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002035 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2036 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002037 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002038}
Tony Barbour75d79f02016-08-30 09:39:07 -06002039
Tony Barbour75d79f02016-08-30 09:39:07 -06002040
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002041#endif // MEM_TRACKER_TESTS
2042
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002043#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002044
2045TEST_F(VkLayerTest, LeakAnObject) {
2046 VkResult err;
2047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002048 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002049
2050 // Note that we have to create a new device since destroying the
2051 // framework's device causes Teardown() to fail and just calling Teardown
2052 // will destroy the errorMonitor.
2053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002055
2056 ASSERT_NO_FATAL_FAILURE(InitState());
2057
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002058 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002059 std::vector<VkDeviceQueueCreateInfo> queue_info;
2060 queue_info.reserve(queue_props.size());
2061 std::vector<std::vector<float>> queue_priorities;
2062 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2063 VkDeviceQueueCreateInfo qi = {};
2064 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2065 qi.pNext = NULL;
2066 qi.queueFamilyIndex = i;
2067 qi.queueCount = queue_props[i].queueCount;
2068 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2069 qi.pQueuePriorities = queue_priorities[i].data();
2070 queue_info.push_back(qi);
2071 }
2072
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002073 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002074
2075 // The sacrificial device object
2076 VkDevice testDevice;
2077 VkDeviceCreateInfo device_create_info = {};
2078 auto features = m_device->phy().features();
2079 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2080 device_create_info.pNext = NULL;
2081 device_create_info.queueCreateInfoCount = queue_info.size();
2082 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002083 device_create_info.enabledLayerCount = 0;
2084 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002085 device_create_info.pEnabledFeatures = &features;
2086 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2087 ASSERT_VK_SUCCESS(err);
2088
2089 VkFence fence;
2090 VkFenceCreateInfo fence_create_info = {};
2091 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2092 fence_create_info.pNext = NULL;
2093 fence_create_info.flags = 0;
2094 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2095 ASSERT_VK_SUCCESS(err);
2096
2097 // Induce failure by not calling vkDestroyFence
2098 vkDestroyDevice(testDevice, NULL);
2099 m_errorMonitor->VerifyFound();
2100}
2101
2102TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2103
2104 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2105 "attempt to delete them from another.");
2106
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002108
Cody Northropc31a84f2016-08-22 10:41:47 -06002109 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002110 VkCommandPool command_pool_one;
2111 VkCommandPool command_pool_two;
2112
2113 VkCommandPoolCreateInfo pool_create_info{};
2114 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2115 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2116 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2117
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002118 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002120 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002121
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002122 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002123 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002124 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002125 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002126 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002127 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002128 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002129
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002130 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002131
2132 m_errorMonitor->VerifyFound();
2133
2134 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2135 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2136}
2137
2138TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2139 VkResult err;
2140
2141 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002142 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002143
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002145
2146 ASSERT_NO_FATAL_FAILURE(InitState());
2147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2148
2149 VkDescriptorPoolSize ds_type_count = {};
2150 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2151 ds_type_count.descriptorCount = 1;
2152
2153 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2154 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2155 ds_pool_ci.pNext = NULL;
2156 ds_pool_ci.flags = 0;
2157 ds_pool_ci.maxSets = 1;
2158 ds_pool_ci.poolSizeCount = 1;
2159 ds_pool_ci.pPoolSizes = &ds_type_count;
2160
2161 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002162 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002163 ASSERT_VK_SUCCESS(err);
2164
2165 // Create a second descriptor pool
2166 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002167 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002168 ASSERT_VK_SUCCESS(err);
2169
2170 VkDescriptorSetLayoutBinding dsl_binding = {};
2171 dsl_binding.binding = 0;
2172 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2173 dsl_binding.descriptorCount = 1;
2174 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2175 dsl_binding.pImmutableSamplers = NULL;
2176
2177 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2178 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2179 ds_layout_ci.pNext = NULL;
2180 ds_layout_ci.bindingCount = 1;
2181 ds_layout_ci.pBindings = &dsl_binding;
2182
2183 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002184 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002185 ASSERT_VK_SUCCESS(err);
2186
2187 VkDescriptorSet descriptorSet;
2188 VkDescriptorSetAllocateInfo alloc_info = {};
2189 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2190 alloc_info.descriptorSetCount = 1;
2191 alloc_info.descriptorPool = ds_pool_one;
2192 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002193 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002194 ASSERT_VK_SUCCESS(err);
2195
2196 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2197
2198 m_errorMonitor->VerifyFound();
2199
2200 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2201 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2202 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2203}
2204
2205TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002207
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002208 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002209
2210 ASSERT_NO_FATAL_FAILURE(InitState());
2211
2212 // Pass bogus handle into GetImageMemoryRequirements
2213 VkMemoryRequirements mem_reqs;
2214 uint64_t fakeImageHandle = 0xCADECADE;
2215 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2216
2217 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2218
2219 m_errorMonitor->VerifyFound();
2220}
2221
Karl Schultz6addd812016-02-02 17:17:23 -07002222TEST_F(VkLayerTest, PipelineNotBound) {
2223 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002224
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002225 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002226
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002228
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002229 ASSERT_NO_FATAL_FAILURE(InitState());
2230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002231
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002232 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002233 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2234 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002235
2236 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002237 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2238 ds_pool_ci.pNext = NULL;
2239 ds_pool_ci.maxSets = 1;
2240 ds_pool_ci.poolSizeCount = 1;
2241 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002242
2243 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002244 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002245 ASSERT_VK_SUCCESS(err);
2246
2247 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002248 dsl_binding.binding = 0;
2249 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2250 dsl_binding.descriptorCount = 1;
2251 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2252 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002253
2254 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002255 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2256 ds_layout_ci.pNext = NULL;
2257 ds_layout_ci.bindingCount = 1;
2258 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002259
2260 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002261 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002262 ASSERT_VK_SUCCESS(err);
2263
2264 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002265 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002266 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002267 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002268 alloc_info.descriptorPool = ds_pool;
2269 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002270 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002271 ASSERT_VK_SUCCESS(err);
2272
2273 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002274 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2275 pipeline_layout_ci.pNext = NULL;
2276 pipeline_layout_ci.setLayoutCount = 1;
2277 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002278
2279 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002280 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002281 ASSERT_VK_SUCCESS(err);
2282
Mark Youngad779052016-01-06 14:26:04 -07002283 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002284
2285 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002286 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002287
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002288 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002289
Chia-I Wuf7458c52015-10-26 21:10:41 +08002290 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2291 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002293}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002294
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002295TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2296 VkResult err;
2297
2298 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2299 "during bind[Buffer|Image]Memory time");
2300
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002301 ASSERT_NO_FATAL_FAILURE(InitState());
2302
2303 // Create an image, allocate memory, set a bad typeIndex and then try to
2304 // bind it
2305 VkImage image;
2306 VkDeviceMemory mem;
2307 VkMemoryRequirements mem_reqs;
2308 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2309 const int32_t tex_width = 32;
2310 const int32_t tex_height = 32;
2311
2312 VkImageCreateInfo image_create_info = {};
2313 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2314 image_create_info.pNext = NULL;
2315 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2316 image_create_info.format = tex_format;
2317 image_create_info.extent.width = tex_width;
2318 image_create_info.extent.height = tex_height;
2319 image_create_info.extent.depth = 1;
2320 image_create_info.mipLevels = 1;
2321 image_create_info.arrayLayers = 1;
2322 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2323 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2324 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2325 image_create_info.flags = 0;
2326
2327 VkMemoryAllocateInfo mem_alloc = {};
2328 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2329 mem_alloc.pNext = NULL;
2330 mem_alloc.allocationSize = 0;
2331 mem_alloc.memoryTypeIndex = 0;
2332
2333 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2334 ASSERT_VK_SUCCESS(err);
2335
2336 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2337 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002338
2339 // Introduce Failure, select invalid TypeIndex
2340 VkPhysicalDeviceMemoryProperties memory_info;
2341
2342 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2343 unsigned int i;
2344 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2345 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2346 mem_alloc.memoryTypeIndex = i;
2347 break;
2348 }
2349 }
2350 if (i >= memory_info.memoryTypeCount) {
2351 printf("No invalid memory type index could be found; skipped.\n");
2352 vkDestroyImage(m_device->device(), image, NULL);
2353 return;
2354 }
2355
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002356 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 -06002357
2358 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2359 ASSERT_VK_SUCCESS(err);
2360
2361 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2362 (void)err;
2363
2364 m_errorMonitor->VerifyFound();
2365
2366 vkDestroyImage(m_device->device(), image, NULL);
2367 vkFreeMemory(m_device->device(), mem, NULL);
2368}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002369
Karl Schultz6addd812016-02-02 17:17:23 -07002370TEST_F(VkLayerTest, BindInvalidMemory) {
2371 VkResult err;
2372 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002373
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002375
Tobin Ehlisec598302015-09-15 15:02:17 -06002376 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002377
2378 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002379 VkImage image;
2380 VkDeviceMemory mem;
2381 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002382
Karl Schultz6addd812016-02-02 17:17:23 -07002383 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2384 const int32_t tex_width = 32;
2385 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002386
2387 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002388 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2389 image_create_info.pNext = NULL;
2390 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2391 image_create_info.format = tex_format;
2392 image_create_info.extent.width = tex_width;
2393 image_create_info.extent.height = tex_height;
2394 image_create_info.extent.depth = 1;
2395 image_create_info.mipLevels = 1;
2396 image_create_info.arrayLayers = 1;
2397 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2398 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2399 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2400 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002401
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002402 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002403 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2404 mem_alloc.pNext = NULL;
2405 mem_alloc.allocationSize = 0;
2406 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002407
Chia-I Wuf7458c52015-10-26 21:10:41 +08002408 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002409 ASSERT_VK_SUCCESS(err);
2410
Karl Schultz6addd812016-02-02 17:17:23 -07002411 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002412
2413 mem_alloc.allocationSize = mem_reqs.size;
2414
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002415 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002416 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002417
2418 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002419 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002420 ASSERT_VK_SUCCESS(err);
2421
2422 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002423 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002424
2425 // Try to bind free memory that has been freed
2426 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2427 // This may very well return an error.
2428 (void)err;
2429
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002430 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002431
Chia-I Wuf7458c52015-10-26 21:10:41 +08002432 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002433}
2434
Karl Schultz6addd812016-02-02 17:17:23 -07002435TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2436 VkResult err;
2437 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002438
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002440
Tobin Ehlisec598302015-09-15 15:02:17 -06002441 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002442
Karl Schultz6addd812016-02-02 17:17:23 -07002443 // Create an image object, allocate memory, destroy the object and then try
2444 // to bind it
2445 VkImage image;
2446 VkDeviceMemory mem;
2447 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002448
Karl Schultz6addd812016-02-02 17:17:23 -07002449 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2450 const int32_t tex_width = 32;
2451 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002452
2453 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002454 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2455 image_create_info.pNext = NULL;
2456 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2457 image_create_info.format = tex_format;
2458 image_create_info.extent.width = tex_width;
2459 image_create_info.extent.height = tex_height;
2460 image_create_info.extent.depth = 1;
2461 image_create_info.mipLevels = 1;
2462 image_create_info.arrayLayers = 1;
2463 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2464 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2465 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2466 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002467
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002468 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002469 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2470 mem_alloc.pNext = NULL;
2471 mem_alloc.allocationSize = 0;
2472 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002473
Chia-I Wuf7458c52015-10-26 21:10:41 +08002474 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002475 ASSERT_VK_SUCCESS(err);
2476
Karl Schultz6addd812016-02-02 17:17:23 -07002477 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002478
2479 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002480 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002481 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002482
2483 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002484 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002485 ASSERT_VK_SUCCESS(err);
2486
2487 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002488 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002489 ASSERT_VK_SUCCESS(err);
2490
2491 // Now Try to bind memory to this destroyed object
2492 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2493 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002494 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002495
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002496 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002497
Chia-I Wuf7458c52015-10-26 21:10:41 +08002498 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002499}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002500
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002501#endif // OBJ_TRACKER_TESTS
2502
Tobin Ehlis0788f522015-05-26 16:11:58 -06002503#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002504
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002505TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2506 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2507
2508 ASSERT_NO_FATAL_FAILURE(InitState());
2509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2510
2511 VkVertexInputBindingDescription input_binding;
2512 memset(&input_binding, 0, sizeof(input_binding));
2513
2514 VkVertexInputAttributeDescription input_attribs;
2515 memset(&input_attribs, 0, sizeof(input_attribs));
2516
2517 // Pick a really bad format for this purpose and make sure it should fail
2518 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2519 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2520 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2521 printf("Format unsuitable for test; skipped.\n");
2522 return;
2523 }
2524
2525 input_attribs.location = 0;
2526 char const *vsSource = "#version 450\n"
2527 "\n"
2528 "out gl_PerVertex {\n"
2529 " vec4 gl_Position;\n"
2530 "};\n"
2531 "void main(){\n"
2532 " gl_Position = vec4(1);\n"
2533 "}\n";
2534 char const *fsSource = "#version 450\n"
2535 "\n"
2536 "layout(location=0) out vec4 color;\n"
2537 "void main(){\n"
2538 " color = vec4(1);\n"
2539 "}\n";
2540
2541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2542 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2543 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2544
2545 VkPipelineObj pipe(m_device);
2546 pipe.AddColorAttachment();
2547 pipe.AddShader(&vs);
2548 pipe.AddShader(&fs);
2549
2550 pipe.AddVertexInputBindings(&input_binding, 1);
2551 pipe.AddVertexInputAttribs(&input_attribs, 1);
2552
2553 VkDescriptorSetObj descriptorSet(m_device);
2554 descriptorSet.AppendDummy();
2555 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2556
2557 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2558
2559 m_errorMonitor->VerifyFound();
2560}
2561
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002562TEST_F(VkLayerTest, ImageSampleCounts) {
2563
2564 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2565 "validation errors.");
2566 ASSERT_NO_FATAL_FAILURE(InitState());
2567
2568 VkMemoryPropertyFlags reqs = 0;
2569 VkImageCreateInfo image_create_info = {};
2570 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2571 image_create_info.pNext = NULL;
2572 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2573 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2574 image_create_info.extent.width = 256;
2575 image_create_info.extent.height = 256;
2576 image_create_info.extent.depth = 1;
2577 image_create_info.mipLevels = 1;
2578 image_create_info.arrayLayers = 1;
2579 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2580 image_create_info.flags = 0;
2581
2582 VkImageBlit blit_region = {};
2583 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2584 blit_region.srcSubresource.baseArrayLayer = 0;
2585 blit_region.srcSubresource.layerCount = 1;
2586 blit_region.srcSubresource.mipLevel = 0;
2587 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2588 blit_region.dstSubresource.baseArrayLayer = 0;
2589 blit_region.dstSubresource.layerCount = 1;
2590 blit_region.dstSubresource.mipLevel = 0;
2591
2592 // Create two images, the source with sampleCount = 2, and attempt to blit
2593 // between them
2594 {
2595 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002596 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002597 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002598 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002599 image_create_info.samples = VK_SAMPLE_COUNT_1_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_2_BIT but "
2606 "must be VK_SAMPLE_COUNT_1_BIT");
2607 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2608 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002609 m_errorMonitor->VerifyFound();
2610 m_commandBuffer->EndCommandBuffer();
2611 }
2612
2613 // Create two images, the dest with sampleCount = 4, and attempt to blit
2614 // between them
2615 {
2616 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002617 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002618 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002619 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002620 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002622 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002623 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002624 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2626 "of VK_SAMPLE_COUNT_4_BIT but "
2627 "must be VK_SAMPLE_COUNT_1_BIT");
2628 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2629 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002630 m_errorMonitor->VerifyFound();
2631 m_commandBuffer->EndCommandBuffer();
2632 }
2633
2634 VkBufferImageCopy copy_region = {};
2635 copy_region.bufferRowLength = 128;
2636 copy_region.bufferImageHeight = 128;
2637 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2638 copy_region.imageSubresource.layerCount = 1;
2639 copy_region.imageExtent.height = 64;
2640 copy_region.imageExtent.width = 64;
2641 copy_region.imageExtent.depth = 1;
2642
2643 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2644 // buffer to image
2645 {
2646 vk_testing::Buffer src_buffer;
2647 VkMemoryPropertyFlags reqs = 0;
2648 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2649 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002650 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002651 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002652 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002653 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2655 "of VK_SAMPLE_COUNT_8_BIT but "
2656 "must be VK_SAMPLE_COUNT_1_BIT");
2657 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2658 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002659 m_errorMonitor->VerifyFound();
2660 m_commandBuffer->EndCommandBuffer();
2661 }
2662
2663 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2664 // image to buffer
2665 {
2666 vk_testing::Buffer dst_buffer;
2667 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2668 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002669 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002670 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002671 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002672 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2674 "of VK_SAMPLE_COUNT_2_BIT but "
2675 "must be VK_SAMPLE_COUNT_1_BIT");
2676 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002677 dst_buffer.handle(), 1, &copy_region);
2678 m_errorMonitor->VerifyFound();
2679 m_commandBuffer->EndCommandBuffer();
2680 }
2681}
2682
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002683TEST_F(VkLayerTest, BlitImageFormats) {
2684
2685 // Image blit with mismatched formats
2686 const char * expected_message =
2687 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2688 " the other one must also have signed/unsigned integer format";
2689
2690 ASSERT_NO_FATAL_FAILURE(InitState());
2691
2692 VkImageObj src_image(m_device);
2693 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2694 VkImageObj dst_image(m_device);
2695 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2696 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002697 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 -06002698
2699 VkImageBlit blitRegion = {};
2700 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2701 blitRegion.srcSubresource.baseArrayLayer = 0;
2702 blitRegion.srcSubresource.layerCount = 1;
2703 blitRegion.srcSubresource.mipLevel = 0;
2704 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2705 blitRegion.dstSubresource.baseArrayLayer = 0;
2706 blitRegion.dstSubresource.layerCount = 1;
2707 blitRegion.dstSubresource.mipLevel = 0;
2708
2709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2710
2711 // Unsigned int vs not an int
2712 BeginCommandBuffer();
2713 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2714 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2715
2716 m_errorMonitor->VerifyFound();
2717
2718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2719
2720 // Unsigned int vs signed int
2721 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2722 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2723
2724 m_errorMonitor->VerifyFound();
2725
2726 EndCommandBuffer();
2727}
2728
2729
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002730TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2731 VkResult err;
2732 bool pass;
2733
2734 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2735 ASSERT_NO_FATAL_FAILURE(InitState());
2736
2737 // If w/d/h granularity is 1, test is not meaningful
2738 // TODO: When virtual device limits are available, create a set of limits for this test that
2739 // will always have a granularity of > 1 for w, h, and d
2740 auto index = m_device->graphics_queue_node_index_;
2741 auto queue_family_properties = m_device->phy().queue_properties();
2742
2743 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2744 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2745 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2746 return;
2747 }
2748
2749 // Create two images of different types and try to copy between them
2750 VkImage srcImage;
2751 VkImage dstImage;
2752 VkDeviceMemory srcMem;
2753 VkDeviceMemory destMem;
2754 VkMemoryRequirements memReqs;
2755
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002756 VkImageCreateInfo image_create_info = {};
2757 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2758 image_create_info.pNext = NULL;
2759 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2760 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2761 image_create_info.extent.width = 32;
2762 image_create_info.extent.height = 32;
2763 image_create_info.extent.depth = 1;
2764 image_create_info.mipLevels = 1;
2765 image_create_info.arrayLayers = 4;
2766 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2767 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2768 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2769 image_create_info.flags = 0;
2770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002771 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002772 ASSERT_VK_SUCCESS(err);
2773
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002774 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002775 ASSERT_VK_SUCCESS(err);
2776
2777 // Allocate memory
2778 VkMemoryAllocateInfo memAlloc = {};
2779 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2780 memAlloc.pNext = NULL;
2781 memAlloc.allocationSize = 0;
2782 memAlloc.memoryTypeIndex = 0;
2783
2784 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2785 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002786 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002787 ASSERT_TRUE(pass);
2788 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2789 ASSERT_VK_SUCCESS(err);
2790
2791 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2792 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002793 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002794 ASSERT_VK_SUCCESS(err);
2795 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2796 ASSERT_VK_SUCCESS(err);
2797
2798 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2799 ASSERT_VK_SUCCESS(err);
2800 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2801 ASSERT_VK_SUCCESS(err);
2802
2803 BeginCommandBuffer();
2804 VkImageCopy copyRegion;
2805 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2806 copyRegion.srcSubresource.mipLevel = 0;
2807 copyRegion.srcSubresource.baseArrayLayer = 0;
2808 copyRegion.srcSubresource.layerCount = 1;
2809 copyRegion.srcOffset.x = 0;
2810 copyRegion.srcOffset.y = 0;
2811 copyRegion.srcOffset.z = 0;
2812 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2813 copyRegion.dstSubresource.mipLevel = 0;
2814 copyRegion.dstSubresource.baseArrayLayer = 0;
2815 copyRegion.dstSubresource.layerCount = 1;
2816 copyRegion.dstOffset.x = 0;
2817 copyRegion.dstOffset.y = 0;
2818 copyRegion.dstOffset.z = 0;
2819 copyRegion.extent.width = 1;
2820 copyRegion.extent.height = 1;
2821 copyRegion.extent.depth = 1;
2822
2823 // Introduce failure by setting srcOffset to a bad granularity value
2824 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2826 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002827 m_errorMonitor->VerifyFound();
2828
2829 // Introduce failure by setting extent to a bad granularity value
2830 copyRegion.srcOffset.y = 0;
2831 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2833 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002834 m_errorMonitor->VerifyFound();
2835
2836 // Now do some buffer/image copies
2837 vk_testing::Buffer buffer;
2838 VkMemoryPropertyFlags reqs = 0;
2839 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2840 VkBufferImageCopy region = {};
2841 region.bufferOffset = 0;
2842 region.bufferRowLength = 3;
2843 region.bufferImageHeight = 128;
2844 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2845 region.imageSubresource.layerCount = 1;
2846 region.imageExtent.height = 16;
2847 region.imageExtent.width = 16;
2848 region.imageExtent.depth = 1;
2849 region.imageOffset.x = 0;
2850 region.imageOffset.y = 0;
2851 region.imageOffset.z = 0;
2852
2853 // Introduce failure by setting bufferRowLength to a bad granularity value
2854 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2856 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2857 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002858 m_errorMonitor->VerifyFound();
2859 region.bufferRowLength = 128;
2860
2861 // Introduce failure by setting bufferOffset to a bad granularity value
2862 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2864 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2865 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002866 m_errorMonitor->VerifyFound();
2867 region.bufferOffset = 0;
2868
2869 // Introduce failure by setting bufferImageHeight to a bad granularity value
2870 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2872 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2873 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002874 m_errorMonitor->VerifyFound();
2875 region.bufferImageHeight = 128;
2876
2877 // Introduce failure by setting imageExtent to a bad granularity value
2878 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2880 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2881 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002882 m_errorMonitor->VerifyFound();
2883 region.imageExtent.width = 16;
2884
2885 // Introduce failure by setting imageOffset to a bad granularity value
2886 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2888 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2889 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002890 m_errorMonitor->VerifyFound();
2891
2892 EndCommandBuffer();
2893
2894 vkDestroyImage(m_device->device(), srcImage, NULL);
2895 vkDestroyImage(m_device->device(), dstImage, NULL);
2896 vkFreeMemory(m_device->device(), srcMem, NULL);
2897 vkFreeMemory(m_device->device(), destMem, NULL);
2898}
2899
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002900TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002901 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2902 "attempt to submit them on a queue created in a different "
2903 "queue family.");
2904
Cody Northropc31a84f2016-08-22 10:41:47 -06002905 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002906 // This test is meaningless unless we have multiple queue families
2907 auto queue_family_properties = m_device->phy().queue_properties();
2908 if (queue_family_properties.size() < 2) {
2909 return;
2910 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002912 // Get safe index of another queue family
2913 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2914 ASSERT_NO_FATAL_FAILURE(InitState());
2915 // Create a second queue using a different queue family
2916 VkQueue other_queue;
2917 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2918
2919 // Record an empty cmd buffer
2920 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2921 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2922 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2923 vkEndCommandBuffer(m_commandBuffer->handle());
2924
2925 // And submit on the wrong queue
2926 VkSubmitInfo submit_info = {};
2927 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2928 submit_info.commandBufferCount = 1;
2929 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002930 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002931
2932 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002933}
2934
Chris Forbes4c24a922016-11-16 08:59:10 +13002935TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2936 ASSERT_NO_FATAL_FAILURE(InitState());
2937
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002938 // There are no attachments, but refer to attachment 0.
2939 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002940 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002941 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2942 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002943 };
2944
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002945 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2946 nullptr,
2947 0,
2948 0,
2949 nullptr,
2950 1,
2951 subpasses,
2952 0,
2953 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002954 VkRenderPass rp;
2955
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002956 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002958 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002959 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2960 m_errorMonitor->VerifyFound();
2961}
2962
Chris Forbesa58c4522016-09-28 15:19:39 +13002963TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2964 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2965 ASSERT_NO_FATAL_FAILURE(InitState());
2966
2967 // A renderpass with two subpasses, both writing the same attachment.
2968 VkAttachmentDescription attach[] = {
2969 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2970 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2971 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2972 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2973 },
2974 };
2975 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2976 VkSubpassDescription subpasses[] = {
2977 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2978 1, &ref, nullptr, nullptr, 0, nullptr },
2979 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2980 1, &ref, nullptr, nullptr, 0, nullptr },
2981 };
2982 VkSubpassDependency dep = {
2983 0, 1,
2984 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2985 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2986 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2987 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2988 VK_DEPENDENCY_BY_REGION_BIT
2989 };
2990 VkRenderPassCreateInfo rpci = {
2991 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2992 0, 1, attach, 2, subpasses, 1, &dep
2993 };
2994 VkRenderPass rp;
2995 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2996 ASSERT_VK_SUCCESS(err);
2997
2998 VkImageObj image(m_device);
2999 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
3000 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
3001 VK_IMAGE_TILING_OPTIMAL, 0);
3002 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3003
3004 VkFramebufferCreateInfo fbci = {
3005 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
3006 0, rp, 1, &imageView, 32, 32, 1
3007 };
3008 VkFramebuffer fb;
3009 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3010 ASSERT_VK_SUCCESS(err);
3011
3012 char const *vsSource =
3013 "#version 450\n"
3014 "void main() { gl_Position = vec4(1); }\n";
3015 char const *fsSource =
3016 "#version 450\n"
3017 "layout(location=0) out vec4 color;\n"
3018 "void main() { color = vec4(1); }\n";
3019
3020 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3021 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3022 VkPipelineObj pipe(m_device);
3023 pipe.AddColorAttachment();
3024 pipe.AddShader(&vs);
3025 pipe.AddShader(&fs);
3026 VkViewport view_port = {};
3027 m_viewports.push_back(view_port);
3028 pipe.SetViewport(m_viewports);
3029 VkRect2D rect = {};
3030 m_scissors.push_back(rect);
3031 pipe.SetScissor(m_scissors);
3032
3033 VkPipelineLayoutCreateInfo plci = {
3034 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
3035 0, 0, nullptr, 0, nullptr
3036 };
3037 VkPipelineLayout pl;
3038 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3039 ASSERT_VK_SUCCESS(err);
3040 pipe.CreateVKPipeline(pl, rp);
3041
3042 BeginCommandBuffer();
3043
3044 VkRenderPassBeginInfo rpbi = {
3045 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
3046 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
3047 };
3048
3049 // subtest 1: bind in the wrong subpass
3050 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3051 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3053 "built for subpass 0 but used in subpass 1");
3054 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3055 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3056 m_errorMonitor->VerifyFound();
3057
3058 vkCmdEndRenderPass(m_commandBuffer->handle());
3059
3060 // subtest 2: bind in correct subpass, then transition to next subpass
3061 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3062 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3063 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3065 "built for subpass 0 but used in subpass 1");
3066 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3067 m_errorMonitor->VerifyFound();
3068
3069 vkCmdEndRenderPass(m_commandBuffer->handle());
3070
3071 EndCommandBuffer();
3072
3073 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3074 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3075 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3076}
3077
Tony Barbour4e919972016-08-09 13:27:40 -06003078TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3079 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3080 "with extent outside of framebuffer");
3081 ASSERT_NO_FATAL_FAILURE(InitState());
3082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3083
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3085 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003086
3087 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3088 m_renderPassBeginInfo.renderArea.extent.width = 257;
3089 m_renderPassBeginInfo.renderArea.extent.height = 257;
3090 BeginCommandBuffer();
3091 m_errorMonitor->VerifyFound();
3092}
3093
3094TEST_F(VkLayerTest, DisabledIndependentBlend) {
3095 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3096 "blend and then specifying different blend states for two "
3097 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003098 VkPhysicalDeviceFeatures features = {};
3099 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003100 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003101
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3103 "Invalid Pipeline CreateInfo: If independent blend feature not "
3104 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003105
Cody Northropc31a84f2016-08-22 10:41:47 -06003106 VkDescriptorSetObj descriptorSet(m_device);
3107 descriptorSet.AppendDummy();
3108 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003109
Cody Northropc31a84f2016-08-22 10:41:47 -06003110 VkPipelineObj pipeline(m_device);
3111 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003112 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003113 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003114
Cody Northropc31a84f2016-08-22 10:41:47 -06003115 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3116 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3117 att_state1.blendEnable = VK_TRUE;
3118 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3119 att_state2.blendEnable = VK_FALSE;
3120 pipeline.AddColorAttachment(0, &att_state1);
3121 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003122 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003123 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003124}
3125
Chris Forbes26ec2122016-11-29 08:58:33 +13003126#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003127TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3128 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3129 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003130 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003131
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3133 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003134
3135 // Create a renderPass with a single color attachment
3136 VkAttachmentReference attach = {};
3137 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3138 VkSubpassDescription subpass = {};
3139 VkRenderPassCreateInfo rpci = {};
3140 rpci.subpassCount = 1;
3141 rpci.pSubpasses = &subpass;
3142 rpci.attachmentCount = 1;
3143 VkAttachmentDescription attach_desc = {};
3144 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3145 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3146 rpci.pAttachments = &attach_desc;
3147 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3148 VkRenderPass rp;
3149 subpass.pDepthStencilAttachment = &attach;
3150 subpass.pColorAttachments = NULL;
3151 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3152 m_errorMonitor->VerifyFound();
3153}
Chris Forbes26ec2122016-11-29 08:58:33 +13003154#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003155
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003156TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3157 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3158 "attachment reference of VK_ATTACHMENT_UNUSED");
3159
3160 ASSERT_NO_FATAL_FAILURE(InitState());
3161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3162
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003164
3165 VkAttachmentReference color_attach = {};
3166 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3167 color_attach.attachment = 0;
3168 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3169 VkSubpassDescription subpass = {};
3170 subpass.colorAttachmentCount = 1;
3171 subpass.pColorAttachments = &color_attach;
3172 subpass.preserveAttachmentCount = 1;
3173 subpass.pPreserveAttachments = &preserve_attachment;
3174
3175 VkRenderPassCreateInfo rpci = {};
3176 rpci.subpassCount = 1;
3177 rpci.pSubpasses = &subpass;
3178 rpci.attachmentCount = 1;
3179 VkAttachmentDescription attach_desc = {};
3180 attach_desc.format = VK_FORMAT_UNDEFINED;
3181 rpci.pAttachments = &attach_desc;
3182 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3183 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003184 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003185
3186 m_errorMonitor->VerifyFound();
3187
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003188 if (result == VK_SUCCESS) {
3189 vkDestroyRenderPass(m_device->device(), rp, NULL);
3190 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003191}
3192
Chris Forbesc5389742016-06-29 11:49:23 +12003193TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003194 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3195 "when the source of a subpass multisample resolve "
3196 "does not have multiple samples.");
3197
Chris Forbesc5389742016-06-29 11:49:23 +12003198 ASSERT_NO_FATAL_FAILURE(InitState());
3199
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3201 "Subpass 0 requests multisample resolve from attachment 0 which has "
3202 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003203
3204 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003205 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3206 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3207 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3208 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3209 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3210 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003211 };
3212
3213 VkAttachmentReference color = {
3214 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3215 };
3216
3217 VkAttachmentReference resolve = {
3218 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3219 };
3220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003221 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003223 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003224
3225 VkRenderPass rp;
3226 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3227
3228 m_errorMonitor->VerifyFound();
3229
3230 if (err == VK_SUCCESS)
3231 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3232}
3233
3234TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003235 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3236 "when a subpass multisample resolve operation is "
3237 "requested, and the destination of that resolve has "
3238 "multiple samples.");
3239
Chris Forbesc5389742016-06-29 11:49:23 +12003240 ASSERT_NO_FATAL_FAILURE(InitState());
3241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3243 "Subpass 0 requests multisample resolve into attachment 1, which "
3244 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003245
3246 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003247 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3248 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3249 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3250 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3251 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3252 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003253 };
3254
3255 VkAttachmentReference color = {
3256 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3257 };
3258
3259 VkAttachmentReference resolve = {
3260 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3261 };
3262
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003263 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003264
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003265 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003266
3267 VkRenderPass rp;
3268 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3269
3270 m_errorMonitor->VerifyFound();
3271
3272 if (err == VK_SUCCESS)
3273 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3274}
3275
Chris Forbes3f128ef2016-06-29 14:58:53 +12003276TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003277 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3278 "when the color and depth attachments used by a subpass "
3279 "have inconsistent sample counts");
3280
Chris Forbes3f128ef2016-06-29 14:58:53 +12003281 ASSERT_NO_FATAL_FAILURE(InitState());
3282
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3284 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003285
3286 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003287 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3288 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3289 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3290 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3291 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3292 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003293 };
3294
3295 VkAttachmentReference color[] = {
3296 {
3297 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3298 },
3299 {
3300 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3301 },
3302 };
3303
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003304 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003305
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003306 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003307
3308 VkRenderPass rp;
3309 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3310
3311 m_errorMonitor->VerifyFound();
3312
3313 if (err == VK_SUCCESS)
3314 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3315}
3316
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003317TEST_F(VkLayerTest, FramebufferCreateErrors) {
3318 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003319 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003320 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003321 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3322 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3323 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3324 " 6. Framebuffer attachment where dimensions don't match\n"
3325 " 7. Framebuffer attachment w/o identity swizzle\n"
3326 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003327
3328 ASSERT_NO_FATAL_FAILURE(InitState());
3329 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3330
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3332 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3333 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003334
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003335 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003336 VkAttachmentReference attach = {};
3337 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3338 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003339 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003340 VkRenderPassCreateInfo rpci = {};
3341 rpci.subpassCount = 1;
3342 rpci.pSubpasses = &subpass;
3343 rpci.attachmentCount = 1;
3344 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003345 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003346 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003347 rpci.pAttachments = &attach_desc;
3348 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3349 VkRenderPass rp;
3350 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3351 ASSERT_VK_SUCCESS(err);
3352
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003353 VkImageView ivs[2];
3354 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3355 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003356 VkFramebufferCreateInfo fb_info = {};
3357 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3358 fb_info.pNext = NULL;
3359 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003360 // Set mis-matching attachmentCount
3361 fb_info.attachmentCount = 2;
3362 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003363 fb_info.width = 100;
3364 fb_info.height = 100;
3365 fb_info.layers = 1;
3366
3367 VkFramebuffer fb;
3368 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3369
3370 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003371 if (err == VK_SUCCESS) {
3372 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3373 }
3374 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003375
3376 // Create a renderPass with a depth-stencil attachment created with
3377 // IMAGE_USAGE_COLOR_ATTACHMENT
3378 // Add our color attachment to pDepthStencilAttachment
3379 subpass.pDepthStencilAttachment = &attach;
3380 subpass.pColorAttachments = NULL;
3381 VkRenderPass rp_ds;
3382 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3383 ASSERT_VK_SUCCESS(err);
3384 // Set correct attachment count, but attachment has COLOR usage bit set
3385 fb_info.attachmentCount = 1;
3386 fb_info.renderPass = rp_ds;
3387
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003389 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3390
3391 m_errorMonitor->VerifyFound();
3392 if (err == VK_SUCCESS) {
3393 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3394 }
3395 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003396
3397 // Create new renderpass with alternate attachment format from fb
3398 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3399 subpass.pDepthStencilAttachment = NULL;
3400 subpass.pColorAttachments = &attach;
3401 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3402 ASSERT_VK_SUCCESS(err);
3403
3404 // Cause error due to mis-matched formats between rp & fb
3405 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3406 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3408 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003409 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3410
3411 m_errorMonitor->VerifyFound();
3412 if (err == VK_SUCCESS) {
3413 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3414 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003415 vkDestroyRenderPass(m_device->device(), rp, NULL);
3416
3417 // Create new renderpass with alternate sample count from fb
3418 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3419 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3420 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3421 ASSERT_VK_SUCCESS(err);
3422
3423 // Cause error due to mis-matched sample count between rp & fb
3424 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3426 "that do not match the "
3427 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003428 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3429
3430 m_errorMonitor->VerifyFound();
3431 if (err == VK_SUCCESS) {
3432 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3433 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003434
3435 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003436
3437 // Create a custom imageView with non-1 mip levels
3438 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003439 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 -06003440 ASSERT_TRUE(image.initialized());
3441
3442 VkImageView view;
3443 VkImageViewCreateInfo ivci = {};
3444 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3445 ivci.image = image.handle();
3446 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3447 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3448 ivci.subresourceRange.layerCount = 1;
3449 ivci.subresourceRange.baseMipLevel = 0;
3450 // Set level count 2 (only 1 is allowed for FB attachment)
3451 ivci.subresourceRange.levelCount = 2;
3452 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3453 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3454 ASSERT_VK_SUCCESS(err);
3455 // Re-create renderpass to have matching sample count
3456 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3457 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3458 ASSERT_VK_SUCCESS(err);
3459
3460 fb_info.renderPass = rp;
3461 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003463 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3464
3465 m_errorMonitor->VerifyFound();
3466 if (err == VK_SUCCESS) {
3467 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3468 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003469 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003470 // Update view to original color buffer and grow FB dimensions too big
3471 fb_info.pAttachments = ivs;
3472 fb_info.height = 1024;
3473 fb_info.width = 1024;
3474 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3476 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003477 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3478
3479 m_errorMonitor->VerifyFound();
3480 if (err == VK_SUCCESS) {
3481 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3482 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003483 // Create view attachment with non-identity swizzle
3484 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3485 ivci.image = image.handle();
3486 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3487 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3488 ivci.subresourceRange.layerCount = 1;
3489 ivci.subresourceRange.baseMipLevel = 0;
3490 ivci.subresourceRange.levelCount = 1;
3491 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3492 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3493 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3494 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3495 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3496 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3497 ASSERT_VK_SUCCESS(err);
3498
3499 fb_info.pAttachments = &view;
3500 fb_info.height = 100;
3501 fb_info.width = 100;
3502 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3504 "framebuffer attachments must have "
3505 "been created with the identity "
3506 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003507 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3508
3509 m_errorMonitor->VerifyFound();
3510 if (err == VK_SUCCESS) {
3511 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3512 }
3513 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003514 // Request fb that exceeds max dimensions
3515 // reset attachment to color attachment
3516 fb_info.pAttachments = ivs;
3517 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3518 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3519 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3521 "dimensions exceed physical device "
3522 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003523 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3524
3525 m_errorMonitor->VerifyFound();
3526 if (err == VK_SUCCESS) {
3527 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3528 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003529
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003530 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003531}
3532
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003533TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003534 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3535 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003536
Cody Northropc31a84f2016-08-22 10:41:47 -06003537 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003538 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3540 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003541 m_errorMonitor->VerifyFound();
3542}
3543
3544TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003545 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3546 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003547
Cody Northropc31a84f2016-08-22 10:41:47 -06003548 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003549 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3551 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003552 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003553}
3554
3555TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003556 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3557 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003558
Cody Northropc31a84f2016-08-22 10:41:47 -06003559 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003560 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003561 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 -06003562 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003563 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003564}
3565
3566TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003567 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3568 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003569
Cody Northropc31a84f2016-08-22 10:41:47 -06003570 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003571 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003572 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 -06003573 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003574 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003575}
3576
Cortd713fe82016-07-27 09:51:27 -07003577TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003578 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3579 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003580
3581 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003582 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3584 "Dynamic blend constants state not set for this command buffer");
3585 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003586 m_errorMonitor->VerifyFound();
3587}
3588
3589TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003590 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3591 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003592
3593 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003594 if (!m_device->phy().features().depthBounds) {
3595 printf("Device does not support depthBounds test; skipped.\n");
3596 return;
3597 }
3598 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3600 "Dynamic depth bounds state not set for this command buffer");
3601 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003602 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003603}
3604
3605TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003606 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3607 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003608
3609 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003610 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3612 "Dynamic stencil read mask state not set for this command buffer");
3613 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003614 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003615}
3616
3617TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003618 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3619 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003620
3621 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003622 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3624 "Dynamic stencil write mask state not set for this command buffer");
3625 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003626 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003627}
3628
3629TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003630 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3631 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003632
3633 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003634 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3636 "Dynamic stencil reference state not set for this command buffer");
3637 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003638 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003639}
3640
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003641TEST_F(VkLayerTest, IndexBufferNotBound) {
3642 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003643
3644 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3646 "Index buffer object not bound to this command buffer when Indexed ");
3647 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003648 m_errorMonitor->VerifyFound();
3649}
3650
Karl Schultz6addd812016-02-02 17:17:23 -07003651TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3653 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3654 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003655
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003656 ASSERT_NO_FATAL_FAILURE(InitState());
3657 ASSERT_NO_FATAL_FAILURE(InitViewport());
3658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3659
Karl Schultz6addd812016-02-02 17:17:23 -07003660 // We luck out b/c by default the framework creates CB w/ the
3661 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003662 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003663 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003664 EndCommandBuffer();
3665
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003666 // Bypass framework since it does the waits automatically
3667 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003668 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003669 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3670 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003671 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003672 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003673 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003674 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003675 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003676 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003677 submit_info.pSignalSemaphores = NULL;
3678
Chris Forbes40028e22016-06-13 09:59:34 +12003679 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003680 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003681 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003682
Karl Schultz6addd812016-02-02 17:17:23 -07003683 // Cause validation error by re-submitting cmd buffer that should only be
3684 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003685 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003686 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003687
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003688 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003689}
3690
Karl Schultz6addd812016-02-02 17:17:23 -07003691TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003692 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003693 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003694
3695 ASSERT_NO_FATAL_FAILURE(InitState());
3696 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003697
Karl Schultz6addd812016-02-02 17:17:23 -07003698 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3699 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003700 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003701 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003702 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003703
3704 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003705 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3706 ds_pool_ci.pNext = NULL;
3707 ds_pool_ci.flags = 0;
3708 ds_pool_ci.maxSets = 1;
3709 ds_pool_ci.poolSizeCount = 1;
3710 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003711
3712 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003713 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003714 ASSERT_VK_SUCCESS(err);
3715
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003716 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3717 dsl_binding_samp.binding = 0;
3718 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3719 dsl_binding_samp.descriptorCount = 1;
3720 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3721 dsl_binding_samp.pImmutableSamplers = NULL;
3722
3723 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3724 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3725 ds_layout_ci.pNext = NULL;
3726 ds_layout_ci.bindingCount = 1;
3727 ds_layout_ci.pBindings = &dsl_binding_samp;
3728
3729 VkDescriptorSetLayout ds_layout_samp;
3730 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3731 ASSERT_VK_SUCCESS(err);
3732
3733 // Try to allocate 2 sets when pool only has 1 set
3734 VkDescriptorSet descriptor_sets[2];
3735 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3736 VkDescriptorSetAllocateInfo alloc_info = {};
3737 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3738 alloc_info.descriptorSetCount = 2;
3739 alloc_info.descriptorPool = ds_pool;
3740 alloc_info.pSetLayouts = set_layouts;
3741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3742 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3743 m_errorMonitor->VerifyFound();
3744
3745 alloc_info.descriptorSetCount = 1;
3746 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003747 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003748 dsl_binding.binding = 0;
3749 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3750 dsl_binding.descriptorCount = 1;
3751 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3752 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003753
Karl Schultz6addd812016-02-02 17:17:23 -07003754 ds_layout_ci.bindingCount = 1;
3755 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003756
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003757 VkDescriptorSetLayout ds_layout_ub;
3758 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003759 ASSERT_VK_SUCCESS(err);
3760
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003761 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003762 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003763 alloc_info.pSetLayouts = &ds_layout_ub;
3764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3765 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003766
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003767 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003768
Karl Schultz2825ab92016-12-02 08:23:14 -07003769 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003770 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003771 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003772}
3773
Karl Schultz6addd812016-02-02 17:17:23 -07003774TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3775 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003776
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3778 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3779 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003780
Tobin Ehlise735c692015-10-08 13:13:50 -06003781 ASSERT_NO_FATAL_FAILURE(InitState());
3782 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003783
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003784 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003785 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3786 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003787
3788 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003789 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3790 ds_pool_ci.pNext = NULL;
3791 ds_pool_ci.maxSets = 1;
3792 ds_pool_ci.poolSizeCount = 1;
3793 ds_pool_ci.flags = 0;
3794 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3795 // app can only call vkResetDescriptorPool on this pool.;
3796 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003797
3798 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003799 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003800 ASSERT_VK_SUCCESS(err);
3801
3802 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003803 dsl_binding.binding = 0;
3804 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3805 dsl_binding.descriptorCount = 1;
3806 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3807 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003808
3809 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003810 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3811 ds_layout_ci.pNext = NULL;
3812 ds_layout_ci.bindingCount = 1;
3813 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003814
3815 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003816 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003817 ASSERT_VK_SUCCESS(err);
3818
3819 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003820 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003821 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003822 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003823 alloc_info.descriptorPool = ds_pool;
3824 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003825 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003826 ASSERT_VK_SUCCESS(err);
3827
3828 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003829 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003830
Chia-I Wuf7458c52015-10-26 21:10:41 +08003831 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3832 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003833}
3834
Karl Schultz6addd812016-02-02 17:17:23 -07003835TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003836 // Attempt to clear Descriptor Pool with bad object.
3837 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003838
3839 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003841 uint64_t fake_pool_handle = 0xbaad6001;
3842 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3843 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003844 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003845}
3846
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003847TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003848 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3849 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003850 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003851 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003852
3853 uint64_t fake_set_handle = 0xbaad6001;
3854 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003855 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003857
3858 ASSERT_NO_FATAL_FAILURE(InitState());
3859
3860 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3861 layout_bindings[0].binding = 0;
3862 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3863 layout_bindings[0].descriptorCount = 1;
3864 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3865 layout_bindings[0].pImmutableSamplers = NULL;
3866
3867 VkDescriptorSetLayout descriptor_set_layout;
3868 VkDescriptorSetLayoutCreateInfo dslci = {};
3869 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3870 dslci.pNext = NULL;
3871 dslci.bindingCount = 1;
3872 dslci.pBindings = layout_bindings;
3873 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003874 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003875
3876 VkPipelineLayout pipeline_layout;
3877 VkPipelineLayoutCreateInfo plci = {};
3878 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3879 plci.pNext = NULL;
3880 plci.setLayoutCount = 1;
3881 plci.pSetLayouts = &descriptor_set_layout;
3882 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003883 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003884
3885 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003886 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3887 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003888 m_errorMonitor->VerifyFound();
3889 EndCommandBuffer();
3890 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3891 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003892}
3893
Karl Schultz6addd812016-02-02 17:17:23 -07003894TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003895 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3896 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003897 uint64_t fake_layout_handle = 0xbaad6001;
3898 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003900 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003901 VkPipelineLayout pipeline_layout;
3902 VkPipelineLayoutCreateInfo plci = {};
3903 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3904 plci.pNext = NULL;
3905 plci.setLayoutCount = 1;
3906 plci.pSetLayouts = &bad_layout;
3907 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3908
3909 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003910}
3911
Mark Muellerd4914412016-06-13 17:52:06 -06003912TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3913 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3914 "1) A uniform buffer update must have a valid buffer index."
3915 "2) When using an array of descriptors in a single WriteDescriptor,"
3916 " the descriptor types and stageflags must all be the same."
3917 "3) Immutable Sampler state must match across descriptors");
3918
3919 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003920 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3921 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3922 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3923 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3924 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003925
Mark Muellerd4914412016-06-13 17:52:06 -06003926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3927
3928 ASSERT_NO_FATAL_FAILURE(InitState());
3929 VkDescriptorPoolSize ds_type_count[4] = {};
3930 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3931 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003932 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003933 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003934 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003935 ds_type_count[2].descriptorCount = 1;
3936 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3937 ds_type_count[3].descriptorCount = 1;
3938
3939 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3940 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3941 ds_pool_ci.maxSets = 1;
3942 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3943 ds_pool_ci.pPoolSizes = ds_type_count;
3944
3945 VkDescriptorPool ds_pool;
3946 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3947 ASSERT_VK_SUCCESS(err);
3948
Mark Muellerb9896722016-06-16 09:54:29 -06003949 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003950 layout_binding[0].binding = 0;
3951 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3952 layout_binding[0].descriptorCount = 1;
3953 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3954 layout_binding[0].pImmutableSamplers = NULL;
3955
3956 layout_binding[1].binding = 1;
3957 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3958 layout_binding[1].descriptorCount = 1;
3959 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3960 layout_binding[1].pImmutableSamplers = NULL;
3961
3962 VkSamplerCreateInfo sampler_ci = {};
3963 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3964 sampler_ci.pNext = NULL;
3965 sampler_ci.magFilter = VK_FILTER_NEAREST;
3966 sampler_ci.minFilter = VK_FILTER_NEAREST;
3967 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3968 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3969 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3970 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3971 sampler_ci.mipLodBias = 1.0;
3972 sampler_ci.anisotropyEnable = VK_FALSE;
3973 sampler_ci.maxAnisotropy = 1;
3974 sampler_ci.compareEnable = VK_FALSE;
3975 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3976 sampler_ci.minLod = 1.0;
3977 sampler_ci.maxLod = 1.0;
3978 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3979 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3980 VkSampler sampler;
3981
3982 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3983 ASSERT_VK_SUCCESS(err);
3984
3985 layout_binding[2].binding = 2;
3986 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3987 layout_binding[2].descriptorCount = 1;
3988 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3989 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3990
Mark Muellerd4914412016-06-13 17:52:06 -06003991 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3992 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3993 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3994 ds_layout_ci.pBindings = layout_binding;
3995 VkDescriptorSetLayout ds_layout;
3996 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3997 ASSERT_VK_SUCCESS(err);
3998
3999 VkDescriptorSetAllocateInfo alloc_info = {};
4000 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4001 alloc_info.descriptorSetCount = 1;
4002 alloc_info.descriptorPool = ds_pool;
4003 alloc_info.pSetLayouts = &ds_layout;
4004 VkDescriptorSet descriptorSet;
4005 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4006 ASSERT_VK_SUCCESS(err);
4007
4008 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4009 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4010 pipeline_layout_ci.pNext = NULL;
4011 pipeline_layout_ci.setLayoutCount = 1;
4012 pipeline_layout_ci.pSetLayouts = &ds_layout;
4013
4014 VkPipelineLayout pipeline_layout;
4015 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4016 ASSERT_VK_SUCCESS(err);
4017
Mark Mueller5c838ce2016-06-16 09:54:29 -06004018 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004019 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4020 descriptor_write.dstSet = descriptorSet;
4021 descriptor_write.dstBinding = 0;
4022 descriptor_write.descriptorCount = 1;
4023 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4024
Mark Mueller5c838ce2016-06-16 09:54:29 -06004025 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004026 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4027 m_errorMonitor->VerifyFound();
4028
4029 // Create a buffer to update the descriptor with
4030 uint32_t qfi = 0;
4031 VkBufferCreateInfo buffCI = {};
4032 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4033 buffCI.size = 1024;
4034 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4035 buffCI.queueFamilyIndexCount = 1;
4036 buffCI.pQueueFamilyIndices = &qfi;
4037
4038 VkBuffer dyub;
4039 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4040 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004041
Tony Barboure132c5f2016-12-12 11:50:20 -07004042 VkDeviceMemory mem;
4043 VkMemoryRequirements mem_reqs;
4044 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4045
4046 VkMemoryAllocateInfo mem_alloc_info = {};
4047 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4048 mem_alloc_info.allocationSize = mem_reqs.size;
4049 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4050 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4051 ASSERT_VK_SUCCESS(err);
4052
4053 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4054 ASSERT_VK_SUCCESS(err);
4055
4056 VkDescriptorBufferInfo buffInfo[2] = {};
4057 buffInfo[0].buffer = dyub;
4058 buffInfo[0].offset = 0;
4059 buffInfo[0].range = 1024;
4060 buffInfo[1].buffer = dyub;
4061 buffInfo[1].offset = 0;
4062 buffInfo[1].range = 1024;
4063 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004064 descriptor_write.descriptorCount = 2;
4065
Mark Mueller5c838ce2016-06-16 09:54:29 -06004066 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4068 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4069 m_errorMonitor->VerifyFound();
4070
Mark Mueller5c838ce2016-06-16 09:54:29 -06004071 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4072 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004073 descriptor_write.dstBinding = 1;
4074 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004075
Mark Mueller5c838ce2016-06-16 09:54:29 -06004076 // Make pImageInfo index non-null to avoid complaints of it missing
4077 VkDescriptorImageInfo imageInfo = {};
4078 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4079 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4081 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4082 m_errorMonitor->VerifyFound();
4083
Mark Muellerd4914412016-06-13 17:52:06 -06004084 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004085 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004086 vkDestroySampler(m_device->device(), sampler, NULL);
4087 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4088 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4089 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4090}
4091
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004092TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4093 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4094 "due to a buffer dependency being destroyed.");
4095 ASSERT_NO_FATAL_FAILURE(InitState());
4096
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004097 VkBuffer buffer;
4098 VkDeviceMemory mem;
4099 VkMemoryRequirements mem_reqs;
4100
4101 VkBufferCreateInfo buf_info = {};
4102 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004103 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004104 buf_info.size = 256;
4105 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4106 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4107 ASSERT_VK_SUCCESS(err);
4108
4109 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4110
4111 VkMemoryAllocateInfo alloc_info = {};
4112 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4113 alloc_info.allocationSize = 256;
4114 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004115 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 -06004116 if (!pass) {
4117 vkDestroyBuffer(m_device->device(), buffer, NULL);
4118 return;
4119 }
4120 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4121 ASSERT_VK_SUCCESS(err);
4122
4123 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4124 ASSERT_VK_SUCCESS(err);
4125
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004126 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004127 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004128 m_commandBuffer->EndCommandBuffer();
4129
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004131 // Destroy buffer dependency prior to submit to cause ERROR
4132 vkDestroyBuffer(m_device->device(), buffer, NULL);
4133
4134 VkSubmitInfo submit_info = {};
4135 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4136 submit_info.commandBufferCount = 1;
4137 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4138 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4139
4140 m_errorMonitor->VerifyFound();
4141 vkFreeMemory(m_device->handle(), mem, NULL);
4142}
4143
Tobin Ehlisea413442016-09-28 10:23:59 -06004144TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4145 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4146
4147 ASSERT_NO_FATAL_FAILURE(InitState());
4148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4149
4150 VkDescriptorPoolSize ds_type_count;
4151 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4152 ds_type_count.descriptorCount = 1;
4153
4154 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4155 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4156 ds_pool_ci.maxSets = 1;
4157 ds_pool_ci.poolSizeCount = 1;
4158 ds_pool_ci.pPoolSizes = &ds_type_count;
4159
4160 VkDescriptorPool ds_pool;
4161 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4162 ASSERT_VK_SUCCESS(err);
4163
4164 VkDescriptorSetLayoutBinding layout_binding;
4165 layout_binding.binding = 0;
4166 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4167 layout_binding.descriptorCount = 1;
4168 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4169 layout_binding.pImmutableSamplers = NULL;
4170
4171 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4172 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4173 ds_layout_ci.bindingCount = 1;
4174 ds_layout_ci.pBindings = &layout_binding;
4175 VkDescriptorSetLayout ds_layout;
4176 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4177 ASSERT_VK_SUCCESS(err);
4178
4179 VkDescriptorSetAllocateInfo alloc_info = {};
4180 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4181 alloc_info.descriptorSetCount = 1;
4182 alloc_info.descriptorPool = ds_pool;
4183 alloc_info.pSetLayouts = &ds_layout;
4184 VkDescriptorSet descriptor_set;
4185 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4186 ASSERT_VK_SUCCESS(err);
4187
4188 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4189 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4190 pipeline_layout_ci.pNext = NULL;
4191 pipeline_layout_ci.setLayoutCount = 1;
4192 pipeline_layout_ci.pSetLayouts = &ds_layout;
4193
4194 VkPipelineLayout pipeline_layout;
4195 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4196 ASSERT_VK_SUCCESS(err);
4197
4198 VkBuffer buffer;
4199 uint32_t queue_family_index = 0;
4200 VkBufferCreateInfo buffer_create_info = {};
4201 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4202 buffer_create_info.size = 1024;
4203 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4204 buffer_create_info.queueFamilyIndexCount = 1;
4205 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4206
4207 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4208 ASSERT_VK_SUCCESS(err);
4209
4210 VkMemoryRequirements memory_reqs;
4211 VkDeviceMemory buffer_memory;
4212
4213 VkMemoryAllocateInfo memory_info = {};
4214 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4215 memory_info.allocationSize = 0;
4216 memory_info.memoryTypeIndex = 0;
4217
4218 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4219 memory_info.allocationSize = memory_reqs.size;
4220 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4221 ASSERT_TRUE(pass);
4222
4223 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4224 ASSERT_VK_SUCCESS(err);
4225 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4226 ASSERT_VK_SUCCESS(err);
4227
4228 VkBufferView view;
4229 VkBufferViewCreateInfo bvci = {};
4230 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4231 bvci.buffer = buffer;
4232 bvci.format = VK_FORMAT_R8_UNORM;
4233 bvci.range = VK_WHOLE_SIZE;
4234
4235 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4236 ASSERT_VK_SUCCESS(err);
4237
4238 VkWriteDescriptorSet descriptor_write = {};
4239 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4240 descriptor_write.dstSet = descriptor_set;
4241 descriptor_write.dstBinding = 0;
4242 descriptor_write.descriptorCount = 1;
4243 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4244 descriptor_write.pTexelBufferView = &view;
4245
4246 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4247
4248 char const *vsSource = "#version 450\n"
4249 "\n"
4250 "out gl_PerVertex { \n"
4251 " vec4 gl_Position;\n"
4252 "};\n"
4253 "void main(){\n"
4254 " gl_Position = vec4(1);\n"
4255 "}\n";
4256 char const *fsSource = "#version 450\n"
4257 "\n"
4258 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4259 "layout(location=0) out vec4 x;\n"
4260 "void main(){\n"
4261 " x = imageLoad(s, 0);\n"
4262 "}\n";
4263 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4264 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4265 VkPipelineObj pipe(m_device);
4266 pipe.AddShader(&vs);
4267 pipe.AddShader(&fs);
4268 pipe.AddColorAttachment();
4269 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4270
4271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4273
4274 BeginCommandBuffer();
4275 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4276 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4277 VkRect2D scissor = {{0, 0}, {16, 16}};
4278 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4279 // Bind pipeline to cmd buffer
4280 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4281 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4282 &descriptor_set, 0, nullptr);
4283 Draw(1, 0, 0, 0);
4284 EndCommandBuffer();
4285
4286 // Delete BufferView in order to invalidate cmd buffer
4287 vkDestroyBufferView(m_device->device(), view, NULL);
4288 // Now attempt submit of cmd buffer
4289 VkSubmitInfo submit_info = {};
4290 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4291 submit_info.commandBufferCount = 1;
4292 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4293 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4294 m_errorMonitor->VerifyFound();
4295
4296 // Clean-up
4297 vkDestroyBuffer(m_device->device(), buffer, NULL);
4298 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4299 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4300 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4301 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4302}
4303
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004304TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4305 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4306 "due to an image dependency being destroyed.");
4307 ASSERT_NO_FATAL_FAILURE(InitState());
4308
4309 VkImage image;
4310 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4311 VkImageCreateInfo image_create_info = {};
4312 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4313 image_create_info.pNext = NULL;
4314 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4315 image_create_info.format = tex_format;
4316 image_create_info.extent.width = 32;
4317 image_create_info.extent.height = 32;
4318 image_create_info.extent.depth = 1;
4319 image_create_info.mipLevels = 1;
4320 image_create_info.arrayLayers = 1;
4321 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4322 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004323 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004324 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004325 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004326 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004327 // Have to bind memory to image before recording cmd in cmd buffer using it
4328 VkMemoryRequirements mem_reqs;
4329 VkDeviceMemory image_mem;
4330 bool pass;
4331 VkMemoryAllocateInfo mem_alloc = {};
4332 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4333 mem_alloc.pNext = NULL;
4334 mem_alloc.memoryTypeIndex = 0;
4335 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4336 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004337 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004338 ASSERT_TRUE(pass);
4339 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4340 ASSERT_VK_SUCCESS(err);
4341 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4342 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004343
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004344 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004345 VkClearColorValue ccv;
4346 ccv.float32[0] = 1.0f;
4347 ccv.float32[1] = 1.0f;
4348 ccv.float32[2] = 1.0f;
4349 ccv.float32[3] = 1.0f;
4350 VkImageSubresourceRange isr = {};
4351 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004352 isr.baseArrayLayer = 0;
4353 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004354 isr.layerCount = 1;
4355 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004356 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004357 m_commandBuffer->EndCommandBuffer();
4358
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004360 // Destroy image dependency prior to submit to cause ERROR
4361 vkDestroyImage(m_device->device(), image, NULL);
4362
4363 VkSubmitInfo submit_info = {};
4364 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4365 submit_info.commandBufferCount = 1;
4366 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4367 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4368
4369 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004370 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004371}
4372
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004373TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4374 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4375 "due to a framebuffer image dependency being destroyed.");
4376 VkFormatProperties format_properties;
4377 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004378 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4379 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004380 return;
4381 }
4382
4383 ASSERT_NO_FATAL_FAILURE(InitState());
4384 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4385
4386 VkImageCreateInfo image_ci = {};
4387 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4388 image_ci.pNext = NULL;
4389 image_ci.imageType = VK_IMAGE_TYPE_2D;
4390 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4391 image_ci.extent.width = 32;
4392 image_ci.extent.height = 32;
4393 image_ci.extent.depth = 1;
4394 image_ci.mipLevels = 1;
4395 image_ci.arrayLayers = 1;
4396 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4397 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004398 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004399 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4400 image_ci.flags = 0;
4401 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004402 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004403
4404 VkMemoryRequirements memory_reqs;
4405 VkDeviceMemory image_memory;
4406 bool pass;
4407 VkMemoryAllocateInfo memory_info = {};
4408 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4409 memory_info.pNext = NULL;
4410 memory_info.allocationSize = 0;
4411 memory_info.memoryTypeIndex = 0;
4412 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4413 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004414 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004415 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004416 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004417 ASSERT_VK_SUCCESS(err);
4418 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4419 ASSERT_VK_SUCCESS(err);
4420
4421 VkImageViewCreateInfo ivci = {
4422 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4423 nullptr,
4424 0,
4425 image,
4426 VK_IMAGE_VIEW_TYPE_2D,
4427 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004428 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004429 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4430 };
4431 VkImageView view;
4432 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4433 ASSERT_VK_SUCCESS(err);
4434
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004435 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004436 VkFramebuffer fb;
4437 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4438 ASSERT_VK_SUCCESS(err);
4439
4440 // Just use default renderpass with our framebuffer
4441 m_renderPassBeginInfo.framebuffer = fb;
4442 // Create Null cmd buffer for submit
4443 BeginCommandBuffer();
4444 EndCommandBuffer();
4445 // Destroy image attached to framebuffer to invalidate cmd buffer
4446 vkDestroyImage(m_device->device(), image, NULL);
4447 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004449 QueueCommandBuffer(false);
4450 m_errorMonitor->VerifyFound();
4451
4452 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4453 vkDestroyImageView(m_device->device(), view, nullptr);
4454 vkFreeMemory(m_device->device(), image_memory, nullptr);
4455}
4456
Tobin Ehlisb329f992016-10-12 13:20:29 -06004457TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4458 TEST_DESCRIPTION("Delete in-use framebuffer.");
4459 VkFormatProperties format_properties;
4460 VkResult err = VK_SUCCESS;
4461 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4462
4463 ASSERT_NO_FATAL_FAILURE(InitState());
4464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4465
4466 VkImageObj image(m_device);
4467 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4468 ASSERT_TRUE(image.initialized());
4469 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4470
4471 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4472 VkFramebuffer fb;
4473 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4474 ASSERT_VK_SUCCESS(err);
4475
4476 // Just use default renderpass with our framebuffer
4477 m_renderPassBeginInfo.framebuffer = fb;
4478 // Create Null cmd buffer for submit
4479 BeginCommandBuffer();
4480 EndCommandBuffer();
4481 // Submit cmd buffer to put it in-flight
4482 VkSubmitInfo submit_info = {};
4483 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4484 submit_info.commandBufferCount = 1;
4485 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4486 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4487 // Destroy framebuffer while in-flight
4488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4489 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4490 m_errorMonitor->VerifyFound();
4491 // Wait for queue to complete so we can safely destroy everything
4492 vkQueueWaitIdle(m_device->m_queue);
4493 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4494}
4495
Tobin Ehlis88becd72016-09-21 14:33:41 -06004496TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4497 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4498 VkFormatProperties format_properties;
4499 VkResult err = VK_SUCCESS;
4500 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004501
4502 ASSERT_NO_FATAL_FAILURE(InitState());
4503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4504
4505 VkImageCreateInfo image_ci = {};
4506 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4507 image_ci.pNext = NULL;
4508 image_ci.imageType = VK_IMAGE_TYPE_2D;
4509 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4510 image_ci.extent.width = 256;
4511 image_ci.extent.height = 256;
4512 image_ci.extent.depth = 1;
4513 image_ci.mipLevels = 1;
4514 image_ci.arrayLayers = 1;
4515 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4516 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004517 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004518 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4519 image_ci.flags = 0;
4520 VkImage image;
4521 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4522
4523 VkMemoryRequirements memory_reqs;
4524 VkDeviceMemory image_memory;
4525 bool pass;
4526 VkMemoryAllocateInfo memory_info = {};
4527 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4528 memory_info.pNext = NULL;
4529 memory_info.allocationSize = 0;
4530 memory_info.memoryTypeIndex = 0;
4531 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4532 memory_info.allocationSize = memory_reqs.size;
4533 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4534 ASSERT_TRUE(pass);
4535 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4536 ASSERT_VK_SUCCESS(err);
4537 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4538 ASSERT_VK_SUCCESS(err);
4539
4540 VkImageViewCreateInfo ivci = {
4541 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4542 nullptr,
4543 0,
4544 image,
4545 VK_IMAGE_VIEW_TYPE_2D,
4546 VK_FORMAT_B8G8R8A8_UNORM,
4547 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4548 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4549 };
4550 VkImageView view;
4551 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4552 ASSERT_VK_SUCCESS(err);
4553
4554 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4555 VkFramebuffer fb;
4556 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4557 ASSERT_VK_SUCCESS(err);
4558
4559 // Just use default renderpass with our framebuffer
4560 m_renderPassBeginInfo.framebuffer = fb;
4561 // Create Null cmd buffer for submit
4562 BeginCommandBuffer();
4563 EndCommandBuffer();
4564 // Submit cmd buffer to put it (and attached imageView) in-flight
4565 VkSubmitInfo submit_info = {};
4566 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4567 submit_info.commandBufferCount = 1;
4568 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4569 // Submit cmd buffer to put framebuffer and children in-flight
4570 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4571 // Destroy image attached to framebuffer while in-flight
4572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4573 vkDestroyImage(m_device->device(), image, NULL);
4574 m_errorMonitor->VerifyFound();
4575 // Wait for queue to complete so we can safely destroy image and other objects
4576 vkQueueWaitIdle(m_device->m_queue);
4577 vkDestroyImage(m_device->device(), image, NULL);
4578 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4579 vkDestroyImageView(m_device->device(), view, nullptr);
4580 vkFreeMemory(m_device->device(), image_memory, nullptr);
4581}
4582
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004583TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4584 TEST_DESCRIPTION("Delete in-use renderPass.");
4585
4586 ASSERT_NO_FATAL_FAILURE(InitState());
4587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4588
4589 // Create simple renderpass
4590 VkAttachmentReference attach = {};
4591 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4592 VkSubpassDescription subpass = {};
4593 subpass.pColorAttachments = &attach;
4594 VkRenderPassCreateInfo rpci = {};
4595 rpci.subpassCount = 1;
4596 rpci.pSubpasses = &subpass;
4597 rpci.attachmentCount = 1;
4598 VkAttachmentDescription attach_desc = {};
4599 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4600 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4601 rpci.pAttachments = &attach_desc;
4602 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4603 VkRenderPass rp;
4604 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4605 ASSERT_VK_SUCCESS(err);
4606
4607 // Create a pipeline that uses the given renderpass
4608 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4609 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4610
4611 VkPipelineLayout pipeline_layout;
4612 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4613 ASSERT_VK_SUCCESS(err);
4614
4615 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4616 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4617 vp_state_ci.viewportCount = 1;
4618 VkViewport vp = {}; // Just need dummy vp to point to
4619 vp_state_ci.pViewports = &vp;
4620 vp_state_ci.scissorCount = 1;
4621 VkRect2D scissors = {}; // Dummy scissors to point to
4622 vp_state_ci.pScissors = &scissors;
4623
4624 VkPipelineShaderStageCreateInfo shaderStages[2];
4625 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4626
4627 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4628 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4629 // but add it to be able to run on more devices
4630 shaderStages[0] = vs.GetStageCreateInfo();
4631 shaderStages[1] = fs.GetStageCreateInfo();
4632
4633 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4634 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4635
4636 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4637 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4638 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4639
4640 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4641 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4642 rs_ci.rasterizerDiscardEnable = true;
4643 rs_ci.lineWidth = 1.0f;
4644
4645 VkPipelineColorBlendAttachmentState att = {};
4646 att.blendEnable = VK_FALSE;
4647 att.colorWriteMask = 0xf;
4648
4649 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4650 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4651 cb_ci.attachmentCount = 1;
4652 cb_ci.pAttachments = &att;
4653
4654 VkGraphicsPipelineCreateInfo gp_ci = {};
4655 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4656 gp_ci.stageCount = 2;
4657 gp_ci.pStages = shaderStages;
4658 gp_ci.pVertexInputState = &vi_ci;
4659 gp_ci.pInputAssemblyState = &ia_ci;
4660 gp_ci.pViewportState = &vp_state_ci;
4661 gp_ci.pRasterizationState = &rs_ci;
4662 gp_ci.pColorBlendState = &cb_ci;
4663 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4664 gp_ci.layout = pipeline_layout;
4665 gp_ci.renderPass = rp;
4666
4667 VkPipelineCacheCreateInfo pc_ci = {};
4668 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4669
4670 VkPipeline pipeline;
4671 VkPipelineCache pipe_cache;
4672 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4673 ASSERT_VK_SUCCESS(err);
4674
4675 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4676 ASSERT_VK_SUCCESS(err);
4677 // Bind pipeline to cmd buffer, will also bind renderpass
4678 m_commandBuffer->BeginCommandBuffer();
4679 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4680 m_commandBuffer->EndCommandBuffer();
4681
4682 VkSubmitInfo submit_info = {};
4683 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4684 submit_info.commandBufferCount = 1;
4685 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4686 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4687
4688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4689 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4690 m_errorMonitor->VerifyFound();
4691
4692 // Wait for queue to complete so we can safely destroy everything
4693 vkQueueWaitIdle(m_device->m_queue);
4694 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4695 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4696 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4697 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4698}
4699
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004700TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004701 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004702 ASSERT_NO_FATAL_FAILURE(InitState());
4703
4704 VkImage image;
4705 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4706 VkImageCreateInfo image_create_info = {};
4707 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4708 image_create_info.pNext = NULL;
4709 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4710 image_create_info.format = tex_format;
4711 image_create_info.extent.width = 32;
4712 image_create_info.extent.height = 32;
4713 image_create_info.extent.depth = 1;
4714 image_create_info.mipLevels = 1;
4715 image_create_info.arrayLayers = 1;
4716 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4717 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004718 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004719 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004720 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004721 ASSERT_VK_SUCCESS(err);
4722 // Have to bind memory to image before recording cmd in cmd buffer using it
4723 VkMemoryRequirements mem_reqs;
4724 VkDeviceMemory image_mem;
4725 bool pass;
4726 VkMemoryAllocateInfo mem_alloc = {};
4727 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4728 mem_alloc.pNext = NULL;
4729 mem_alloc.memoryTypeIndex = 0;
4730 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4731 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004732 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004733 ASSERT_TRUE(pass);
4734 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4735 ASSERT_VK_SUCCESS(err);
4736
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004737 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004739 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004740
4741 m_commandBuffer->BeginCommandBuffer();
4742 VkClearColorValue ccv;
4743 ccv.float32[0] = 1.0f;
4744 ccv.float32[1] = 1.0f;
4745 ccv.float32[2] = 1.0f;
4746 ccv.float32[3] = 1.0f;
4747 VkImageSubresourceRange isr = {};
4748 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4749 isr.baseArrayLayer = 0;
4750 isr.baseMipLevel = 0;
4751 isr.layerCount = 1;
4752 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004753 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004754 m_commandBuffer->EndCommandBuffer();
4755
4756 m_errorMonitor->VerifyFound();
4757 vkDestroyImage(m_device->device(), image, NULL);
4758 vkFreeMemory(m_device->device(), image_mem, nullptr);
4759}
4760
4761TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004762 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004763 ASSERT_NO_FATAL_FAILURE(InitState());
4764
4765 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004766 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 -06004767 VK_IMAGE_TILING_OPTIMAL, 0);
4768 ASSERT_TRUE(image.initialized());
4769
4770 VkBuffer buffer;
4771 VkDeviceMemory mem;
4772 VkMemoryRequirements mem_reqs;
4773
4774 VkBufferCreateInfo buf_info = {};
4775 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004776 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004777 buf_info.size = 256;
4778 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4779 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4780 ASSERT_VK_SUCCESS(err);
4781
4782 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4783
4784 VkMemoryAllocateInfo alloc_info = {};
4785 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4786 alloc_info.allocationSize = 256;
4787 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004788 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 -06004789 if (!pass) {
4790 vkDestroyBuffer(m_device->device(), buffer, NULL);
4791 return;
4792 }
4793 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4794 ASSERT_VK_SUCCESS(err);
4795
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004796 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004798 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004799 VkBufferImageCopy region = {};
4800 region.bufferRowLength = 128;
4801 region.bufferImageHeight = 128;
4802 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4803
4804 region.imageSubresource.layerCount = 1;
4805 region.imageExtent.height = 4;
4806 region.imageExtent.width = 4;
4807 region.imageExtent.depth = 1;
4808 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004809 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4810 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004811 m_commandBuffer->EndCommandBuffer();
4812
4813 m_errorMonitor->VerifyFound();
4814
4815 vkDestroyBuffer(m_device->device(), buffer, NULL);
4816 vkFreeMemory(m_device->handle(), mem, NULL);
4817}
4818
Tobin Ehlis85940f52016-07-07 16:57:21 -06004819TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4820 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4821 "due to an event dependency being destroyed.");
4822 ASSERT_NO_FATAL_FAILURE(InitState());
4823
4824 VkEvent event;
4825 VkEventCreateInfo evci = {};
4826 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4827 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4828 ASSERT_VK_SUCCESS(result);
4829
4830 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004831 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004832 m_commandBuffer->EndCommandBuffer();
4833
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004835 // Destroy event dependency prior to submit to cause ERROR
4836 vkDestroyEvent(m_device->device(), event, NULL);
4837
4838 VkSubmitInfo submit_info = {};
4839 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4840 submit_info.commandBufferCount = 1;
4841 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4842 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4843
4844 m_errorMonitor->VerifyFound();
4845}
4846
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004847TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4848 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4849 "due to a query pool dependency being destroyed.");
4850 ASSERT_NO_FATAL_FAILURE(InitState());
4851
4852 VkQueryPool query_pool;
4853 VkQueryPoolCreateInfo qpci{};
4854 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4855 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4856 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004857 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004858 ASSERT_VK_SUCCESS(result);
4859
4860 m_commandBuffer->BeginCommandBuffer();
4861 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4862 m_commandBuffer->EndCommandBuffer();
4863
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004865 // Destroy query pool dependency prior to submit to cause ERROR
4866 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4867
4868 VkSubmitInfo submit_info = {};
4869 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4870 submit_info.commandBufferCount = 1;
4871 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4872 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4873
4874 m_errorMonitor->VerifyFound();
4875}
4876
Tobin Ehlis24130d92016-07-08 15:50:53 -06004877TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4878 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4879 "due to a pipeline dependency being destroyed.");
4880 ASSERT_NO_FATAL_FAILURE(InitState());
4881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4882
4883 VkResult err;
4884
4885 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4886 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4887
4888 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004889 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004890 ASSERT_VK_SUCCESS(err);
4891
4892 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4893 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4894 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004895 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004896 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004897 vp_state_ci.scissorCount = 1;
4898 VkRect2D scissors = {}; // Dummy scissors to point to
4899 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004900
4901 VkPipelineShaderStageCreateInfo shaderStages[2];
4902 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004904 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4905 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4906 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004907 shaderStages[0] = vs.GetStageCreateInfo();
4908 shaderStages[1] = fs.GetStageCreateInfo();
4909
4910 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4911 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4912
4913 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4914 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4915 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4916
4917 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4918 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004919 rs_ci.rasterizerDiscardEnable = true;
4920 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004921
4922 VkPipelineColorBlendAttachmentState att = {};
4923 att.blendEnable = VK_FALSE;
4924 att.colorWriteMask = 0xf;
4925
4926 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4927 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4928 cb_ci.attachmentCount = 1;
4929 cb_ci.pAttachments = &att;
4930
4931 VkGraphicsPipelineCreateInfo gp_ci = {};
4932 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4933 gp_ci.stageCount = 2;
4934 gp_ci.pStages = shaderStages;
4935 gp_ci.pVertexInputState = &vi_ci;
4936 gp_ci.pInputAssemblyState = &ia_ci;
4937 gp_ci.pViewportState = &vp_state_ci;
4938 gp_ci.pRasterizationState = &rs_ci;
4939 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004940 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4941 gp_ci.layout = pipeline_layout;
4942 gp_ci.renderPass = renderPass();
4943
4944 VkPipelineCacheCreateInfo pc_ci = {};
4945 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4946
4947 VkPipeline pipeline;
4948 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004950 ASSERT_VK_SUCCESS(err);
4951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004952 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004953 ASSERT_VK_SUCCESS(err);
4954
4955 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004956 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004957 m_commandBuffer->EndCommandBuffer();
4958 // Now destroy pipeline in order to cause error when submitting
4959 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004962
4963 VkSubmitInfo submit_info = {};
4964 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4965 submit_info.commandBufferCount = 1;
4966 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4967 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4968
4969 m_errorMonitor->VerifyFound();
4970 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4971 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4972}
4973
Tobin Ehlis31289162016-08-17 14:57:58 -06004974TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4975 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4976 "due to a bound descriptor set with a buffer dependency "
4977 "being destroyed.");
4978 ASSERT_NO_FATAL_FAILURE(InitState());
4979 ASSERT_NO_FATAL_FAILURE(InitViewport());
4980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4981
4982 VkDescriptorPoolSize ds_type_count = {};
4983 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4984 ds_type_count.descriptorCount = 1;
4985
4986 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4987 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4988 ds_pool_ci.pNext = NULL;
4989 ds_pool_ci.maxSets = 1;
4990 ds_pool_ci.poolSizeCount = 1;
4991 ds_pool_ci.pPoolSizes = &ds_type_count;
4992
4993 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004994 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004995 ASSERT_VK_SUCCESS(err);
4996
4997 VkDescriptorSetLayoutBinding dsl_binding = {};
4998 dsl_binding.binding = 0;
4999 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5000 dsl_binding.descriptorCount = 1;
5001 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5002 dsl_binding.pImmutableSamplers = NULL;
5003
5004 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5005 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5006 ds_layout_ci.pNext = NULL;
5007 ds_layout_ci.bindingCount = 1;
5008 ds_layout_ci.pBindings = &dsl_binding;
5009 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005011 ASSERT_VK_SUCCESS(err);
5012
5013 VkDescriptorSet descriptorSet;
5014 VkDescriptorSetAllocateInfo alloc_info = {};
5015 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5016 alloc_info.descriptorSetCount = 1;
5017 alloc_info.descriptorPool = ds_pool;
5018 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005019 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005020 ASSERT_VK_SUCCESS(err);
5021
5022 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5023 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5024 pipeline_layout_ci.pNext = NULL;
5025 pipeline_layout_ci.setLayoutCount = 1;
5026 pipeline_layout_ci.pSetLayouts = &ds_layout;
5027
5028 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005029 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005030 ASSERT_VK_SUCCESS(err);
5031
5032 // Create a buffer to update the descriptor with
5033 uint32_t qfi = 0;
5034 VkBufferCreateInfo buffCI = {};
5035 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5036 buffCI.size = 1024;
5037 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5038 buffCI.queueFamilyIndexCount = 1;
5039 buffCI.pQueueFamilyIndices = &qfi;
5040
5041 VkBuffer buffer;
5042 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5043 ASSERT_VK_SUCCESS(err);
5044 // Allocate memory and bind to buffer so we can make it to the appropriate
5045 // error
5046 VkMemoryAllocateInfo mem_alloc = {};
5047 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5048 mem_alloc.pNext = NULL;
5049 mem_alloc.allocationSize = 1024;
5050 mem_alloc.memoryTypeIndex = 0;
5051
5052 VkMemoryRequirements memReqs;
5053 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005054 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005055 if (!pass) {
5056 vkDestroyBuffer(m_device->device(), buffer, NULL);
5057 return;
5058 }
5059
5060 VkDeviceMemory mem;
5061 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5062 ASSERT_VK_SUCCESS(err);
5063 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5064 ASSERT_VK_SUCCESS(err);
5065 // Correctly update descriptor to avoid "NOT_UPDATED" error
5066 VkDescriptorBufferInfo buffInfo = {};
5067 buffInfo.buffer = buffer;
5068 buffInfo.offset = 0;
5069 buffInfo.range = 1024;
5070
5071 VkWriteDescriptorSet descriptor_write;
5072 memset(&descriptor_write, 0, sizeof(descriptor_write));
5073 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5074 descriptor_write.dstSet = descriptorSet;
5075 descriptor_write.dstBinding = 0;
5076 descriptor_write.descriptorCount = 1;
5077 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5078 descriptor_write.pBufferInfo = &buffInfo;
5079
5080 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5081
5082 // Create PSO to be used for draw-time errors below
5083 char const *vsSource = "#version 450\n"
5084 "\n"
5085 "out gl_PerVertex { \n"
5086 " vec4 gl_Position;\n"
5087 "};\n"
5088 "void main(){\n"
5089 " gl_Position = vec4(1);\n"
5090 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005091 char const *fsSource = "#version 450\n"
5092 "\n"
5093 "layout(location=0) out vec4 x;\n"
5094 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5095 "void main(){\n"
5096 " x = vec4(bar.y);\n"
5097 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005098 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5099 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5100 VkPipelineObj pipe(m_device);
5101 pipe.AddShader(&vs);
5102 pipe.AddShader(&fs);
5103 pipe.AddColorAttachment();
5104 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5105
5106 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005107 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5108 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5109 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005110 Draw(1, 0, 0, 0);
5111 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005113 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5114 vkDestroyBuffer(m_device->device(), buffer, NULL);
5115 // Attempt to submit cmd buffer
5116 VkSubmitInfo submit_info = {};
5117 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5118 submit_info.commandBufferCount = 1;
5119 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5120 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5121 m_errorMonitor->VerifyFound();
5122 // Cleanup
5123 vkFreeMemory(m_device->device(), mem, NULL);
5124
5125 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5126 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5127 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5128}
5129
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005130TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5131 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5132 "due to a bound descriptor sets with a combined image "
5133 "sampler having their image, sampler, and descriptor set "
5134 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005135 "submit associated cmd buffers. Attempt to destroy a "
5136 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005137 ASSERT_NO_FATAL_FAILURE(InitState());
5138 ASSERT_NO_FATAL_FAILURE(InitViewport());
5139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5140
5141 VkDescriptorPoolSize ds_type_count = {};
5142 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5143 ds_type_count.descriptorCount = 1;
5144
5145 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5146 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5147 ds_pool_ci.pNext = NULL;
5148 ds_pool_ci.maxSets = 1;
5149 ds_pool_ci.poolSizeCount = 1;
5150 ds_pool_ci.pPoolSizes = &ds_type_count;
5151
5152 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005153 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005154 ASSERT_VK_SUCCESS(err);
5155
5156 VkDescriptorSetLayoutBinding dsl_binding = {};
5157 dsl_binding.binding = 0;
5158 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5159 dsl_binding.descriptorCount = 1;
5160 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5161 dsl_binding.pImmutableSamplers = NULL;
5162
5163 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5164 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5165 ds_layout_ci.pNext = NULL;
5166 ds_layout_ci.bindingCount = 1;
5167 ds_layout_ci.pBindings = &dsl_binding;
5168 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005169 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005170 ASSERT_VK_SUCCESS(err);
5171
5172 VkDescriptorSet descriptorSet;
5173 VkDescriptorSetAllocateInfo alloc_info = {};
5174 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5175 alloc_info.descriptorSetCount = 1;
5176 alloc_info.descriptorPool = ds_pool;
5177 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005178 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005179 ASSERT_VK_SUCCESS(err);
5180
5181 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5182 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5183 pipeline_layout_ci.pNext = NULL;
5184 pipeline_layout_ci.setLayoutCount = 1;
5185 pipeline_layout_ci.pSetLayouts = &ds_layout;
5186
5187 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005188 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005189 ASSERT_VK_SUCCESS(err);
5190
5191 // Create images to update the descriptor with
5192 VkImage image;
5193 VkImage image2;
5194 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5195 const int32_t tex_width = 32;
5196 const int32_t tex_height = 32;
5197 VkImageCreateInfo image_create_info = {};
5198 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5199 image_create_info.pNext = NULL;
5200 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5201 image_create_info.format = tex_format;
5202 image_create_info.extent.width = tex_width;
5203 image_create_info.extent.height = tex_height;
5204 image_create_info.extent.depth = 1;
5205 image_create_info.mipLevels = 1;
5206 image_create_info.arrayLayers = 1;
5207 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5208 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5209 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5210 image_create_info.flags = 0;
5211 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5212 ASSERT_VK_SUCCESS(err);
5213 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5214 ASSERT_VK_SUCCESS(err);
5215
5216 VkMemoryRequirements memory_reqs;
5217 VkDeviceMemory image_memory;
5218 bool pass;
5219 VkMemoryAllocateInfo memory_info = {};
5220 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5221 memory_info.pNext = NULL;
5222 memory_info.allocationSize = 0;
5223 memory_info.memoryTypeIndex = 0;
5224 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5225 // Allocate enough memory for both images
5226 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005227 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005228 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005229 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005230 ASSERT_VK_SUCCESS(err);
5231 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5232 ASSERT_VK_SUCCESS(err);
5233 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005234 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005235 ASSERT_VK_SUCCESS(err);
5236
5237 VkImageViewCreateInfo image_view_create_info = {};
5238 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5239 image_view_create_info.image = image;
5240 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5241 image_view_create_info.format = tex_format;
5242 image_view_create_info.subresourceRange.layerCount = 1;
5243 image_view_create_info.subresourceRange.baseMipLevel = 0;
5244 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005245 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005246
5247 VkImageView view;
5248 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005249 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005250 ASSERT_VK_SUCCESS(err);
5251 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005252 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005253 ASSERT_VK_SUCCESS(err);
5254 // Create Samplers
5255 VkSamplerCreateInfo sampler_ci = {};
5256 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5257 sampler_ci.pNext = NULL;
5258 sampler_ci.magFilter = VK_FILTER_NEAREST;
5259 sampler_ci.minFilter = VK_FILTER_NEAREST;
5260 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5261 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5262 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5263 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5264 sampler_ci.mipLodBias = 1.0;
5265 sampler_ci.anisotropyEnable = VK_FALSE;
5266 sampler_ci.maxAnisotropy = 1;
5267 sampler_ci.compareEnable = VK_FALSE;
5268 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5269 sampler_ci.minLod = 1.0;
5270 sampler_ci.maxLod = 1.0;
5271 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5272 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5273 VkSampler sampler;
5274 VkSampler sampler2;
5275 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5276 ASSERT_VK_SUCCESS(err);
5277 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5278 ASSERT_VK_SUCCESS(err);
5279 // Update descriptor with image and sampler
5280 VkDescriptorImageInfo img_info = {};
5281 img_info.sampler = sampler;
5282 img_info.imageView = view;
5283 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5284
5285 VkWriteDescriptorSet descriptor_write;
5286 memset(&descriptor_write, 0, sizeof(descriptor_write));
5287 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5288 descriptor_write.dstSet = descriptorSet;
5289 descriptor_write.dstBinding = 0;
5290 descriptor_write.descriptorCount = 1;
5291 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5292 descriptor_write.pImageInfo = &img_info;
5293
5294 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5295
5296 // Create PSO to be used for draw-time errors below
5297 char const *vsSource = "#version 450\n"
5298 "\n"
5299 "out gl_PerVertex { \n"
5300 " vec4 gl_Position;\n"
5301 "};\n"
5302 "void main(){\n"
5303 " gl_Position = vec4(1);\n"
5304 "}\n";
5305 char const *fsSource = "#version 450\n"
5306 "\n"
5307 "layout(set=0, binding=0) uniform sampler2D s;\n"
5308 "layout(location=0) out vec4 x;\n"
5309 "void main(){\n"
5310 " x = texture(s, vec2(1));\n"
5311 "}\n";
5312 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5313 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5314 VkPipelineObj pipe(m_device);
5315 pipe.AddShader(&vs);
5316 pipe.AddShader(&fs);
5317 pipe.AddColorAttachment();
5318 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5319
5320 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005322 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005323 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5324 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5325 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005326 Draw(1, 0, 0, 0);
5327 EndCommandBuffer();
5328 // Destroy sampler invalidates the cmd buffer, causing error on submit
5329 vkDestroySampler(m_device->device(), sampler, NULL);
5330 // Attempt to submit cmd buffer
5331 VkSubmitInfo submit_info = {};
5332 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5333 submit_info.commandBufferCount = 1;
5334 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5335 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5336 m_errorMonitor->VerifyFound();
5337 // Now re-update descriptor with valid sampler and delete image
5338 img_info.sampler = sampler2;
5339 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005341 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005342 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5343 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5344 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005345 Draw(1, 0, 0, 0);
5346 EndCommandBuffer();
5347 // Destroy image invalidates the cmd buffer, causing error on submit
5348 vkDestroyImage(m_device->device(), image, NULL);
5349 // Attempt to submit cmd buffer
5350 submit_info = {};
5351 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5352 submit_info.commandBufferCount = 1;
5353 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5354 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5355 m_errorMonitor->VerifyFound();
5356 // Now update descriptor to be valid, but then free descriptor
5357 img_info.imageView = view2;
5358 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005360 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005361 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5362 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5363 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005364 Draw(1, 0, 0, 0);
5365 EndCommandBuffer();
5366 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005368 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005369 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005370 // Attempt to submit cmd buffer
5371 submit_info = {};
5372 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5373 submit_info.commandBufferCount = 1;
5374 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5375 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5376 m_errorMonitor->VerifyFound();
5377 // Cleanup
5378 vkFreeMemory(m_device->device(), image_memory, NULL);
5379 vkDestroySampler(m_device->device(), sampler2, NULL);
5380 vkDestroyImage(m_device->device(), image2, NULL);
5381 vkDestroyImageView(m_device->device(), view, NULL);
5382 vkDestroyImageView(m_device->device(), view2, NULL);
5383 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5385 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5386}
5387
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005388TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5389 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5390 ASSERT_NO_FATAL_FAILURE(InitState());
5391 ASSERT_NO_FATAL_FAILURE(InitViewport());
5392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5393
5394 VkDescriptorPoolSize ds_type_count = {};
5395 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5396 ds_type_count.descriptorCount = 1;
5397
5398 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5399 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5400 ds_pool_ci.pNext = NULL;
5401 ds_pool_ci.maxSets = 1;
5402 ds_pool_ci.poolSizeCount = 1;
5403 ds_pool_ci.pPoolSizes = &ds_type_count;
5404
5405 VkDescriptorPool ds_pool;
5406 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5407 ASSERT_VK_SUCCESS(err);
5408
5409 VkDescriptorSetLayoutBinding dsl_binding = {};
5410 dsl_binding.binding = 0;
5411 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5412 dsl_binding.descriptorCount = 1;
5413 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5414 dsl_binding.pImmutableSamplers = NULL;
5415
5416 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5417 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5418 ds_layout_ci.pNext = NULL;
5419 ds_layout_ci.bindingCount = 1;
5420 ds_layout_ci.pBindings = &dsl_binding;
5421 VkDescriptorSetLayout ds_layout;
5422 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5423 ASSERT_VK_SUCCESS(err);
5424
5425 VkDescriptorSet descriptor_set;
5426 VkDescriptorSetAllocateInfo alloc_info = {};
5427 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5428 alloc_info.descriptorSetCount = 1;
5429 alloc_info.descriptorPool = ds_pool;
5430 alloc_info.pSetLayouts = &ds_layout;
5431 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5432 ASSERT_VK_SUCCESS(err);
5433
5434 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5435 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5436 pipeline_layout_ci.pNext = NULL;
5437 pipeline_layout_ci.setLayoutCount = 1;
5438 pipeline_layout_ci.pSetLayouts = &ds_layout;
5439
5440 VkPipelineLayout pipeline_layout;
5441 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5442 ASSERT_VK_SUCCESS(err);
5443
5444 // Create image to update the descriptor with
5445 VkImageObj image(m_device);
5446 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5447 ASSERT_TRUE(image.initialized());
5448
5449 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5450 // Create Sampler
5451 VkSamplerCreateInfo sampler_ci = {};
5452 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5453 sampler_ci.pNext = NULL;
5454 sampler_ci.magFilter = VK_FILTER_NEAREST;
5455 sampler_ci.minFilter = VK_FILTER_NEAREST;
5456 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5457 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5458 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5459 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5460 sampler_ci.mipLodBias = 1.0;
5461 sampler_ci.anisotropyEnable = VK_FALSE;
5462 sampler_ci.maxAnisotropy = 1;
5463 sampler_ci.compareEnable = VK_FALSE;
5464 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5465 sampler_ci.minLod = 1.0;
5466 sampler_ci.maxLod = 1.0;
5467 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5468 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5469 VkSampler sampler;
5470 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5471 ASSERT_VK_SUCCESS(err);
5472 // Update descriptor with image and sampler
5473 VkDescriptorImageInfo img_info = {};
5474 img_info.sampler = sampler;
5475 img_info.imageView = view;
5476 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5477
5478 VkWriteDescriptorSet descriptor_write;
5479 memset(&descriptor_write, 0, sizeof(descriptor_write));
5480 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5481 descriptor_write.dstSet = descriptor_set;
5482 descriptor_write.dstBinding = 0;
5483 descriptor_write.descriptorCount = 1;
5484 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5485 descriptor_write.pImageInfo = &img_info;
5486
5487 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5488
5489 // Create PSO to be used for draw-time errors below
5490 char const *vsSource = "#version 450\n"
5491 "\n"
5492 "out gl_PerVertex { \n"
5493 " vec4 gl_Position;\n"
5494 "};\n"
5495 "void main(){\n"
5496 " gl_Position = vec4(1);\n"
5497 "}\n";
5498 char const *fsSource = "#version 450\n"
5499 "\n"
5500 "layout(set=0, binding=0) uniform sampler2D s;\n"
5501 "layout(location=0) out vec4 x;\n"
5502 "void main(){\n"
5503 " x = texture(s, vec2(1));\n"
5504 "}\n";
5505 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5506 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5507 VkPipelineObj pipe(m_device);
5508 pipe.AddShader(&vs);
5509 pipe.AddShader(&fs);
5510 pipe.AddColorAttachment();
5511 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5512
5513 BeginCommandBuffer();
5514 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5515 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5516 &descriptor_set, 0, NULL);
5517 Draw(1, 0, 0, 0);
5518 EndCommandBuffer();
5519 // Submit cmd buffer to put pool in-flight
5520 VkSubmitInfo submit_info = {};
5521 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5522 submit_info.commandBufferCount = 1;
5523 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5524 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5525 // Destroy pool while in-flight, causing error
5526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5527 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5528 m_errorMonitor->VerifyFound();
5529 vkQueueWaitIdle(m_device->m_queue);
5530 // Cleanup
5531 vkDestroySampler(m_device->device(), sampler, NULL);
5532 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5533 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5534 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5535}
5536
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005537TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5538 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5539 ASSERT_NO_FATAL_FAILURE(InitState());
5540 ASSERT_NO_FATAL_FAILURE(InitViewport());
5541 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5542
5543 VkDescriptorPoolSize ds_type_count = {};
5544 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5545 ds_type_count.descriptorCount = 1;
5546
5547 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5548 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5549 ds_pool_ci.pNext = NULL;
5550 ds_pool_ci.maxSets = 1;
5551 ds_pool_ci.poolSizeCount = 1;
5552 ds_pool_ci.pPoolSizes = &ds_type_count;
5553
5554 VkDescriptorPool ds_pool;
5555 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5556 ASSERT_VK_SUCCESS(err);
5557
5558 VkDescriptorSetLayoutBinding dsl_binding = {};
5559 dsl_binding.binding = 0;
5560 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5561 dsl_binding.descriptorCount = 1;
5562 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5563 dsl_binding.pImmutableSamplers = NULL;
5564
5565 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5566 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5567 ds_layout_ci.pNext = NULL;
5568 ds_layout_ci.bindingCount = 1;
5569 ds_layout_ci.pBindings = &dsl_binding;
5570 VkDescriptorSetLayout ds_layout;
5571 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5572 ASSERT_VK_SUCCESS(err);
5573
5574 VkDescriptorSet descriptorSet;
5575 VkDescriptorSetAllocateInfo alloc_info = {};
5576 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5577 alloc_info.descriptorSetCount = 1;
5578 alloc_info.descriptorPool = ds_pool;
5579 alloc_info.pSetLayouts = &ds_layout;
5580 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5581 ASSERT_VK_SUCCESS(err);
5582
5583 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5584 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5585 pipeline_layout_ci.pNext = NULL;
5586 pipeline_layout_ci.setLayoutCount = 1;
5587 pipeline_layout_ci.pSetLayouts = &ds_layout;
5588
5589 VkPipelineLayout pipeline_layout;
5590 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5591 ASSERT_VK_SUCCESS(err);
5592
5593 // Create images to update the descriptor with
5594 VkImage image;
5595 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5596 const int32_t tex_width = 32;
5597 const int32_t tex_height = 32;
5598 VkImageCreateInfo image_create_info = {};
5599 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5600 image_create_info.pNext = NULL;
5601 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5602 image_create_info.format = tex_format;
5603 image_create_info.extent.width = tex_width;
5604 image_create_info.extent.height = tex_height;
5605 image_create_info.extent.depth = 1;
5606 image_create_info.mipLevels = 1;
5607 image_create_info.arrayLayers = 1;
5608 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5609 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5610 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5611 image_create_info.flags = 0;
5612 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5613 ASSERT_VK_SUCCESS(err);
5614 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5615 VkMemoryRequirements memory_reqs;
5616 VkDeviceMemory image_memory;
5617 bool pass;
5618 VkMemoryAllocateInfo memory_info = {};
5619 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5620 memory_info.pNext = NULL;
5621 memory_info.allocationSize = 0;
5622 memory_info.memoryTypeIndex = 0;
5623 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5624 // Allocate enough memory for image
5625 memory_info.allocationSize = memory_reqs.size;
5626 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5627 ASSERT_TRUE(pass);
5628 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5629 ASSERT_VK_SUCCESS(err);
5630 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5631 ASSERT_VK_SUCCESS(err);
5632
5633 VkImageViewCreateInfo image_view_create_info = {};
5634 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5635 image_view_create_info.image = image;
5636 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5637 image_view_create_info.format = tex_format;
5638 image_view_create_info.subresourceRange.layerCount = 1;
5639 image_view_create_info.subresourceRange.baseMipLevel = 0;
5640 image_view_create_info.subresourceRange.levelCount = 1;
5641 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5642
5643 VkImageView view;
5644 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5645 ASSERT_VK_SUCCESS(err);
5646 // Create Samplers
5647 VkSamplerCreateInfo sampler_ci = {};
5648 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5649 sampler_ci.pNext = NULL;
5650 sampler_ci.magFilter = VK_FILTER_NEAREST;
5651 sampler_ci.minFilter = VK_FILTER_NEAREST;
5652 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5653 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5654 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5655 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5656 sampler_ci.mipLodBias = 1.0;
5657 sampler_ci.anisotropyEnable = VK_FALSE;
5658 sampler_ci.maxAnisotropy = 1;
5659 sampler_ci.compareEnable = VK_FALSE;
5660 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5661 sampler_ci.minLod = 1.0;
5662 sampler_ci.maxLod = 1.0;
5663 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5664 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5665 VkSampler sampler;
5666 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5667 ASSERT_VK_SUCCESS(err);
5668 // Update descriptor with image and sampler
5669 VkDescriptorImageInfo img_info = {};
5670 img_info.sampler = sampler;
5671 img_info.imageView = view;
5672 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5673
5674 VkWriteDescriptorSet descriptor_write;
5675 memset(&descriptor_write, 0, sizeof(descriptor_write));
5676 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5677 descriptor_write.dstSet = descriptorSet;
5678 descriptor_write.dstBinding = 0;
5679 descriptor_write.descriptorCount = 1;
5680 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5681 descriptor_write.pImageInfo = &img_info;
5682 // Break memory binding and attempt update
5683 vkFreeMemory(m_device->device(), image_memory, nullptr);
5684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005685 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5687 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5688 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5689 m_errorMonitor->VerifyFound();
5690 // Cleanup
5691 vkDestroyImage(m_device->device(), image, NULL);
5692 vkDestroySampler(m_device->device(), sampler, NULL);
5693 vkDestroyImageView(m_device->device(), view, NULL);
5694 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5695 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5696 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5697}
5698
Karl Schultz6addd812016-02-02 17:17:23 -07005699TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005700 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5701 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005702 // Create a valid cmd buffer
5703 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005704 uint64_t fake_pipeline_handle = 0xbaad6001;
5705 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005706 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5708
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Karl Schultzbdb75952016-04-19 11:36:49 -06005710 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005711 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005712 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005713
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005714 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005715 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 -06005716 Draw(1, 0, 0, 0);
5717 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005718
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005719 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005720 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 +12005721 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005722 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5723 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005724}
5725
Karl Schultz6addd812016-02-02 17:17:23 -07005726TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005727 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005728 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005729
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005731
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005732 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005733 ASSERT_NO_FATAL_FAILURE(InitViewport());
5734 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005735 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005736 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5737 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005738
5739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5741 ds_pool_ci.pNext = NULL;
5742 ds_pool_ci.maxSets = 1;
5743 ds_pool_ci.poolSizeCount = 1;
5744 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005745
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005746 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005747 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005748 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005749
Tony Barboureb254902015-07-15 12:50:33 -06005750 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005751 dsl_binding.binding = 0;
5752 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5753 dsl_binding.descriptorCount = 1;
5754 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5755 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005756
Tony Barboureb254902015-07-15 12:50:33 -06005757 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005758 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5759 ds_layout_ci.pNext = NULL;
5760 ds_layout_ci.bindingCount = 1;
5761 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005762 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005763 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005764 ASSERT_VK_SUCCESS(err);
5765
5766 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005767 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005768 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005769 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005770 alloc_info.descriptorPool = ds_pool;
5771 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005772 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005773 ASSERT_VK_SUCCESS(err);
5774
Tony Barboureb254902015-07-15 12:50:33 -06005775 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005776 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5777 pipeline_layout_ci.pNext = NULL;
5778 pipeline_layout_ci.setLayoutCount = 1;
5779 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005780
5781 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005782 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005783 ASSERT_VK_SUCCESS(err);
5784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005785 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005786 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005787 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005788 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005789
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005790 VkPipelineObj pipe(m_device);
5791 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005792 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005793 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005794 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005795
5796 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005797 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5798 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5799 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005800
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005801 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005802
Chia-I Wuf7458c52015-10-26 21:10:41 +08005803 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5804 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5805 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005806}
5807
Karl Schultz6addd812016-02-02 17:17:23 -07005808TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005809 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005810 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005811
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005813
5814 ASSERT_NO_FATAL_FAILURE(InitState());
5815 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005816 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5817 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005818
5819 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005820 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5821 ds_pool_ci.pNext = NULL;
5822 ds_pool_ci.maxSets = 1;
5823 ds_pool_ci.poolSizeCount = 1;
5824 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005825
5826 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005827 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005828 ASSERT_VK_SUCCESS(err);
5829
5830 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005831 dsl_binding.binding = 0;
5832 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5833 dsl_binding.descriptorCount = 1;
5834 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5835 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005836
5837 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005838 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5839 ds_layout_ci.pNext = NULL;
5840 ds_layout_ci.bindingCount = 1;
5841 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005842 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005843 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005844 ASSERT_VK_SUCCESS(err);
5845
5846 VkDescriptorSet descriptorSet;
5847 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005848 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005849 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005850 alloc_info.descriptorPool = ds_pool;
5851 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005852 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005853 ASSERT_VK_SUCCESS(err);
5854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005855 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005856 VkWriteDescriptorSet descriptor_write;
5857 memset(&descriptor_write, 0, sizeof(descriptor_write));
5858 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5859 descriptor_write.dstSet = descriptorSet;
5860 descriptor_write.dstBinding = 0;
5861 descriptor_write.descriptorCount = 1;
5862 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5863 descriptor_write.pTexelBufferView = &view;
5864
5865 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5866
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005867 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005868
5869 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5870 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5871}
5872
Mark Youngd339ba32016-05-30 13:28:35 -06005873TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005874 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 -06005875
5876 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005878 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005879
5880 ASSERT_NO_FATAL_FAILURE(InitState());
5881
5882 // Create a buffer with no bound memory and then attempt to create
5883 // a buffer view.
5884 VkBufferCreateInfo buff_ci = {};
5885 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005886 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005887 buff_ci.size = 256;
5888 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5889 VkBuffer buffer;
5890 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5891 ASSERT_VK_SUCCESS(err);
5892
5893 VkBufferViewCreateInfo buff_view_ci = {};
5894 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5895 buff_view_ci.buffer = buffer;
5896 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5897 buff_view_ci.range = VK_WHOLE_SIZE;
5898 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005899 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005900
5901 m_errorMonitor->VerifyFound();
5902 vkDestroyBuffer(m_device->device(), buffer, NULL);
5903 // If last error is success, it still created the view, so delete it.
5904 if (err == VK_SUCCESS) {
5905 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5906 }
5907}
5908
Karl Schultz6addd812016-02-02 17:17:23 -07005909TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5910 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5911 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005912 // 1. No dynamicOffset supplied
5913 // 2. Too many dynamicOffsets supplied
5914 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005915 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5917 "0 dynamicOffsets are left in "
5918 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005919
5920 ASSERT_NO_FATAL_FAILURE(InitState());
5921 ASSERT_NO_FATAL_FAILURE(InitViewport());
5922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5923
5924 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005925 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5926 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005927
5928 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005929 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5930 ds_pool_ci.pNext = NULL;
5931 ds_pool_ci.maxSets = 1;
5932 ds_pool_ci.poolSizeCount = 1;
5933 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005934
5935 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005936 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005937 ASSERT_VK_SUCCESS(err);
5938
5939 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005940 dsl_binding.binding = 0;
5941 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5942 dsl_binding.descriptorCount = 1;
5943 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5944 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005945
5946 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005947 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5948 ds_layout_ci.pNext = NULL;
5949 ds_layout_ci.bindingCount = 1;
5950 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005951 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005952 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005953 ASSERT_VK_SUCCESS(err);
5954
5955 VkDescriptorSet descriptorSet;
5956 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005957 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005958 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005959 alloc_info.descriptorPool = ds_pool;
5960 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005961 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005962 ASSERT_VK_SUCCESS(err);
5963
5964 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005965 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5966 pipeline_layout_ci.pNext = NULL;
5967 pipeline_layout_ci.setLayoutCount = 1;
5968 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005969
5970 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005971 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005972 ASSERT_VK_SUCCESS(err);
5973
5974 // Create a buffer to update the descriptor with
5975 uint32_t qfi = 0;
5976 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005977 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5978 buffCI.size = 1024;
5979 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5980 buffCI.queueFamilyIndexCount = 1;
5981 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005982
5983 VkBuffer dyub;
5984 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5985 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005986 // Allocate memory and bind to buffer so we can make it to the appropriate
5987 // error
5988 VkMemoryAllocateInfo mem_alloc = {};
5989 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5990 mem_alloc.pNext = NULL;
5991 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005992 mem_alloc.memoryTypeIndex = 0;
5993
5994 VkMemoryRequirements memReqs;
5995 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005996 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005997 if (!pass) {
5998 vkDestroyBuffer(m_device->device(), dyub, NULL);
5999 return;
6000 }
6001
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006002 VkDeviceMemory mem;
6003 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6004 ASSERT_VK_SUCCESS(err);
6005 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6006 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006007 // Correctly update descriptor to avoid "NOT_UPDATED" error
6008 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006009 buffInfo.buffer = dyub;
6010 buffInfo.offset = 0;
6011 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006012
6013 VkWriteDescriptorSet descriptor_write;
6014 memset(&descriptor_write, 0, sizeof(descriptor_write));
6015 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6016 descriptor_write.dstSet = descriptorSet;
6017 descriptor_write.dstBinding = 0;
6018 descriptor_write.descriptorCount = 1;
6019 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6020 descriptor_write.pBufferInfo = &buffInfo;
6021
6022 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6023
6024 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006025 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6026 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006027 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006028 uint32_t pDynOff[2] = {512, 756};
6029 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6031 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6032 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6033 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006034 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006035 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
6037 "offset 0 and range 1024 that "
6038 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006039 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006040 char const *vsSource = "#version 450\n"
6041 "\n"
6042 "out gl_PerVertex { \n"
6043 " vec4 gl_Position;\n"
6044 "};\n"
6045 "void main(){\n"
6046 " gl_Position = vec4(1);\n"
6047 "}\n";
6048 char const *fsSource = "#version 450\n"
6049 "\n"
6050 "layout(location=0) out vec4 x;\n"
6051 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6052 "void main(){\n"
6053 " x = vec4(bar.y);\n"
6054 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006055 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6056 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6057 VkPipelineObj pipe(m_device);
6058 pipe.AddShader(&vs);
6059 pipe.AddShader(&fs);
6060 pipe.AddColorAttachment();
6061 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6062
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006063 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6064 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6065 VkRect2D scissor = {{0, 0}, {16, 16}};
6066 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6067
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006068 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006069 // This update should succeed, but offset size of 512 will overstep buffer
6070 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006071 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6072 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006073 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006074 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006075
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006076 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006077 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006078
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006079 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006080 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006081 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6082}
6083
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006084TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6085 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6086 "that doesn't have memory bound");
6087 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006089 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6091 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006092
6093 ASSERT_NO_FATAL_FAILURE(InitState());
6094 ASSERT_NO_FATAL_FAILURE(InitViewport());
6095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6096
6097 VkDescriptorPoolSize ds_type_count = {};
6098 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6099 ds_type_count.descriptorCount = 1;
6100
6101 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6102 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6103 ds_pool_ci.pNext = NULL;
6104 ds_pool_ci.maxSets = 1;
6105 ds_pool_ci.poolSizeCount = 1;
6106 ds_pool_ci.pPoolSizes = &ds_type_count;
6107
6108 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006109 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006110 ASSERT_VK_SUCCESS(err);
6111
6112 VkDescriptorSetLayoutBinding dsl_binding = {};
6113 dsl_binding.binding = 0;
6114 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6115 dsl_binding.descriptorCount = 1;
6116 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6117 dsl_binding.pImmutableSamplers = NULL;
6118
6119 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6120 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6121 ds_layout_ci.pNext = NULL;
6122 ds_layout_ci.bindingCount = 1;
6123 ds_layout_ci.pBindings = &dsl_binding;
6124 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006125 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006126 ASSERT_VK_SUCCESS(err);
6127
6128 VkDescriptorSet descriptorSet;
6129 VkDescriptorSetAllocateInfo alloc_info = {};
6130 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6131 alloc_info.descriptorSetCount = 1;
6132 alloc_info.descriptorPool = ds_pool;
6133 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006134 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006135 ASSERT_VK_SUCCESS(err);
6136
6137 // Create a buffer to update the descriptor with
6138 uint32_t qfi = 0;
6139 VkBufferCreateInfo buffCI = {};
6140 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6141 buffCI.size = 1024;
6142 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6143 buffCI.queueFamilyIndexCount = 1;
6144 buffCI.pQueueFamilyIndices = &qfi;
6145
6146 VkBuffer dyub;
6147 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6148 ASSERT_VK_SUCCESS(err);
6149
6150 // Attempt to update descriptor without binding memory to it
6151 VkDescriptorBufferInfo buffInfo = {};
6152 buffInfo.buffer = dyub;
6153 buffInfo.offset = 0;
6154 buffInfo.range = 1024;
6155
6156 VkWriteDescriptorSet descriptor_write;
6157 memset(&descriptor_write, 0, sizeof(descriptor_write));
6158 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6159 descriptor_write.dstSet = descriptorSet;
6160 descriptor_write.dstBinding = 0;
6161 descriptor_write.descriptorCount = 1;
6162 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6163 descriptor_write.pBufferInfo = &buffInfo;
6164
6165 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6166 m_errorMonitor->VerifyFound();
6167
6168 vkDestroyBuffer(m_device->device(), dyub, NULL);
6169 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6170 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6171}
6172
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006173TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006174 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006175 ASSERT_NO_FATAL_FAILURE(InitState());
6176 ASSERT_NO_FATAL_FAILURE(InitViewport());
6177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6178
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006179 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006180 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006181 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6182 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6183 pipeline_layout_ci.pushConstantRangeCount = 1;
6184 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6185
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006186 //
6187 // Check for invalid push constant ranges in pipeline layouts.
6188 //
6189 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006190 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006191 char const *msg;
6192 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006193
Karl Schultzc81037d2016-05-12 08:11:23 -06006194 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6195 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6196 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6197 "vkCreatePipelineLayout() call has push constants index 0 with "
6198 "size 0."},
6199 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6200 "vkCreatePipelineLayout() call has push constants index 0 with "
6201 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006202 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006203 "vkCreatePipelineLayout() call has push constants index 0 with "
6204 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006205 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006206 "vkCreatePipelineLayout() call has push constants index 0 with "
6207 "size 0."},
6208 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6209 "vkCreatePipelineLayout() call has push constants index 0 with "
6210 "offset 1. Offset must"},
6211 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6212 "vkCreatePipelineLayout() call has push constants index 0 "
6213 "with offset "},
6214 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6215 "vkCreatePipelineLayout() call has push constants "
6216 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006217 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006218 "vkCreatePipelineLayout() call has push constants index 0 "
6219 "with offset "},
6220 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6221 "vkCreatePipelineLayout() call has push "
6222 "constants index 0 with offset "},
6223 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6224 "vkCreatePipelineLayout() call has push "
6225 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006226 }};
6227
6228 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006229 for (const auto &iter : range_tests) {
6230 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6232 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006233 m_errorMonitor->VerifyFound();
6234 if (VK_SUCCESS == err) {
6235 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6236 }
6237 }
6238
6239 // Check for invalid stage flag
6240 pc_range.offset = 0;
6241 pc_range.size = 16;
6242 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006243 m_errorMonitor->SetDesiredFailureMsg(
6244 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6245 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006246 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006247 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006248 if (VK_SUCCESS == err) {
6249 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6250 }
6251
6252 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006253 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006254 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006255 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006256 char const *msg;
6257 };
6258
Karl Schultzc81037d2016-05-12 08:11:23 -06006259 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006260 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6261 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6262 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6263 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6264 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006265 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006266 {
6267 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6268 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6269 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6270 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6271 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006272 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006273 },
6274 {
6275 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6276 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6277 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6278 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6279 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006280 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006281 },
6282 {
6283 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6284 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6285 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6286 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6287 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006288 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006289 },
6290 {
6291 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6292 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6293 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6294 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6295 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006296 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006297 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006298
Karl Schultzc81037d2016-05-12 08:11:23 -06006299 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006300 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006301 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6303 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006304 m_errorMonitor->VerifyFound();
6305 if (VK_SUCCESS == err) {
6306 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6307 }
6308 }
6309
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006310 //
6311 // CmdPushConstants tests
6312 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006313 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006314
6315 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006316 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6317 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006318 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6319 "vkCmdPushConstants() call has push constants with size 1. Size "
6320 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006321 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006322 "vkCmdPushConstants() call has push constants with size 1. Size "
6323 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006324 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006325 "vkCmdPushConstants() call has push constants with offset 1. "
6326 "Offset must be a multiple of 4."},
6327 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6328 "vkCmdPushConstants() call has push constants with offset 1. "
6329 "Offset must be a multiple of 4."},
6330 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6331 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6332 "0x1 not within flag-matching ranges in pipeline layout"},
6333 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6334 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6335 "0x1 not within flag-matching ranges in pipeline layout"},
6336 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6337 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6338 "0x1 not within flag-matching ranges in pipeline layout"},
6339 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6340 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6341 "0x1 not within flag-matching ranges in pipeline layout"},
6342 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6343 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6344 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006345 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006346 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6347 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006348 }};
6349
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006350 BeginCommandBuffer();
6351
6352 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006353 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006354 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006355 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006356 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006357 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006358 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006359 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006360 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6362 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006363 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006364 m_errorMonitor->VerifyFound();
6365 }
6366
6367 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006369 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006370 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006371 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006372
Karl Schultzc81037d2016-05-12 08:11:23 -06006373 // overlapping range tests with cmd
6374 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6375 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6376 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6377 "0x1 not within flag-matching ranges in pipeline layout"},
6378 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6379 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6380 "0x1 not within flag-matching ranges in pipeline layout"},
6381 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6382 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6383 "0x1 not within flag-matching ranges in pipeline layout"},
6384 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006385 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006386 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006387 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6388 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006389 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006390 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006391 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006392 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006393 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006394 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6396 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006397 iter.range.size, dummy_values);
6398 m_errorMonitor->VerifyFound();
6399 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006400 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6401
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006402 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006403}
6404
Karl Schultz6addd812016-02-02 17:17:23 -07006405TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006406 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006407 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006408
6409 ASSERT_NO_FATAL_FAILURE(InitState());
6410 ASSERT_NO_FATAL_FAILURE(InitViewport());
6411 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6412
Mike Stroyanb8a61002016-06-20 16:00:28 -06006413 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6414 VkImageTiling tiling;
6415 VkFormatProperties format_properties;
6416 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006417 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006418 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006419 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006420 tiling = VK_IMAGE_TILING_OPTIMAL;
6421 } else {
6422 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6423 "skipped.\n");
6424 return;
6425 }
6426
Tobin Ehlis559c6382015-11-05 09:52:49 -07006427 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6428 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006429 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6430 ds_type_count[0].descriptorCount = 10;
6431 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6432 ds_type_count[1].descriptorCount = 2;
6433 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6434 ds_type_count[2].descriptorCount = 2;
6435 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6436 ds_type_count[3].descriptorCount = 5;
6437 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6438 // type
6439 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6440 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6441 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006442
6443 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006444 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6445 ds_pool_ci.pNext = NULL;
6446 ds_pool_ci.maxSets = 5;
6447 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6448 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006449
6450 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006451 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006452 ASSERT_VK_SUCCESS(err);
6453
6454 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6455 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006456 dsl_binding[0].binding = 0;
6457 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6458 dsl_binding[0].descriptorCount = 5;
6459 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6460 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006461
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006462 // Create layout identical to set0 layout but w/ different stageFlags
6463 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006464 dsl_fs_stage_only.binding = 0;
6465 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6466 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006467 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6468 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006469 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006470 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006471 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6472 ds_layout_ci.pNext = NULL;
6473 ds_layout_ci.bindingCount = 1;
6474 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006475 static const uint32_t NUM_LAYOUTS = 4;
6476 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006477 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006478 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6479 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006480 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006481 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006482 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006483 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006484 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006485 dsl_binding[0].binding = 0;
6486 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006487 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006488 dsl_binding[1].binding = 1;
6489 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6490 dsl_binding[1].descriptorCount = 2;
6491 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6492 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006493 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006494 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006495 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006496 ASSERT_VK_SUCCESS(err);
6497 dsl_binding[0].binding = 0;
6498 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006499 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006500 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006501 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006502 ASSERT_VK_SUCCESS(err);
6503 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006504 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006505 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006506 ASSERT_VK_SUCCESS(err);
6507
6508 static const uint32_t NUM_SETS = 4;
6509 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6510 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006511 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006512 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006513 alloc_info.descriptorPool = ds_pool;
6514 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006516 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006517 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006518 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006519 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006520 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006521 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006522
6523 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006524 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6525 pipeline_layout_ci.pNext = NULL;
6526 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6527 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006528
6529 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006530 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006531 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006532 // Create pipelineLayout with only one setLayout
6533 pipeline_layout_ci.setLayoutCount = 1;
6534 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006535 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006536 ASSERT_VK_SUCCESS(err);
6537 // Create pipelineLayout with 2 descriptor setLayout at index 0
6538 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6539 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006540 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006541 ASSERT_VK_SUCCESS(err);
6542 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6543 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6544 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006545 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006546 ASSERT_VK_SUCCESS(err);
6547 // Create pipelineLayout with UB type, but stageFlags for FS only
6548 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6549 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006550 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006551 ASSERT_VK_SUCCESS(err);
6552 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6553 VkDescriptorSetLayout pl_bad_s0[2] = {};
6554 pl_bad_s0[0] = ds_layout_fs_only;
6555 pl_bad_s0[1] = ds_layout[1];
6556 pipeline_layout_ci.setLayoutCount = 2;
6557 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6558 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006559 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006560 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006561
6562 // Create a buffer to update the descriptor with
6563 uint32_t qfi = 0;
6564 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006565 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6566 buffCI.size = 1024;
6567 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6568 buffCI.queueFamilyIndexCount = 1;
6569 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006570
6571 VkBuffer dyub;
6572 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6573 ASSERT_VK_SUCCESS(err);
6574 // Correctly update descriptor to avoid "NOT_UPDATED" error
6575 static const uint32_t NUM_BUFFS = 5;
6576 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006577 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006578 buffInfo[i].buffer = dyub;
6579 buffInfo[i].offset = 0;
6580 buffInfo[i].range = 1024;
6581 }
Karl Schultz6addd812016-02-02 17:17:23 -07006582 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006583 const int32_t tex_width = 32;
6584 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006585 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006586 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6587 image_create_info.pNext = NULL;
6588 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6589 image_create_info.format = tex_format;
6590 image_create_info.extent.width = tex_width;
6591 image_create_info.extent.height = tex_height;
6592 image_create_info.extent.depth = 1;
6593 image_create_info.mipLevels = 1;
6594 image_create_info.arrayLayers = 1;
6595 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006596 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006597 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006598 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006599 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6600 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006601
Karl Schultz6addd812016-02-02 17:17:23 -07006602 VkMemoryRequirements memReqs;
6603 VkDeviceMemory imageMem;
6604 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006605 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006606 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6607 memAlloc.pNext = NULL;
6608 memAlloc.allocationSize = 0;
6609 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006610 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6611 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006612 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006613 ASSERT_TRUE(pass);
6614 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6615 ASSERT_VK_SUCCESS(err);
6616 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6617 ASSERT_VK_SUCCESS(err);
6618
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006619 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006620 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6621 image_view_create_info.image = image;
6622 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6623 image_view_create_info.format = tex_format;
6624 image_view_create_info.subresourceRange.layerCount = 1;
6625 image_view_create_info.subresourceRange.baseMipLevel = 0;
6626 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006627 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006628
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006629 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006630 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006631 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006632 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006633 imageInfo[0].imageView = view;
6634 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6635 imageInfo[1].imageView = view;
6636 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006637 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006638 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006639 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006640 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006641
6642 static const uint32_t NUM_SET_UPDATES = 3;
6643 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6644 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6645 descriptor_write[0].dstSet = descriptorSet[0];
6646 descriptor_write[0].dstBinding = 0;
6647 descriptor_write[0].descriptorCount = 5;
6648 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6649 descriptor_write[0].pBufferInfo = buffInfo;
6650 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6651 descriptor_write[1].dstSet = descriptorSet[1];
6652 descriptor_write[1].dstBinding = 0;
6653 descriptor_write[1].descriptorCount = 2;
6654 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6655 descriptor_write[1].pImageInfo = imageInfo;
6656 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6657 descriptor_write[2].dstSet = descriptorSet[1];
6658 descriptor_write[2].dstBinding = 1;
6659 descriptor_write[2].descriptorCount = 2;
6660 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006661 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006662
6663 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006664
Tobin Ehlis88452832015-12-03 09:40:56 -07006665 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006666 char const *vsSource = "#version 450\n"
6667 "\n"
6668 "out gl_PerVertex {\n"
6669 " vec4 gl_Position;\n"
6670 "};\n"
6671 "void main(){\n"
6672 " gl_Position = vec4(1);\n"
6673 "}\n";
6674 char const *fsSource = "#version 450\n"
6675 "\n"
6676 "layout(location=0) out vec4 x;\n"
6677 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6678 "void main(){\n"
6679 " x = vec4(bar.y);\n"
6680 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006681 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6682 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006683 VkPipelineObj pipe(m_device);
6684 pipe.AddShader(&vs);
6685 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006686 pipe.AddColorAttachment();
6687 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006688
6689 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006690
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006691 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006692 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6693 // of PSO
6694 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6695 // cmd_pipeline.c
6696 // due to the fact that cmd_alloc_dset_data() has not been called in
6697 // cmd_bind_graphics_pipeline()
6698 // TODO : Want to cause various binding incompatibility issues here to test
6699 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006700 // First cause various verify_layout_compatibility() fails
6701 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006702 // verify_set_layout_compatibility fail cases:
6703 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006705 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6706 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006707 m_errorMonitor->VerifyFound();
6708
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006709 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6711 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6712 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006713 m_errorMonitor->VerifyFound();
6714
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006715 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006716 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6717 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6719 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6720 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006721 m_errorMonitor->VerifyFound();
6722
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006723 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6724 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6726 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6727 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006728 m_errorMonitor->VerifyFound();
6729
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006730 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6731 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6733 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6734 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6735 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006736 m_errorMonitor->VerifyFound();
6737
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006738 // Cause INFO messages due to disturbing previously bound Sets
6739 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006740 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6741 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006742 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6744 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6745 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006746 m_errorMonitor->VerifyFound();
6747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006748 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6749 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006750 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6752 "any subsequent sets were disturbed ");
6753 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6754 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006755 m_errorMonitor->VerifyFound();
6756
Tobin Ehlis10fad692016-07-07 12:00:36 -06006757 // Now that we're done actively using the pipelineLayout that gfx pipeline
6758 // was created with, we should be able to delete it. Do that now to verify
6759 // that validation obeys pipelineLayout lifetime
6760 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6761
Tobin Ehlis88452832015-12-03 09:40:56 -07006762 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006763 // 1. Error due to not binding required set (we actually use same code as
6764 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006765 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6766 &descriptorSet[0], 0, NULL);
6767 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6768 &descriptorSet[1], 0, NULL);
6769 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 -07006770 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006771 m_errorMonitor->VerifyFound();
6772
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006773 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006774 // 2. Error due to bound set not being compatible with PSO's
6775 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006776 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6777 &descriptorSet[0], 0, NULL);
6778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006779 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006780 m_errorMonitor->VerifyFound();
6781
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006782 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006783 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006784 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6785 }
6786 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006787 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006788 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6789 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006790 vkFreeMemory(m_device->device(), imageMem, NULL);
6791 vkDestroyImage(m_device->device(), image, NULL);
6792 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006793}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006794
Karl Schultz6addd812016-02-02 17:17:23 -07006795TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006796
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6798 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006799
6800 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006801 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006802 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006803 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006804
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006805 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006806}
6807
Karl Schultz6addd812016-02-02 17:17:23 -07006808TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6809 VkResult err;
6810 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006811
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006813
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006814 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006815
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006816 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006817 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006818 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006819 cmd.commandPool = m_commandPool;
6820 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006821 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006822
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006823 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006824 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006825
6826 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006827 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006828 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006829 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006830 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006831 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 -07006832 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006833
6834 // The error should be caught by validation of the BeginCommandBuffer call
6835 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6836
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006837 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006838 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006839}
6840
Karl Schultz6addd812016-02-02 17:17:23 -07006841TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006842 // Cause error due to Begin while recording CB
6843 // Then cause 2 errors for attempting to reset CB w/o having
6844 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6845 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006847
6848 ASSERT_NO_FATAL_FAILURE(InitState());
6849
6850 // Calls AllocateCommandBuffers
6851 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6852
Karl Schultz6addd812016-02-02 17:17:23 -07006853 // Force the failure by setting the Renderpass and Framebuffer fields with
6854 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006855 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006856 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006857 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6858 cmd_buf_info.pNext = NULL;
6859 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006860 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006861
6862 // Begin CB to transition to recording state
6863 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6864 // Can't re-begin. This should trigger error
6865 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006866 m_errorMonitor->VerifyFound();
6867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006869 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6870 // Reset attempt will trigger error due to incorrect CommandPool state
6871 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006872 m_errorMonitor->VerifyFound();
6873
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006875 // Transition CB to RECORDED state
6876 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6877 // Now attempting to Begin will implicitly reset, which triggers error
6878 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006879 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006880}
6881
Karl Schultz6addd812016-02-02 17:17:23 -07006882TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006883 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006884 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006885
Mike Weiblencce7ec72016-10-17 19:33:05 -06006886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006887
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006888 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006890
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006891 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006892 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6893 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006894
6895 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006896 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6897 ds_pool_ci.pNext = NULL;
6898 ds_pool_ci.maxSets = 1;
6899 ds_pool_ci.poolSizeCount = 1;
6900 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006901
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006902 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006903 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006904 ASSERT_VK_SUCCESS(err);
6905
Tony Barboureb254902015-07-15 12:50:33 -06006906 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006907 dsl_binding.binding = 0;
6908 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6909 dsl_binding.descriptorCount = 1;
6910 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6911 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006912
Tony Barboureb254902015-07-15 12:50:33 -06006913 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006914 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6915 ds_layout_ci.pNext = NULL;
6916 ds_layout_ci.bindingCount = 1;
6917 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006918
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006919 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006920 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006921 ASSERT_VK_SUCCESS(err);
6922
6923 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006924 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006925 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006926 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006927 alloc_info.descriptorPool = ds_pool;
6928 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006929 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006930 ASSERT_VK_SUCCESS(err);
6931
Tony Barboureb254902015-07-15 12:50:33 -06006932 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006933 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6934 pipeline_layout_ci.setLayoutCount = 1;
6935 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006936
6937 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006938 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006939 ASSERT_VK_SUCCESS(err);
6940
Tobin Ehlise68360f2015-10-01 11:15:13 -06006941 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006942 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006943
6944 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006945 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6946 vp_state_ci.scissorCount = 1;
6947 vp_state_ci.pScissors = &sc;
6948 vp_state_ci.viewportCount = 1;
6949 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006950
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006951 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6952 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6953 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6954 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6955 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6956 rs_state_ci.depthClampEnable = VK_FALSE;
6957 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6958 rs_state_ci.depthBiasEnable = VK_FALSE;
6959
Tony Barboureb254902015-07-15 12:50:33 -06006960 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006961 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6962 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006963 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006964 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6965 gp_ci.layout = pipeline_layout;
6966 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006967
6968 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006969 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6970 pc_ci.initialDataSize = 0;
6971 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006972
6973 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006974 VkPipelineCache pipelineCache;
6975
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006976 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006977 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006978 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006979
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006980 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006981
Chia-I Wuf7458c52015-10-26 21:10:41 +08006982 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6983 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6984 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6985 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006986}
Tobin Ehlis912df022015-09-17 08:46:18 -06006987/*// TODO : This test should be good, but needs Tess support in compiler to run
6988TEST_F(VkLayerTest, InvalidPatchControlPoints)
6989{
6990 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006991 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006992
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006994 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6995primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006996
Tobin Ehlis912df022015-09-17 08:46:18 -06006997 ASSERT_NO_FATAL_FAILURE(InitState());
6998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006999
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007000 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007001 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007002 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007003
7004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7006 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007007 ds_pool_ci.poolSizeCount = 1;
7008 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007009
7010 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007011 err = vkCreateDescriptorPool(m_device->device(),
7012VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007013 ASSERT_VK_SUCCESS(err);
7014
7015 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007016 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007018 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007019 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7020 dsl_binding.pImmutableSamplers = NULL;
7021
7022 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007023 ds_layout_ci.sType =
7024VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007025 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007026 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007027 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007028
7029 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007030 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7031&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007032 ASSERT_VK_SUCCESS(err);
7033
7034 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007035 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7036VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007037 ASSERT_VK_SUCCESS(err);
7038
7039 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007040 pipeline_layout_ci.sType =
7041VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007042 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007043 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007044 pipeline_layout_ci.pSetLayouts = &ds_layout;
7045
7046 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007047 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7048&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007049 ASSERT_VK_SUCCESS(err);
7050
7051 VkPipelineShaderStageCreateInfo shaderStages[3];
7052 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7053
Karl Schultz6addd812016-02-02 17:17:23 -07007054 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7055this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007056 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007057 VkShaderObj
7058tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7059this);
7060 VkShaderObj
7061te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7062this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007063
Karl Schultz6addd812016-02-02 17:17:23 -07007064 shaderStages[0].sType =
7065VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007066 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007067 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007068 shaderStages[1].sType =
7069VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007070 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007071 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007072 shaderStages[2].sType =
7073VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007074 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007075 shaderStages[2].shader = te.handle();
7076
7077 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007078 iaCI.sType =
7079VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007080 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007081
7082 VkPipelineTessellationStateCreateInfo tsCI = {};
7083 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7084 tsCI.patchControlPoints = 0; // This will cause an error
7085
7086 VkGraphicsPipelineCreateInfo gp_ci = {};
7087 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7088 gp_ci.pNext = NULL;
7089 gp_ci.stageCount = 3;
7090 gp_ci.pStages = shaderStages;
7091 gp_ci.pVertexInputState = NULL;
7092 gp_ci.pInputAssemblyState = &iaCI;
7093 gp_ci.pTessellationState = &tsCI;
7094 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007095 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007096 gp_ci.pMultisampleState = NULL;
7097 gp_ci.pDepthStencilState = NULL;
7098 gp_ci.pColorBlendState = NULL;
7099 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7100 gp_ci.layout = pipeline_layout;
7101 gp_ci.renderPass = renderPass();
7102
7103 VkPipelineCacheCreateInfo pc_ci = {};
7104 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7105 pc_ci.pNext = NULL;
7106 pc_ci.initialSize = 0;
7107 pc_ci.initialData = 0;
7108 pc_ci.maxSize = 0;
7109
7110 VkPipeline pipeline;
7111 VkPipelineCache pipelineCache;
7112
Karl Schultz6addd812016-02-02 17:17:23 -07007113 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7114&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007115 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007116 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7117&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007119 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007120
Chia-I Wuf7458c52015-10-26 21:10:41 +08007121 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7122 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7123 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7124 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007125}
7126*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007127// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007128TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007129 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007130
Mark Lobodzinski6fcae552016-12-18 08:57:03 -07007131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007132
Tobin Ehlise68360f2015-10-01 11:15:13 -06007133 ASSERT_NO_FATAL_FAILURE(InitState());
7134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007135
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007136 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007137 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7138 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007139
7140 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007141 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7142 ds_pool_ci.maxSets = 1;
7143 ds_pool_ci.poolSizeCount = 1;
7144 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007145
7146 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007147 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007148 ASSERT_VK_SUCCESS(err);
7149
7150 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007151 dsl_binding.binding = 0;
7152 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7153 dsl_binding.descriptorCount = 1;
7154 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007155
7156 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007157 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7158 ds_layout_ci.bindingCount = 1;
7159 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007160
7161 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007162 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007163 ASSERT_VK_SUCCESS(err);
7164
7165 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007166 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007167 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007168 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007169 alloc_info.descriptorPool = ds_pool;
7170 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007171 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007172 ASSERT_VK_SUCCESS(err);
7173
7174 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007175 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7176 pipeline_layout_ci.setLayoutCount = 1;
7177 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007178
7179 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007180 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007181 ASSERT_VK_SUCCESS(err);
7182
7183 VkViewport vp = {}; // Just need dummy vp to point to
7184
7185 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007186 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7187 vp_state_ci.scissorCount = 0;
7188 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7189 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007190
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007191 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7192 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7193 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7194 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7195 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7196 rs_state_ci.depthClampEnable = VK_FALSE;
7197 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7198 rs_state_ci.depthBiasEnable = VK_FALSE;
7199
Cody Northropeb3a6c12015-10-05 14:44:45 -06007200 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007201 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007203 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007204 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7205 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007206 shaderStages[0] = vs.GetStageCreateInfo();
7207 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007208
7209 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007210 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7211 gp_ci.stageCount = 2;
7212 gp_ci.pStages = shaderStages;
7213 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007214 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007215 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7216 gp_ci.layout = pipeline_layout;
7217 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007218
7219 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007220 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007221
7222 VkPipeline pipeline;
7223 VkPipelineCache pipelineCache;
7224
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007225 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007226 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007227 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007228
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007229 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007230
Chia-I Wuf7458c52015-10-26 21:10:41 +08007231 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7232 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7233 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7234 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007235}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007236
7237// Don't set viewport state in PSO. This is an error b/c we always need this state for the counts even if the data is going to be
7238// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007239TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007240 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007241
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007242 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7243
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007245
Tobin Ehlise68360f2015-10-01 11:15:13 -06007246 ASSERT_NO_FATAL_FAILURE(InitState());
7247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007248
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007249 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007250 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7251 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007252
7253 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007254 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7255 ds_pool_ci.maxSets = 1;
7256 ds_pool_ci.poolSizeCount = 1;
7257 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007258
7259 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007260 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007261 ASSERT_VK_SUCCESS(err);
7262
7263 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007264 dsl_binding.binding = 0;
7265 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7266 dsl_binding.descriptorCount = 1;
7267 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007268
7269 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007270 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7271 ds_layout_ci.bindingCount = 1;
7272 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007273
7274 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007275 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007276 ASSERT_VK_SUCCESS(err);
7277
7278 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007279 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007280 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007281 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007282 alloc_info.descriptorPool = ds_pool;
7283 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007284 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007285 ASSERT_VK_SUCCESS(err);
7286
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007287 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7288 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7289 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7290
7291 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7292 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7293 vi_ci.pNext = nullptr;
7294 vi_ci.vertexBindingDescriptionCount = 0;
7295 vi_ci.pVertexBindingDescriptions = nullptr;
7296 vi_ci.vertexAttributeDescriptionCount = 0;
7297 vi_ci.pVertexAttributeDescriptions = nullptr;
7298
7299 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7300 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7301 pipe_ms_state_ci.pNext = NULL;
7302 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7303 pipe_ms_state_ci.sampleShadingEnable = 0;
7304 pipe_ms_state_ci.minSampleShading = 1.0;
7305 pipe_ms_state_ci.pSampleMask = NULL;
7306
Tobin Ehlise68360f2015-10-01 11:15:13 -06007307 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007308 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7309 pipeline_layout_ci.setLayoutCount = 1;
7310 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007311
7312 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007313 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007314 ASSERT_VK_SUCCESS(err);
7315
7316 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7317 // Set scissor as dynamic to avoid second error
7318 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007319 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7320 dyn_state_ci.dynamicStateCount = 1;
7321 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007322
Cody Northropeb3a6c12015-10-05 14:44:45 -06007323 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007324 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007325
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007326 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007327 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7328 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007329 shaderStages[0] = vs.GetStageCreateInfo();
7330 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007331
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007332 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7333 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7334 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7335 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7336 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7337 rs_state_ci.depthClampEnable = VK_FALSE;
7338 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7339 rs_state_ci.depthBiasEnable = VK_FALSE;
7340
Tobin Ehlise68360f2015-10-01 11:15:13 -06007341 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007342 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7343 gp_ci.stageCount = 2;
7344 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007345 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007346 // Not setting VP state w/o dynamic vp state should cause validation error
7347 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007348 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007349 gp_ci.pVertexInputState = &vi_ci;
7350 gp_ci.pInputAssemblyState = &ia_ci;
7351 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007352 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7353 gp_ci.layout = pipeline_layout;
7354 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007355
7356 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007357 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007358
7359 VkPipeline pipeline;
7360 VkPipelineCache pipelineCache;
7361
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007362 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007363 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007364 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007365
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007366 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007367
Chia-I Wuf7458c52015-10-26 21:10:41 +08007368 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7369 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7370 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7371 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007372}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007373
7374// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7375// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007376TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7377 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007378
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007380
Tobin Ehlise68360f2015-10-01 11:15:13 -06007381 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007382
7383 if (!m_device->phy().features().multiViewport) {
7384 printf("Device does not support multiple viewports/scissors; skipped.\n");
7385 return;
7386 }
7387
Tobin Ehlise68360f2015-10-01 11:15:13 -06007388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007389
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007390 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007391 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7392 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007393
7394 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007395 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7396 ds_pool_ci.maxSets = 1;
7397 ds_pool_ci.poolSizeCount = 1;
7398 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007399
7400 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007401 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007402 ASSERT_VK_SUCCESS(err);
7403
7404 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007405 dsl_binding.binding = 0;
7406 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7407 dsl_binding.descriptorCount = 1;
7408 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007409
7410 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007411 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7412 ds_layout_ci.bindingCount = 1;
7413 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007414
7415 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007416 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007417 ASSERT_VK_SUCCESS(err);
7418
7419 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007420 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007421 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007422 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007423 alloc_info.descriptorPool = ds_pool;
7424 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007425 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007426 ASSERT_VK_SUCCESS(err);
7427
7428 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007429 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7430 pipeline_layout_ci.setLayoutCount = 1;
7431 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007432
7433 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007434 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007435 ASSERT_VK_SUCCESS(err);
7436
7437 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007438 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7439 vp_state_ci.viewportCount = 1;
7440 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7441 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007442 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007443
7444 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7445 // Set scissor as dynamic to avoid that error
7446 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007447 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7448 dyn_state_ci.dynamicStateCount = 1;
7449 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007450
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007451 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7452 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7453 pipe_ms_state_ci.pNext = NULL;
7454 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7455 pipe_ms_state_ci.sampleShadingEnable = 0;
7456 pipe_ms_state_ci.minSampleShading = 1.0;
7457 pipe_ms_state_ci.pSampleMask = NULL;
7458
Cody Northropeb3a6c12015-10-05 14:44:45 -06007459 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007460 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007461
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007462 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007463 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7464 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007465 shaderStages[0] = vs.GetStageCreateInfo();
7466 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007467
Cody Northropf6622dc2015-10-06 10:33:21 -06007468 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7469 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7470 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007471 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007472 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007473 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007474 vi_ci.pVertexAttributeDescriptions = nullptr;
7475
7476 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7477 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7478 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7479
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007480 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007481 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007482 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007483 rs_ci.pNext = nullptr;
7484
Mark Youngc89c6312016-03-31 16:03:20 -06007485 VkPipelineColorBlendAttachmentState att = {};
7486 att.blendEnable = VK_FALSE;
7487 att.colorWriteMask = 0xf;
7488
Cody Northropf6622dc2015-10-06 10:33:21 -06007489 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7490 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7491 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007492 cb_ci.attachmentCount = 1;
7493 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007494
Tobin Ehlise68360f2015-10-01 11:15:13 -06007495 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007496 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7497 gp_ci.stageCount = 2;
7498 gp_ci.pStages = shaderStages;
7499 gp_ci.pVertexInputState = &vi_ci;
7500 gp_ci.pInputAssemblyState = &ia_ci;
7501 gp_ci.pViewportState = &vp_state_ci;
7502 gp_ci.pRasterizationState = &rs_ci;
7503 gp_ci.pColorBlendState = &cb_ci;
7504 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007505 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007506 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7507 gp_ci.layout = pipeline_layout;
7508 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007509
7510 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007511 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007512
7513 VkPipeline pipeline;
7514 VkPipelineCache pipelineCache;
7515
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007516 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007517 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007518 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007519
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007520 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007521
Tobin Ehlisd332f282015-10-02 11:00:56 -06007522 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007523 // First need to successfully create the PSO from above by setting
7524 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007525 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 -07007526
7527 VkViewport vp = {}; // Just need dummy vp to point to
7528 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007529 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007530 ASSERT_VK_SUCCESS(err);
7531 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007532 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007533 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007534 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007535 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007536 Draw(1, 0, 0, 0);
7537
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007538 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007539
7540 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7541 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7542 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7543 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007544 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007545}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007546
7547// Create PSO w/o non-zero scissorCount but no scissor data, then run second test where dynamic viewportCount doesn't match PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007548// viewportCount
7549TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7550 VkResult err;
7551
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007553
7554 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007555
7556 if (!m_device->phy().features().multiViewport) {
7557 printf("Device does not support multiple viewports/scissors; skipped.\n");
7558 return;
7559 }
7560
Karl Schultz6addd812016-02-02 17:17:23 -07007561 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7562
7563 VkDescriptorPoolSize ds_type_count = {};
7564 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7565 ds_type_count.descriptorCount = 1;
7566
7567 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7568 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7569 ds_pool_ci.maxSets = 1;
7570 ds_pool_ci.poolSizeCount = 1;
7571 ds_pool_ci.pPoolSizes = &ds_type_count;
7572
7573 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007574 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007575 ASSERT_VK_SUCCESS(err);
7576
7577 VkDescriptorSetLayoutBinding dsl_binding = {};
7578 dsl_binding.binding = 0;
7579 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7580 dsl_binding.descriptorCount = 1;
7581 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7582
7583 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7584 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7585 ds_layout_ci.bindingCount = 1;
7586 ds_layout_ci.pBindings = &dsl_binding;
7587
7588 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007589 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007590 ASSERT_VK_SUCCESS(err);
7591
7592 VkDescriptorSet descriptorSet;
7593 VkDescriptorSetAllocateInfo alloc_info = {};
7594 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7595 alloc_info.descriptorSetCount = 1;
7596 alloc_info.descriptorPool = ds_pool;
7597 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007598 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007599 ASSERT_VK_SUCCESS(err);
7600
7601 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7602 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7603 pipeline_layout_ci.setLayoutCount = 1;
7604 pipeline_layout_ci.pSetLayouts = &ds_layout;
7605
7606 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007607 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007608 ASSERT_VK_SUCCESS(err);
7609
7610 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7611 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7612 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007613 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007614 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007615 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007616
7617 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7618 // Set scissor as dynamic to avoid that error
7619 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7620 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7621 dyn_state_ci.dynamicStateCount = 1;
7622 dyn_state_ci.pDynamicStates = &vp_state;
7623
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007624 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7625 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7626 pipe_ms_state_ci.pNext = NULL;
7627 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7628 pipe_ms_state_ci.sampleShadingEnable = 0;
7629 pipe_ms_state_ci.minSampleShading = 1.0;
7630 pipe_ms_state_ci.pSampleMask = NULL;
7631
Karl Schultz6addd812016-02-02 17:17:23 -07007632 VkPipelineShaderStageCreateInfo shaderStages[2];
7633 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7634
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007635 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007636 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7637 // We shouldn't need a fragment shader but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007638 shaderStages[0] = vs.GetStageCreateInfo();
7639 shaderStages[1] = fs.GetStageCreateInfo();
7640
7641 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7642 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7643 vi_ci.pNext = nullptr;
7644 vi_ci.vertexBindingDescriptionCount = 0;
7645 vi_ci.pVertexBindingDescriptions = nullptr;
7646 vi_ci.vertexAttributeDescriptionCount = 0;
7647 vi_ci.pVertexAttributeDescriptions = nullptr;
7648
7649 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7650 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7651 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7652
7653 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7654 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007655 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007656 rs_ci.pNext = nullptr;
7657
Mark Youngc89c6312016-03-31 16:03:20 -06007658 VkPipelineColorBlendAttachmentState att = {};
7659 att.blendEnable = VK_FALSE;
7660 att.colorWriteMask = 0xf;
7661
Karl Schultz6addd812016-02-02 17:17:23 -07007662 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7663 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7664 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007665 cb_ci.attachmentCount = 1;
7666 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007667
7668 VkGraphicsPipelineCreateInfo gp_ci = {};
7669 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7670 gp_ci.stageCount = 2;
7671 gp_ci.pStages = shaderStages;
7672 gp_ci.pVertexInputState = &vi_ci;
7673 gp_ci.pInputAssemblyState = &ia_ci;
7674 gp_ci.pViewportState = &vp_state_ci;
7675 gp_ci.pRasterizationState = &rs_ci;
7676 gp_ci.pColorBlendState = &cb_ci;
7677 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007678 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007679 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7680 gp_ci.layout = pipeline_layout;
7681 gp_ci.renderPass = renderPass();
7682
7683 VkPipelineCacheCreateInfo pc_ci = {};
7684 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7685
7686 VkPipeline pipeline;
7687 VkPipelineCache pipelineCache;
7688
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007689 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007690 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007691 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007692
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007693 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007694
7695 // Now hit second fail case where we set scissor w/ different count than PSO
7696 // First need to successfully create the PSO from above by setting
7697 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007698 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 -06007699
Tobin Ehlisd332f282015-10-02 11:00:56 -06007700 VkRect2D sc = {}; // Just need dummy vp to point to
7701 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007702 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007703 ASSERT_VK_SUCCESS(err);
7704 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007705 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007706 VkViewport viewports[1] = {};
7707 viewports[0].width = 8;
7708 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007709 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007710 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007711 Draw(1, 0, 0, 0);
7712
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007713 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007714
Chia-I Wuf7458c52015-10-26 21:10:41 +08007715 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7716 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7717 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7718 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007719 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007720}
7721
Mark Young7394fdd2016-03-31 14:56:43 -06007722TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7723 VkResult err;
7724
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007726
7727 ASSERT_NO_FATAL_FAILURE(InitState());
7728 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7729
7730 VkDescriptorPoolSize ds_type_count = {};
7731 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7732 ds_type_count.descriptorCount = 1;
7733
7734 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7735 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7736 ds_pool_ci.maxSets = 1;
7737 ds_pool_ci.poolSizeCount = 1;
7738 ds_pool_ci.pPoolSizes = &ds_type_count;
7739
7740 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007741 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007742 ASSERT_VK_SUCCESS(err);
7743
7744 VkDescriptorSetLayoutBinding dsl_binding = {};
7745 dsl_binding.binding = 0;
7746 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7747 dsl_binding.descriptorCount = 1;
7748 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7749
7750 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7751 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7752 ds_layout_ci.bindingCount = 1;
7753 ds_layout_ci.pBindings = &dsl_binding;
7754
7755 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007756 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007757 ASSERT_VK_SUCCESS(err);
7758
7759 VkDescriptorSet descriptorSet;
7760 VkDescriptorSetAllocateInfo alloc_info = {};
7761 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7762 alloc_info.descriptorSetCount = 1;
7763 alloc_info.descriptorPool = ds_pool;
7764 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007765 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007766 ASSERT_VK_SUCCESS(err);
7767
7768 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7769 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7770 pipeline_layout_ci.setLayoutCount = 1;
7771 pipeline_layout_ci.pSetLayouts = &ds_layout;
7772
7773 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007774 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007775 ASSERT_VK_SUCCESS(err);
7776
7777 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7778 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7779 vp_state_ci.scissorCount = 1;
7780 vp_state_ci.pScissors = NULL;
7781 vp_state_ci.viewportCount = 1;
7782 vp_state_ci.pViewports = NULL;
7783
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007784 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007785 // Set scissor as dynamic to avoid that error
7786 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7787 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7788 dyn_state_ci.dynamicStateCount = 2;
7789 dyn_state_ci.pDynamicStates = dynamic_states;
7790
7791 VkPipelineShaderStageCreateInfo shaderStages[2];
7792 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7793
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007794 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7795 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007796 this); // TODO - We shouldn't need a fragment shader
7797 // but add it to be able to run on more devices
7798 shaderStages[0] = vs.GetStageCreateInfo();
7799 shaderStages[1] = fs.GetStageCreateInfo();
7800
7801 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7802 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7803 vi_ci.pNext = nullptr;
7804 vi_ci.vertexBindingDescriptionCount = 0;
7805 vi_ci.pVertexBindingDescriptions = nullptr;
7806 vi_ci.vertexAttributeDescriptionCount = 0;
7807 vi_ci.pVertexAttributeDescriptions = nullptr;
7808
7809 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7810 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7811 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7812
7813 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7814 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7815 rs_ci.pNext = nullptr;
7816
Mark Young47107952016-05-02 15:59:55 -06007817 // Check too low (line width of -1.0f).
7818 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007819
7820 VkPipelineColorBlendAttachmentState att = {};
7821 att.blendEnable = VK_FALSE;
7822 att.colorWriteMask = 0xf;
7823
7824 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7825 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7826 cb_ci.pNext = nullptr;
7827 cb_ci.attachmentCount = 1;
7828 cb_ci.pAttachments = &att;
7829
7830 VkGraphicsPipelineCreateInfo gp_ci = {};
7831 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7832 gp_ci.stageCount = 2;
7833 gp_ci.pStages = shaderStages;
7834 gp_ci.pVertexInputState = &vi_ci;
7835 gp_ci.pInputAssemblyState = &ia_ci;
7836 gp_ci.pViewportState = &vp_state_ci;
7837 gp_ci.pRasterizationState = &rs_ci;
7838 gp_ci.pColorBlendState = &cb_ci;
7839 gp_ci.pDynamicState = &dyn_state_ci;
7840 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7841 gp_ci.layout = pipeline_layout;
7842 gp_ci.renderPass = renderPass();
7843
7844 VkPipelineCacheCreateInfo pc_ci = {};
7845 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7846
7847 VkPipeline pipeline;
7848 VkPipelineCache pipelineCache;
7849
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007850 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007851 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007852 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007853
7854 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007855 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007856
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007858
7859 // Check too high (line width of 65536.0f).
7860 rs_ci.lineWidth = 65536.0f;
7861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007862 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007863 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007864 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007865
7866 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007867 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007870
7871 dyn_state_ci.dynamicStateCount = 3;
7872
7873 rs_ci.lineWidth = 1.0f;
7874
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007875 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007876 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007877 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007878 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007879 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007880
7881 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007882 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007883 m_errorMonitor->VerifyFound();
7884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007886
7887 // Check too high with dynamic setting.
7888 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7889 m_errorMonitor->VerifyFound();
7890 EndCommandBuffer();
7891
7892 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7893 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7894 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7895 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007896 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007897}
7898
Karl Schultz6addd812016-02-02 17:17:23 -07007899TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007900 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7902 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007903
7904 ASSERT_NO_FATAL_FAILURE(InitState());
7905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007906
Tony Barbourfe3351b2015-07-28 10:17:20 -06007907 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007908 // Don't care about RenderPass handle b/c error should be flagged before
7909 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007910 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007911
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007912 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007913}
7914
Karl Schultz6addd812016-02-02 17:17:23 -07007915TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007916 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7918 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007919
7920 ASSERT_NO_FATAL_FAILURE(InitState());
7921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007922
Tony Barbourfe3351b2015-07-28 10:17:20 -06007923 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007924 // Just create a dummy Renderpass that's non-NULL so we can get to the
7925 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007926 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007927
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007928 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007929}
7930
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007931TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7932 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7933 "the number of renderPass attachments that use loadOp"
7934 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7935
7936 ASSERT_NO_FATAL_FAILURE(InitState());
7937 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7938
7939 // Create a renderPass with a single attachment that uses loadOp CLEAR
7940 VkAttachmentReference attach = {};
7941 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7942 VkSubpassDescription subpass = {};
7943 subpass.inputAttachmentCount = 1;
7944 subpass.pInputAttachments = &attach;
7945 VkRenderPassCreateInfo rpci = {};
7946 rpci.subpassCount = 1;
7947 rpci.pSubpasses = &subpass;
7948 rpci.attachmentCount = 1;
7949 VkAttachmentDescription attach_desc = {};
7950 attach_desc.format = VK_FORMAT_UNDEFINED;
7951 // Set loadOp to CLEAR
7952 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7953 rpci.pAttachments = &attach_desc;
7954 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7955 VkRenderPass rp;
7956 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7957
7958 VkCommandBufferInheritanceInfo hinfo = {};
7959 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7960 hinfo.renderPass = VK_NULL_HANDLE;
7961 hinfo.subpass = 0;
7962 hinfo.framebuffer = VK_NULL_HANDLE;
7963 hinfo.occlusionQueryEnable = VK_FALSE;
7964 hinfo.queryFlags = 0;
7965 hinfo.pipelineStatistics = 0;
7966 VkCommandBufferBeginInfo info = {};
7967 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7968 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7969 info.pInheritanceInfo = &hinfo;
7970
7971 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7972 VkRenderPassBeginInfo rp_begin = {};
7973 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7974 rp_begin.pNext = NULL;
7975 rp_begin.renderPass = renderPass();
7976 rp_begin.framebuffer = framebuffer();
7977 rp_begin.clearValueCount = 0; // Should be 1
7978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7980 "there must be at least 1 entries in "
7981 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007983 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007984
7985 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007986
7987 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007988}
7989
Slawomir Cygan0808f392016-11-28 17:53:23 +01007990TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
7991 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
7992 "the number of renderPass attachments that use loadOp"
7993 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7994
7995 ASSERT_NO_FATAL_FAILURE(InitState());
7996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7997
7998 // Create a renderPass with a single attachment that uses loadOp CLEAR
7999 VkAttachmentReference attach = {};
8000 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8001 VkSubpassDescription subpass = {};
8002 subpass.inputAttachmentCount = 1;
8003 subpass.pInputAttachments = &attach;
8004 VkRenderPassCreateInfo rpci = {};
8005 rpci.subpassCount = 1;
8006 rpci.pSubpasses = &subpass;
8007 rpci.attachmentCount = 1;
8008 VkAttachmentDescription attach_desc = {};
8009 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8010 // Set loadOp to CLEAR
8011 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8012 rpci.pAttachments = &attach_desc;
8013 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8014 VkRenderPass rp;
8015 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8016
8017 VkCommandBufferBeginInfo info = {};
8018 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8019 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8020
8021 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8022 VkRenderPassBeginInfo rp_begin = {};
8023 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8024 rp_begin.pNext = NULL;
8025 rp_begin.renderPass = renderPass();
8026 rp_begin.framebuffer = framebuffer();
8027 rp_begin.clearValueCount = 2; // Should be 1
8028
8029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
8030 " 2 but only first 1 entries in pClearValues array are used");
8031
8032 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8033
8034 m_errorMonitor->VerifyFound();
8035
8036 vkDestroyRenderPass(m_device->device(), rp, NULL);
8037}
8038
8039
Cody Northrop3bb4d962016-05-09 16:15:57 -06008040TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
8041
8042 TEST_DESCRIPTION("End a command buffer with an active render pass");
8043
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8045 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008046
8047 ASSERT_NO_FATAL_FAILURE(InitState());
8048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8049
8050 // The framework's BeginCommandBuffer calls CreateRenderPass
8051 BeginCommandBuffer();
8052
8053 // Call directly into vkEndCommandBuffer instead of the
8054 // the framework's EndCommandBuffer, which inserts a
8055 // vkEndRenderPass
8056 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
8057
8058 m_errorMonitor->VerifyFound();
8059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008060 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8061 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008062}
8063
Karl Schultz6addd812016-02-02 17:17:23 -07008064TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008065 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8067 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008068
8069 ASSERT_NO_FATAL_FAILURE(InitState());
8070 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008071
8072 // Renderpass is started here
8073 BeginCommandBuffer();
8074
8075 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008076 vk_testing::Buffer dstBuffer;
8077 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008078
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008079 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008080
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008081 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008082}
8083
Karl Schultz6addd812016-02-02 17:17:23 -07008084TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008085 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8087 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008088
8089 ASSERT_NO_FATAL_FAILURE(InitState());
8090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008091
8092 // Renderpass is started here
8093 BeginCommandBuffer();
8094
8095 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008096 vk_testing::Buffer dstBuffer;
8097 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008098
Karl Schultz6addd812016-02-02 17:17:23 -07008099 VkDeviceSize dstOffset = 0;
8100 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008101 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008102
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008103 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008104
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008105 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008106}
8107
Karl Schultz6addd812016-02-02 17:17:23 -07008108TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008109 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8111 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008112
8113 ASSERT_NO_FATAL_FAILURE(InitState());
8114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008115
8116 // Renderpass is started here
8117 BeginCommandBuffer();
8118
Michael Lentine0a369f62016-02-03 16:51:46 -06008119 VkClearColorValue clear_color;
8120 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008121 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8122 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8123 const int32_t tex_width = 32;
8124 const int32_t tex_height = 32;
8125 VkImageCreateInfo image_create_info = {};
8126 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8127 image_create_info.pNext = NULL;
8128 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8129 image_create_info.format = tex_format;
8130 image_create_info.extent.width = tex_width;
8131 image_create_info.extent.height = tex_height;
8132 image_create_info.extent.depth = 1;
8133 image_create_info.mipLevels = 1;
8134 image_create_info.arrayLayers = 1;
8135 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8136 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8137 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008138
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008139 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008140 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008142 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008143
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008144 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008145
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008146 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008147}
8148
Karl Schultz6addd812016-02-02 17:17:23 -07008149TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008150 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8152 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008153
8154 ASSERT_NO_FATAL_FAILURE(InitState());
8155 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008156
8157 // Renderpass is started here
8158 BeginCommandBuffer();
8159
8160 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008161 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008162 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8163 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8164 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8165 image_create_info.extent.width = 64;
8166 image_create_info.extent.height = 64;
8167 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8168 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008169
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008170 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008171 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008172
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008175 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8176 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008177
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008178 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008179}
8180
Karl Schultz6addd812016-02-02 17:17:23 -07008181TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008182 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008183 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008184
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8186 "must be issued inside an active "
8187 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008188
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008189 ASSERT_NO_FATAL_FAILURE(InitState());
8190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008191
8192 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008193 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008194 ASSERT_VK_SUCCESS(err);
8195
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008196 VkClearAttachment color_attachment;
8197 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8198 color_attachment.clearValue.color.float32[0] = 0;
8199 color_attachment.clearValue.color.float32[1] = 0;
8200 color_attachment.clearValue.color.float32[2] = 0;
8201 color_attachment.clearValue.color.float32[3] = 0;
8202 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008203 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008204 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008205
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008206 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008207}
8208
Chris Forbes3b97e932016-09-07 11:29:24 +12008209TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8210 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8211 "called too many times in a renderpass instance");
8212
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8214 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008215
8216 ASSERT_NO_FATAL_FAILURE(InitState());
8217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8218
8219 BeginCommandBuffer();
8220
8221 // error here.
8222 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8223 m_errorMonitor->VerifyFound();
8224
8225 EndCommandBuffer();
8226}
8227
Chris Forbes6d624702016-09-07 13:57:05 +12008228TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8229 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8230 "called before the final subpass has been reached");
8231
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8233 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008234
8235 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008236 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8237 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008238
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008239 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008240
8241 VkRenderPass rp;
8242 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8243 ASSERT_VK_SUCCESS(err);
8244
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008245 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008246
8247 VkFramebuffer fb;
8248 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8249 ASSERT_VK_SUCCESS(err);
8250
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008251 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008252
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008253 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 +12008254
8255 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8256
8257 // Error here.
8258 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8259 m_errorMonitor->VerifyFound();
8260
8261 // Clean up.
8262 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8263 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8264}
8265
Karl Schultz9e66a292016-04-21 15:57:51 -06008266TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8267 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8269 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008270
8271 ASSERT_NO_FATAL_FAILURE(InitState());
8272 BeginCommandBuffer();
8273
8274 VkBufferMemoryBarrier buf_barrier = {};
8275 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8276 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8277 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8278 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8279 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8280 buf_barrier.buffer = VK_NULL_HANDLE;
8281 buf_barrier.offset = 0;
8282 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008283 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8284 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008285
8286 m_errorMonitor->VerifyFound();
8287}
8288
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008289TEST_F(VkLayerTest, InvalidBarriers) {
8290 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8291
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008293
8294 ASSERT_NO_FATAL_FAILURE(InitState());
8295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8296
8297 VkMemoryBarrier mem_barrier = {};
8298 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8299 mem_barrier.pNext = NULL;
8300 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8301 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8302 BeginCommandBuffer();
8303 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008304 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008305 &mem_barrier, 0, nullptr, 0, nullptr);
8306 m_errorMonitor->VerifyFound();
8307
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008309 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008310 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 -06008311 ASSERT_TRUE(image.initialized());
8312 VkImageMemoryBarrier img_barrier = {};
8313 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8314 img_barrier.pNext = NULL;
8315 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8316 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8317 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8318 // New layout can't be UNDEFINED
8319 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8320 img_barrier.image = image.handle();
8321 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8322 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8323 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8324 img_barrier.subresourceRange.baseArrayLayer = 0;
8325 img_barrier.subresourceRange.baseMipLevel = 0;
8326 img_barrier.subresourceRange.layerCount = 1;
8327 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008328 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8329 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008330 m_errorMonitor->VerifyFound();
8331 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8332
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8334 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008335 // baseArrayLayer + layerCount must be <= image's arrayLayers
8336 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008337 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8338 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008339 m_errorMonitor->VerifyFound();
8340 img_barrier.subresourceRange.baseArrayLayer = 0;
8341
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008343 // baseMipLevel + levelCount must be <= image's mipLevels
8344 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008345 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8346 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008347 m_errorMonitor->VerifyFound();
8348 img_barrier.subresourceRange.baseMipLevel = 0;
8349
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008350 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 -06008351 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008352 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8353 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008354 VkBufferMemoryBarrier buf_barrier = {};
8355 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8356 buf_barrier.pNext = NULL;
8357 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8358 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8359 buf_barrier.buffer = buffer.handle();
8360 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8361 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8362 buf_barrier.offset = 0;
8363 buf_barrier.size = VK_WHOLE_SIZE;
8364 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008365 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8366 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008367 m_errorMonitor->VerifyFound();
8368 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008371 buf_barrier.offset = 257;
8372 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008373 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8374 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008375 m_errorMonitor->VerifyFound();
8376 buf_barrier.offset = 0;
8377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008379 buf_barrier.size = 257;
8380 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008381 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8382 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008383 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008384
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008385 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008386 m_errorMonitor->SetDesiredFailureMsg(
8387 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8388 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8389 m_errorMonitor->SetDesiredFailureMsg(
8390 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8391 "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 -06008392 VkDepthStencilObj ds_image(m_device);
8393 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8394 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008395 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8396 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008397 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008398 // Use of COLOR aspect on DS image is error
8399 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008400 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8401 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008402 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008403 // Now test depth-only
8404 VkFormatProperties format_props;
8405
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008406 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8407 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8409 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8411 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008412 VkDepthStencilObj d_image(m_device);
8413 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8414 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008415 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008416 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008417 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008418 // Use of COLOR aspect on depth image is error
8419 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008420 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8421 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008422 m_errorMonitor->VerifyFound();
8423 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008424 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8425 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008426 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8428 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008429 VkDepthStencilObj s_image(m_device);
8430 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8431 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008432 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008433 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008434 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008435 // Use of COLOR aspect on depth image is error
8436 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008437 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8438 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008439 m_errorMonitor->VerifyFound();
8440 }
8441 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8443 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8445 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008446 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008447 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 -06008448 ASSERT_TRUE(c_image.initialized());
8449 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8450 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8451 img_barrier.image = c_image.handle();
8452 // Set aspect to depth (non-color)
8453 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8455 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008456 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008457
8458 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8459
8460 // Create command pool with incompatible queueflags
8461 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8462 uint32_t queue_family_index = UINT32_MAX;
8463 for (uint32_t i = 0; i < queue_props.size(); i++) {
8464 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8465 queue_family_index = i;
8466 break;
8467 }
8468 }
8469 if (queue_family_index == UINT32_MAX) {
8470 printf("No non-compute queue found; skipped.\n");
8471 return;
8472 }
8473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8474
8475 VkCommandPool command_pool;
8476 VkCommandPoolCreateInfo pool_create_info{};
8477 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8478 pool_create_info.queueFamilyIndex = queue_family_index;
8479 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8480 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8481
8482 // Allocate a command buffer
8483 VkCommandBuffer bad_command_buffer;
8484 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8485 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8486 command_buffer_allocate_info.commandPool = command_pool;
8487 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8488 command_buffer_allocate_info.commandBufferCount = 1;
8489 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8490
8491 VkCommandBufferBeginInfo cbbi = {};
8492 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8493 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8494 buf_barrier.offset = 0;
8495 buf_barrier.size = VK_WHOLE_SIZE;
8496 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8497 &buf_barrier, 0, nullptr);
8498 m_errorMonitor->VerifyFound();
8499
8500 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8501 vkEndCommandBuffer(bad_command_buffer);
8502 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8503 printf("The non-compute queue does not support graphics; skipped.\n");
8504 return;
8505 }
8506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8507 VkEvent event;
8508 VkEventCreateInfo event_create_info{};
8509 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8510 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8511 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8512 nullptr, 0, nullptr);
8513 m_errorMonitor->VerifyFound();
8514
8515 vkEndCommandBuffer(bad_command_buffer);
8516 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008517}
8518
Tony Barbour18ba25c2016-09-29 13:42:40 -06008519TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8520 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8521
8522 m_errorMonitor->SetDesiredFailureMsg(
8523 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8524 "must have required access bit");
8525 ASSERT_NO_FATAL_FAILURE(InitState());
8526 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008527 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 -06008528 ASSERT_TRUE(image.initialized());
8529
8530 VkImageMemoryBarrier barrier = {};
8531 VkImageSubresourceRange range;
8532 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8533 barrier.srcAccessMask = 0;
8534 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8535 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8536 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8537 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8538 barrier.image = image.handle();
8539 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8540 range.baseMipLevel = 0;
8541 range.levelCount = 1;
8542 range.baseArrayLayer = 0;
8543 range.layerCount = 1;
8544 barrier.subresourceRange = range;
8545 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8546 cmdbuf.BeginCommandBuffer();
8547 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8548 &barrier);
8549 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8550 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8551 barrier.srcAccessMask = 0;
8552 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8553 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8554 &barrier);
8555
8556 m_errorMonitor->VerifyFound();
8557}
8558
Karl Schultz6addd812016-02-02 17:17:23 -07008559TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008560 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008561 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008562
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008564
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008565 ASSERT_NO_FATAL_FAILURE(InitState());
8566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008567 uint32_t qfi = 0;
8568 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008569 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8570 buffCI.size = 1024;
8571 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8572 buffCI.queueFamilyIndexCount = 1;
8573 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008574
8575 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008576 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008577 ASSERT_VK_SUCCESS(err);
8578
8579 BeginCommandBuffer();
8580 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008581 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8582 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008583 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008584 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008585
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008586 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008587
Chia-I Wuf7458c52015-10-26 21:10:41 +08008588 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008589}
8590
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008591TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8592 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8594 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8595 "of the indices specified when the device was created, via the "
8596 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008597
8598 ASSERT_NO_FATAL_FAILURE(InitState());
8599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8600 VkBufferCreateInfo buffCI = {};
8601 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8602 buffCI.size = 1024;
8603 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8604 buffCI.queueFamilyIndexCount = 1;
8605 // Introduce failure by specifying invalid queue_family_index
8606 uint32_t qfi = 777;
8607 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008608 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008609
8610 VkBuffer ib;
8611 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8612
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008613 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008614 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008615}
8616
Karl Schultz6addd812016-02-02 17:17:23 -07008617TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008618TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008619 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008620
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008621 ASSERT_NO_FATAL_FAILURE(InitState());
8622 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008623
Chris Forbesf29a84f2016-10-06 18:39:28 +13008624 // An empty primary command buffer
8625 VkCommandBufferObj cb(m_device, m_commandPool);
8626 cb.BeginCommandBuffer();
8627 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008628
Chris Forbesf29a84f2016-10-06 18:39:28 +13008629 m_commandBuffer->BeginCommandBuffer();
8630 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8631 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008632
Chris Forbesf29a84f2016-10-06 18:39:28 +13008633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8634 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008635 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008636}
8637
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008638TEST_F(VkLayerTest, DSUsageBitsErrors) {
8639 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8640 "that do not have correct usage bits sets.");
8641 VkResult err;
8642
8643 ASSERT_NO_FATAL_FAILURE(InitState());
8644 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8645 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8646 ds_type_count[i].type = VkDescriptorType(i);
8647 ds_type_count[i].descriptorCount = 1;
8648 }
8649 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8650 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8651 ds_pool_ci.pNext = NULL;
8652 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8653 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8654 ds_pool_ci.pPoolSizes = ds_type_count;
8655
8656 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008657 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008658 ASSERT_VK_SUCCESS(err);
8659
8660 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008661 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008662 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8663 dsl_binding[i].binding = 0;
8664 dsl_binding[i].descriptorType = VkDescriptorType(i);
8665 dsl_binding[i].descriptorCount = 1;
8666 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8667 dsl_binding[i].pImmutableSamplers = NULL;
8668 }
8669
8670 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8671 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8672 ds_layout_ci.pNext = NULL;
8673 ds_layout_ci.bindingCount = 1;
8674 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8675 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8676 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008677 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008678 ASSERT_VK_SUCCESS(err);
8679 }
8680 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8681 VkDescriptorSetAllocateInfo alloc_info = {};
8682 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8683 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8684 alloc_info.descriptorPool = ds_pool;
8685 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008686 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008687 ASSERT_VK_SUCCESS(err);
8688
8689 // Create a buffer & bufferView to be used for invalid updates
8690 VkBufferCreateInfo buff_ci = {};
8691 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8692 // This usage is not valid for any descriptor type
8693 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8694 buff_ci.size = 256;
8695 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8696 VkBuffer buffer;
8697 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8698 ASSERT_VK_SUCCESS(err);
8699
8700 VkBufferViewCreateInfo buff_view_ci = {};
8701 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8702 buff_view_ci.buffer = buffer;
8703 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8704 buff_view_ci.range = VK_WHOLE_SIZE;
8705 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008706 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008707 ASSERT_VK_SUCCESS(err);
8708
8709 // Create an image to be used for invalid updates
8710 VkImageCreateInfo image_ci = {};
8711 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8712 image_ci.imageType = VK_IMAGE_TYPE_2D;
8713 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8714 image_ci.extent.width = 64;
8715 image_ci.extent.height = 64;
8716 image_ci.extent.depth = 1;
8717 image_ci.mipLevels = 1;
8718 image_ci.arrayLayers = 1;
8719 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8720 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8721 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8722 // This usage is not valid for any descriptor type
8723 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8724 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8725 VkImage image;
8726 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8727 ASSERT_VK_SUCCESS(err);
8728 // Bind memory to image
8729 VkMemoryRequirements mem_reqs;
8730 VkDeviceMemory image_mem;
8731 bool pass;
8732 VkMemoryAllocateInfo mem_alloc = {};
8733 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8734 mem_alloc.pNext = NULL;
8735 mem_alloc.allocationSize = 0;
8736 mem_alloc.memoryTypeIndex = 0;
8737 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8738 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008739 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008740 ASSERT_TRUE(pass);
8741 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8742 ASSERT_VK_SUCCESS(err);
8743 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8744 ASSERT_VK_SUCCESS(err);
8745 // Now create view for image
8746 VkImageViewCreateInfo image_view_ci = {};
8747 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8748 image_view_ci.image = image;
8749 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8750 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8751 image_view_ci.subresourceRange.layerCount = 1;
8752 image_view_ci.subresourceRange.baseArrayLayer = 0;
8753 image_view_ci.subresourceRange.levelCount = 1;
8754 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8755 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008756 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008757 ASSERT_VK_SUCCESS(err);
8758
8759 VkDescriptorBufferInfo buff_info = {};
8760 buff_info.buffer = buffer;
8761 VkDescriptorImageInfo img_info = {};
8762 img_info.imageView = image_view;
8763 VkWriteDescriptorSet descriptor_write = {};
8764 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8765 descriptor_write.dstBinding = 0;
8766 descriptor_write.descriptorCount = 1;
8767 descriptor_write.pTexelBufferView = &buff_view;
8768 descriptor_write.pBufferInfo = &buff_info;
8769 descriptor_write.pImageInfo = &img_info;
8770
8771 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008772 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8773 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8774 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8775 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8776 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8777 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8778 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8779 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8780 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8781 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8782 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008783 // Start loop at 1 as SAMPLER desc type has no usage bit error
8784 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8785 descriptor_write.descriptorType = VkDescriptorType(i);
8786 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008788
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008789 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008790
8791 m_errorMonitor->VerifyFound();
8792 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8793 }
8794 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8795 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008796 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008797 vkDestroyImageView(m_device->device(), image_view, NULL);
8798 vkDestroyBuffer(m_device->device(), buffer, NULL);
8799 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008800 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008801 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8802}
8803
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008804TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008805 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8806 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8807 "1. offset value greater than buffer size\n"
8808 "2. range value of 0\n"
8809 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008810 VkResult err;
8811
8812 ASSERT_NO_FATAL_FAILURE(InitState());
8813 VkDescriptorPoolSize ds_type_count = {};
8814 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8815 ds_type_count.descriptorCount = 1;
8816
8817 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8818 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8819 ds_pool_ci.pNext = NULL;
8820 ds_pool_ci.maxSets = 1;
8821 ds_pool_ci.poolSizeCount = 1;
8822 ds_pool_ci.pPoolSizes = &ds_type_count;
8823
8824 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008825 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008826 ASSERT_VK_SUCCESS(err);
8827
8828 // Create layout with single uniform buffer descriptor
8829 VkDescriptorSetLayoutBinding dsl_binding = {};
8830 dsl_binding.binding = 0;
8831 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8832 dsl_binding.descriptorCount = 1;
8833 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8834 dsl_binding.pImmutableSamplers = NULL;
8835
8836 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8837 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8838 ds_layout_ci.pNext = NULL;
8839 ds_layout_ci.bindingCount = 1;
8840 ds_layout_ci.pBindings = &dsl_binding;
8841 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008842 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008843 ASSERT_VK_SUCCESS(err);
8844
8845 VkDescriptorSet descriptor_set = {};
8846 VkDescriptorSetAllocateInfo alloc_info = {};
8847 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8848 alloc_info.descriptorSetCount = 1;
8849 alloc_info.descriptorPool = ds_pool;
8850 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008851 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008852 ASSERT_VK_SUCCESS(err);
8853
8854 // Create a buffer to be used for invalid updates
8855 VkBufferCreateInfo buff_ci = {};
8856 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8857 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8858 buff_ci.size = 256;
8859 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8860 VkBuffer buffer;
8861 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8862 ASSERT_VK_SUCCESS(err);
8863 // Have to bind memory to buffer before descriptor update
8864 VkMemoryAllocateInfo mem_alloc = {};
8865 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8866 mem_alloc.pNext = NULL;
8867 mem_alloc.allocationSize = 256;
8868 mem_alloc.memoryTypeIndex = 0;
8869
8870 VkMemoryRequirements mem_reqs;
8871 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008872 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008873 if (!pass) {
8874 vkDestroyBuffer(m_device->device(), buffer, NULL);
8875 return;
8876 }
8877
8878 VkDeviceMemory mem;
8879 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8880 ASSERT_VK_SUCCESS(err);
8881 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8882 ASSERT_VK_SUCCESS(err);
8883
8884 VkDescriptorBufferInfo buff_info = {};
8885 buff_info.buffer = buffer;
8886 // First make offset 1 larger than buffer size
8887 buff_info.offset = 257;
8888 buff_info.range = VK_WHOLE_SIZE;
8889 VkWriteDescriptorSet descriptor_write = {};
8890 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8891 descriptor_write.dstBinding = 0;
8892 descriptor_write.descriptorCount = 1;
8893 descriptor_write.pTexelBufferView = nullptr;
8894 descriptor_write.pBufferInfo = &buff_info;
8895 descriptor_write.pImageInfo = nullptr;
8896
8897 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8898 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008900
8901 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8902
8903 m_errorMonitor->VerifyFound();
8904 // Now cause error due to range of 0
8905 buff_info.offset = 0;
8906 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8908 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008909
8910 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8911
8912 m_errorMonitor->VerifyFound();
8913 // Now cause error due to range exceeding buffer size - offset
8914 buff_info.offset = 128;
8915 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008916 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 -06008917
8918 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8919
8920 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008921 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008922 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8923 vkDestroyBuffer(m_device->device(), buffer, NULL);
8924 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8925 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8926}
8927
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008928TEST_F(VkLayerTest, DSAspectBitsErrors) {
8929 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8930 // are set, but could expand this test to hit more cases.
8931 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8932 "that do not have correct aspect bits sets.");
8933 VkResult err;
8934
8935 ASSERT_NO_FATAL_FAILURE(InitState());
8936 VkDescriptorPoolSize ds_type_count = {};
8937 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8938 ds_type_count.descriptorCount = 1;
8939
8940 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8941 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8942 ds_pool_ci.pNext = NULL;
8943 ds_pool_ci.maxSets = 5;
8944 ds_pool_ci.poolSizeCount = 1;
8945 ds_pool_ci.pPoolSizes = &ds_type_count;
8946
8947 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008948 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008949 ASSERT_VK_SUCCESS(err);
8950
8951 VkDescriptorSetLayoutBinding dsl_binding = {};
8952 dsl_binding.binding = 0;
8953 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8954 dsl_binding.descriptorCount = 1;
8955 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8956 dsl_binding.pImmutableSamplers = NULL;
8957
8958 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8959 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8960 ds_layout_ci.pNext = NULL;
8961 ds_layout_ci.bindingCount = 1;
8962 ds_layout_ci.pBindings = &dsl_binding;
8963 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008964 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008965 ASSERT_VK_SUCCESS(err);
8966
8967 VkDescriptorSet descriptor_set = {};
8968 VkDescriptorSetAllocateInfo alloc_info = {};
8969 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8970 alloc_info.descriptorSetCount = 1;
8971 alloc_info.descriptorPool = ds_pool;
8972 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008973 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008974 ASSERT_VK_SUCCESS(err);
8975
8976 // Create an image to be used for invalid updates
8977 VkImageCreateInfo image_ci = {};
8978 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8979 image_ci.imageType = VK_IMAGE_TYPE_2D;
8980 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8981 image_ci.extent.width = 64;
8982 image_ci.extent.height = 64;
8983 image_ci.extent.depth = 1;
8984 image_ci.mipLevels = 1;
8985 image_ci.arrayLayers = 1;
8986 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8987 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8988 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8989 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8990 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8991 VkImage image;
8992 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8993 ASSERT_VK_SUCCESS(err);
8994 // Bind memory to image
8995 VkMemoryRequirements mem_reqs;
8996 VkDeviceMemory image_mem;
8997 bool pass;
8998 VkMemoryAllocateInfo mem_alloc = {};
8999 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9000 mem_alloc.pNext = NULL;
9001 mem_alloc.allocationSize = 0;
9002 mem_alloc.memoryTypeIndex = 0;
9003 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9004 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009005 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009006 ASSERT_TRUE(pass);
9007 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9008 ASSERT_VK_SUCCESS(err);
9009 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9010 ASSERT_VK_SUCCESS(err);
9011 // Now create view for image
9012 VkImageViewCreateInfo image_view_ci = {};
9013 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9014 image_view_ci.image = image;
9015 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9016 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9017 image_view_ci.subresourceRange.layerCount = 1;
9018 image_view_ci.subresourceRange.baseArrayLayer = 0;
9019 image_view_ci.subresourceRange.levelCount = 1;
9020 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009021 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009022
9023 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009024 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009025 ASSERT_VK_SUCCESS(err);
9026
9027 VkDescriptorImageInfo img_info = {};
9028 img_info.imageView = image_view;
9029 VkWriteDescriptorSet descriptor_write = {};
9030 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9031 descriptor_write.dstBinding = 0;
9032 descriptor_write.descriptorCount = 1;
9033 descriptor_write.pTexelBufferView = NULL;
9034 descriptor_write.pBufferInfo = NULL;
9035 descriptor_write.pImageInfo = &img_info;
9036 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9037 descriptor_write.dstSet = descriptor_set;
9038 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9039 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009041
9042 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9043
9044 m_errorMonitor->VerifyFound();
9045 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9046 vkDestroyImage(m_device->device(), image, NULL);
9047 vkFreeMemory(m_device->device(), image_mem, NULL);
9048 vkDestroyImageView(m_device->device(), image_view, NULL);
9049 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9050 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9051}
9052
Karl Schultz6addd812016-02-02 17:17:23 -07009053TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009054 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009055 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009056
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9058 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9059 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009060
Tobin Ehlis3b780662015-05-28 12:11:26 -06009061 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009062 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009063 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009064 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9065 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009066
9067 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009068 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9069 ds_pool_ci.pNext = NULL;
9070 ds_pool_ci.maxSets = 1;
9071 ds_pool_ci.poolSizeCount = 1;
9072 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009073
Tobin Ehlis3b780662015-05-28 12:11:26 -06009074 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009075 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009076 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009077 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009078 dsl_binding.binding = 0;
9079 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9080 dsl_binding.descriptorCount = 1;
9081 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9082 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009083
Tony Barboureb254902015-07-15 12:50:33 -06009084 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009085 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9086 ds_layout_ci.pNext = NULL;
9087 ds_layout_ci.bindingCount = 1;
9088 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009089
Tobin Ehlis3b780662015-05-28 12:11:26 -06009090 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009091 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009092 ASSERT_VK_SUCCESS(err);
9093
9094 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009095 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009096 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009097 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009098 alloc_info.descriptorPool = ds_pool;
9099 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009100 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009101 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009102
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009103 VkSamplerCreateInfo sampler_ci = {};
9104 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9105 sampler_ci.pNext = NULL;
9106 sampler_ci.magFilter = VK_FILTER_NEAREST;
9107 sampler_ci.minFilter = VK_FILTER_NEAREST;
9108 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9109 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9110 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9111 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9112 sampler_ci.mipLodBias = 1.0;
9113 sampler_ci.anisotropyEnable = VK_FALSE;
9114 sampler_ci.maxAnisotropy = 1;
9115 sampler_ci.compareEnable = VK_FALSE;
9116 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9117 sampler_ci.minLod = 1.0;
9118 sampler_ci.maxLod = 1.0;
9119 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9120 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9121 VkSampler sampler;
9122 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9123 ASSERT_VK_SUCCESS(err);
9124
9125 VkDescriptorImageInfo info = {};
9126 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009127
9128 VkWriteDescriptorSet descriptor_write;
9129 memset(&descriptor_write, 0, sizeof(descriptor_write));
9130 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009131 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009132 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009133 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009134 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009135 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009136
9137 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9138
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009139 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009140
Chia-I Wuf7458c52015-10-26 21:10:41 +08009141 vkDestroySampler(m_device->device(), sampler, NULL);
9142 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9143 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009144}
9145
Karl Schultz6addd812016-02-02 17:17:23 -07009146TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009147 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009148 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009149
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009151
Tobin Ehlis3b780662015-05-28 12:11:26 -06009152 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009153 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009154 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009155 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9156 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009157
9158 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009159 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9160 ds_pool_ci.pNext = NULL;
9161 ds_pool_ci.maxSets = 1;
9162 ds_pool_ci.poolSizeCount = 1;
9163 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009164
Tobin Ehlis3b780662015-05-28 12:11:26 -06009165 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009166 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009167 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009168
Tony Barboureb254902015-07-15 12:50:33 -06009169 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009170 dsl_binding.binding = 0;
9171 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9172 dsl_binding.descriptorCount = 1;
9173 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9174 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009175
9176 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009177 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9178 ds_layout_ci.pNext = NULL;
9179 ds_layout_ci.bindingCount = 1;
9180 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009181
Tobin Ehlis3b780662015-05-28 12:11:26 -06009182 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009183 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009184 ASSERT_VK_SUCCESS(err);
9185
9186 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009187 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009188 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009189 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009190 alloc_info.descriptorPool = ds_pool;
9191 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009192 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009193 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009194
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009195 // Correctly update descriptor to avoid "NOT_UPDATED" error
9196 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009197 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009198 buff_info.offset = 0;
9199 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009200
9201 VkWriteDescriptorSet descriptor_write;
9202 memset(&descriptor_write, 0, sizeof(descriptor_write));
9203 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009204 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009205 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009206 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009207 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9208 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009209
9210 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9211
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009212 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009213
Chia-I Wuf7458c52015-10-26 21:10:41 +08009214 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9215 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009216}
9217
Karl Schultz6addd812016-02-02 17:17:23 -07009218TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009219 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009220 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009221
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009223
Tobin Ehlis3b780662015-05-28 12:11:26 -06009224 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009225 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009226 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009227 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9228 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009229
9230 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009231 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9232 ds_pool_ci.pNext = NULL;
9233 ds_pool_ci.maxSets = 1;
9234 ds_pool_ci.poolSizeCount = 1;
9235 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009236
Tobin Ehlis3b780662015-05-28 12:11:26 -06009237 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009238 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009239 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009240
Tony Barboureb254902015-07-15 12:50:33 -06009241 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009242 dsl_binding.binding = 0;
9243 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9244 dsl_binding.descriptorCount = 1;
9245 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9246 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009247
9248 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009249 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9250 ds_layout_ci.pNext = NULL;
9251 ds_layout_ci.bindingCount = 1;
9252 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009253 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009254 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009255 ASSERT_VK_SUCCESS(err);
9256
9257 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009258 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009259 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009260 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009261 alloc_info.descriptorPool = ds_pool;
9262 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009263 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009264 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009265
Tony Barboureb254902015-07-15 12:50:33 -06009266 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009267 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9268 sampler_ci.pNext = NULL;
9269 sampler_ci.magFilter = VK_FILTER_NEAREST;
9270 sampler_ci.minFilter = VK_FILTER_NEAREST;
9271 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9272 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9273 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9274 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9275 sampler_ci.mipLodBias = 1.0;
9276 sampler_ci.anisotropyEnable = VK_FALSE;
9277 sampler_ci.maxAnisotropy = 1;
9278 sampler_ci.compareEnable = VK_FALSE;
9279 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9280 sampler_ci.minLod = 1.0;
9281 sampler_ci.maxLod = 1.0;
9282 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9283 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009284
Tobin Ehlis3b780662015-05-28 12:11:26 -06009285 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009286 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009287 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009288
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009289 VkDescriptorImageInfo info = {};
9290 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009291
9292 VkWriteDescriptorSet descriptor_write;
9293 memset(&descriptor_write, 0, sizeof(descriptor_write));
9294 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009295 descriptor_write.dstSet = descriptorSet;
9296 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009297 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009298 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009299 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009300 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009301
9302 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009304 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009305
Chia-I Wuf7458c52015-10-26 21:10:41 +08009306 vkDestroySampler(m_device->device(), sampler, NULL);
9307 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9308 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009309}
9310
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009311TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9312 // Create layout w/ empty binding and attempt to update it
9313 VkResult err;
9314
9315 ASSERT_NO_FATAL_FAILURE(InitState());
9316
9317 VkDescriptorPoolSize ds_type_count = {};
9318 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9319 ds_type_count.descriptorCount = 1;
9320
9321 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9322 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9323 ds_pool_ci.pNext = NULL;
9324 ds_pool_ci.maxSets = 1;
9325 ds_pool_ci.poolSizeCount = 1;
9326 ds_pool_ci.pPoolSizes = &ds_type_count;
9327
9328 VkDescriptorPool ds_pool;
9329 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9330 ASSERT_VK_SUCCESS(err);
9331
9332 VkDescriptorSetLayoutBinding dsl_binding = {};
9333 dsl_binding.binding = 0;
9334 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9335 dsl_binding.descriptorCount = 0;
9336 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9337 dsl_binding.pImmutableSamplers = NULL;
9338
9339 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9340 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9341 ds_layout_ci.pNext = NULL;
9342 ds_layout_ci.bindingCount = 1;
9343 ds_layout_ci.pBindings = &dsl_binding;
9344 VkDescriptorSetLayout ds_layout;
9345 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9346 ASSERT_VK_SUCCESS(err);
9347
9348 VkDescriptorSet descriptor_set;
9349 VkDescriptorSetAllocateInfo alloc_info = {};
9350 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9351 alloc_info.descriptorSetCount = 1;
9352 alloc_info.descriptorPool = ds_pool;
9353 alloc_info.pSetLayouts = &ds_layout;
9354 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9355 ASSERT_VK_SUCCESS(err);
9356
9357 VkSamplerCreateInfo sampler_ci = {};
9358 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9359 sampler_ci.magFilter = VK_FILTER_NEAREST;
9360 sampler_ci.minFilter = VK_FILTER_NEAREST;
9361 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9362 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9363 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9364 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9365 sampler_ci.mipLodBias = 1.0;
9366 sampler_ci.maxAnisotropy = 1;
9367 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9368 sampler_ci.minLod = 1.0;
9369 sampler_ci.maxLod = 1.0;
9370 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9371
9372 VkSampler sampler;
9373 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9374 ASSERT_VK_SUCCESS(err);
9375
9376 VkDescriptorImageInfo info = {};
9377 info.sampler = sampler;
9378
9379 VkWriteDescriptorSet descriptor_write;
9380 memset(&descriptor_write, 0, sizeof(descriptor_write));
9381 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9382 descriptor_write.dstSet = descriptor_set;
9383 descriptor_write.dstBinding = 0;
9384 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9385 // This is the wrong type, but empty binding error will be flagged first
9386 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9387 descriptor_write.pImageInfo = &info;
9388
9389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9390 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9391 m_errorMonitor->VerifyFound();
9392
9393 vkDestroySampler(m_device->device(), sampler, NULL);
9394 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9395 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9396}
9397
Karl Schultz6addd812016-02-02 17:17:23 -07009398TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9399 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9400 // types
9401 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009402
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009403 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 -06009404
Tobin Ehlis3b780662015-05-28 12:11:26 -06009405 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009406
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009407 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009408 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9409 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009410
9411 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009412 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9413 ds_pool_ci.pNext = NULL;
9414 ds_pool_ci.maxSets = 1;
9415 ds_pool_ci.poolSizeCount = 1;
9416 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009417
Tobin Ehlis3b780662015-05-28 12:11:26 -06009418 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009419 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009420 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009421 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009422 dsl_binding.binding = 0;
9423 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9424 dsl_binding.descriptorCount = 1;
9425 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9426 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009427
Tony Barboureb254902015-07-15 12:50:33 -06009428 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009429 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9430 ds_layout_ci.pNext = NULL;
9431 ds_layout_ci.bindingCount = 1;
9432 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009433
Tobin Ehlis3b780662015-05-28 12:11:26 -06009434 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009435 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009436 ASSERT_VK_SUCCESS(err);
9437
9438 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009439 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009440 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009441 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009442 alloc_info.descriptorPool = ds_pool;
9443 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009444 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009445 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009446
Tony Barboureb254902015-07-15 12:50:33 -06009447 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009448 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9449 sampler_ci.pNext = NULL;
9450 sampler_ci.magFilter = VK_FILTER_NEAREST;
9451 sampler_ci.minFilter = VK_FILTER_NEAREST;
9452 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9453 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9454 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9455 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9456 sampler_ci.mipLodBias = 1.0;
9457 sampler_ci.anisotropyEnable = VK_FALSE;
9458 sampler_ci.maxAnisotropy = 1;
9459 sampler_ci.compareEnable = VK_FALSE;
9460 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9461 sampler_ci.minLod = 1.0;
9462 sampler_ci.maxLod = 1.0;
9463 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9464 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009465 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009466 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009467 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009468
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009469 VkDescriptorImageInfo info = {};
9470 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009471
9472 VkWriteDescriptorSet descriptor_write;
9473 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009474 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009475 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009476 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009477 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009478 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009479 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009480
9481 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9482
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009483 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009484
Chia-I Wuf7458c52015-10-26 21:10:41 +08009485 vkDestroySampler(m_device->device(), sampler, NULL);
9486 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9487 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009488}
9489
Karl Schultz6addd812016-02-02 17:17:23 -07009490TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009491 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009492 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009493
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9495 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009496
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009497 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009498 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9499 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009500 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009501 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9502 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009503
9504 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009505 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9506 ds_pool_ci.pNext = NULL;
9507 ds_pool_ci.maxSets = 1;
9508 ds_pool_ci.poolSizeCount = 1;
9509 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009510
9511 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009512 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009513 ASSERT_VK_SUCCESS(err);
9514
9515 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009516 dsl_binding.binding = 0;
9517 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9518 dsl_binding.descriptorCount = 1;
9519 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9520 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009521
9522 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009523 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9524 ds_layout_ci.pNext = NULL;
9525 ds_layout_ci.bindingCount = 1;
9526 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009527 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009528 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009529 ASSERT_VK_SUCCESS(err);
9530
9531 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009532 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009533 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009534 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009535 alloc_info.descriptorPool = ds_pool;
9536 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009537 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009538 ASSERT_VK_SUCCESS(err);
9539
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009540 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009541
9542 VkDescriptorImageInfo descriptor_info;
9543 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9544 descriptor_info.sampler = sampler;
9545
9546 VkWriteDescriptorSet descriptor_write;
9547 memset(&descriptor_write, 0, sizeof(descriptor_write));
9548 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009549 descriptor_write.dstSet = descriptorSet;
9550 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009551 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009552 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9553 descriptor_write.pImageInfo = &descriptor_info;
9554
9555 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9556
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009557 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009558
Chia-I Wuf7458c52015-10-26 21:10:41 +08009559 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9560 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009561}
9562
Karl Schultz6addd812016-02-02 17:17:23 -07009563TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9564 // Create a single combined Image/Sampler descriptor and send it an invalid
9565 // imageView
9566 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009567
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009569
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009570 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009571 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009572 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9573 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009574
9575 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009576 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9577 ds_pool_ci.pNext = NULL;
9578 ds_pool_ci.maxSets = 1;
9579 ds_pool_ci.poolSizeCount = 1;
9580 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009581
9582 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009583 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009584 ASSERT_VK_SUCCESS(err);
9585
9586 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009587 dsl_binding.binding = 0;
9588 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9589 dsl_binding.descriptorCount = 1;
9590 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9591 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009592
9593 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009594 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9595 ds_layout_ci.pNext = NULL;
9596 ds_layout_ci.bindingCount = 1;
9597 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009598 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009599 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009600 ASSERT_VK_SUCCESS(err);
9601
9602 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009603 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009604 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009605 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009606 alloc_info.descriptorPool = ds_pool;
9607 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009608 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009609 ASSERT_VK_SUCCESS(err);
9610
9611 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009612 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9613 sampler_ci.pNext = NULL;
9614 sampler_ci.magFilter = VK_FILTER_NEAREST;
9615 sampler_ci.minFilter = VK_FILTER_NEAREST;
9616 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9617 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9618 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9619 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9620 sampler_ci.mipLodBias = 1.0;
9621 sampler_ci.anisotropyEnable = VK_FALSE;
9622 sampler_ci.maxAnisotropy = 1;
9623 sampler_ci.compareEnable = VK_FALSE;
9624 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9625 sampler_ci.minLod = 1.0;
9626 sampler_ci.maxLod = 1.0;
9627 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9628 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009629
9630 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009631 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009632 ASSERT_VK_SUCCESS(err);
9633
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009634 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009635
9636 VkDescriptorImageInfo descriptor_info;
9637 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9638 descriptor_info.sampler = sampler;
9639 descriptor_info.imageView = view;
9640
9641 VkWriteDescriptorSet descriptor_write;
9642 memset(&descriptor_write, 0, sizeof(descriptor_write));
9643 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009644 descriptor_write.dstSet = descriptorSet;
9645 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009646 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009647 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9648 descriptor_write.pImageInfo = &descriptor_info;
9649
9650 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9651
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009652 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009653
Chia-I Wuf7458c52015-10-26 21:10:41 +08009654 vkDestroySampler(m_device->device(), sampler, NULL);
9655 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9656 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009657}
9658
Karl Schultz6addd812016-02-02 17:17:23 -07009659TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9660 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9661 // into the other
9662 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009663
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9665 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9666 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009667
Tobin Ehlis04356f92015-10-27 16:35:27 -06009668 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009669 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009670 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009671 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9672 ds_type_count[0].descriptorCount = 1;
9673 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9674 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009675
9676 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009677 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9678 ds_pool_ci.pNext = NULL;
9679 ds_pool_ci.maxSets = 1;
9680 ds_pool_ci.poolSizeCount = 2;
9681 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009682
9683 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009684 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009685 ASSERT_VK_SUCCESS(err);
9686 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009687 dsl_binding[0].binding = 0;
9688 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9689 dsl_binding[0].descriptorCount = 1;
9690 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9691 dsl_binding[0].pImmutableSamplers = NULL;
9692 dsl_binding[1].binding = 1;
9693 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9694 dsl_binding[1].descriptorCount = 1;
9695 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9696 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009697
9698 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009699 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9700 ds_layout_ci.pNext = NULL;
9701 ds_layout_ci.bindingCount = 2;
9702 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009703
9704 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009705 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009706 ASSERT_VK_SUCCESS(err);
9707
9708 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009709 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009710 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009711 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009712 alloc_info.descriptorPool = ds_pool;
9713 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009714 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009715 ASSERT_VK_SUCCESS(err);
9716
9717 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009718 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9719 sampler_ci.pNext = NULL;
9720 sampler_ci.magFilter = VK_FILTER_NEAREST;
9721 sampler_ci.minFilter = VK_FILTER_NEAREST;
9722 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9723 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9724 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9725 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9726 sampler_ci.mipLodBias = 1.0;
9727 sampler_ci.anisotropyEnable = VK_FALSE;
9728 sampler_ci.maxAnisotropy = 1;
9729 sampler_ci.compareEnable = VK_FALSE;
9730 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9731 sampler_ci.minLod = 1.0;
9732 sampler_ci.maxLod = 1.0;
9733 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9734 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009735
9736 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009737 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009738 ASSERT_VK_SUCCESS(err);
9739
9740 VkDescriptorImageInfo info = {};
9741 info.sampler = sampler;
9742
9743 VkWriteDescriptorSet descriptor_write;
9744 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9745 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009746 descriptor_write.dstSet = descriptorSet;
9747 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009748 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009749 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9750 descriptor_write.pImageInfo = &info;
9751 // This write update should succeed
9752 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9753 // Now perform a copy update that fails due to type mismatch
9754 VkCopyDescriptorSet copy_ds_update;
9755 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9756 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9757 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009758 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009759 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009760 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009761 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009762 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9763
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009764 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009765 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009766 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 -06009767 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9768 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9769 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009770 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009771 copy_ds_update.dstSet = descriptorSet;
9772 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009773 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009774 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9775
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009776 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009777
Tobin Ehlis04356f92015-10-27 16:35:27 -06009778 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9780 "update array offset of 0 and update of "
9781 "5 descriptors oversteps total number "
9782 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009783
Tobin Ehlis04356f92015-10-27 16:35:27 -06009784 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9785 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9786 copy_ds_update.srcSet = descriptorSet;
9787 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009788 copy_ds_update.dstSet = descriptorSet;
9789 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009790 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009791 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9792
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009793 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009794
Chia-I Wuf7458c52015-10-26 21:10:41 +08009795 vkDestroySampler(m_device->device(), sampler, NULL);
9796 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9797 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009798}
9799
Karl Schultz6addd812016-02-02 17:17:23 -07009800TEST_F(VkLayerTest, NumSamplesMismatch) {
9801 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9802 // sampleCount
9803 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009804
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009806
Tobin Ehlis3b780662015-05-28 12:11:26 -06009807 ASSERT_NO_FATAL_FAILURE(InitState());
9808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009809 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009810 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009811 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009812
9813 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009814 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9815 ds_pool_ci.pNext = NULL;
9816 ds_pool_ci.maxSets = 1;
9817 ds_pool_ci.poolSizeCount = 1;
9818 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009819
Tobin Ehlis3b780662015-05-28 12:11:26 -06009820 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009821 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009822 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009823
Tony Barboureb254902015-07-15 12:50:33 -06009824 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009825 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009826 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009827 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009828 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9829 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009830
Tony Barboureb254902015-07-15 12:50:33 -06009831 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9832 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9833 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009834 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009835 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009836
Tobin Ehlis3b780662015-05-28 12:11:26 -06009837 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009838 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009839 ASSERT_VK_SUCCESS(err);
9840
9841 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009842 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009843 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009844 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009845 alloc_info.descriptorPool = ds_pool;
9846 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009847 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009848 ASSERT_VK_SUCCESS(err);
9849
Tony Barboureb254902015-07-15 12:50:33 -06009850 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009851 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009852 pipe_ms_state_ci.pNext = NULL;
9853 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9854 pipe_ms_state_ci.sampleShadingEnable = 0;
9855 pipe_ms_state_ci.minSampleShading = 1.0;
9856 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009857
Tony Barboureb254902015-07-15 12:50:33 -06009858 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009859 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9860 pipeline_layout_ci.pNext = NULL;
9861 pipeline_layout_ci.setLayoutCount = 1;
9862 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009863
9864 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009865 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009866 ASSERT_VK_SUCCESS(err);
9867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009868 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9869 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9870 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009871 VkPipelineObj pipe(m_device);
9872 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009873 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009874 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009875 pipe.SetMSAA(&pipe_ms_state_ci);
9876 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009877
Tony Barbourfe3351b2015-07-28 10:17:20 -06009878 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009879 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009880
Mark Young29927482016-05-04 14:38:51 -06009881 // Render triangle (the error should trigger on the attempt to draw).
9882 Draw(3, 1, 0, 0);
9883
9884 // Finalize recording of the command buffer
9885 EndCommandBuffer();
9886
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009887 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009888
Chia-I Wuf7458c52015-10-26 21:10:41 +08009889 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9890 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9891 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009892}
Mark Young29927482016-05-04 14:38:51 -06009893
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009894TEST_F(VkLayerTest, RenderPassIncompatible) {
9895 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9896 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009897 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009898 VkResult err;
9899
9900 ASSERT_NO_FATAL_FAILURE(InitState());
9901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9902
9903 VkDescriptorSetLayoutBinding dsl_binding = {};
9904 dsl_binding.binding = 0;
9905 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9906 dsl_binding.descriptorCount = 1;
9907 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9908 dsl_binding.pImmutableSamplers = NULL;
9909
9910 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9911 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9912 ds_layout_ci.pNext = NULL;
9913 ds_layout_ci.bindingCount = 1;
9914 ds_layout_ci.pBindings = &dsl_binding;
9915
9916 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009917 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009918 ASSERT_VK_SUCCESS(err);
9919
9920 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9921 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9922 pipeline_layout_ci.pNext = NULL;
9923 pipeline_layout_ci.setLayoutCount = 1;
9924 pipeline_layout_ci.pSetLayouts = &ds_layout;
9925
9926 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009927 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009928 ASSERT_VK_SUCCESS(err);
9929
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009930 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9931 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9932 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009933 // Create a renderpass that will be incompatible with default renderpass
9934 VkAttachmentReference attach = {};
9935 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9936 VkAttachmentReference color_att = {};
9937 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9938 VkSubpassDescription subpass = {};
9939 subpass.inputAttachmentCount = 1;
9940 subpass.pInputAttachments = &attach;
9941 subpass.colorAttachmentCount = 1;
9942 subpass.pColorAttachments = &color_att;
9943 VkRenderPassCreateInfo rpci = {};
9944 rpci.subpassCount = 1;
9945 rpci.pSubpasses = &subpass;
9946 rpci.attachmentCount = 1;
9947 VkAttachmentDescription attach_desc = {};
9948 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009949 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9950 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009951 rpci.pAttachments = &attach_desc;
9952 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9953 VkRenderPass rp;
9954 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9955 VkPipelineObj pipe(m_device);
9956 pipe.AddShader(&vs);
9957 pipe.AddShader(&fs);
9958 pipe.AddColorAttachment();
9959 VkViewport view_port = {};
9960 m_viewports.push_back(view_port);
9961 pipe.SetViewport(m_viewports);
9962 VkRect2D rect = {};
9963 m_scissors.push_back(rect);
9964 pipe.SetScissor(m_scissors);
9965 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9966
9967 VkCommandBufferInheritanceInfo cbii = {};
9968 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9969 cbii.renderPass = rp;
9970 cbii.subpass = 0;
9971 VkCommandBufferBeginInfo cbbi = {};
9972 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9973 cbbi.pInheritanceInfo = &cbii;
9974 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9975 VkRenderPassBeginInfo rpbi = {};
9976 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9977 rpbi.framebuffer = m_framebuffer;
9978 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009979 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9980 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009983 // Render triangle (the error should trigger on the attempt to draw).
9984 Draw(3, 1, 0, 0);
9985
9986 // Finalize recording of the command buffer
9987 EndCommandBuffer();
9988
9989 m_errorMonitor->VerifyFound();
9990
9991 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9992 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9993 vkDestroyRenderPass(m_device->device(), rp, NULL);
9994}
9995
Mark Youngc89c6312016-03-31 16:03:20 -06009996TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9997 // Create Pipeline where the number of blend attachments doesn't match the
9998 // number of color attachments. In this case, we don't add any color
9999 // blend attachments even though we have a color attachment.
10000 VkResult err;
10001
10002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010003 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010004
10005 ASSERT_NO_FATAL_FAILURE(InitState());
10006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10007 VkDescriptorPoolSize ds_type_count = {};
10008 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10009 ds_type_count.descriptorCount = 1;
10010
10011 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10012 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10013 ds_pool_ci.pNext = NULL;
10014 ds_pool_ci.maxSets = 1;
10015 ds_pool_ci.poolSizeCount = 1;
10016 ds_pool_ci.pPoolSizes = &ds_type_count;
10017
10018 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010019 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010020 ASSERT_VK_SUCCESS(err);
10021
10022 VkDescriptorSetLayoutBinding dsl_binding = {};
10023 dsl_binding.binding = 0;
10024 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10025 dsl_binding.descriptorCount = 1;
10026 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10027 dsl_binding.pImmutableSamplers = NULL;
10028
10029 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10030 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10031 ds_layout_ci.pNext = NULL;
10032 ds_layout_ci.bindingCount = 1;
10033 ds_layout_ci.pBindings = &dsl_binding;
10034
10035 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010036 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010037 ASSERT_VK_SUCCESS(err);
10038
10039 VkDescriptorSet descriptorSet;
10040 VkDescriptorSetAllocateInfo alloc_info = {};
10041 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10042 alloc_info.descriptorSetCount = 1;
10043 alloc_info.descriptorPool = ds_pool;
10044 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010045 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010046 ASSERT_VK_SUCCESS(err);
10047
10048 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010049 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010050 pipe_ms_state_ci.pNext = NULL;
10051 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10052 pipe_ms_state_ci.sampleShadingEnable = 0;
10053 pipe_ms_state_ci.minSampleShading = 1.0;
10054 pipe_ms_state_ci.pSampleMask = NULL;
10055
10056 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10057 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10058 pipeline_layout_ci.pNext = NULL;
10059 pipeline_layout_ci.setLayoutCount = 1;
10060 pipeline_layout_ci.pSetLayouts = &ds_layout;
10061
10062 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010063 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010064 ASSERT_VK_SUCCESS(err);
10065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10067 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10068 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010069 VkPipelineObj pipe(m_device);
10070 pipe.AddShader(&vs);
10071 pipe.AddShader(&fs);
10072 pipe.SetMSAA(&pipe_ms_state_ci);
10073 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10074
10075 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010076 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010077
Mark Young29927482016-05-04 14:38:51 -060010078 // Render triangle (the error should trigger on the attempt to draw).
10079 Draw(3, 1, 0, 0);
10080
10081 // Finalize recording of the command buffer
10082 EndCommandBuffer();
10083
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010084 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010085
10086 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10087 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10088 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10089}
Mark Young29927482016-05-04 14:38:51 -060010090
Mark Muellerd4914412016-06-13 17:52:06 -060010091TEST_F(VkLayerTest, MissingClearAttachment) {
10092 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10093 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010094 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120010095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +130010096 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -060010097
10098 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10099 m_errorMonitor->VerifyFound();
10100}
10101
Karl Schultz6addd812016-02-02 17:17:23 -070010102TEST_F(VkLayerTest, ClearCmdNoDraw) {
10103 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
10104 // to issuing a Draw
10105 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010106
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060010108 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010109
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010110 ASSERT_NO_FATAL_FAILURE(InitState());
10111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010112
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010113 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010114 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10115 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010116
10117 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010118 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10119 ds_pool_ci.pNext = NULL;
10120 ds_pool_ci.maxSets = 1;
10121 ds_pool_ci.poolSizeCount = 1;
10122 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010123
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010124 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010125 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010126 ASSERT_VK_SUCCESS(err);
10127
Tony Barboureb254902015-07-15 12:50:33 -060010128 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010129 dsl_binding.binding = 0;
10130 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10131 dsl_binding.descriptorCount = 1;
10132 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10133 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010134
Tony Barboureb254902015-07-15 12:50:33 -060010135 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010136 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10137 ds_layout_ci.pNext = NULL;
10138 ds_layout_ci.bindingCount = 1;
10139 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010140
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010141 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010142 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010143 ASSERT_VK_SUCCESS(err);
10144
10145 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010146 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010147 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010148 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010149 alloc_info.descriptorPool = ds_pool;
10150 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010151 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010152 ASSERT_VK_SUCCESS(err);
10153
Tony Barboureb254902015-07-15 12:50:33 -060010154 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010155 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010156 pipe_ms_state_ci.pNext = NULL;
10157 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10158 pipe_ms_state_ci.sampleShadingEnable = 0;
10159 pipe_ms_state_ci.minSampleShading = 1.0;
10160 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010161
Tony Barboureb254902015-07-15 12:50:33 -060010162 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010163 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10164 pipeline_layout_ci.pNext = NULL;
10165 pipeline_layout_ci.setLayoutCount = 1;
10166 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010167
10168 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010169 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010170 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010172 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010173 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010174 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010175 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010176
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010177 VkPipelineObj pipe(m_device);
10178 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010179 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010180 pipe.SetMSAA(&pipe_ms_state_ci);
10181 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010182
10183 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010184
Karl Schultz6addd812016-02-02 17:17:23 -070010185 // Main thing we care about for this test is that the VkImage obj we're
10186 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010187 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010188 VkClearAttachment color_attachment;
10189 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10190 color_attachment.clearValue.color.float32[0] = 1.0;
10191 color_attachment.clearValue.color.float32[1] = 1.0;
10192 color_attachment.clearValue.color.float32[2] = 1.0;
10193 color_attachment.clearValue.color.float32[3] = 1.0;
10194 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010195 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010197 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010198
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010199 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010200
Chia-I Wuf7458c52015-10-26 21:10:41 +080010201 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10202 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10203 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010204}
10205
Karl Schultz6addd812016-02-02 17:17:23 -070010206TEST_F(VkLayerTest, VtxBufferBadIndex) {
10207 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010208
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10210 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010211
Tobin Ehlis502480b2015-06-24 15:53:07 -060010212 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010213 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010215
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010216 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010217 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10218 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010219
10220 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010221 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10222 ds_pool_ci.pNext = NULL;
10223 ds_pool_ci.maxSets = 1;
10224 ds_pool_ci.poolSizeCount = 1;
10225 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010226
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010227 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010228 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010229 ASSERT_VK_SUCCESS(err);
10230
Tony Barboureb254902015-07-15 12:50:33 -060010231 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010232 dsl_binding.binding = 0;
10233 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10234 dsl_binding.descriptorCount = 1;
10235 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10236 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010237
Tony Barboureb254902015-07-15 12:50:33 -060010238 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010239 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10240 ds_layout_ci.pNext = NULL;
10241 ds_layout_ci.bindingCount = 1;
10242 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010243
Tobin Ehlis502480b2015-06-24 15:53:07 -060010244 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010245 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010246 ASSERT_VK_SUCCESS(err);
10247
10248 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010249 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010250 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010251 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010252 alloc_info.descriptorPool = ds_pool;
10253 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010254 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010255 ASSERT_VK_SUCCESS(err);
10256
Tony Barboureb254902015-07-15 12:50:33 -060010257 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010258 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010259 pipe_ms_state_ci.pNext = NULL;
10260 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10261 pipe_ms_state_ci.sampleShadingEnable = 0;
10262 pipe_ms_state_ci.minSampleShading = 1.0;
10263 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010264
Tony Barboureb254902015-07-15 12:50:33 -060010265 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010266 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10267 pipeline_layout_ci.pNext = NULL;
10268 pipeline_layout_ci.setLayoutCount = 1;
10269 pipeline_layout_ci.pSetLayouts = &ds_layout;
10270 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010272 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010273 ASSERT_VK_SUCCESS(err);
10274
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010275 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10276 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10277 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010278 VkPipelineObj pipe(m_device);
10279 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010280 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010281 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010282 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010283 pipe.SetViewport(m_viewports);
10284 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010285 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010286
10287 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010288 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010289 // Don't care about actual data, just need to get to draw to flag error
10290 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010291 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010292 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010293 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010294
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010295 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010296
Chia-I Wuf7458c52015-10-26 21:10:41 +080010297 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10298 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10299 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010300}
Mark Muellerdfe37552016-07-07 14:47:42 -060010301
Mark Mueller2ee294f2016-08-04 12:59:48 -060010302TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10303 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10304 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010305 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010307 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10308 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010309
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010310 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10311 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010314
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010316 // The following test fails with recent NVidia drivers.
10317 // By the time core_validation is reached, the NVidia
10318 // driver has sanitized the invalid condition and core_validation
10319 // is not introduced to the failure condition. This is not the case
10320 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010321 // uint32_t count = static_cast<uint32_t>(~0);
10322 // VkPhysicalDevice physical_device;
10323 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10324 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010325
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010327 float queue_priority = 0.0;
10328
10329 VkDeviceQueueCreateInfo queue_create_info = {};
10330 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10331 queue_create_info.queueCount = 1;
10332 queue_create_info.pQueuePriorities = &queue_priority;
10333 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10334
10335 VkPhysicalDeviceFeatures features = m_device->phy().features();
10336 VkDevice testDevice;
10337 VkDeviceCreateInfo device_create_info = {};
10338 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10339 device_create_info.queueCreateInfoCount = 1;
10340 device_create_info.pQueueCreateInfos = &queue_create_info;
10341 device_create_info.pEnabledFeatures = &features;
10342 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10343 m_errorMonitor->VerifyFound();
10344
10345 queue_create_info.queueFamilyIndex = 1;
10346
10347 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10348 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10349 for (unsigned i = 0; i < feature_count; i++) {
10350 if (VK_FALSE == feature_array[i]) {
10351 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010353 device_create_info.pEnabledFeatures = &features;
10354 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10355 m_errorMonitor->VerifyFound();
10356 break;
10357 }
10358 }
10359}
10360
Tobin Ehlis16edf082016-11-21 12:33:49 -070010361TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10362 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10363
10364 ASSERT_NO_FATAL_FAILURE(InitState());
10365
10366 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10367 std::vector<VkDeviceQueueCreateInfo> queue_info;
10368 queue_info.reserve(queue_props.size());
10369 std::vector<std::vector<float>> queue_priorities;
10370 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10371 VkDeviceQueueCreateInfo qi{};
10372 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10373 qi.queueFamilyIndex = i;
10374 qi.queueCount = queue_props[i].queueCount;
10375 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10376 qi.pQueuePriorities = queue_priorities[i].data();
10377 queue_info.push_back(qi);
10378 }
10379
10380 std::vector<const char *> device_extension_names;
10381
10382 VkDevice local_device;
10383 VkDeviceCreateInfo device_create_info = {};
10384 auto features = m_device->phy().features();
10385 // Intentionally disable pipeline stats
10386 features.pipelineStatisticsQuery = VK_FALSE;
10387 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10388 device_create_info.pNext = NULL;
10389 device_create_info.queueCreateInfoCount = queue_info.size();
10390 device_create_info.pQueueCreateInfos = queue_info.data();
10391 device_create_info.enabledLayerCount = 0;
10392 device_create_info.ppEnabledLayerNames = NULL;
10393 device_create_info.pEnabledFeatures = &features;
10394 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10395 ASSERT_VK_SUCCESS(err);
10396
10397 VkQueryPoolCreateInfo qpci{};
10398 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10399 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10400 qpci.queryCount = 1;
10401 VkQueryPool query_pool;
10402
10403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10404 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10405 m_errorMonitor->VerifyFound();
10406
10407 vkDestroyDevice(local_device, nullptr);
10408}
10409
Mark Mueller2ee294f2016-08-04 12:59:48 -060010410TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10411 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10412 "End a command buffer with a query still in progress.");
10413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010414 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10415 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10416 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010418 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010421
10422 ASSERT_NO_FATAL_FAILURE(InitState());
10423
10424 VkEvent event;
10425 VkEventCreateInfo event_create_info{};
10426 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10427 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10428
Mark Mueller2ee294f2016-08-04 12:59:48 -060010429 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010430 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010431
10432 BeginCommandBuffer();
10433
10434 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010435 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 -060010436 ASSERT_TRUE(image.initialized());
10437 VkImageMemoryBarrier img_barrier = {};
10438 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10439 img_barrier.pNext = NULL;
10440 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10441 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10442 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10443 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10444 img_barrier.image = image.handle();
10445 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010446
10447 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10448 // that layer validation catches the case when it is not.
10449 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010450 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10451 img_barrier.subresourceRange.baseArrayLayer = 0;
10452 img_barrier.subresourceRange.baseMipLevel = 0;
10453 img_barrier.subresourceRange.layerCount = 1;
10454 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010455 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10456 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010457 m_errorMonitor->VerifyFound();
10458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010460
10461 VkQueryPool query_pool;
10462 VkQueryPoolCreateInfo query_pool_create_info = {};
10463 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10464 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10465 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010466 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010468 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010469 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10470
10471 vkEndCommandBuffer(m_commandBuffer->handle());
10472 m_errorMonitor->VerifyFound();
10473
10474 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10475 vkDestroyEvent(m_device->device(), event, nullptr);
10476}
10477
Mark Muellerdfe37552016-07-07 14:47:42 -060010478TEST_F(VkLayerTest, VertexBufferInvalid) {
10479 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10480 "delete a buffer twice, use an invalid offset for each "
10481 "buffer type, and attempt to bind a null buffer");
10482
10483 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10484 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010485 const char *invalid_offset_message = "vkBindBufferMemory(): "
10486 "memoryOffset is 0x";
10487 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10488 "storage memoryOffset "
10489 "is 0x";
10490 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10491 "texel memoryOffset "
10492 "is 0x";
10493 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10494 "uniform memoryOffset "
10495 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010496
10497 ASSERT_NO_FATAL_FAILURE(InitState());
10498 ASSERT_NO_FATAL_FAILURE(InitViewport());
10499 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10500
10501 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010503 pipe_ms_state_ci.pNext = NULL;
10504 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10505 pipe_ms_state_ci.sampleShadingEnable = 0;
10506 pipe_ms_state_ci.minSampleShading = 1.0;
10507 pipe_ms_state_ci.pSampleMask = nullptr;
10508
10509 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10510 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10511 VkPipelineLayout pipeline_layout;
10512
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010513 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010514 ASSERT_VK_SUCCESS(err);
10515
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010516 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10517 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010518 VkPipelineObj pipe(m_device);
10519 pipe.AddShader(&vs);
10520 pipe.AddShader(&fs);
10521 pipe.AddColorAttachment();
10522 pipe.SetMSAA(&pipe_ms_state_ci);
10523 pipe.SetViewport(m_viewports);
10524 pipe.SetScissor(m_scissors);
10525 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10526
10527 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010528 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010529
10530 {
10531 // Create and bind a vertex buffer in a reduced scope, which will cause
10532 // it to be deleted upon leaving this scope
10533 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010535 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10536 draw_verticies.AddVertexInputToPipe(pipe);
10537 }
10538
10539 Draw(1, 0, 0, 0);
10540
10541 EndCommandBuffer();
10542
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010544 QueueCommandBuffer(false);
10545 m_errorMonitor->VerifyFound();
10546
10547 {
10548 // Create and bind a vertex buffer in a reduced scope, and delete it
10549 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010550 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010552 buffer_test.TestDoubleDestroy();
10553 }
10554 m_errorMonitor->VerifyFound();
10555
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010556 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010557 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10559 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10560 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010561 m_errorMonitor->VerifyFound();
10562 }
10563
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010564 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10565 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010566 // Create and bind a memory buffer with an invalid offset again,
10567 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10569 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10570 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010571 m_errorMonitor->VerifyFound();
10572 }
10573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010574 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010575 // Create and bind a memory buffer with an invalid offset again, but
10576 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10578 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10579 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010580 m_errorMonitor->VerifyFound();
10581 }
10582
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010583 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010584 // Create and bind a memory buffer with an invalid offset again, but
10585 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10587 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10588 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010589 m_errorMonitor->VerifyFound();
10590 }
10591
10592 {
10593 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010595 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10596 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010597 m_errorMonitor->VerifyFound();
10598 }
10599
10600 {
10601 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010603 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10604 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010605 }
10606 m_errorMonitor->VerifyFound();
10607
10608 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10609}
10610
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010611// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10612TEST_F(VkLayerTest, InvalidImageLayout) {
10613 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010614 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10615 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010616 // 3 in ValidateCmdBufImageLayouts
10617 // * -1 Attempt to submit cmd buf w/ deleted image
10618 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10619 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010620
10621 ASSERT_NO_FATAL_FAILURE(InitState());
10622 // Create src & dst images to use for copy operations
10623 VkImage src_image;
10624 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010625 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010626
10627 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10628 const int32_t tex_width = 32;
10629 const int32_t tex_height = 32;
10630
10631 VkImageCreateInfo image_create_info = {};
10632 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10633 image_create_info.pNext = NULL;
10634 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10635 image_create_info.format = tex_format;
10636 image_create_info.extent.width = tex_width;
10637 image_create_info.extent.height = tex_height;
10638 image_create_info.extent.depth = 1;
10639 image_create_info.mipLevels = 1;
10640 image_create_info.arrayLayers = 4;
10641 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10642 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10643 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010644 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010645 image_create_info.flags = 0;
10646
10647 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10648 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010649 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010650 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10651 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010652 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10653 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10654 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10655 ASSERT_VK_SUCCESS(err);
10656
10657 // Allocate memory
10658 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010659 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010660 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010661 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10662 mem_alloc.pNext = NULL;
10663 mem_alloc.allocationSize = 0;
10664 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010665
10666 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010667 mem_alloc.allocationSize = img_mem_reqs.size;
10668 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010669 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010670 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010671 ASSERT_VK_SUCCESS(err);
10672
10673 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010674 mem_alloc.allocationSize = img_mem_reqs.size;
10675 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010676 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010677 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010678 ASSERT_VK_SUCCESS(err);
10679
10680 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010681 mem_alloc.allocationSize = img_mem_reqs.size;
10682 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010683 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010684 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010685 ASSERT_VK_SUCCESS(err);
10686
10687 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10688 ASSERT_VK_SUCCESS(err);
10689 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10690 ASSERT_VK_SUCCESS(err);
10691 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10692 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010693
10694 BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010695 VkImageCopy copy_region;
10696 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10697 copy_region.srcSubresource.mipLevel = 0;
10698 copy_region.srcSubresource.baseArrayLayer = 0;
10699 copy_region.srcSubresource.layerCount = 1;
10700 copy_region.srcOffset.x = 0;
10701 copy_region.srcOffset.y = 0;
10702 copy_region.srcOffset.z = 0;
10703 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10704 copy_region.dstSubresource.mipLevel = 0;
10705 copy_region.dstSubresource.baseArrayLayer = 0;
10706 copy_region.dstSubresource.layerCount = 1;
10707 copy_region.dstOffset.x = 0;
10708 copy_region.dstOffset.y = 0;
10709 copy_region.dstOffset.z = 0;
10710 copy_region.extent.width = 1;
10711 copy_region.extent.height = 1;
10712 copy_region.extent.depth = 1;
10713
10714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10715 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10716 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010717 m_errorMonitor->VerifyFound();
10718 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10720 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10721 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010722 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010723 m_errorMonitor->VerifyFound();
10724 // Final src error is due to bad layout type
10725 m_errorMonitor->SetDesiredFailureMsg(
10726 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10727 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010728 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010729 m_errorMonitor->VerifyFound();
10730 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10732 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010733 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010734 m_errorMonitor->VerifyFound();
10735 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10737 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10738 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010739 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010740 m_errorMonitor->VerifyFound();
10741 m_errorMonitor->SetDesiredFailureMsg(
10742 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10743 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010744 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010745 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010746
Cort3b021012016-12-07 12:00:57 -080010747 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10748 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10749 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10750 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10751 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10752 transfer_dst_image_barrier[0].srcAccessMask = 0;
10753 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10754 transfer_dst_image_barrier[0].image = dst_image;
10755 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10756 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10757 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10758 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10759 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10760 transfer_dst_image_barrier[0].image = depth_image;
10761 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10762 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10763 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10764
10765 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010766 VkClearColorValue color_clear_value = {};
10767 VkImageSubresourceRange clear_range;
10768 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10769 clear_range.baseMipLevel = 0;
10770 clear_range.baseArrayLayer = 0;
10771 clear_range.layerCount = 1;
10772 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010773
Cort3b021012016-12-07 12:00:57 -080010774 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10775 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010778 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010779 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010780 // Fail due to provided layout not matching actual current layout for color clear.
10781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010782 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010783 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010784
Cort530cf382016-12-08 09:59:47 -080010785 VkClearDepthStencilValue depth_clear_value = {};
10786 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010787
10788 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10789 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010792 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010793 m_errorMonitor->VerifyFound();
10794 // Fail due to provided layout not matching actual current layout for depth clear.
10795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010796 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010797 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010798
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010799 // Now cause error due to bad image layout transition in PipelineBarrier
10800 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010801 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010802 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010803 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010804 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010805 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10806 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010807 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10809 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10810 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10811 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10812 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010813 m_errorMonitor->VerifyFound();
10814
10815 // Finally some layout errors at RenderPass create time
10816 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10817 VkAttachmentReference attach = {};
10818 // perf warning for GENERAL layout w/ non-DS input attachment
10819 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10820 VkSubpassDescription subpass = {};
10821 subpass.inputAttachmentCount = 1;
10822 subpass.pInputAttachments = &attach;
10823 VkRenderPassCreateInfo rpci = {};
10824 rpci.subpassCount = 1;
10825 rpci.pSubpasses = &subpass;
10826 rpci.attachmentCount = 1;
10827 VkAttachmentDescription attach_desc = {};
10828 attach_desc.format = VK_FORMAT_UNDEFINED;
10829 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010830 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010831 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10833 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010834 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10835 m_errorMonitor->VerifyFound();
10836 // error w/ non-general layout
10837 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10838
10839 m_errorMonitor->SetDesiredFailureMsg(
10840 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10841 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10842 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10843 m_errorMonitor->VerifyFound();
10844 subpass.inputAttachmentCount = 0;
10845 subpass.colorAttachmentCount = 1;
10846 subpass.pColorAttachments = &attach;
10847 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10848 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10850 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010851 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10852 m_errorMonitor->VerifyFound();
10853 // error w/ non-color opt or GENERAL layout for color attachment
10854 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10855 m_errorMonitor->SetDesiredFailureMsg(
10856 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10857 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10858 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10859 m_errorMonitor->VerifyFound();
10860 subpass.colorAttachmentCount = 0;
10861 subpass.pDepthStencilAttachment = &attach;
10862 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10863 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10865 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010866 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10867 m_errorMonitor->VerifyFound();
10868 // error w/ non-ds opt or GENERAL layout for color attachment
10869 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10871 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10872 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010873 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10874 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010875 // For this error we need a valid renderpass so create default one
10876 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10877 attach.attachment = 0;
10878 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10879 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10880 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10881 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10882 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10883 // Can't do a CLEAR load on READ_ONLY initialLayout
10884 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10885 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10886 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10888 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10889 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010890 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10891 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010892
Cort3b021012016-12-07 12:00:57 -080010893 vkFreeMemory(m_device->device(), src_image_mem, NULL);
10894 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
10895 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010896 vkDestroyImage(m_device->device(), src_image, NULL);
10897 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080010898 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010899}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010900
Tobin Ehlise0936662016-10-11 08:10:51 -060010901TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10902 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10903 VkResult err;
10904
10905 ASSERT_NO_FATAL_FAILURE(InitState());
10906
10907 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10908 VkImageTiling tiling;
10909 VkFormatProperties format_properties;
10910 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10911 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10912 tiling = VK_IMAGE_TILING_LINEAR;
10913 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10914 tiling = VK_IMAGE_TILING_OPTIMAL;
10915 } else {
10916 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10917 "skipped.\n");
10918 return;
10919 }
10920
10921 VkDescriptorPoolSize ds_type = {};
10922 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10923 ds_type.descriptorCount = 1;
10924
10925 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10926 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10927 ds_pool_ci.maxSets = 1;
10928 ds_pool_ci.poolSizeCount = 1;
10929 ds_pool_ci.pPoolSizes = &ds_type;
10930 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10931
10932 VkDescriptorPool ds_pool;
10933 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10934 ASSERT_VK_SUCCESS(err);
10935
10936 VkDescriptorSetLayoutBinding dsl_binding = {};
10937 dsl_binding.binding = 0;
10938 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10939 dsl_binding.descriptorCount = 1;
10940 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10941 dsl_binding.pImmutableSamplers = NULL;
10942
10943 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10944 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10945 ds_layout_ci.pNext = NULL;
10946 ds_layout_ci.bindingCount = 1;
10947 ds_layout_ci.pBindings = &dsl_binding;
10948
10949 VkDescriptorSetLayout ds_layout;
10950 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10951 ASSERT_VK_SUCCESS(err);
10952
10953 VkDescriptorSetAllocateInfo alloc_info = {};
10954 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10955 alloc_info.descriptorSetCount = 1;
10956 alloc_info.descriptorPool = ds_pool;
10957 alloc_info.pSetLayouts = &ds_layout;
10958 VkDescriptorSet descriptor_set;
10959 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10960 ASSERT_VK_SUCCESS(err);
10961
10962 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10963 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10964 pipeline_layout_ci.pNext = NULL;
10965 pipeline_layout_ci.setLayoutCount = 1;
10966 pipeline_layout_ci.pSetLayouts = &ds_layout;
10967 VkPipelineLayout pipeline_layout;
10968 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10969 ASSERT_VK_SUCCESS(err);
10970
10971 VkImageObj image(m_device);
10972 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10973 ASSERT_TRUE(image.initialized());
10974 VkImageView view = image.targetView(tex_format);
10975
10976 VkDescriptorImageInfo image_info = {};
10977 image_info.imageView = view;
10978 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10979
10980 VkWriteDescriptorSet descriptor_write = {};
10981 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10982 descriptor_write.dstSet = descriptor_set;
10983 descriptor_write.dstBinding = 0;
10984 descriptor_write.descriptorCount = 1;
10985 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10986 descriptor_write.pImageInfo = &image_info;
10987
10988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10989 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10990 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10991 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10992 m_errorMonitor->VerifyFound();
10993
10994 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10995 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10996 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10997 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10998}
10999
Mark Mueller93b938f2016-08-18 10:27:40 -060011000TEST_F(VkLayerTest, SimultaneousUse) {
11001 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11002 "in primary and secondary command buffers.");
11003
11004 ASSERT_NO_FATAL_FAILURE(InitState());
11005 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11006
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011007 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011008 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11009 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011010
11011 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011012 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011013 command_buffer_allocate_info.commandPool = m_commandPool;
11014 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11015 command_buffer_allocate_info.commandBufferCount = 1;
11016
11017 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011018 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011019 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11020 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011021 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011022 command_buffer_inheritance_info.renderPass = m_renderPass;
11023 command_buffer_inheritance_info.framebuffer = m_framebuffer;
11024 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011025 command_buffer_begin_info.flags =
11026 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011027 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11028
11029 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011030 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11031 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060011032 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011033 vkEndCommandBuffer(secondary_command_buffer);
11034
Mark Mueller93b938f2016-08-18 10:27:40 -060011035 VkSubmitInfo submit_info = {};
11036 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11037 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011038 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060011039 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060011040
Mark Mueller4042b652016-09-05 22:52:21 -060011041 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011042 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11044 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011045 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011046 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11047 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011048
11049 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060011050 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11051
Mark Mueller4042b652016-09-05 22:52:21 -060011052 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011053 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011054 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011055
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11057 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011058 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011059 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11060 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011061}
11062
Mark Mueller917f6bc2016-08-30 10:57:19 -060011063TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11064 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11065 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011066 "Delete objects that are inuse. Call VkQueueSubmit "
11067 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011068
11069 ASSERT_NO_FATAL_FAILURE(InitState());
11070 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011072 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
11073 const char *cannot_delete_event_message = "Cannot delete event 0x";
11074 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
11075 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011076
11077 BeginCommandBuffer();
11078
11079 VkEvent event;
11080 VkEventCreateInfo event_create_info = {};
11081 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11082 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011083 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011084
Mark Muellerc8d441e2016-08-23 17:36:00 -060011085 EndCommandBuffer();
11086 vkDestroyEvent(m_device->device(), event, nullptr);
11087
11088 VkSubmitInfo submit_info = {};
11089 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11090 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011091 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011093 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11094 m_errorMonitor->VerifyFound();
11095
11096 m_errorMonitor->SetDesiredFailureMsg(0, "");
11097 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11098
11099 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11100
Mark Mueller917f6bc2016-08-30 10:57:19 -060011101 VkSemaphoreCreateInfo semaphore_create_info = {};
11102 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11103 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011104 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011105 VkFenceCreateInfo fence_create_info = {};
11106 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11107 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011108 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011109
11110 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011111 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011112 descriptor_pool_type_count.descriptorCount = 1;
11113
11114 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11115 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11116 descriptor_pool_create_info.maxSets = 1;
11117 descriptor_pool_create_info.poolSizeCount = 1;
11118 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011119 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011120
11121 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011122 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011123
11124 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011125 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011126 descriptorset_layout_binding.descriptorCount = 1;
11127 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11128
11129 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011130 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011131 descriptorset_layout_create_info.bindingCount = 1;
11132 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11133
11134 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011135 ASSERT_VK_SUCCESS(
11136 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011137
11138 VkDescriptorSet descriptorset;
11139 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011140 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011141 descriptorset_allocate_info.descriptorSetCount = 1;
11142 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11143 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011144 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011145
Mark Mueller4042b652016-09-05 22:52:21 -060011146 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11147
11148 VkDescriptorBufferInfo buffer_info = {};
11149 buffer_info.buffer = buffer_test.GetBuffer();
11150 buffer_info.offset = 0;
11151 buffer_info.range = 1024;
11152
11153 VkWriteDescriptorSet write_descriptor_set = {};
11154 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11155 write_descriptor_set.dstSet = descriptorset;
11156 write_descriptor_set.descriptorCount = 1;
11157 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11158 write_descriptor_set.pBufferInfo = &buffer_info;
11159
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011160 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011161
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011162 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11163 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011164
11165 VkPipelineObj pipe(m_device);
11166 pipe.AddColorAttachment();
11167 pipe.AddShader(&vs);
11168 pipe.AddShader(&fs);
11169
11170 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011171 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011172 pipeline_layout_create_info.setLayoutCount = 1;
11173 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11174
11175 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011176 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011177
11178 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11179
Mark Muellerc8d441e2016-08-23 17:36:00 -060011180 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011181 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011183 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11184 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11185 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011186
Mark Muellerc8d441e2016-08-23 17:36:00 -060011187 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011188
Mark Mueller917f6bc2016-08-30 10:57:19 -060011189 submit_info.signalSemaphoreCount = 1;
11190 submit_info.pSignalSemaphores = &semaphore;
11191 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011194 vkDestroyEvent(m_device->device(), event, nullptr);
11195 m_errorMonitor->VerifyFound();
11196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011198 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11199 m_errorMonitor->VerifyFound();
11200
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011202 vkDestroyFence(m_device->device(), fence, nullptr);
11203 m_errorMonitor->VerifyFound();
11204
Tobin Ehlis122207b2016-09-01 08:50:06 -070011205 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011206 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11207 vkDestroyFence(m_device->device(), fence, nullptr);
11208 vkDestroyEvent(m_device->device(), event, nullptr);
11209 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011210 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011211 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11212}
11213
Tobin Ehlis2adda372016-09-01 08:51:06 -070011214TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11215 TEST_DESCRIPTION("Delete in-use query pool.");
11216
11217 ASSERT_NO_FATAL_FAILURE(InitState());
11218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11219
11220 VkQueryPool query_pool;
11221 VkQueryPoolCreateInfo query_pool_ci{};
11222 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11223 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11224 query_pool_ci.queryCount = 1;
11225 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
11226 BeginCommandBuffer();
11227 // Reset query pool to create binding with cmd buffer
11228 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11229
11230 EndCommandBuffer();
11231
11232 VkSubmitInfo submit_info = {};
11233 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11234 submit_info.commandBufferCount = 1;
11235 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11236 // Submit cmd buffer and then destroy query pool while in-flight
11237 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070011240 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11241 m_errorMonitor->VerifyFound();
11242
11243 vkQueueWaitIdle(m_device->m_queue);
11244 // Now that cmd buffer done we can safely destroy query_pool
11245 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11246}
11247
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011248TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11249 TEST_DESCRIPTION("Delete in-use pipeline.");
11250
11251 ASSERT_NO_FATAL_FAILURE(InitState());
11252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11253
11254 // Empty pipeline layout used for binding PSO
11255 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11256 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11257 pipeline_layout_ci.setLayoutCount = 0;
11258 pipeline_layout_ci.pSetLayouts = NULL;
11259
11260 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011261 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011262 ASSERT_VK_SUCCESS(err);
11263
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011265 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011266 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11267 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011268 // Store pipeline handle so we can actually delete it before test finishes
11269 VkPipeline delete_this_pipeline;
11270 { // Scope pipeline so it will be auto-deleted
11271 VkPipelineObj pipe(m_device);
11272 pipe.AddShader(&vs);
11273 pipe.AddShader(&fs);
11274 pipe.AddColorAttachment();
11275 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11276 delete_this_pipeline = pipe.handle();
11277
11278 BeginCommandBuffer();
11279 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011280 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011281
11282 EndCommandBuffer();
11283
11284 VkSubmitInfo submit_info = {};
11285 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11286 submit_info.commandBufferCount = 1;
11287 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11288 // Submit cmd buffer and then pipeline destroyed while in-flight
11289 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11290 } // Pipeline deletion triggered here
11291 m_errorMonitor->VerifyFound();
11292 // Make sure queue finished and then actually delete pipeline
11293 vkQueueWaitIdle(m_device->m_queue);
11294 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11295 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11296}
11297
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011298TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11299 TEST_DESCRIPTION("Delete in-use imageView.");
11300
11301 ASSERT_NO_FATAL_FAILURE(InitState());
11302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11303
11304 VkDescriptorPoolSize ds_type_count;
11305 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11306 ds_type_count.descriptorCount = 1;
11307
11308 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11309 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11310 ds_pool_ci.maxSets = 1;
11311 ds_pool_ci.poolSizeCount = 1;
11312 ds_pool_ci.pPoolSizes = &ds_type_count;
11313
11314 VkDescriptorPool ds_pool;
11315 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11316 ASSERT_VK_SUCCESS(err);
11317
11318 VkSamplerCreateInfo sampler_ci = {};
11319 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11320 sampler_ci.pNext = NULL;
11321 sampler_ci.magFilter = VK_FILTER_NEAREST;
11322 sampler_ci.minFilter = VK_FILTER_NEAREST;
11323 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11324 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11325 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11326 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11327 sampler_ci.mipLodBias = 1.0;
11328 sampler_ci.anisotropyEnable = VK_FALSE;
11329 sampler_ci.maxAnisotropy = 1;
11330 sampler_ci.compareEnable = VK_FALSE;
11331 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11332 sampler_ci.minLod = 1.0;
11333 sampler_ci.maxLod = 1.0;
11334 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11335 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11336 VkSampler sampler;
11337
11338 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11339 ASSERT_VK_SUCCESS(err);
11340
11341 VkDescriptorSetLayoutBinding layout_binding;
11342 layout_binding.binding = 0;
11343 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11344 layout_binding.descriptorCount = 1;
11345 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11346 layout_binding.pImmutableSamplers = NULL;
11347
11348 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11349 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11350 ds_layout_ci.bindingCount = 1;
11351 ds_layout_ci.pBindings = &layout_binding;
11352 VkDescriptorSetLayout ds_layout;
11353 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11354 ASSERT_VK_SUCCESS(err);
11355
11356 VkDescriptorSetAllocateInfo alloc_info = {};
11357 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11358 alloc_info.descriptorSetCount = 1;
11359 alloc_info.descriptorPool = ds_pool;
11360 alloc_info.pSetLayouts = &ds_layout;
11361 VkDescriptorSet descriptor_set;
11362 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11363 ASSERT_VK_SUCCESS(err);
11364
11365 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11366 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11367 pipeline_layout_ci.pNext = NULL;
11368 pipeline_layout_ci.setLayoutCount = 1;
11369 pipeline_layout_ci.pSetLayouts = &ds_layout;
11370
11371 VkPipelineLayout pipeline_layout;
11372 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11373 ASSERT_VK_SUCCESS(err);
11374
11375 VkImageObj image(m_device);
11376 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11377 ASSERT_TRUE(image.initialized());
11378
11379 VkImageView view;
11380 VkImageViewCreateInfo ivci = {};
11381 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11382 ivci.image = image.handle();
11383 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11384 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11385 ivci.subresourceRange.layerCount = 1;
11386 ivci.subresourceRange.baseMipLevel = 0;
11387 ivci.subresourceRange.levelCount = 1;
11388 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11389
11390 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11391 ASSERT_VK_SUCCESS(err);
11392
11393 VkDescriptorImageInfo image_info{};
11394 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11395 image_info.imageView = view;
11396 image_info.sampler = sampler;
11397
11398 VkWriteDescriptorSet descriptor_write = {};
11399 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11400 descriptor_write.dstSet = descriptor_set;
11401 descriptor_write.dstBinding = 0;
11402 descriptor_write.descriptorCount = 1;
11403 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11404 descriptor_write.pImageInfo = &image_info;
11405
11406 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11407
11408 // Create PSO to use the sampler
11409 char const *vsSource = "#version 450\n"
11410 "\n"
11411 "out gl_PerVertex { \n"
11412 " vec4 gl_Position;\n"
11413 "};\n"
11414 "void main(){\n"
11415 " gl_Position = vec4(1);\n"
11416 "}\n";
11417 char const *fsSource = "#version 450\n"
11418 "\n"
11419 "layout(set=0, binding=0) uniform sampler2D s;\n"
11420 "layout(location=0) out vec4 x;\n"
11421 "void main(){\n"
11422 " x = texture(s, vec2(1));\n"
11423 "}\n";
11424 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11425 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11426 VkPipelineObj pipe(m_device);
11427 pipe.AddShader(&vs);
11428 pipe.AddShader(&fs);
11429 pipe.AddColorAttachment();
11430 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11431
11432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11433
11434 BeginCommandBuffer();
11435 // Bind pipeline to cmd buffer
11436 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11437 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11438 &descriptor_set, 0, nullptr);
11439 Draw(1, 0, 0, 0);
11440 EndCommandBuffer();
11441 // Submit cmd buffer then destroy sampler
11442 VkSubmitInfo submit_info = {};
11443 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11444 submit_info.commandBufferCount = 1;
11445 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11446 // Submit cmd buffer and then destroy imageView while in-flight
11447 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11448
11449 vkDestroyImageView(m_device->device(), view, nullptr);
11450 m_errorMonitor->VerifyFound();
11451 vkQueueWaitIdle(m_device->m_queue);
11452 // Now we can actually destroy imageView
11453 vkDestroyImageView(m_device->device(), view, NULL);
11454 vkDestroySampler(m_device->device(), sampler, nullptr);
11455 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11456 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11457 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11458}
11459
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011460TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11461 TEST_DESCRIPTION("Delete in-use bufferView.");
11462
11463 ASSERT_NO_FATAL_FAILURE(InitState());
11464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11465
11466 VkDescriptorPoolSize ds_type_count;
11467 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11468 ds_type_count.descriptorCount = 1;
11469
11470 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11471 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11472 ds_pool_ci.maxSets = 1;
11473 ds_pool_ci.poolSizeCount = 1;
11474 ds_pool_ci.pPoolSizes = &ds_type_count;
11475
11476 VkDescriptorPool ds_pool;
11477 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11478 ASSERT_VK_SUCCESS(err);
11479
11480 VkDescriptorSetLayoutBinding layout_binding;
11481 layout_binding.binding = 0;
11482 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11483 layout_binding.descriptorCount = 1;
11484 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11485 layout_binding.pImmutableSamplers = NULL;
11486
11487 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11488 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11489 ds_layout_ci.bindingCount = 1;
11490 ds_layout_ci.pBindings = &layout_binding;
11491 VkDescriptorSetLayout ds_layout;
11492 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11493 ASSERT_VK_SUCCESS(err);
11494
11495 VkDescriptorSetAllocateInfo alloc_info = {};
11496 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11497 alloc_info.descriptorSetCount = 1;
11498 alloc_info.descriptorPool = ds_pool;
11499 alloc_info.pSetLayouts = &ds_layout;
11500 VkDescriptorSet descriptor_set;
11501 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11502 ASSERT_VK_SUCCESS(err);
11503
11504 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11505 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11506 pipeline_layout_ci.pNext = NULL;
11507 pipeline_layout_ci.setLayoutCount = 1;
11508 pipeline_layout_ci.pSetLayouts = &ds_layout;
11509
11510 VkPipelineLayout pipeline_layout;
11511 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11512 ASSERT_VK_SUCCESS(err);
11513
11514 VkBuffer buffer;
11515 uint32_t queue_family_index = 0;
11516 VkBufferCreateInfo buffer_create_info = {};
11517 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11518 buffer_create_info.size = 1024;
11519 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11520 buffer_create_info.queueFamilyIndexCount = 1;
11521 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11522
11523 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11524 ASSERT_VK_SUCCESS(err);
11525
11526 VkMemoryRequirements memory_reqs;
11527 VkDeviceMemory buffer_memory;
11528
11529 VkMemoryAllocateInfo memory_info = {};
11530 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11531 memory_info.allocationSize = 0;
11532 memory_info.memoryTypeIndex = 0;
11533
11534 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11535 memory_info.allocationSize = memory_reqs.size;
11536 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11537 ASSERT_TRUE(pass);
11538
11539 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11540 ASSERT_VK_SUCCESS(err);
11541 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11542 ASSERT_VK_SUCCESS(err);
11543
11544 VkBufferView view;
11545 VkBufferViewCreateInfo bvci = {};
11546 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11547 bvci.buffer = buffer;
11548 bvci.format = VK_FORMAT_R8_UNORM;
11549 bvci.range = VK_WHOLE_SIZE;
11550
11551 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11552 ASSERT_VK_SUCCESS(err);
11553
11554 VkWriteDescriptorSet descriptor_write = {};
11555 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11556 descriptor_write.dstSet = descriptor_set;
11557 descriptor_write.dstBinding = 0;
11558 descriptor_write.descriptorCount = 1;
11559 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11560 descriptor_write.pTexelBufferView = &view;
11561
11562 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11563
11564 char const *vsSource = "#version 450\n"
11565 "\n"
11566 "out gl_PerVertex { \n"
11567 " vec4 gl_Position;\n"
11568 "};\n"
11569 "void main(){\n"
11570 " gl_Position = vec4(1);\n"
11571 "}\n";
11572 char const *fsSource = "#version 450\n"
11573 "\n"
11574 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11575 "layout(location=0) out vec4 x;\n"
11576 "void main(){\n"
11577 " x = imageLoad(s, 0);\n"
11578 "}\n";
11579 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11580 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11581 VkPipelineObj pipe(m_device);
11582 pipe.AddShader(&vs);
11583 pipe.AddShader(&fs);
11584 pipe.AddColorAttachment();
11585 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11586
11587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11588
11589 BeginCommandBuffer();
11590 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11591 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11592 VkRect2D scissor = {{0, 0}, {16, 16}};
11593 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11594 // Bind pipeline to cmd buffer
11595 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11596 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11597 &descriptor_set, 0, nullptr);
11598 Draw(1, 0, 0, 0);
11599 EndCommandBuffer();
11600
11601 VkSubmitInfo submit_info = {};
11602 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11603 submit_info.commandBufferCount = 1;
11604 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11605 // Submit cmd buffer and then destroy bufferView while in-flight
11606 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11607
11608 vkDestroyBufferView(m_device->device(), view, nullptr);
11609 m_errorMonitor->VerifyFound();
11610 vkQueueWaitIdle(m_device->m_queue);
11611 // Now we can actually destroy bufferView
11612 vkDestroyBufferView(m_device->device(), view, NULL);
11613 vkDestroyBuffer(m_device->device(), buffer, NULL);
11614 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11615 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11616 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11617 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11618}
11619
Tobin Ehlis209532e2016-09-07 13:52:18 -060011620TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11621 TEST_DESCRIPTION("Delete in-use sampler.");
11622
11623 ASSERT_NO_FATAL_FAILURE(InitState());
11624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11625
11626 VkDescriptorPoolSize ds_type_count;
11627 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11628 ds_type_count.descriptorCount = 1;
11629
11630 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11631 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11632 ds_pool_ci.maxSets = 1;
11633 ds_pool_ci.poolSizeCount = 1;
11634 ds_pool_ci.pPoolSizes = &ds_type_count;
11635
11636 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011637 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011638 ASSERT_VK_SUCCESS(err);
11639
11640 VkSamplerCreateInfo sampler_ci = {};
11641 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11642 sampler_ci.pNext = NULL;
11643 sampler_ci.magFilter = VK_FILTER_NEAREST;
11644 sampler_ci.minFilter = VK_FILTER_NEAREST;
11645 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11646 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11647 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11648 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11649 sampler_ci.mipLodBias = 1.0;
11650 sampler_ci.anisotropyEnable = VK_FALSE;
11651 sampler_ci.maxAnisotropy = 1;
11652 sampler_ci.compareEnable = VK_FALSE;
11653 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11654 sampler_ci.minLod = 1.0;
11655 sampler_ci.maxLod = 1.0;
11656 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11657 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11658 VkSampler sampler;
11659
11660 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11661 ASSERT_VK_SUCCESS(err);
11662
11663 VkDescriptorSetLayoutBinding layout_binding;
11664 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011665 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011666 layout_binding.descriptorCount = 1;
11667 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11668 layout_binding.pImmutableSamplers = NULL;
11669
11670 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11671 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11672 ds_layout_ci.bindingCount = 1;
11673 ds_layout_ci.pBindings = &layout_binding;
11674 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011675 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011676 ASSERT_VK_SUCCESS(err);
11677
11678 VkDescriptorSetAllocateInfo alloc_info = {};
11679 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11680 alloc_info.descriptorSetCount = 1;
11681 alloc_info.descriptorPool = ds_pool;
11682 alloc_info.pSetLayouts = &ds_layout;
11683 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011684 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011685 ASSERT_VK_SUCCESS(err);
11686
11687 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11688 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11689 pipeline_layout_ci.pNext = NULL;
11690 pipeline_layout_ci.setLayoutCount = 1;
11691 pipeline_layout_ci.pSetLayouts = &ds_layout;
11692
11693 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011694 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011695 ASSERT_VK_SUCCESS(err);
11696
11697 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011698 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 -060011699 ASSERT_TRUE(image.initialized());
11700
11701 VkImageView view;
11702 VkImageViewCreateInfo ivci = {};
11703 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11704 ivci.image = image.handle();
11705 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11706 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11707 ivci.subresourceRange.layerCount = 1;
11708 ivci.subresourceRange.baseMipLevel = 0;
11709 ivci.subresourceRange.levelCount = 1;
11710 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11711
11712 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11713 ASSERT_VK_SUCCESS(err);
11714
11715 VkDescriptorImageInfo image_info{};
11716 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11717 image_info.imageView = view;
11718 image_info.sampler = sampler;
11719
11720 VkWriteDescriptorSet descriptor_write = {};
11721 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11722 descriptor_write.dstSet = descriptor_set;
11723 descriptor_write.dstBinding = 0;
11724 descriptor_write.descriptorCount = 1;
11725 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11726 descriptor_write.pImageInfo = &image_info;
11727
11728 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11729
11730 // Create PSO to use the sampler
11731 char const *vsSource = "#version 450\n"
11732 "\n"
11733 "out gl_PerVertex { \n"
11734 " vec4 gl_Position;\n"
11735 "};\n"
11736 "void main(){\n"
11737 " gl_Position = vec4(1);\n"
11738 "}\n";
11739 char const *fsSource = "#version 450\n"
11740 "\n"
11741 "layout(set=0, binding=0) uniform sampler2D s;\n"
11742 "layout(location=0) out vec4 x;\n"
11743 "void main(){\n"
11744 " x = texture(s, vec2(1));\n"
11745 "}\n";
11746 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11747 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11748 VkPipelineObj pipe(m_device);
11749 pipe.AddShader(&vs);
11750 pipe.AddShader(&fs);
11751 pipe.AddColorAttachment();
11752 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11753
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011755
11756 BeginCommandBuffer();
11757 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011758 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11759 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11760 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011761 Draw(1, 0, 0, 0);
11762 EndCommandBuffer();
11763 // Submit cmd buffer then destroy sampler
11764 VkSubmitInfo submit_info = {};
11765 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11766 submit_info.commandBufferCount = 1;
11767 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11768 // Submit cmd buffer and then destroy sampler while in-flight
11769 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11770
11771 vkDestroySampler(m_device->device(), sampler, nullptr);
11772 m_errorMonitor->VerifyFound();
11773 vkQueueWaitIdle(m_device->m_queue);
11774 // Now we can actually destroy sampler
11775 vkDestroySampler(m_device->device(), sampler, nullptr);
11776 vkDestroyImageView(m_device->device(), view, NULL);
11777 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11778 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11779 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11780}
11781
Mark Mueller1cd9f412016-08-25 13:23:52 -060011782TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011783 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011784 "signaled but not waited on by the queue. Wait on a "
11785 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011786
11787 ASSERT_NO_FATAL_FAILURE(InitState());
11788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11789
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011790 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11791 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11792 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011793
11794 BeginCommandBuffer();
11795 EndCommandBuffer();
11796
11797 VkSemaphoreCreateInfo semaphore_create_info = {};
11798 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11799 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011800 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011801 VkSubmitInfo submit_info = {};
11802 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11803 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011804 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011805 submit_info.signalSemaphoreCount = 1;
11806 submit_info.pSignalSemaphores = &semaphore;
11807 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11808 m_errorMonitor->SetDesiredFailureMsg(0, "");
11809 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11810 BeginCommandBuffer();
11811 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011813 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11814 m_errorMonitor->VerifyFound();
11815
Mark Mueller1cd9f412016-08-25 13:23:52 -060011816 VkFenceCreateInfo fence_create_info = {};
11817 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11818 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011819 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011822 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11823 m_errorMonitor->VerifyFound();
11824
Mark Mueller4042b652016-09-05 22:52:21 -060011825 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011826 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011827 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11828}
11829
Tobin Ehlis4af23302016-07-19 10:50:30 -060011830TEST_F(VkLayerTest, FramebufferIncompatible) {
11831 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11832 "that does not match the framebuffer for the active "
11833 "renderpass.");
11834 ASSERT_NO_FATAL_FAILURE(InitState());
11835 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11836
11837 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011838 VkAttachmentDescription attachment = {0,
11839 VK_FORMAT_B8G8R8A8_UNORM,
11840 VK_SAMPLE_COUNT_1_BIT,
11841 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11842 VK_ATTACHMENT_STORE_OP_STORE,
11843 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11844 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11845 VK_IMAGE_LAYOUT_UNDEFINED,
11846 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011847
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011848 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011849
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011850 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011851
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011852 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011853
11854 VkRenderPass rp;
11855 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11856 ASSERT_VK_SUCCESS(err);
11857
11858 // A compatible framebuffer.
11859 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011860 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 -060011861 ASSERT_TRUE(image.initialized());
11862
11863 VkImageViewCreateInfo ivci = {
11864 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11865 nullptr,
11866 0,
11867 image.handle(),
11868 VK_IMAGE_VIEW_TYPE_2D,
11869 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011870 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11871 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011872 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11873 };
11874 VkImageView view;
11875 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11876 ASSERT_VK_SUCCESS(err);
11877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011878 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011879 VkFramebuffer fb;
11880 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11881 ASSERT_VK_SUCCESS(err);
11882
11883 VkCommandBufferAllocateInfo cbai = {};
11884 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11885 cbai.commandPool = m_commandPool;
11886 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11887 cbai.commandBufferCount = 1;
11888
11889 VkCommandBuffer sec_cb;
11890 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11891 ASSERT_VK_SUCCESS(err);
11892 VkCommandBufferBeginInfo cbbi = {};
11893 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011894 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011895 cbii.renderPass = renderPass();
11896 cbii.framebuffer = fb;
11897 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11898 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011899 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 -060011900 cbbi.pInheritanceInfo = &cbii;
11901 vkBeginCommandBuffer(sec_cb, &cbbi);
11902 vkEndCommandBuffer(sec_cb);
11903
Chris Forbes3400bc52016-09-13 18:10:34 +120011904 VkCommandBufferBeginInfo cbbi2 = {
11905 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11906 0, nullptr
11907 };
11908 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11909 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011910
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011912 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011913 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11914 m_errorMonitor->VerifyFound();
11915 // Cleanup
11916 vkDestroyImageView(m_device->device(), view, NULL);
11917 vkDestroyRenderPass(m_device->device(), rp, NULL);
11918 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11919}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011920
11921TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11922 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11923 "invalid value. If logicOp is not available, attempt to "
11924 "use it and verify that we see the correct error.");
11925 ASSERT_NO_FATAL_FAILURE(InitState());
11926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11927
11928 auto features = m_device->phy().features();
11929 // Set the expected error depending on whether or not logicOp available
11930 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11932 "enabled, logicOpEnable must be "
11933 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011934 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011936 }
11937 // Create a pipeline using logicOp
11938 VkResult err;
11939
11940 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11941 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11942
11943 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011944 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011945 ASSERT_VK_SUCCESS(err);
11946
11947 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11948 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11949 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011950 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011951 vp_state_ci.pViewports = &vp;
11952 vp_state_ci.scissorCount = 1;
11953 VkRect2D scissors = {}; // Dummy scissors to point to
11954 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011955
11956 VkPipelineShaderStageCreateInfo shaderStages[2];
11957 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011959 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11960 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011961 shaderStages[0] = vs.GetStageCreateInfo();
11962 shaderStages[1] = fs.GetStageCreateInfo();
11963
11964 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11965 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11966
11967 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11968 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11969 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11970
11971 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11972 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011973 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011974
11975 VkPipelineColorBlendAttachmentState att = {};
11976 att.blendEnable = VK_FALSE;
11977 att.colorWriteMask = 0xf;
11978
11979 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11980 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11981 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11982 cb_ci.logicOpEnable = VK_TRUE;
11983 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11984 cb_ci.attachmentCount = 1;
11985 cb_ci.pAttachments = &att;
11986
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011987 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11988 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11989 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11990
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011991 VkGraphicsPipelineCreateInfo gp_ci = {};
11992 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11993 gp_ci.stageCount = 2;
11994 gp_ci.pStages = shaderStages;
11995 gp_ci.pVertexInputState = &vi_ci;
11996 gp_ci.pInputAssemblyState = &ia_ci;
11997 gp_ci.pViewportState = &vp_state_ci;
11998 gp_ci.pRasterizationState = &rs_ci;
11999 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012000 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012001 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12002 gp_ci.layout = pipeline_layout;
12003 gp_ci.renderPass = renderPass();
12004
12005 VkPipelineCacheCreateInfo pc_ci = {};
12006 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12007
12008 VkPipeline pipeline;
12009 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012010 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012011 ASSERT_VK_SUCCESS(err);
12012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012013 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012014 m_errorMonitor->VerifyFound();
12015 if (VK_SUCCESS == err) {
12016 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12017 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012018 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12019 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12020}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012021#endif // DRAW_STATE_TESTS
12022
Tobin Ehlis0788f522015-05-26 16:11:58 -060012023#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012024#if GTEST_IS_THREADSAFE
12025struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012026 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012027 VkEvent event;
12028 bool bailout;
12029};
12030
Karl Schultz6addd812016-02-02 17:17:23 -070012031extern "C" void *AddToCommandBuffer(void *arg) {
12032 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012033
Mike Stroyana6d14942016-07-13 15:10:05 -060012034 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012035 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012036 if (data->bailout) {
12037 break;
12038 }
12039 }
12040 return NULL;
12041}
12042
Karl Schultz6addd812016-02-02 17:17:23 -070012043TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012044 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012047
Mike Stroyanaccf7692015-05-12 16:00:45 -060012048 ASSERT_NO_FATAL_FAILURE(InitState());
12049 ASSERT_NO_FATAL_FAILURE(InitViewport());
12050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12051
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012052 // Calls AllocateCommandBuffers
12053 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012054
12055 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012056 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012057
12058 VkEventCreateInfo event_info;
12059 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012060 VkResult err;
12061
12062 memset(&event_info, 0, sizeof(event_info));
12063 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12064
Chia-I Wuf7458c52015-10-26 21:10:41 +080012065 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012066 ASSERT_VK_SUCCESS(err);
12067
Mike Stroyanaccf7692015-05-12 16:00:45 -060012068 err = vkResetEvent(device(), event);
12069 ASSERT_VK_SUCCESS(err);
12070
12071 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012072 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012073 data.event = event;
12074 data.bailout = false;
12075 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012076
12077 // First do some correct operations using multiple threads.
12078 // Add many entries to command buffer from another thread.
12079 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12080 // Make non-conflicting calls from this thread at the same time.
12081 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012082 uint32_t count;
12083 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012084 }
12085 test_platform_thread_join(thread, NULL);
12086
12087 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012088 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012089 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012090 // Add many entries to command buffer from this thread at the same time.
12091 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012092
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012093 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012094 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012095
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012096 m_errorMonitor->SetBailout(NULL);
12097
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012098 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012099
Chia-I Wuf7458c52015-10-26 21:10:41 +080012100 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012101}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012102#endif // GTEST_IS_THREADSAFE
12103#endif // THREADING_TESTS
12104
Chris Forbes9f7ff632015-05-25 11:13:08 +120012105#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012106TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012107 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12108 "with an impossible code size");
12109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012111
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012112 ASSERT_NO_FATAL_FAILURE(InitState());
12113 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12114
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012115 VkShaderModule module;
12116 VkShaderModuleCreateInfo moduleCreateInfo;
12117 struct icd_spv_header spv;
12118
12119 spv.magic = ICD_SPV_MAGIC;
12120 spv.version = ICD_SPV_VERSION;
12121 spv.gen_magic = 0;
12122
12123 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12124 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012125 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012126 moduleCreateInfo.codeSize = 4;
12127 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012128 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012129
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012130 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012131}
12132
Karl Schultz6addd812016-02-02 17:17:23 -070012133TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012134 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12135 "with a bad magic number");
12136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012138
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012139 ASSERT_NO_FATAL_FAILURE(InitState());
12140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12141
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012142 VkShaderModule module;
12143 VkShaderModuleCreateInfo moduleCreateInfo;
12144 struct icd_spv_header spv;
12145
12146 spv.magic = ~ICD_SPV_MAGIC;
12147 spv.version = ICD_SPV_VERSION;
12148 spv.gen_magic = 0;
12149
12150 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12151 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012152 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012153 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12154 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012155 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012156
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012157 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012158}
12159
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012160#if 0
12161// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012162TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012164 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012165
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012166 ASSERT_NO_FATAL_FAILURE(InitState());
12167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12168
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012169 VkShaderModule module;
12170 VkShaderModuleCreateInfo moduleCreateInfo;
12171 struct icd_spv_header spv;
12172
12173 spv.magic = ICD_SPV_MAGIC;
12174 spv.version = ~ICD_SPV_VERSION;
12175 spv.gen_magic = 0;
12176
12177 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12178 moduleCreateInfo.pNext = NULL;
12179
Karl Schultz6addd812016-02-02 17:17:23 -070012180 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012181 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12182 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012183 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012184
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012185 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012186}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012187#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012188
Karl Schultz6addd812016-02-02 17:17:23 -070012189TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012190 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12191 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012193
Chris Forbes9f7ff632015-05-25 11:13:08 +120012194 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012197 char const *vsSource = "#version 450\n"
12198 "\n"
12199 "layout(location=0) out float x;\n"
12200 "out gl_PerVertex {\n"
12201 " vec4 gl_Position;\n"
12202 "};\n"
12203 "void main(){\n"
12204 " gl_Position = vec4(1);\n"
12205 " x = 0;\n"
12206 "}\n";
12207 char const *fsSource = "#version 450\n"
12208 "\n"
12209 "layout(location=0) out vec4 color;\n"
12210 "void main(){\n"
12211 " color = vec4(1);\n"
12212 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012213
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012214 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12215 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012216
12217 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012218 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012219 pipe.AddShader(&vs);
12220 pipe.AddShader(&fs);
12221
Chris Forbes9f7ff632015-05-25 11:13:08 +120012222 VkDescriptorSetObj descriptorSet(m_device);
12223 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012224 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012225
Tony Barbour5781e8f2015-08-04 16:23:11 -060012226 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012227
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012228 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012229}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012230
Mark Mueller098c9cb2016-09-08 09:01:57 -060012231TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12232 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12233
12234 ASSERT_NO_FATAL_FAILURE(InitState());
12235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12236
12237 const char *bad_specialization_message =
12238 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12239
12240 char const *vsSource =
12241 "#version 450\n"
12242 "\n"
12243 "out gl_PerVertex {\n"
12244 " vec4 gl_Position;\n"
12245 "};\n"
12246 "void main(){\n"
12247 " gl_Position = vec4(1);\n"
12248 "}\n";
12249
12250 char const *fsSource =
12251 "#version 450\n"
12252 "\n"
12253 "layout (constant_id = 0) const float r = 0.0f;\n"
12254 "layout(location = 0) out vec4 uFragColor;\n"
12255 "void main(){\n"
12256 " uFragColor = vec4(r,1,0,1);\n"
12257 "}\n";
12258
12259 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12260 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12261
12262 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12263 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12264
12265 VkPipelineLayout pipeline_layout;
12266 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12267
12268 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12269 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12270 vp_state_create_info.viewportCount = 1;
12271 VkViewport viewport = {};
12272 vp_state_create_info.pViewports = &viewport;
12273 vp_state_create_info.scissorCount = 1;
12274 VkRect2D scissors = {};
12275 vp_state_create_info.pScissors = &scissors;
12276
12277 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12278
12279 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12280 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12281 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12282 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12283
12284 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12285 vs.GetStageCreateInfo(),
12286 fs.GetStageCreateInfo()
12287 };
12288
12289 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12290 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12291
12292 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12293 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12294 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12295
12296 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12297 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12298 rasterization_state_create_info.pNext = nullptr;
12299 rasterization_state_create_info.lineWidth = 1.0f;
12300 rasterization_state_create_info.rasterizerDiscardEnable = true;
12301
12302 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12303 color_blend_attachment_state.blendEnable = VK_FALSE;
12304 color_blend_attachment_state.colorWriteMask = 0xf;
12305
12306 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12307 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12308 color_blend_state_create_info.attachmentCount = 1;
12309 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12310
12311 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12312 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12313 graphicspipe_create_info.stageCount = 2;
12314 graphicspipe_create_info.pStages = shader_stage_create_info;
12315 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12316 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12317 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12318 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12319 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12320 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12321 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12322 graphicspipe_create_info.layout = pipeline_layout;
12323 graphicspipe_create_info.renderPass = renderPass();
12324
12325 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12326 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12327
12328 VkPipelineCache pipelineCache;
12329 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12330
12331 // This structure maps constant ids to data locations.
12332 const VkSpecializationMapEntry entry =
12333 // id, offset, size
12334 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12335
12336 uint32_t data = 1;
12337
12338 // Set up the info describing spec map and data
12339 const VkSpecializationInfo specialization_info = {
12340 1,
12341 &entry,
12342 1 * sizeof(float),
12343 &data,
12344 };
12345 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12346
12347 VkPipeline pipeline;
12348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12349 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12350 m_errorMonitor->VerifyFound();
12351
12352 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12353 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12354}
12355
12356TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12357 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12358
12359 ASSERT_NO_FATAL_FAILURE(InitState());
12360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12361
12362 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12363
12364 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12365 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12366 descriptor_pool_type_count[0].descriptorCount = 1;
12367 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12368 descriptor_pool_type_count[1].descriptorCount = 1;
12369
12370 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12371 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12372 descriptor_pool_create_info.maxSets = 1;
12373 descriptor_pool_create_info.poolSizeCount = 2;
12374 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12375 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12376
12377 VkDescriptorPool descriptorset_pool;
12378 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12379
12380 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12381 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12382 descriptorset_layout_binding.descriptorCount = 1;
12383 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12384
12385 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12386 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12387 descriptorset_layout_create_info.bindingCount = 1;
12388 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12389
12390 VkDescriptorSetLayout descriptorset_layout;
12391 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12392
12393 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12394 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12395 descriptorset_allocate_info.descriptorSetCount = 1;
12396 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12397 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12398 VkDescriptorSet descriptorset;
12399 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12400
12401 // Challenge core_validation with a non uniform buffer type.
12402 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12403
Mark Mueller098c9cb2016-09-08 09:01:57 -060012404 char const *vsSource =
12405 "#version 450\n"
12406 "\n"
12407 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12408 " mat4 mvp;\n"
12409 "} ubuf;\n"
12410 "out gl_PerVertex {\n"
12411 " vec4 gl_Position;\n"
12412 "};\n"
12413 "void main(){\n"
12414 " gl_Position = ubuf.mvp * vec4(1);\n"
12415 "}\n";
12416
12417 char const *fsSource =
12418 "#version 450\n"
12419 "\n"
12420 "layout(location = 0) out vec4 uFragColor;\n"
12421 "void main(){\n"
12422 " uFragColor = vec4(0,1,0,1);\n"
12423 "}\n";
12424
12425 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12426 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12427
12428 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12429 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12430 pipeline_layout_create_info.setLayoutCount = 1;
12431 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12432
12433 VkPipelineLayout pipeline_layout;
12434 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12435
12436 VkPipelineObj pipe(m_device);
12437 pipe.AddColorAttachment();
12438 pipe.AddShader(&vs);
12439 pipe.AddShader(&fs);
12440
12441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12442 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12443 m_errorMonitor->VerifyFound();
12444
12445 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12446 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12447 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12448}
12449
12450TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12451 TEST_DESCRIPTION(
12452 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12453
12454 ASSERT_NO_FATAL_FAILURE(InitState());
12455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12456
12457 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12458
12459 VkDescriptorPoolSize descriptor_pool_type_count = {};
12460 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12461 descriptor_pool_type_count.descriptorCount = 1;
12462
12463 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12464 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12465 descriptor_pool_create_info.maxSets = 1;
12466 descriptor_pool_create_info.poolSizeCount = 1;
12467 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12468 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12469
12470 VkDescriptorPool descriptorset_pool;
12471 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12472
12473 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12474 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12475 descriptorset_layout_binding.descriptorCount = 1;
12476 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12477 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12478
12479 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12480 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12481 descriptorset_layout_create_info.bindingCount = 1;
12482 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12483
12484 VkDescriptorSetLayout descriptorset_layout;
12485 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12486 nullptr, &descriptorset_layout));
12487
12488 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12489 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12490 descriptorset_allocate_info.descriptorSetCount = 1;
12491 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12492 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12493 VkDescriptorSet descriptorset;
12494 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12495
12496 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12497
Mark Mueller098c9cb2016-09-08 09:01:57 -060012498 char const *vsSource =
12499 "#version 450\n"
12500 "\n"
12501 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12502 " mat4 mvp;\n"
12503 "} ubuf;\n"
12504 "out gl_PerVertex {\n"
12505 " vec4 gl_Position;\n"
12506 "};\n"
12507 "void main(){\n"
12508 " gl_Position = ubuf.mvp * vec4(1);\n"
12509 "}\n";
12510
12511 char const *fsSource =
12512 "#version 450\n"
12513 "\n"
12514 "layout(location = 0) out vec4 uFragColor;\n"
12515 "void main(){\n"
12516 " uFragColor = vec4(0,1,0,1);\n"
12517 "}\n";
12518
12519 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12520 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12521
12522 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12523 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12524 pipeline_layout_create_info.setLayoutCount = 1;
12525 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12526
12527 VkPipelineLayout pipeline_layout;
12528 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12529
12530 VkPipelineObj pipe(m_device);
12531 pipe.AddColorAttachment();
12532 pipe.AddShader(&vs);
12533 pipe.AddShader(&fs);
12534
12535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12536 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12537 m_errorMonitor->VerifyFound();
12538
12539 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12540 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12541 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12542}
12543
12544TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12545 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12546 "accessible from the current shader stage.");
12547
12548 ASSERT_NO_FATAL_FAILURE(InitState());
12549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12550
12551 const char *push_constant_not_accessible_message =
12552 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12553
12554 char const *vsSource =
12555 "#version 450\n"
12556 "\n"
12557 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12558 "out gl_PerVertex {\n"
12559 " vec4 gl_Position;\n"
12560 "};\n"
12561 "void main(){\n"
12562 " gl_Position = vec4(consts.x);\n"
12563 "}\n";
12564
12565 char const *fsSource =
12566 "#version 450\n"
12567 "\n"
12568 "layout(location = 0) out vec4 uFragColor;\n"
12569 "void main(){\n"
12570 " uFragColor = vec4(0,1,0,1);\n"
12571 "}\n";
12572
12573 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12574 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12575
12576 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12577 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12578
12579 // Set up a push constant range
12580 VkPushConstantRange push_constant_ranges = {};
12581 // Set to the wrong stage to challenge core_validation
12582 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12583 push_constant_ranges.size = 4;
12584
12585 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12586 pipeline_layout_create_info.pushConstantRangeCount = 1;
12587
12588 VkPipelineLayout pipeline_layout;
12589 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12590
12591 VkPipelineObj pipe(m_device);
12592 pipe.AddColorAttachment();
12593 pipe.AddShader(&vs);
12594 pipe.AddShader(&fs);
12595
12596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12597 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12598 m_errorMonitor->VerifyFound();
12599
12600 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12601}
12602
12603TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12604 TEST_DESCRIPTION(
12605 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12606
12607 ASSERT_NO_FATAL_FAILURE(InitState());
12608 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12609
12610 const char *feature_not_enabled_message =
12611 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12612
12613 // Some awkward steps are required to test with custom device features.
12614 std::vector<const char *> device_extension_names;
12615 auto features = m_device->phy().features();
12616 // Disable support for 64 bit floats
12617 features.shaderFloat64 = false;
12618 // The sacrificial device object
12619 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12620
12621 char const *vsSource = "#version 450\n"
12622 "\n"
12623 "out gl_PerVertex {\n"
12624 " vec4 gl_Position;\n"
12625 "};\n"
12626 "void main(){\n"
12627 " gl_Position = vec4(1);\n"
12628 "}\n";
12629 char const *fsSource = "#version 450\n"
12630 "\n"
12631 "layout(location=0) out vec4 color;\n"
12632 "void main(){\n"
12633 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12634 " color = vec4(green);\n"
12635 "}\n";
12636
12637 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12638 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12639
12640 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012641
12642 VkPipelineObj pipe(&test_device);
12643 pipe.AddColorAttachment();
12644 pipe.AddShader(&vs);
12645 pipe.AddShader(&fs);
12646
12647 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12648 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12649 VkPipelineLayout pipeline_layout;
12650 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12651
12652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12653 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12654 m_errorMonitor->VerifyFound();
12655
12656 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12657}
12658
12659TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12660 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12661
12662 ASSERT_NO_FATAL_FAILURE(InitState());
12663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12664
12665 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12666
12667 char const *vsSource = "#version 450\n"
12668 "\n"
12669 "out gl_PerVertex {\n"
12670 " vec4 gl_Position;\n"
12671 "};\n"
12672 "layout(xfb_buffer = 1) out;"
12673 "void main(){\n"
12674 " gl_Position = vec4(1);\n"
12675 "}\n";
12676 char const *fsSource = "#version 450\n"
12677 "\n"
12678 "layout(location=0) out vec4 color;\n"
12679 "void main(){\n"
12680 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12681 " color = vec4(green);\n"
12682 "}\n";
12683
12684 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12685 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12686
12687 VkPipelineObj pipe(m_device);
12688 pipe.AddColorAttachment();
12689 pipe.AddShader(&vs);
12690 pipe.AddShader(&fs);
12691
12692 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12693 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12694 VkPipelineLayout pipeline_layout;
12695 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12696
12697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12698 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12699 m_errorMonitor->VerifyFound();
12700
12701 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12702}
12703
Karl Schultz6addd812016-02-02 17:17:23 -070012704TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012705 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12706 "which is not present in the outputs of the previous stage");
12707
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012709
Chris Forbes59cb88d2015-05-25 11:13:13 +120012710 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012711 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012712
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012713 char const *vsSource = "#version 450\n"
12714 "\n"
12715 "out gl_PerVertex {\n"
12716 " vec4 gl_Position;\n"
12717 "};\n"
12718 "void main(){\n"
12719 " gl_Position = vec4(1);\n"
12720 "}\n";
12721 char const *fsSource = "#version 450\n"
12722 "\n"
12723 "layout(location=0) in float x;\n"
12724 "layout(location=0) out vec4 color;\n"
12725 "void main(){\n"
12726 " color = vec4(x);\n"
12727 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012728
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012729 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12730 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012731
12732 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012733 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012734 pipe.AddShader(&vs);
12735 pipe.AddShader(&fs);
12736
Chris Forbes59cb88d2015-05-25 11:13:13 +120012737 VkDescriptorSetObj descriptorSet(m_device);
12738 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012739 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012740
Tony Barbour5781e8f2015-08-04 16:23:11 -060012741 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012742
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012743 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012744}
12745
Karl Schultz6addd812016-02-02 17:17:23 -070012746TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012747 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12748 "within an interace block, which is not present in the outputs "
12749 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012751
12752 ASSERT_NO_FATAL_FAILURE(InitState());
12753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12754
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012755 char const *vsSource = "#version 450\n"
12756 "\n"
12757 "out gl_PerVertex {\n"
12758 " vec4 gl_Position;\n"
12759 "};\n"
12760 "void main(){\n"
12761 " gl_Position = vec4(1);\n"
12762 "}\n";
12763 char const *fsSource = "#version 450\n"
12764 "\n"
12765 "in block { layout(location=0) float x; } ins;\n"
12766 "layout(location=0) out vec4 color;\n"
12767 "void main(){\n"
12768 " color = vec4(ins.x);\n"
12769 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012770
12771 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12772 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12773
12774 VkPipelineObj pipe(m_device);
12775 pipe.AddColorAttachment();
12776 pipe.AddShader(&vs);
12777 pipe.AddShader(&fs);
12778
12779 VkDescriptorSetObj descriptorSet(m_device);
12780 descriptorSet.AppendDummy();
12781 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12782
12783 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12784
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012785 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012786}
12787
Karl Schultz6addd812016-02-02 17:17:23 -070012788TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012789 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012790 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12792 "output arr[2] of float32' vs 'ptr to "
12793 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012794
12795 ASSERT_NO_FATAL_FAILURE(InitState());
12796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12797
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012798 char const *vsSource = "#version 450\n"
12799 "\n"
12800 "layout(location=0) out float x[2];\n"
12801 "out gl_PerVertex {\n"
12802 " vec4 gl_Position;\n"
12803 "};\n"
12804 "void main(){\n"
12805 " x[0] = 0; x[1] = 0;\n"
12806 " gl_Position = vec4(1);\n"
12807 "}\n";
12808 char const *fsSource = "#version 450\n"
12809 "\n"
12810 "layout(location=0) in float x[3];\n"
12811 "layout(location=0) out vec4 color;\n"
12812 "void main(){\n"
12813 " color = vec4(x[0] + x[1] + x[2]);\n"
12814 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012815
12816 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12817 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12818
12819 VkPipelineObj pipe(m_device);
12820 pipe.AddColorAttachment();
12821 pipe.AddShader(&vs);
12822 pipe.AddShader(&fs);
12823
12824 VkDescriptorSetObj descriptorSet(m_device);
12825 descriptorSet.AppendDummy();
12826 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12827
12828 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12829
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012830 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012831}
12832
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012833
Karl Schultz6addd812016-02-02 17:17:23 -070012834TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012835 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012836 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012838
Chris Forbesb56af562015-05-25 11:13:17 +120012839 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012841
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012842 char const *vsSource = "#version 450\n"
12843 "\n"
12844 "layout(location=0) out int x;\n"
12845 "out gl_PerVertex {\n"
12846 " vec4 gl_Position;\n"
12847 "};\n"
12848 "void main(){\n"
12849 " x = 0;\n"
12850 " gl_Position = vec4(1);\n"
12851 "}\n";
12852 char const *fsSource = "#version 450\n"
12853 "\n"
12854 "layout(location=0) in float x;\n" /* VS writes int */
12855 "layout(location=0) out vec4 color;\n"
12856 "void main(){\n"
12857 " color = vec4(x);\n"
12858 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012859
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012860 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12861 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012862
12863 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012864 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012865 pipe.AddShader(&vs);
12866 pipe.AddShader(&fs);
12867
Chris Forbesb56af562015-05-25 11:13:17 +120012868 VkDescriptorSetObj descriptorSet(m_device);
12869 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012870 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012871
Tony Barbour5781e8f2015-08-04 16:23:11 -060012872 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012873
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012874 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012875}
12876
Karl Schultz6addd812016-02-02 17:17:23 -070012877TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012878 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012879 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012880 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012882
12883 ASSERT_NO_FATAL_FAILURE(InitState());
12884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012886 char const *vsSource = "#version 450\n"
12887 "\n"
12888 "out block { layout(location=0) int x; } outs;\n"
12889 "out gl_PerVertex {\n"
12890 " vec4 gl_Position;\n"
12891 "};\n"
12892 "void main(){\n"
12893 " outs.x = 0;\n"
12894 " gl_Position = vec4(1);\n"
12895 "}\n";
12896 char const *fsSource = "#version 450\n"
12897 "\n"
12898 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12899 "layout(location=0) out vec4 color;\n"
12900 "void main(){\n"
12901 " color = vec4(ins.x);\n"
12902 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012903
12904 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12905 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12906
12907 VkPipelineObj pipe(m_device);
12908 pipe.AddColorAttachment();
12909 pipe.AddShader(&vs);
12910 pipe.AddShader(&fs);
12911
12912 VkDescriptorSetObj descriptorSet(m_device);
12913 descriptorSet.AppendDummy();
12914 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12915
12916 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12917
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012918 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012919}
12920
12921TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012922 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012923 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012924 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012925 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 +130012926
12927 ASSERT_NO_FATAL_FAILURE(InitState());
12928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12929
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012930 char const *vsSource = "#version 450\n"
12931 "\n"
12932 "out block { layout(location=1) float x; } outs;\n"
12933 "out gl_PerVertex {\n"
12934 " vec4 gl_Position;\n"
12935 "};\n"
12936 "void main(){\n"
12937 " outs.x = 0;\n"
12938 " gl_Position = vec4(1);\n"
12939 "}\n";
12940 char const *fsSource = "#version 450\n"
12941 "\n"
12942 "in block { layout(location=0) float x; } ins;\n"
12943 "layout(location=0) out vec4 color;\n"
12944 "void main(){\n"
12945 " color = vec4(ins.x);\n"
12946 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012947
12948 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12949 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12950
12951 VkPipelineObj pipe(m_device);
12952 pipe.AddColorAttachment();
12953 pipe.AddShader(&vs);
12954 pipe.AddShader(&fs);
12955
12956 VkDescriptorSetObj descriptorSet(m_device);
12957 descriptorSet.AppendDummy();
12958 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12959
12960 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12961
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012962 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012963}
12964
12965TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012966 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012967 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012968 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012969 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 +130012970
12971 ASSERT_NO_FATAL_FAILURE(InitState());
12972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12973
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012974 char const *vsSource = "#version 450\n"
12975 "\n"
12976 "out block { layout(location=0, component=0) float x; } outs;\n"
12977 "out gl_PerVertex {\n"
12978 " vec4 gl_Position;\n"
12979 "};\n"
12980 "void main(){\n"
12981 " outs.x = 0;\n"
12982 " gl_Position = vec4(1);\n"
12983 "}\n";
12984 char const *fsSource = "#version 450\n"
12985 "\n"
12986 "in block { layout(location=0, component=1) float x; } ins;\n"
12987 "layout(location=0) out vec4 color;\n"
12988 "void main(){\n"
12989 " color = vec4(ins.x);\n"
12990 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012991
12992 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12993 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12994
12995 VkPipelineObj pipe(m_device);
12996 pipe.AddColorAttachment();
12997 pipe.AddShader(&vs);
12998 pipe.AddShader(&fs);
12999
13000 VkDescriptorSetObj descriptorSet(m_device);
13001 descriptorSet.AppendDummy();
13002 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13003
13004 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13005
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013006 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013007}
13008
Chris Forbes1f3b0152016-11-30 12:48:40 +130013009TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13010 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13011
13012 ASSERT_NO_FATAL_FAILURE(InitState());
13013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13014
13015 char const *vsSource = "#version 450\n"
13016 "layout(location=0) out mediump float x;\n"
13017 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13018 char const *fsSource = "#version 450\n"
13019 "layout(location=0) in highp float x;\n"
13020 "layout(location=0) out vec4 color;\n"
13021 "void main() { color = vec4(x); }\n";
13022
13023 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13024 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13025
13026 VkPipelineObj pipe(m_device);
13027 pipe.AddColorAttachment();
13028 pipe.AddShader(&vs);
13029 pipe.AddShader(&fs);
13030
13031 VkDescriptorSetObj descriptorSet(m_device);
13032 descriptorSet.AppendDummy();
13033 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13034
13035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13036
13037 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13038
13039 m_errorMonitor->VerifyFound();
13040}
13041
Chris Forbes870a39e2016-11-30 12:55:56 +130013042TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13043 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13044
13045 ASSERT_NO_FATAL_FAILURE(InitState());
13046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13047
13048 char const *vsSource = "#version 450\n"
13049 "out block { layout(location=0) mediump float x; };\n"
13050 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13051 char const *fsSource = "#version 450\n"
13052 "in block { layout(location=0) highp float x; };\n"
13053 "layout(location=0) out vec4 color;\n"
13054 "void main() { color = vec4(x); }\n";
13055
13056 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13057 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13058
13059 VkPipelineObj pipe(m_device);
13060 pipe.AddColorAttachment();
13061 pipe.AddShader(&vs);
13062 pipe.AddShader(&fs);
13063
13064 VkDescriptorSetObj descriptorSet(m_device);
13065 descriptorSet.AppendDummy();
13066 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13067
13068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13069
13070 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13071
13072 m_errorMonitor->VerifyFound();
13073}
13074
Karl Schultz6addd812016-02-02 17:17:23 -070013075TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013076 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13077 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013079
Chris Forbesde136e02015-05-25 11:13:28 +120013080 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013082
13083 VkVertexInputBindingDescription input_binding;
13084 memset(&input_binding, 0, sizeof(input_binding));
13085
13086 VkVertexInputAttributeDescription input_attrib;
13087 memset(&input_attrib, 0, sizeof(input_attrib));
13088 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013090 char const *vsSource = "#version 450\n"
13091 "\n"
13092 "out gl_PerVertex {\n"
13093 " vec4 gl_Position;\n"
13094 "};\n"
13095 "void main(){\n"
13096 " gl_Position = vec4(1);\n"
13097 "}\n";
13098 char const *fsSource = "#version 450\n"
13099 "\n"
13100 "layout(location=0) out vec4 color;\n"
13101 "void main(){\n"
13102 " color = vec4(1);\n"
13103 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013104
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013105 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13106 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013107
13108 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013109 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013110 pipe.AddShader(&vs);
13111 pipe.AddShader(&fs);
13112
13113 pipe.AddVertexInputBindings(&input_binding, 1);
13114 pipe.AddVertexInputAttribs(&input_attrib, 1);
13115
Chris Forbesde136e02015-05-25 11:13:28 +120013116 VkDescriptorSetObj descriptorSet(m_device);
13117 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013118 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013119
Tony Barbour5781e8f2015-08-04 16:23:11 -060013120 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013121
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013122 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013123}
13124
Karl Schultz6addd812016-02-02 17:17:23 -070013125TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013126 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13127 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013129
13130 ASSERT_NO_FATAL_FAILURE(InitState());
13131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13132
13133 VkVertexInputBindingDescription input_binding;
13134 memset(&input_binding, 0, sizeof(input_binding));
13135
13136 VkVertexInputAttributeDescription input_attrib;
13137 memset(&input_attrib, 0, sizeof(input_attrib));
13138 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013140 char const *vsSource = "#version 450\n"
13141 "\n"
13142 "layout(location=1) in float x;\n"
13143 "out gl_PerVertex {\n"
13144 " vec4 gl_Position;\n"
13145 "};\n"
13146 "void main(){\n"
13147 " gl_Position = vec4(x);\n"
13148 "}\n";
13149 char const *fsSource = "#version 450\n"
13150 "\n"
13151 "layout(location=0) out vec4 color;\n"
13152 "void main(){\n"
13153 " color = vec4(1);\n"
13154 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013155
13156 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13157 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13158
13159 VkPipelineObj pipe(m_device);
13160 pipe.AddColorAttachment();
13161 pipe.AddShader(&vs);
13162 pipe.AddShader(&fs);
13163
13164 pipe.AddVertexInputBindings(&input_binding, 1);
13165 pipe.AddVertexInputAttribs(&input_attrib, 1);
13166
13167 VkDescriptorSetObj descriptorSet(m_device);
13168 descriptorSet.AppendDummy();
13169 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13170
13171 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13172
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013173 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013174}
13175
Karl Schultz6addd812016-02-02 17:17:23 -070013176TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013177 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013178 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013179 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 -060013180
Chris Forbes62e8e502015-05-25 11:13:29 +120013181 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013183
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013184 char const *vsSource = "#version 450\n"
13185 "\n"
13186 "layout(location=0) in vec4 x;\n" /* not provided */
13187 "out gl_PerVertex {\n"
13188 " vec4 gl_Position;\n"
13189 "};\n"
13190 "void main(){\n"
13191 " gl_Position = x;\n"
13192 "}\n";
13193 char const *fsSource = "#version 450\n"
13194 "\n"
13195 "layout(location=0) out vec4 color;\n"
13196 "void main(){\n"
13197 " color = vec4(1);\n"
13198 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013199
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013200 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13201 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013202
13203 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013204 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013205 pipe.AddShader(&vs);
13206 pipe.AddShader(&fs);
13207
Chris Forbes62e8e502015-05-25 11:13:29 +120013208 VkDescriptorSetObj descriptorSet(m_device);
13209 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013210 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013211
Tony Barbour5781e8f2015-08-04 16:23:11 -060013212 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013213
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013214 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013215}
13216
Karl Schultz6addd812016-02-02 17:17:23 -070013217TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013218 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13219 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013220 "vertex shader input that consumes it");
13221 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 -060013222
Chris Forbesc97d98e2015-05-25 11:13:31 +120013223 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013224 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013225
13226 VkVertexInputBindingDescription input_binding;
13227 memset(&input_binding, 0, sizeof(input_binding));
13228
13229 VkVertexInputAttributeDescription input_attrib;
13230 memset(&input_attrib, 0, sizeof(input_attrib));
13231 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13232
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013233 char const *vsSource = "#version 450\n"
13234 "\n"
13235 "layout(location=0) in int x;\n" /* attrib provided float */
13236 "out gl_PerVertex {\n"
13237 " vec4 gl_Position;\n"
13238 "};\n"
13239 "void main(){\n"
13240 " gl_Position = vec4(x);\n"
13241 "}\n";
13242 char const *fsSource = "#version 450\n"
13243 "\n"
13244 "layout(location=0) out vec4 color;\n"
13245 "void main(){\n"
13246 " color = vec4(1);\n"
13247 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013248
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013249 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13250 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013251
13252 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013253 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013254 pipe.AddShader(&vs);
13255 pipe.AddShader(&fs);
13256
13257 pipe.AddVertexInputBindings(&input_binding, 1);
13258 pipe.AddVertexInputAttribs(&input_attrib, 1);
13259
Chris Forbesc97d98e2015-05-25 11:13:31 +120013260 VkDescriptorSetObj descriptorSet(m_device);
13261 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013262 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013263
Tony Barbour5781e8f2015-08-04 16:23:11 -060013264 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013265
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013266 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013267}
13268
Chris Forbesc68b43c2016-04-06 11:18:47 +120013269TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013270 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13271 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13273 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013274
13275 ASSERT_NO_FATAL_FAILURE(InitState());
13276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013278 char const *vsSource = "#version 450\n"
13279 "\n"
13280 "out gl_PerVertex {\n"
13281 " vec4 gl_Position;\n"
13282 "};\n"
13283 "void main(){\n"
13284 " gl_Position = vec4(1);\n"
13285 "}\n";
13286 char const *fsSource = "#version 450\n"
13287 "\n"
13288 "layout(location=0) out vec4 color;\n"
13289 "void main(){\n"
13290 " color = vec4(1);\n"
13291 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013292
13293 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13294 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13295
13296 VkPipelineObj pipe(m_device);
13297 pipe.AddColorAttachment();
13298 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013299 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013300 pipe.AddShader(&fs);
13301
13302 VkDescriptorSetObj descriptorSet(m_device);
13303 descriptorSet.AppendDummy();
13304 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13305
13306 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13307
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013308 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013309}
13310
Chris Forbes82ff92a2016-09-09 10:50:24 +120013311TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13313 "No entrypoint found named `foo`");
13314
13315 ASSERT_NO_FATAL_FAILURE(InitState());
13316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13317
13318 char const *vsSource = "#version 450\n"
13319 "out gl_PerVertex {\n"
13320 " vec4 gl_Position;\n"
13321 "};\n"
13322 "void main(){\n"
13323 " gl_Position = vec4(0);\n"
13324 "}\n";
13325 char const *fsSource = "#version 450\n"
13326 "\n"
13327 "layout(location=0) out vec4 color;\n"
13328 "void main(){\n"
13329 " color = vec4(1);\n"
13330 "}\n";
13331
13332 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13333 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13334
13335 VkPipelineObj pipe(m_device);
13336 pipe.AddColorAttachment();
13337 pipe.AddShader(&vs);
13338 pipe.AddShader(&fs);
13339
13340 VkDescriptorSetObj descriptorSet(m_device);
13341 descriptorSet.AppendDummy();
13342 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13343
13344 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13345
13346 m_errorMonitor->VerifyFound();
13347}
13348
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013349TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13350 m_errorMonitor->SetDesiredFailureMsg(
13351 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13352 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13353 "uses a depth/stencil attachment");
13354
13355 ASSERT_NO_FATAL_FAILURE(InitState());
13356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13357
13358 char const *vsSource = "#version 450\n"
13359 "void main(){ gl_Position = vec4(0); }\n";
13360 char const *fsSource = "#version 450\n"
13361 "\n"
13362 "layout(location=0) out vec4 color;\n"
13363 "void main(){\n"
13364 " color = vec4(1);\n"
13365 "}\n";
13366
13367 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13368 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13369
13370 VkPipelineObj pipe(m_device);
13371 pipe.AddColorAttachment();
13372 pipe.AddShader(&vs);
13373 pipe.AddShader(&fs);
13374
13375 VkDescriptorSetObj descriptorSet(m_device);
13376 descriptorSet.AppendDummy();
13377 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13378
13379 VkAttachmentDescription attachments[] = {
13380 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13381 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13382 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13383 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13384 },
13385 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13386 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13387 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13388 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13389 },
13390 };
13391 VkAttachmentReference refs[] = {
13392 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13393 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13394 };
13395 VkSubpassDescription subpass = {
13396 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13397 1, &refs[0], nullptr, &refs[1],
13398 0, nullptr
13399 };
13400 VkRenderPassCreateInfo rpci = {
13401 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13402 0, 2, attachments, 1, &subpass, 0, nullptr
13403 };
13404 VkRenderPass rp;
13405 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13406 ASSERT_VK_SUCCESS(err);
13407
13408 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13409
13410 m_errorMonitor->VerifyFound();
13411
13412 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13413}
13414
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013415TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013416 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13417 "the TCS without the patch decoration, but consumed in the TES "
13418 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13420 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013421
13422 ASSERT_NO_FATAL_FAILURE(InitState());
13423 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13424
Chris Forbesc1e852d2016-04-04 19:26:42 +120013425 if (!m_device->phy().features().tessellationShader) {
13426 printf("Device does not support tessellation shaders; skipped.\n");
13427 return;
13428 }
13429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013430 char const *vsSource = "#version 450\n"
13431 "void main(){}\n";
13432 char const *tcsSource = "#version 450\n"
13433 "layout(location=0) out int x[];\n"
13434 "layout(vertices=3) out;\n"
13435 "void main(){\n"
13436 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13437 " gl_TessLevelInner[0] = 1;\n"
13438 " x[gl_InvocationID] = gl_InvocationID;\n"
13439 "}\n";
13440 char const *tesSource = "#version 450\n"
13441 "layout(triangles, equal_spacing, cw) in;\n"
13442 "layout(location=0) patch in int x;\n"
13443 "out gl_PerVertex { vec4 gl_Position; };\n"
13444 "void main(){\n"
13445 " gl_Position.xyz = gl_TessCoord;\n"
13446 " gl_Position.w = x;\n"
13447 "}\n";
13448 char const *fsSource = "#version 450\n"
13449 "layout(location=0) out vec4 color;\n"
13450 "void main(){\n"
13451 " color = vec4(1);\n"
13452 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013453
13454 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13455 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13456 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13457 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013459 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13460 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013461
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013462 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013463
13464 VkPipelineObj pipe(m_device);
13465 pipe.SetInputAssembly(&iasci);
13466 pipe.SetTessellation(&tsci);
13467 pipe.AddColorAttachment();
13468 pipe.AddShader(&vs);
13469 pipe.AddShader(&tcs);
13470 pipe.AddShader(&tes);
13471 pipe.AddShader(&fs);
13472
13473 VkDescriptorSetObj descriptorSet(m_device);
13474 descriptorSet.AppendDummy();
13475 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13476
13477 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13478
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013479 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013480}
13481
Karl Schultz6addd812016-02-02 17:17:23 -070013482TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013483 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13484 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13486 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013487
Chris Forbes280ba2c2015-06-12 11:16:41 +120013488 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013489 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013490
13491 /* Two binding descriptions for binding 0 */
13492 VkVertexInputBindingDescription input_bindings[2];
13493 memset(input_bindings, 0, sizeof(input_bindings));
13494
13495 VkVertexInputAttributeDescription input_attrib;
13496 memset(&input_attrib, 0, sizeof(input_attrib));
13497 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13498
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013499 char const *vsSource = "#version 450\n"
13500 "\n"
13501 "layout(location=0) in float x;\n" /* attrib provided float */
13502 "out gl_PerVertex {\n"
13503 " vec4 gl_Position;\n"
13504 "};\n"
13505 "void main(){\n"
13506 " gl_Position = vec4(x);\n"
13507 "}\n";
13508 char const *fsSource = "#version 450\n"
13509 "\n"
13510 "layout(location=0) out vec4 color;\n"
13511 "void main(){\n"
13512 " color = vec4(1);\n"
13513 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013514
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013515 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13516 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013517
13518 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013519 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013520 pipe.AddShader(&vs);
13521 pipe.AddShader(&fs);
13522
13523 pipe.AddVertexInputBindings(input_bindings, 2);
13524 pipe.AddVertexInputAttribs(&input_attrib, 1);
13525
Chris Forbes280ba2c2015-06-12 11:16:41 +120013526 VkDescriptorSetObj descriptorSet(m_device);
13527 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013528 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013529
Tony Barbour5781e8f2015-08-04 16:23:11 -060013530 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013531
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013532 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013533}
Chris Forbes8f68b562015-05-25 11:13:32 +120013534
Karl Schultz6addd812016-02-02 17:17:23 -070013535TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013536 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013537 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013539
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013540 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013541
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013542 char const *vsSource = "#version 450\n"
13543 "\n"
13544 "out gl_PerVertex {\n"
13545 " vec4 gl_Position;\n"
13546 "};\n"
13547 "void main(){\n"
13548 " gl_Position = vec4(1);\n"
13549 "}\n";
13550 char const *fsSource = "#version 450\n"
13551 "\n"
13552 "void main(){\n"
13553 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013554
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013555 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13556 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013557
13558 VkPipelineObj pipe(m_device);
13559 pipe.AddShader(&vs);
13560 pipe.AddShader(&fs);
13561
Chia-I Wu08accc62015-07-07 11:50:03 +080013562 /* set up CB 0, not written */
13563 pipe.AddColorAttachment();
13564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013565
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013566 VkDescriptorSetObj descriptorSet(m_device);
13567 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013568 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013569
Tony Barbour5781e8f2015-08-04 16:23:11 -060013570 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013571
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013572 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013573}
13574
Karl Schultz6addd812016-02-02 17:17:23 -070013575TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013576 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013577 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013579 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013580
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013581 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013582
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013583 char const *vsSource = "#version 450\n"
13584 "\n"
13585 "out gl_PerVertex {\n"
13586 " vec4 gl_Position;\n"
13587 "};\n"
13588 "void main(){\n"
13589 " gl_Position = vec4(1);\n"
13590 "}\n";
13591 char const *fsSource = "#version 450\n"
13592 "\n"
13593 "layout(location=0) out vec4 x;\n"
13594 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13595 "void main(){\n"
13596 " x = vec4(1);\n"
13597 " y = vec4(1);\n"
13598 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013599
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013600 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13601 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013602
13603 VkPipelineObj pipe(m_device);
13604 pipe.AddShader(&vs);
13605 pipe.AddShader(&fs);
13606
Chia-I Wu08accc62015-07-07 11:50:03 +080013607 /* set up CB 0, not written */
13608 pipe.AddColorAttachment();
13609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013610 /* FS writes CB 1, but we don't configure it */
13611
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013612 VkDescriptorSetObj descriptorSet(m_device);
13613 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013614 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013615
Tony Barbour5781e8f2015-08-04 16:23:11 -060013616 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013617
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013618 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013619}
13620
Karl Schultz6addd812016-02-02 17:17:23 -070013621TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013622 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013623 "type of an fragment shader output variable, and the format of the corresponding attachment");
13624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013625
Chris Forbesa36d69e2015-05-25 11:13:44 +120013626 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013627
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013628 char const *vsSource = "#version 450\n"
13629 "\n"
13630 "out gl_PerVertex {\n"
13631 " vec4 gl_Position;\n"
13632 "};\n"
13633 "void main(){\n"
13634 " gl_Position = vec4(1);\n"
13635 "}\n";
13636 char const *fsSource = "#version 450\n"
13637 "\n"
13638 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13639 "void main(){\n"
13640 " x = ivec4(1);\n"
13641 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013642
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013643 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13644 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013645
13646 VkPipelineObj pipe(m_device);
13647 pipe.AddShader(&vs);
13648 pipe.AddShader(&fs);
13649
Chia-I Wu08accc62015-07-07 11:50:03 +080013650 /* set up CB 0; type is UNORM by default */
13651 pipe.AddColorAttachment();
13652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013653
Chris Forbesa36d69e2015-05-25 11:13:44 +120013654 VkDescriptorSetObj descriptorSet(m_device);
13655 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013656 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013657
Tony Barbour5781e8f2015-08-04 16:23:11 -060013658 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013659
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013660 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013661}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013662
Karl Schultz6addd812016-02-02 17:17:23 -070013663TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013664 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13665 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013667
Chris Forbes556c76c2015-08-14 12:04:59 +120013668 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013669
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013670 char const *vsSource = "#version 450\n"
13671 "\n"
13672 "out gl_PerVertex {\n"
13673 " vec4 gl_Position;\n"
13674 "};\n"
13675 "void main(){\n"
13676 " gl_Position = vec4(1);\n"
13677 "}\n";
13678 char const *fsSource = "#version 450\n"
13679 "\n"
13680 "layout(location=0) out vec4 x;\n"
13681 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13682 "void main(){\n"
13683 " x = vec4(bar.y);\n"
13684 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013685
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013686 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13687 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013688
Chris Forbes556c76c2015-08-14 12:04:59 +120013689 VkPipelineObj pipe(m_device);
13690 pipe.AddShader(&vs);
13691 pipe.AddShader(&fs);
13692
13693 /* set up CB 0; type is UNORM by default */
13694 pipe.AddColorAttachment();
13695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13696
13697 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013698 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013699
13700 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13701
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013702 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013703}
13704
Chris Forbes5c59e902016-02-26 16:56:09 +130013705TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013706 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13707 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013709
13710 ASSERT_NO_FATAL_FAILURE(InitState());
13711
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013712 char const *vsSource = "#version 450\n"
13713 "\n"
13714 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13715 "out gl_PerVertex {\n"
13716 " vec4 gl_Position;\n"
13717 "};\n"
13718 "void main(){\n"
13719 " gl_Position = vec4(consts.x);\n"
13720 "}\n";
13721 char const *fsSource = "#version 450\n"
13722 "\n"
13723 "layout(location=0) out vec4 x;\n"
13724 "void main(){\n"
13725 " x = vec4(1);\n"
13726 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013727
13728 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13729 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13730
13731 VkPipelineObj pipe(m_device);
13732 pipe.AddShader(&vs);
13733 pipe.AddShader(&fs);
13734
13735 /* set up CB 0; type is UNORM by default */
13736 pipe.AddColorAttachment();
13737 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13738
13739 VkDescriptorSetObj descriptorSet(m_device);
13740 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13741
13742 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13743
13744 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013745 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013746}
13747
Chris Forbes3fb17902016-08-22 14:57:55 +120013748TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13749 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13750 "which is not included in the subpass description");
13751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13752 "consumes input attachment index 0 but not provided in subpass");
13753
13754 ASSERT_NO_FATAL_FAILURE(InitState());
13755
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013756 char const *vsSource = "#version 450\n"
13757 "\n"
13758 "out gl_PerVertex {\n"
13759 " vec4 gl_Position;\n"
13760 "};\n"
13761 "void main(){\n"
13762 " gl_Position = vec4(1);\n"
13763 "}\n";
13764 char const *fsSource = "#version 450\n"
13765 "\n"
13766 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13767 "layout(location=0) out vec4 color;\n"
13768 "void main() {\n"
13769 " color = subpassLoad(x);\n"
13770 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013771
13772 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13773 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13774
13775 VkPipelineObj pipe(m_device);
13776 pipe.AddShader(&vs);
13777 pipe.AddShader(&fs);
13778 pipe.AddColorAttachment();
13779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013781 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13782 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013783 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013784 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013785 ASSERT_VK_SUCCESS(err);
13786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013787 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013788 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013789 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013790 ASSERT_VK_SUCCESS(err);
13791
13792 // error here.
13793 pipe.CreateVKPipeline(pl, renderPass());
13794
13795 m_errorMonitor->VerifyFound();
13796
13797 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13798 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13799}
13800
Chris Forbes5a9a0472016-08-22 16:02:09 +120013801TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13802 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13803 "with a format having a different fundamental type");
13804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13805 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13806
13807 ASSERT_NO_FATAL_FAILURE(InitState());
13808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013809 char const *vsSource = "#version 450\n"
13810 "\n"
13811 "out gl_PerVertex {\n"
13812 " vec4 gl_Position;\n"
13813 "};\n"
13814 "void main(){\n"
13815 " gl_Position = vec4(1);\n"
13816 "}\n";
13817 char const *fsSource = "#version 450\n"
13818 "\n"
13819 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13820 "layout(location=0) out vec4 color;\n"
13821 "void main() {\n"
13822 " color = subpassLoad(x);\n"
13823 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013824
13825 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13826 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13827
13828 VkPipelineObj pipe(m_device);
13829 pipe.AddShader(&vs);
13830 pipe.AddShader(&fs);
13831 pipe.AddColorAttachment();
13832 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13833
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013834 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13835 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013836 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013837 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013838 ASSERT_VK_SUCCESS(err);
13839
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013840 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013841 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013842 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013843 ASSERT_VK_SUCCESS(err);
13844
13845 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013846 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13847 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13848 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13849 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13850 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 +120013851 };
13852 VkAttachmentReference color = {
13853 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13854 };
13855 VkAttachmentReference input = {
13856 1, VK_IMAGE_LAYOUT_GENERAL,
13857 };
13858
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013859 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013861 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013862 VkRenderPass rp;
13863 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13864 ASSERT_VK_SUCCESS(err);
13865
13866 // error here.
13867 pipe.CreateVKPipeline(pl, rp);
13868
13869 m_errorMonitor->VerifyFound();
13870
13871 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13872 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13873 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13874}
13875
Chris Forbes541f7b02016-08-22 15:30:27 +120013876TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13877 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13878 "which is not included in the subpass description -- array case");
13879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13880 "consumes input attachment index 1 but not provided in subpass");
13881
13882 ASSERT_NO_FATAL_FAILURE(InitState());
13883
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013884 char const *vsSource = "#version 450\n"
13885 "\n"
13886 "out gl_PerVertex {\n"
13887 " vec4 gl_Position;\n"
13888 "};\n"
13889 "void main(){\n"
13890 " gl_Position = vec4(1);\n"
13891 "}\n";
13892 char const *fsSource = "#version 450\n"
13893 "\n"
13894 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13895 "layout(location=0) out vec4 color;\n"
13896 "void main() {\n"
13897 " color = subpassLoad(xs[1]);\n"
13898 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013899
13900 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13901 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13902
13903 VkPipelineObj pipe(m_device);
13904 pipe.AddShader(&vs);
13905 pipe.AddShader(&fs);
13906 pipe.AddColorAttachment();
13907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13908
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013909 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13910 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013911 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013912 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013913 ASSERT_VK_SUCCESS(err);
13914
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013915 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013916 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013917 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013918 ASSERT_VK_SUCCESS(err);
13919
13920 // error here.
13921 pipe.CreateVKPipeline(pl, renderPass());
13922
13923 m_errorMonitor->VerifyFound();
13924
13925 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13926 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13927}
13928
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013929TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013930 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13931 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013933
13934 ASSERT_NO_FATAL_FAILURE(InitState());
13935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013936 char const *csSource = "#version 450\n"
13937 "\n"
13938 "layout(local_size_x=1) in;\n"
13939 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13940 "void main(){\n"
13941 " x = vec4(1);\n"
13942 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013943
13944 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13945
13946 VkDescriptorSetObj descriptorSet(m_device);
13947 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13948
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013949 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13950 nullptr,
13951 0,
13952 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13953 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13954 descriptorSet.GetPipelineLayout(),
13955 VK_NULL_HANDLE,
13956 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013957
13958 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013959 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013960
13961 m_errorMonitor->VerifyFound();
13962
13963 if (err == VK_SUCCESS) {
13964 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13965 }
13966}
13967
Chris Forbes22a9b092016-07-19 14:34:05 +120013968TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013969 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13970 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13972 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013973
13974 ASSERT_NO_FATAL_FAILURE(InitState());
13975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013976 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13977 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013978 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013979 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013980 ASSERT_VK_SUCCESS(err);
13981
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013982 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013983 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013984 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013985 ASSERT_VK_SUCCESS(err);
13986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013987 char const *csSource = "#version 450\n"
13988 "\n"
13989 "layout(local_size_x=1) in;\n"
13990 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13991 "void main() {\n"
13992 " x.x = 1.0f;\n"
13993 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013994 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13995
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013996 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13997 nullptr,
13998 0,
13999 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14000 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14001 pl,
14002 VK_NULL_HANDLE,
14003 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014004
14005 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014006 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014007
14008 m_errorMonitor->VerifyFound();
14009
14010 if (err == VK_SUCCESS) {
14011 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14012 }
14013
14014 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14015 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14016}
14017
Chris Forbes50020592016-07-27 13:52:41 +120014018TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
14019 TEST_DESCRIPTION("Test that an error is produced when an image view type "
14020 "does not match the dimensionality declared in the shader");
14021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014022 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 +120014023
14024 ASSERT_NO_FATAL_FAILURE(InitState());
14025 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14026
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014027 char const *vsSource = "#version 450\n"
14028 "\n"
14029 "out gl_PerVertex { vec4 gl_Position; };\n"
14030 "void main() { gl_Position = vec4(0); }\n";
14031 char const *fsSource = "#version 450\n"
14032 "\n"
14033 "layout(set=0, binding=0) uniform sampler3D s;\n"
14034 "layout(location=0) out vec4 color;\n"
14035 "void main() {\n"
14036 " color = texture(s, vec3(0));\n"
14037 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014038 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14039 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14040
14041 VkPipelineObj pipe(m_device);
14042 pipe.AddShader(&vs);
14043 pipe.AddShader(&fs);
14044 pipe.AddColorAttachment();
14045
14046 VkTextureObj texture(m_device, nullptr);
14047 VkSamplerObj sampler(m_device);
14048
14049 VkDescriptorSetObj descriptorSet(m_device);
14050 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14051 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14052
14053 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14054 ASSERT_VK_SUCCESS(err);
14055
14056 BeginCommandBuffer();
14057
14058 m_commandBuffer->BindPipeline(pipe);
14059 m_commandBuffer->BindDescriptorSet(descriptorSet);
14060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014061 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014062 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014063 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014064 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14065
14066 // error produced here.
14067 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14068
14069 m_errorMonitor->VerifyFound();
14070
14071 EndCommandBuffer();
14072}
14073
Chris Forbes5533bfc2016-07-27 14:12:34 +120014074TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14075 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14076 "are consumed via singlesample images types in the shader, or vice versa.");
14077
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014079
14080 ASSERT_NO_FATAL_FAILURE(InitState());
14081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14082
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014083 char const *vsSource = "#version 450\n"
14084 "\n"
14085 "out gl_PerVertex { vec4 gl_Position; };\n"
14086 "void main() { gl_Position = vec4(0); }\n";
14087 char const *fsSource = "#version 450\n"
14088 "\n"
14089 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14090 "layout(location=0) out vec4 color;\n"
14091 "void main() {\n"
14092 " color = texelFetch(s, ivec2(0), 0);\n"
14093 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014094 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14095 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14096
14097 VkPipelineObj pipe(m_device);
14098 pipe.AddShader(&vs);
14099 pipe.AddShader(&fs);
14100 pipe.AddColorAttachment();
14101
14102 VkTextureObj texture(m_device, nullptr);
14103 VkSamplerObj sampler(m_device);
14104
14105 VkDescriptorSetObj descriptorSet(m_device);
14106 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14107 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14108
14109 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14110 ASSERT_VK_SUCCESS(err);
14111
14112 BeginCommandBuffer();
14113
14114 m_commandBuffer->BindPipeline(pipe);
14115 m_commandBuffer->BindDescriptorSet(descriptorSet);
14116
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014117 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014118 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014119 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014120 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14121
14122 // error produced here.
14123 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14124
14125 m_errorMonitor->VerifyFound();
14126
14127 EndCommandBuffer();
14128}
14129
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014130#endif // SHADER_CHECKER_TESTS
14131
14132#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014133TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014135
14136 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014137
14138 // Create an image
14139 VkImage image;
14140
Karl Schultz6addd812016-02-02 17:17:23 -070014141 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14142 const int32_t tex_width = 32;
14143 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014144
14145 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014146 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14147 image_create_info.pNext = NULL;
14148 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14149 image_create_info.format = tex_format;
14150 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014151 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014152 image_create_info.extent.depth = 1;
14153 image_create_info.mipLevels = 1;
14154 image_create_info.arrayLayers = 1;
14155 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14156 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14157 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14158 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014159
14160 // Introduce error by sending down a bogus width extent
14161 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014162 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014163
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014164 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014165}
14166
Mark Youngc48c4c12016-04-11 14:26:49 -060014167TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14169 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014170
14171 ASSERT_NO_FATAL_FAILURE(InitState());
14172
14173 // Create an image
14174 VkImage image;
14175
14176 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14177 const int32_t tex_width = 32;
14178 const int32_t tex_height = 32;
14179
14180 VkImageCreateInfo image_create_info = {};
14181 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14182 image_create_info.pNext = NULL;
14183 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14184 image_create_info.format = tex_format;
14185 image_create_info.extent.width = tex_width;
14186 image_create_info.extent.height = tex_height;
14187 image_create_info.extent.depth = 1;
14188 image_create_info.mipLevels = 1;
14189 image_create_info.arrayLayers = 1;
14190 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14191 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14192 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14193 image_create_info.flags = 0;
14194
14195 // Introduce error by sending down a bogus width extent
14196 image_create_info.extent.width = 0;
14197 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14198
14199 m_errorMonitor->VerifyFound();
14200}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014201#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014202
Tobin Ehliscde08892015-09-22 10:11:37 -060014203#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014204
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014205TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14206 TEST_DESCRIPTION("Create a render pass with an attachment description "
14207 "format set to VK_FORMAT_UNDEFINED");
14208
14209 ASSERT_NO_FATAL_FAILURE(InitState());
14210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014213
14214 VkAttachmentReference color_attach = {};
14215 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14216 color_attach.attachment = 0;
14217 VkSubpassDescription subpass = {};
14218 subpass.colorAttachmentCount = 1;
14219 subpass.pColorAttachments = &color_attach;
14220
14221 VkRenderPassCreateInfo rpci = {};
14222 rpci.subpassCount = 1;
14223 rpci.pSubpasses = &subpass;
14224 rpci.attachmentCount = 1;
14225 VkAttachmentDescription attach_desc = {};
14226 attach_desc.format = VK_FORMAT_UNDEFINED;
14227 rpci.pAttachments = &attach_desc;
14228 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14229 VkRenderPass rp;
14230 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14231
14232 m_errorMonitor->VerifyFound();
14233
14234 if (result == VK_SUCCESS) {
14235 vkDestroyRenderPass(m_device->device(), rp, NULL);
14236 }
14237}
14238
Karl Schultz6addd812016-02-02 17:17:23 -070014239TEST_F(VkLayerTest, InvalidImageView) {
14240 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014243
Tobin Ehliscde08892015-09-22 10:11:37 -060014244 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014245
Mike Stroyana3082432015-09-25 13:39:21 -060014246 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014247 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014248
Karl Schultz6addd812016-02-02 17:17:23 -070014249 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14250 const int32_t tex_width = 32;
14251 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014252
14253 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014254 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14255 image_create_info.pNext = NULL;
14256 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14257 image_create_info.format = tex_format;
14258 image_create_info.extent.width = tex_width;
14259 image_create_info.extent.height = tex_height;
14260 image_create_info.extent.depth = 1;
14261 image_create_info.mipLevels = 1;
14262 image_create_info.arrayLayers = 1;
14263 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14264 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14265 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14266 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014267
Chia-I Wuf7458c52015-10-26 21:10:41 +080014268 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014269 ASSERT_VK_SUCCESS(err);
14270
14271 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014272 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014273 image_view_create_info.image = image;
14274 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14275 image_view_create_info.format = tex_format;
14276 image_view_create_info.subresourceRange.layerCount = 1;
14277 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14278 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014279 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014280
14281 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014282 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014283
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014284 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014285 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014286}
Mike Stroyana3082432015-09-25 13:39:21 -060014287
Mark Youngd339ba32016-05-30 13:28:35 -060014288TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14289 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014291 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014292
14293 ASSERT_NO_FATAL_FAILURE(InitState());
14294
14295 // Create an image and try to create a view with no memory backing the image
14296 VkImage image;
14297
14298 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14299 const int32_t tex_width = 32;
14300 const int32_t tex_height = 32;
14301
14302 VkImageCreateInfo image_create_info = {};
14303 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14304 image_create_info.pNext = NULL;
14305 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14306 image_create_info.format = tex_format;
14307 image_create_info.extent.width = tex_width;
14308 image_create_info.extent.height = tex_height;
14309 image_create_info.extent.depth = 1;
14310 image_create_info.mipLevels = 1;
14311 image_create_info.arrayLayers = 1;
14312 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14313 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14314 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14315 image_create_info.flags = 0;
14316
14317 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14318 ASSERT_VK_SUCCESS(err);
14319
14320 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014321 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014322 image_view_create_info.image = image;
14323 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14324 image_view_create_info.format = tex_format;
14325 image_view_create_info.subresourceRange.layerCount = 1;
14326 image_view_create_info.subresourceRange.baseMipLevel = 0;
14327 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014328 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014329
14330 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014331 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014332
14333 m_errorMonitor->VerifyFound();
14334 vkDestroyImage(m_device->device(), image, NULL);
14335 // If last error is success, it still created the view, so delete it.
14336 if (err == VK_SUCCESS) {
14337 vkDestroyImageView(m_device->device(), view, NULL);
14338 }
Mark Youngd339ba32016-05-30 13:28:35 -060014339}
14340
Karl Schultz6addd812016-02-02 17:17:23 -070014341TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014342 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014344 "formats must have ONLY the "
14345 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14347 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014348
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014349 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014350
Karl Schultz6addd812016-02-02 17:17:23 -070014351 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014352 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014353 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014354 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014355
14356 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014357 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014358 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014359 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14360 image_view_create_info.format = tex_format;
14361 image_view_create_info.subresourceRange.baseMipLevel = 0;
14362 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014363 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014364 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014365 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014366
14367 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014368 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014369
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014370 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014371}
14372
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014373TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014374 VkResult err;
14375 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014376
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14378 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014379
Mike Stroyana3082432015-09-25 13:39:21 -060014380 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014381
14382 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014383 VkImage srcImage;
14384 VkImage dstImage;
14385 VkDeviceMemory srcMem;
14386 VkDeviceMemory destMem;
14387 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014388
14389 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014390 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14391 image_create_info.pNext = NULL;
14392 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14393 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14394 image_create_info.extent.width = 32;
14395 image_create_info.extent.height = 32;
14396 image_create_info.extent.depth = 1;
14397 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014398 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014399 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14400 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14401 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14402 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014403
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014404 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014405 ASSERT_VK_SUCCESS(err);
14406
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014407 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014408 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014409 ASSERT_VK_SUCCESS(err);
14410
14411 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014412 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014413 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14414 memAlloc.pNext = NULL;
14415 memAlloc.allocationSize = 0;
14416 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014417
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014418 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014419 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014420 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014421 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014422 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014423 ASSERT_VK_SUCCESS(err);
14424
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014425 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014426 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014427 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014428 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014429 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014430 ASSERT_VK_SUCCESS(err);
14431
14432 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14433 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014434 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014435 ASSERT_VK_SUCCESS(err);
14436
14437 BeginCommandBuffer();
14438 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014439 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014440 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014441 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014442 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014443 copyRegion.srcOffset.x = 0;
14444 copyRegion.srcOffset.y = 0;
14445 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014446 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014447 copyRegion.dstSubresource.mipLevel = 0;
14448 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014449 // Introduce failure by forcing the dst layerCount to differ from src
14450 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014451 copyRegion.dstOffset.x = 0;
14452 copyRegion.dstOffset.y = 0;
14453 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014454 copyRegion.extent.width = 1;
14455 copyRegion.extent.height = 1;
14456 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014457 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014458 EndCommandBuffer();
14459
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014460 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014461
Chia-I Wuf7458c52015-10-26 21:10:41 +080014462 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014463 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014464 vkFreeMemory(m_device->device(), srcMem, NULL);
14465 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014466}
14467
Tony Barbourd6673642016-05-05 14:46:39 -060014468TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14469
14470 TEST_DESCRIPTION("Creating images with unsuported formats ");
14471
14472 ASSERT_NO_FATAL_FAILURE(InitState());
14473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14474 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014475 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 -060014476 VK_IMAGE_TILING_OPTIMAL, 0);
14477 ASSERT_TRUE(image.initialized());
14478
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014479 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014480 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014481 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014482 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14483 image_create_info.format = VK_FORMAT_UNDEFINED;
14484 image_create_info.extent.width = 32;
14485 image_create_info.extent.height = 32;
14486 image_create_info.extent.depth = 1;
14487 image_create_info.mipLevels = 1;
14488 image_create_info.arrayLayers = 1;
14489 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14490 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14491 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14494 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014495
14496 VkImage localImage;
14497 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14498 m_errorMonitor->VerifyFound();
14499
Tony Barbourd6673642016-05-05 14:46:39 -060014500 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014501 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014502 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14503 VkFormat format = static_cast<VkFormat>(f);
14504 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014505 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014506 unsupported = format;
14507 break;
14508 }
14509 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014510
Tony Barbourd6673642016-05-05 14:46:39 -060014511 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014512 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014514
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014515 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014516 m_errorMonitor->VerifyFound();
14517 }
14518}
14519
14520TEST_F(VkLayerTest, ImageLayerViewTests) {
14521 VkResult ret;
14522 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14523
14524 ASSERT_NO_FATAL_FAILURE(InitState());
14525
14526 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014527 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 -060014528 VK_IMAGE_TILING_OPTIMAL, 0);
14529 ASSERT_TRUE(image.initialized());
14530
14531 VkImageView imgView;
14532 VkImageViewCreateInfo imgViewInfo = {};
14533 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14534 imgViewInfo.image = image.handle();
14535 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14536 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14537 imgViewInfo.subresourceRange.layerCount = 1;
14538 imgViewInfo.subresourceRange.baseMipLevel = 0;
14539 imgViewInfo.subresourceRange.levelCount = 1;
14540 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14541
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014543 // View can't have baseMipLevel >= image's mipLevels - Expect
14544 // VIEW_CREATE_ERROR
14545 imgViewInfo.subresourceRange.baseMipLevel = 1;
14546 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14547 m_errorMonitor->VerifyFound();
14548 imgViewInfo.subresourceRange.baseMipLevel = 0;
14549
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014551 // View can't have baseArrayLayer >= image's arraySize - Expect
14552 // VIEW_CREATE_ERROR
14553 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14554 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14555 m_errorMonitor->VerifyFound();
14556 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14559 "pCreateInfo->subresourceRange."
14560 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014561 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14562 imgViewInfo.subresourceRange.levelCount = 0;
14563 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14564 m_errorMonitor->VerifyFound();
14565 imgViewInfo.subresourceRange.levelCount = 1;
14566
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14568 "pCreateInfo->subresourceRange."
14569 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014570 m_errorMonitor->SetDesiredFailureMsg(
14571 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14572 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014573 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14574 imgViewInfo.subresourceRange.layerCount = 0;
14575 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14576 m_errorMonitor->VerifyFound();
14577 imgViewInfo.subresourceRange.layerCount = 1;
14578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14581 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14582 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014583 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14584 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14585 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14586 m_errorMonitor->VerifyFound();
14587 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14590 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14591 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014592 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14593 // VIEW_CREATE_ERROR
14594 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14595 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14596 m_errorMonitor->VerifyFound();
14597 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14598
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14600 "differing formats but they must be "
14601 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014602 // TODO: Update framework to easily passing mutable flag into ImageObj init
14603 // For now just allowing image for this one test to not have memory bound
14604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14605 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014606 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14607 // VIEW_CREATE_ERROR
14608 VkImageCreateInfo mutImgInfo = image.create_info();
14609 VkImage mutImage;
14610 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014611 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014612 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14613 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14614 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14615 ASSERT_VK_SUCCESS(ret);
14616 imgViewInfo.image = mutImage;
14617 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14618 m_errorMonitor->VerifyFound();
14619 imgViewInfo.image = image.handle();
14620 vkDestroyImage(m_device->handle(), mutImage, NULL);
14621}
14622
14623TEST_F(VkLayerTest, MiscImageLayerTests) {
14624
14625 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14626
14627 ASSERT_NO_FATAL_FAILURE(InitState());
14628
14629 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014630 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 -060014631 VK_IMAGE_TILING_OPTIMAL, 0);
14632 ASSERT_TRUE(image.initialized());
14633
Tony Barbourd6673642016-05-05 14:46:39 -060014634 vk_testing::Buffer buffer;
14635 VkMemoryPropertyFlags reqs = 0;
14636 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14637 VkBufferImageCopy region = {};
14638 region.bufferRowLength = 128;
14639 region.bufferImageHeight = 128;
14640 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14641 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014642 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014643 region.imageExtent.height = 4;
14644 region.imageExtent.width = 4;
14645 region.imageExtent.depth = 1;
14646 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014647
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014648 // Image must have offset.z of 0 and extent.depth of 1
14649 // Introduce failure by setting imageExtent.depth to 0
14650 region.imageExtent.depth = 0;
14651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14652 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14653 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14654 m_errorMonitor->VerifyFound();
14655
14656 region.imageExtent.depth = 1;
14657
14658 // Image must have offset.z of 0 and extent.depth of 1
14659 // Introduce failure by setting imageOffset.z to 4
14660 region.imageOffset.z = 4;
14661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14662 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14663 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14664 m_errorMonitor->VerifyFound();
14665
14666 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014667 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14668 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14669 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014671 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14672 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014673 m_errorMonitor->VerifyFound();
14674
14675 // BufferOffset must be a multiple of 4
14676 // Introduce failure by setting bufferOffset to a value not divisible by 4
14677 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014679 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14680 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014681 m_errorMonitor->VerifyFound();
14682
14683 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14684 region.bufferOffset = 0;
14685 region.imageExtent.height = 128;
14686 region.imageExtent.width = 128;
14687 // Introduce failure by setting bufferRowLength > 0 but less than width
14688 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014690 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14691 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014692 m_errorMonitor->VerifyFound();
14693
14694 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14695 region.bufferRowLength = 128;
14696 // Introduce failure by setting bufferRowHeight > 0 but less than height
14697 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014699 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14700 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014701 m_errorMonitor->VerifyFound();
14702
14703 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14705 "If the format of srcImage is a depth, stencil, depth stencil or "
14706 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014707 // Expect INVALID_FILTER
14708 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014709 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 -060014710 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014711 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 -060014712 VkImageBlit blitRegion = {};
14713 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14714 blitRegion.srcSubresource.baseArrayLayer = 0;
14715 blitRegion.srcSubresource.layerCount = 1;
14716 blitRegion.srcSubresource.mipLevel = 0;
14717 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14718 blitRegion.dstSubresource.baseArrayLayer = 0;
14719 blitRegion.dstSubresource.layerCount = 1;
14720 blitRegion.dstSubresource.mipLevel = 0;
14721
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014722 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14723 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014724 m_errorMonitor->VerifyFound();
14725
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014726 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14728 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14729 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014730 m_errorMonitor->VerifyFound();
14731
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014733 VkImageMemoryBarrier img_barrier;
14734 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14735 img_barrier.pNext = NULL;
14736 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14737 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14738 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14739 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14740 img_barrier.image = image.handle();
14741 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14742 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14743 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14744 img_barrier.subresourceRange.baseArrayLayer = 0;
14745 img_barrier.subresourceRange.baseMipLevel = 0;
14746 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14747 img_barrier.subresourceRange.layerCount = 0;
14748 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014749 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14750 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014751 m_errorMonitor->VerifyFound();
14752 img_barrier.subresourceRange.layerCount = 1;
14753}
14754
14755TEST_F(VkLayerTest, ImageFormatLimits) {
14756
14757 TEST_DESCRIPTION("Exceed the limits of image format ");
14758
Cody Northropc31a84f2016-08-22 10:41:47 -060014759 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014761 VkImageCreateInfo image_create_info = {};
14762 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 = 32;
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_1_BIT;
14772 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14773 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14774 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14775 image_create_info.flags = 0;
14776
14777 VkImage nullImg;
14778 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014779 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14780 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014781 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14782 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14783 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14784 m_errorMonitor->VerifyFound();
14785 image_create_info.extent.depth = 1;
14786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014788 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14789 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14790 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14791 m_errorMonitor->VerifyFound();
14792 image_create_info.mipLevels = 1;
14793
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014795 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14796 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14797 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14798 m_errorMonitor->VerifyFound();
14799 image_create_info.arrayLayers = 1;
14800
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014802 int samples = imgFmtProps.sampleCounts >> 1;
14803 image_create_info.samples = (VkSampleCountFlagBits)samples;
14804 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14805 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14806 m_errorMonitor->VerifyFound();
14807 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14810 "VK_IMAGE_LAYOUT_UNDEFINED or "
14811 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014812 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14813 // Expect INVALID_LAYOUT
14814 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14815 m_errorMonitor->VerifyFound();
14816 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14817}
14818
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014819TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14820
14821 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014823
14824 ASSERT_NO_FATAL_FAILURE(InitState());
14825
14826 VkImageObj src_image(m_device);
14827 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14828 VkImageObj dst_image(m_device);
14829 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14830
14831 BeginCommandBuffer();
14832 VkImageCopy copy_region;
14833 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14834 copy_region.srcSubresource.mipLevel = 0;
14835 copy_region.srcSubresource.baseArrayLayer = 0;
14836 copy_region.srcSubresource.layerCount = 0;
14837 copy_region.srcOffset.x = 0;
14838 copy_region.srcOffset.y = 0;
14839 copy_region.srcOffset.z = 0;
14840 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14841 copy_region.dstSubresource.mipLevel = 0;
14842 copy_region.dstSubresource.baseArrayLayer = 0;
14843 copy_region.dstSubresource.layerCount = 0;
14844 copy_region.dstOffset.x = 0;
14845 copy_region.dstOffset.y = 0;
14846 copy_region.dstOffset.z = 0;
14847 copy_region.extent.width = 64;
14848 copy_region.extent.height = 64;
14849 copy_region.extent.depth = 1;
14850 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14851 &copy_region);
14852 EndCommandBuffer();
14853
14854 m_errorMonitor->VerifyFound();
14855}
14856
14857TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14858
14859 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014861
14862 ASSERT_NO_FATAL_FAILURE(InitState());
14863
14864 VkImageObj src_image(m_device);
14865 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14866 VkImageObj dst_image(m_device);
14867 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14868
14869 BeginCommandBuffer();
14870 VkImageCopy copy_region;
14871 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14872 copy_region.srcSubresource.mipLevel = 0;
14873 copy_region.srcSubresource.baseArrayLayer = 0;
14874 copy_region.srcSubresource.layerCount = 0;
14875 copy_region.srcOffset.x = 0;
14876 copy_region.srcOffset.y = 0;
14877 copy_region.srcOffset.z = 0;
14878 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14879 copy_region.dstSubresource.mipLevel = 0;
14880 copy_region.dstSubresource.baseArrayLayer = 0;
14881 copy_region.dstSubresource.layerCount = 0;
14882 copy_region.dstOffset.x = 0;
14883 copy_region.dstOffset.y = 0;
14884 copy_region.dstOffset.z = 0;
14885 copy_region.extent.width = 64;
14886 copy_region.extent.height = 64;
14887 copy_region.extent.depth = 1;
14888 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14889 &copy_region);
14890 EndCommandBuffer();
14891
14892 m_errorMonitor->VerifyFound();
14893}
14894
Karl Schultz6addd812016-02-02 17:17:23 -070014895TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014896 VkResult err;
14897 bool pass;
14898
14899 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14901 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014902
14903 ASSERT_NO_FATAL_FAILURE(InitState());
14904
14905 // Create two images of different types and try to copy between them
14906 VkImage srcImage;
14907 VkImage dstImage;
14908 VkDeviceMemory srcMem;
14909 VkDeviceMemory destMem;
14910 VkMemoryRequirements memReqs;
14911
14912 VkImageCreateInfo image_create_info = {};
14913 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14914 image_create_info.pNext = NULL;
14915 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14916 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14917 image_create_info.extent.width = 32;
14918 image_create_info.extent.height = 32;
14919 image_create_info.extent.depth = 1;
14920 image_create_info.mipLevels = 1;
14921 image_create_info.arrayLayers = 1;
14922 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14923 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14924 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14925 image_create_info.flags = 0;
14926
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014927 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014928 ASSERT_VK_SUCCESS(err);
14929
14930 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14931 // Introduce failure by creating second image with a different-sized format.
14932 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014934 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014935 ASSERT_VK_SUCCESS(err);
14936
14937 // Allocate memory
14938 VkMemoryAllocateInfo memAlloc = {};
14939 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14940 memAlloc.pNext = NULL;
14941 memAlloc.allocationSize = 0;
14942 memAlloc.memoryTypeIndex = 0;
14943
14944 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14945 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014946 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014947 ASSERT_TRUE(pass);
14948 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14949 ASSERT_VK_SUCCESS(err);
14950
14951 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14952 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014953 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014954 ASSERT_TRUE(pass);
14955 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14956 ASSERT_VK_SUCCESS(err);
14957
14958 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14959 ASSERT_VK_SUCCESS(err);
14960 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14961 ASSERT_VK_SUCCESS(err);
14962
14963 BeginCommandBuffer();
14964 VkImageCopy copyRegion;
14965 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14966 copyRegion.srcSubresource.mipLevel = 0;
14967 copyRegion.srcSubresource.baseArrayLayer = 0;
14968 copyRegion.srcSubresource.layerCount = 0;
14969 copyRegion.srcOffset.x = 0;
14970 copyRegion.srcOffset.y = 0;
14971 copyRegion.srcOffset.z = 0;
14972 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14973 copyRegion.dstSubresource.mipLevel = 0;
14974 copyRegion.dstSubresource.baseArrayLayer = 0;
14975 copyRegion.dstSubresource.layerCount = 0;
14976 copyRegion.dstOffset.x = 0;
14977 copyRegion.dstOffset.y = 0;
14978 copyRegion.dstOffset.z = 0;
14979 copyRegion.extent.width = 1;
14980 copyRegion.extent.height = 1;
14981 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014982 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014983 EndCommandBuffer();
14984
14985 m_errorMonitor->VerifyFound();
14986
14987 vkDestroyImage(m_device->device(), srcImage, NULL);
14988 vkDestroyImage(m_device->device(), dstImage, NULL);
14989 vkFreeMemory(m_device->device(), srcMem, NULL);
14990 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014991}
14992
Karl Schultz6addd812016-02-02 17:17:23 -070014993TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14994 VkResult err;
14995 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014996
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014997 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14999 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015000
Mike Stroyana3082432015-09-25 13:39:21 -060015001 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015002
15003 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015004 VkImage srcImage;
15005 VkImage dstImage;
15006 VkDeviceMemory srcMem;
15007 VkDeviceMemory destMem;
15008 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015009
15010 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015011 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15012 image_create_info.pNext = NULL;
15013 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15014 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15015 image_create_info.extent.width = 32;
15016 image_create_info.extent.height = 32;
15017 image_create_info.extent.depth = 1;
15018 image_create_info.mipLevels = 1;
15019 image_create_info.arrayLayers = 1;
15020 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15021 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15022 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15023 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015024
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015025 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015026 ASSERT_VK_SUCCESS(err);
15027
Karl Schultzbdb75952016-04-19 11:36:49 -060015028 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15029
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015030 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015031 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015032 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015033 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015035 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015036 ASSERT_VK_SUCCESS(err);
15037
15038 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015039 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015040 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15041 memAlloc.pNext = NULL;
15042 memAlloc.allocationSize = 0;
15043 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015044
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015045 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015046 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015047 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015048 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015049 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015050 ASSERT_VK_SUCCESS(err);
15051
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015052 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015053 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015054 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015055 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015056 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015057 ASSERT_VK_SUCCESS(err);
15058
15059 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15060 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015061 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015062 ASSERT_VK_SUCCESS(err);
15063
15064 BeginCommandBuffer();
15065 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015066 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015067 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015068 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015069 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015070 copyRegion.srcOffset.x = 0;
15071 copyRegion.srcOffset.y = 0;
15072 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015073 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015074 copyRegion.dstSubresource.mipLevel = 0;
15075 copyRegion.dstSubresource.baseArrayLayer = 0;
15076 copyRegion.dstSubresource.layerCount = 0;
15077 copyRegion.dstOffset.x = 0;
15078 copyRegion.dstOffset.y = 0;
15079 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015080 copyRegion.extent.width = 1;
15081 copyRegion.extent.height = 1;
15082 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015083 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015084 EndCommandBuffer();
15085
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015086 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015087
Chia-I Wuf7458c52015-10-26 21:10:41 +080015088 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015089 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015090 vkFreeMemory(m_device->device(), srcMem, NULL);
15091 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015092}
15093
Karl Schultz6addd812016-02-02 17:17:23 -070015094TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15095 VkResult err;
15096 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15099 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015100
Mike Stroyana3082432015-09-25 13:39:21 -060015101 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015102
15103 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015104 VkImage srcImage;
15105 VkImage dstImage;
15106 VkDeviceMemory srcMem;
15107 VkDeviceMemory destMem;
15108 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015109
15110 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015111 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15112 image_create_info.pNext = NULL;
15113 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15114 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15115 image_create_info.extent.width = 32;
15116 image_create_info.extent.height = 1;
15117 image_create_info.extent.depth = 1;
15118 image_create_info.mipLevels = 1;
15119 image_create_info.arrayLayers = 1;
15120 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15121 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15122 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15123 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015125 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015126 ASSERT_VK_SUCCESS(err);
15127
Karl Schultz6addd812016-02-02 17:17:23 -070015128 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015130 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015131 ASSERT_VK_SUCCESS(err);
15132
15133 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015134 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015135 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15136 memAlloc.pNext = NULL;
15137 memAlloc.allocationSize = 0;
15138 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015139
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015140 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015141 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015142 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015143 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015144 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015145 ASSERT_VK_SUCCESS(err);
15146
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015147 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015148 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015149 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015150 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015151 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015152 ASSERT_VK_SUCCESS(err);
15153
15154 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15155 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015156 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015157 ASSERT_VK_SUCCESS(err);
15158
15159 BeginCommandBuffer();
15160 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015161 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15162 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015163 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015164 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015165 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015166 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015167 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015168 resolveRegion.srcOffset.x = 0;
15169 resolveRegion.srcOffset.y = 0;
15170 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015171 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015172 resolveRegion.dstSubresource.mipLevel = 0;
15173 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015174 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015175 resolveRegion.dstOffset.x = 0;
15176 resolveRegion.dstOffset.y = 0;
15177 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015178 resolveRegion.extent.width = 1;
15179 resolveRegion.extent.height = 1;
15180 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015181 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015182 EndCommandBuffer();
15183
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015184 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015185
Chia-I Wuf7458c52015-10-26 21:10:41 +080015186 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015187 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015188 vkFreeMemory(m_device->device(), srcMem, NULL);
15189 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015190}
15191
Karl Schultz6addd812016-02-02 17:17:23 -070015192TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15193 VkResult err;
15194 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15197 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015198
Mike Stroyana3082432015-09-25 13:39:21 -060015199 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015200
Chris Forbesa7530692016-05-08 12:35:39 +120015201 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015202 VkImage srcImage;
15203 VkImage dstImage;
15204 VkDeviceMemory srcMem;
15205 VkDeviceMemory destMem;
15206 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015207
15208 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015209 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15210 image_create_info.pNext = NULL;
15211 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15212 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15213 image_create_info.extent.width = 32;
15214 image_create_info.extent.height = 1;
15215 image_create_info.extent.depth = 1;
15216 image_create_info.mipLevels = 1;
15217 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015218 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015219 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15220 // Note: Some implementations expect color attachment usage for any
15221 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015222 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015223 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015225 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015226 ASSERT_VK_SUCCESS(err);
15227
Karl Schultz6addd812016-02-02 17:17:23 -070015228 // Note: Some implementations expect color attachment usage for any
15229 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015230 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015231
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015232 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015233 ASSERT_VK_SUCCESS(err);
15234
15235 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015236 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015237 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15238 memAlloc.pNext = NULL;
15239 memAlloc.allocationSize = 0;
15240 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015241
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015242 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015243 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015244 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015245 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015246 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015247 ASSERT_VK_SUCCESS(err);
15248
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015249 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015250 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015251 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015252 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015253 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015254 ASSERT_VK_SUCCESS(err);
15255
15256 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15257 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015258 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015259 ASSERT_VK_SUCCESS(err);
15260
15261 BeginCommandBuffer();
15262 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015263 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15264 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015265 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015266 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015267 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015268 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015269 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015270 resolveRegion.srcOffset.x = 0;
15271 resolveRegion.srcOffset.y = 0;
15272 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015273 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015274 resolveRegion.dstSubresource.mipLevel = 0;
15275 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015276 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015277 resolveRegion.dstOffset.x = 0;
15278 resolveRegion.dstOffset.y = 0;
15279 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015280 resolveRegion.extent.width = 1;
15281 resolveRegion.extent.height = 1;
15282 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015283 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015284 EndCommandBuffer();
15285
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015286 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015287
Chia-I Wuf7458c52015-10-26 21:10:41 +080015288 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015289 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015290 vkFreeMemory(m_device->device(), srcMem, NULL);
15291 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015292}
15293
Karl Schultz6addd812016-02-02 17:17:23 -070015294TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15295 VkResult err;
15296 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15299 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015300
Mike Stroyana3082432015-09-25 13:39:21 -060015301 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015302
15303 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015304 VkImage srcImage;
15305 VkImage dstImage;
15306 VkDeviceMemory srcMem;
15307 VkDeviceMemory destMem;
15308 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015309
15310 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015311 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15312 image_create_info.pNext = NULL;
15313 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15314 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15315 image_create_info.extent.width = 32;
15316 image_create_info.extent.height = 1;
15317 image_create_info.extent.depth = 1;
15318 image_create_info.mipLevels = 1;
15319 image_create_info.arrayLayers = 1;
15320 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15321 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15322 // Note: Some implementations expect color attachment usage for any
15323 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015324 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015325 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015327 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015328 ASSERT_VK_SUCCESS(err);
15329
Karl Schultz6addd812016-02-02 17:17:23 -070015330 // Set format to something other than source image
15331 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15332 // Note: Some implementations expect color attachment usage for any
15333 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015334 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015335 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015337 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015338 ASSERT_VK_SUCCESS(err);
15339
15340 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015341 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015342 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15343 memAlloc.pNext = NULL;
15344 memAlloc.allocationSize = 0;
15345 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015346
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015347 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015348 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015349 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015350 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015351 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015352 ASSERT_VK_SUCCESS(err);
15353
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015354 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015355 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015356 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015357 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015358 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015359 ASSERT_VK_SUCCESS(err);
15360
15361 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15362 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015363 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015364 ASSERT_VK_SUCCESS(err);
15365
15366 BeginCommandBuffer();
15367 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015368 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15369 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015370 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015371 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015372 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015373 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015374 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015375 resolveRegion.srcOffset.x = 0;
15376 resolveRegion.srcOffset.y = 0;
15377 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015378 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015379 resolveRegion.dstSubresource.mipLevel = 0;
15380 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015381 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015382 resolveRegion.dstOffset.x = 0;
15383 resolveRegion.dstOffset.y = 0;
15384 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015385 resolveRegion.extent.width = 1;
15386 resolveRegion.extent.height = 1;
15387 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015388 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015389 EndCommandBuffer();
15390
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015391 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015392
Chia-I Wuf7458c52015-10-26 21:10:41 +080015393 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015394 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015395 vkFreeMemory(m_device->device(), srcMem, NULL);
15396 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015397}
15398
Karl Schultz6addd812016-02-02 17:17:23 -070015399TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15400 VkResult err;
15401 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15404 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015405
Mike Stroyana3082432015-09-25 13:39:21 -060015406 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015407
15408 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015409 VkImage srcImage;
15410 VkImage dstImage;
15411 VkDeviceMemory srcMem;
15412 VkDeviceMemory destMem;
15413 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015414
15415 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015416 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15417 image_create_info.pNext = NULL;
15418 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15419 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15420 image_create_info.extent.width = 32;
15421 image_create_info.extent.height = 1;
15422 image_create_info.extent.depth = 1;
15423 image_create_info.mipLevels = 1;
15424 image_create_info.arrayLayers = 1;
15425 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15426 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15427 // Note: Some implementations expect color attachment usage for any
15428 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015429 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015430 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015432 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015433 ASSERT_VK_SUCCESS(err);
15434
Karl Schultz6addd812016-02-02 17:17:23 -070015435 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15436 // Note: Some implementations expect color attachment usage for any
15437 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015438 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015439 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015441 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015442 ASSERT_VK_SUCCESS(err);
15443
15444 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015445 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015446 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15447 memAlloc.pNext = NULL;
15448 memAlloc.allocationSize = 0;
15449 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015450
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015451 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015452 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015453 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015454 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015455 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015456 ASSERT_VK_SUCCESS(err);
15457
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015458 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015459 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015460 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015461 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015462 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015463 ASSERT_VK_SUCCESS(err);
15464
15465 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15466 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015467 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015468 ASSERT_VK_SUCCESS(err);
15469
15470 BeginCommandBuffer();
15471 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015472 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15473 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015474 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015475 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015476 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015477 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015478 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015479 resolveRegion.srcOffset.x = 0;
15480 resolveRegion.srcOffset.y = 0;
15481 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015482 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015483 resolveRegion.dstSubresource.mipLevel = 0;
15484 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015485 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015486 resolveRegion.dstOffset.x = 0;
15487 resolveRegion.dstOffset.y = 0;
15488 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015489 resolveRegion.extent.width = 1;
15490 resolveRegion.extent.height = 1;
15491 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015492 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015493 EndCommandBuffer();
15494
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015495 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015496
Chia-I Wuf7458c52015-10-26 21:10:41 +080015497 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015498 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015499 vkFreeMemory(m_device->device(), srcMem, NULL);
15500 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015501}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015502
Karl Schultz6addd812016-02-02 17:17:23 -070015503TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015504 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015505 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15506 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015507 // The image format check comes 2nd in validation so we trigger it first,
15508 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015509 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015510
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15512 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015513
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015514 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015515
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015516 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015517 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15518 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015519
15520 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015521 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15522 ds_pool_ci.pNext = NULL;
15523 ds_pool_ci.maxSets = 1;
15524 ds_pool_ci.poolSizeCount = 1;
15525 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015526
15527 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015528 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015529 ASSERT_VK_SUCCESS(err);
15530
15531 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015532 dsl_binding.binding = 0;
15533 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15534 dsl_binding.descriptorCount = 1;
15535 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15536 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015537
15538 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015539 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15540 ds_layout_ci.pNext = NULL;
15541 ds_layout_ci.bindingCount = 1;
15542 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015543 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015544 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015545 ASSERT_VK_SUCCESS(err);
15546
15547 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015548 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015549 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015550 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015551 alloc_info.descriptorPool = ds_pool;
15552 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015553 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015554 ASSERT_VK_SUCCESS(err);
15555
Karl Schultz6addd812016-02-02 17:17:23 -070015556 VkImage image_bad;
15557 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015558 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015559 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015560 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015561 const int32_t tex_width = 32;
15562 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015563
15564 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015565 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15566 image_create_info.pNext = NULL;
15567 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15568 image_create_info.format = tex_format_bad;
15569 image_create_info.extent.width = tex_width;
15570 image_create_info.extent.height = tex_height;
15571 image_create_info.extent.depth = 1;
15572 image_create_info.mipLevels = 1;
15573 image_create_info.arrayLayers = 1;
15574 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15575 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015576 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015577 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015579 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015580 ASSERT_VK_SUCCESS(err);
15581 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015582 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15583 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015584 ASSERT_VK_SUCCESS(err);
15585
15586 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015587 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015588 image_view_create_info.image = image_bad;
15589 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15590 image_view_create_info.format = tex_format_bad;
15591 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15592 image_view_create_info.subresourceRange.baseMipLevel = 0;
15593 image_view_create_info.subresourceRange.layerCount = 1;
15594 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015595 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015596
15597 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015598 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015599
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015600 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015601
Chia-I Wuf7458c52015-10-26 21:10:41 +080015602 vkDestroyImage(m_device->device(), image_bad, NULL);
15603 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015604 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15605 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015606}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015607
15608TEST_F(VkLayerTest, ClearImageErrors) {
15609 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15610 "ClearDepthStencilImage with a color image.");
15611
15612 ASSERT_NO_FATAL_FAILURE(InitState());
15613 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15614
15615 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15616 BeginCommandBuffer();
15617 m_commandBuffer->EndRenderPass();
15618
15619 // Color image
15620 VkClearColorValue clear_color;
15621 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15622 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15623 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15624 const int32_t img_width = 32;
15625 const int32_t img_height = 32;
15626 VkImageCreateInfo image_create_info = {};
15627 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15628 image_create_info.pNext = NULL;
15629 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15630 image_create_info.format = color_format;
15631 image_create_info.extent.width = img_width;
15632 image_create_info.extent.height = img_height;
15633 image_create_info.extent.depth = 1;
15634 image_create_info.mipLevels = 1;
15635 image_create_info.arrayLayers = 1;
15636 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15637 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15638 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15639
15640 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015641 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015642
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015643 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015644
15645 // Depth/Stencil image
15646 VkClearDepthStencilValue clear_value = {0};
15647 reqs = 0; // don't need HOST_VISIBLE DS image
15648 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15649 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15650 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15651 ds_image_create_info.extent.width = 64;
15652 ds_image_create_info.extent.height = 64;
15653 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15654 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15655
15656 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015657 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015658
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015659 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 -060015660
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015663 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015664 &color_range);
15665
15666 m_errorMonitor->VerifyFound();
15667
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15669 "image created without "
15670 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015671
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015672 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015673 &color_range);
15674
15675 m_errorMonitor->VerifyFound();
15676
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015677 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15679 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015680
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015681 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15682 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015683
15684 m_errorMonitor->VerifyFound();
15685}
Tobin Ehliscde08892015-09-22 10:11:37 -060015686#endif // IMAGE_TESTS
15687
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015688
15689// WSI Enabled Tests
15690//
Chris Forbes09368e42016-10-13 11:59:22 +130015691#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015692TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15693
15694#if defined(VK_USE_PLATFORM_XCB_KHR)
15695 VkSurfaceKHR surface = VK_NULL_HANDLE;
15696
15697 VkResult err;
15698 bool pass;
15699 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15700 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15701 // uint32_t swapchain_image_count = 0;
15702 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15703 // uint32_t image_index = 0;
15704 // VkPresentInfoKHR present_info = {};
15705
15706 ASSERT_NO_FATAL_FAILURE(InitState());
15707
15708 // Use the create function from one of the VK_KHR_*_surface extension in
15709 // order to create a surface, testing all known errors in the process,
15710 // before successfully creating a surface:
15711 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15713 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15714 pass = (err != VK_SUCCESS);
15715 ASSERT_TRUE(pass);
15716 m_errorMonitor->VerifyFound();
15717
15718 // Next, try to create a surface with the wrong
15719 // VkXcbSurfaceCreateInfoKHR::sType:
15720 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15721 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15723 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15724 pass = (err != VK_SUCCESS);
15725 ASSERT_TRUE(pass);
15726 m_errorMonitor->VerifyFound();
15727
15728 // Create a native window, and then correctly create a surface:
15729 xcb_connection_t *connection;
15730 xcb_screen_t *screen;
15731 xcb_window_t xcb_window;
15732 xcb_intern_atom_reply_t *atom_wm_delete_window;
15733
15734 const xcb_setup_t *setup;
15735 xcb_screen_iterator_t iter;
15736 int scr;
15737 uint32_t value_mask, value_list[32];
15738 int width = 1;
15739 int height = 1;
15740
15741 connection = xcb_connect(NULL, &scr);
15742 ASSERT_TRUE(connection != NULL);
15743 setup = xcb_get_setup(connection);
15744 iter = xcb_setup_roots_iterator(setup);
15745 while (scr-- > 0)
15746 xcb_screen_next(&iter);
15747 screen = iter.data;
15748
15749 xcb_window = xcb_generate_id(connection);
15750
15751 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15752 value_list[0] = screen->black_pixel;
15753 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15754
15755 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15756 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15757
15758 /* Magic code that will send notification when window is destroyed */
15759 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15760 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15761
15762 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15763 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15764 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15765 free(reply);
15766
15767 xcb_map_window(connection, xcb_window);
15768
15769 // Force the x/y coordinates to 100,100 results are identical in consecutive
15770 // runs
15771 const uint32_t coords[] = { 100, 100 };
15772 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15773
15774 // Finally, try to correctly create a surface:
15775 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15776 xcb_create_info.pNext = NULL;
15777 xcb_create_info.flags = 0;
15778 xcb_create_info.connection = connection;
15779 xcb_create_info.window = xcb_window;
15780 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15781 pass = (err == VK_SUCCESS);
15782 ASSERT_TRUE(pass);
15783
15784 // Check if surface supports presentation:
15785
15786 // 1st, do so without having queried the queue families:
15787 VkBool32 supported = false;
15788 // TODO: Get the following error to come out:
15789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15790 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15791 "function");
15792 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15793 pass = (err != VK_SUCCESS);
15794 // ASSERT_TRUE(pass);
15795 // m_errorMonitor->VerifyFound();
15796
15797 // Next, query a queue family index that's too large:
15798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15799 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15800 pass = (err != VK_SUCCESS);
15801 ASSERT_TRUE(pass);
15802 m_errorMonitor->VerifyFound();
15803
15804 // Finally, do so correctly:
15805 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15806 // SUPPORTED
15807 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15808 pass = (err == VK_SUCCESS);
15809 ASSERT_TRUE(pass);
15810
15811 // Before proceeding, try to create a swapchain without having called
15812 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15813 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15814 swapchain_create_info.pNext = NULL;
15815 swapchain_create_info.flags = 0;
15816 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15817 swapchain_create_info.surface = surface;
15818 swapchain_create_info.imageArrayLayers = 1;
15819 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15820 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15822 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15823 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15824 pass = (err != VK_SUCCESS);
15825 ASSERT_TRUE(pass);
15826 m_errorMonitor->VerifyFound();
15827
15828 // Get the surface capabilities:
15829 VkSurfaceCapabilitiesKHR surface_capabilities;
15830
15831 // Do so correctly (only error logged by this entrypoint is if the
15832 // extension isn't enabled):
15833 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15834 pass = (err == VK_SUCCESS);
15835 ASSERT_TRUE(pass);
15836
15837 // Get the surface formats:
15838 uint32_t surface_format_count;
15839
15840 // First, try without a pointer to surface_format_count:
15841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15842 "specified as NULL");
15843 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15844 pass = (err == VK_SUCCESS);
15845 ASSERT_TRUE(pass);
15846 m_errorMonitor->VerifyFound();
15847
15848 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15849 // correctly done a 1st try (to get the count):
15850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15851 surface_format_count = 0;
15852 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15853 pass = (err == VK_SUCCESS);
15854 ASSERT_TRUE(pass);
15855 m_errorMonitor->VerifyFound();
15856
15857 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15858 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15859 pass = (err == VK_SUCCESS);
15860 ASSERT_TRUE(pass);
15861
15862 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15863 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15864
15865 // Next, do a 2nd try with surface_format_count being set too high:
15866 surface_format_count += 5;
15867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15868 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15869 pass = (err == VK_SUCCESS);
15870 ASSERT_TRUE(pass);
15871 m_errorMonitor->VerifyFound();
15872
15873 // Finally, do a correct 1st and 2nd try:
15874 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15875 pass = (err == VK_SUCCESS);
15876 ASSERT_TRUE(pass);
15877 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15878 pass = (err == VK_SUCCESS);
15879 ASSERT_TRUE(pass);
15880
15881 // Get the surface present modes:
15882 uint32_t surface_present_mode_count;
15883
15884 // First, try without a pointer to surface_format_count:
15885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15886 "specified as NULL");
15887
15888 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15889 pass = (err == VK_SUCCESS);
15890 ASSERT_TRUE(pass);
15891 m_errorMonitor->VerifyFound();
15892
15893 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15894 // correctly done a 1st try (to get the count):
15895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15896 surface_present_mode_count = 0;
15897 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15898 (VkPresentModeKHR *)&surface_present_mode_count);
15899 pass = (err == VK_SUCCESS);
15900 ASSERT_TRUE(pass);
15901 m_errorMonitor->VerifyFound();
15902
15903 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15904 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15905 pass = (err == VK_SUCCESS);
15906 ASSERT_TRUE(pass);
15907
15908 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15909 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15910
15911 // Next, do a 2nd try with surface_format_count being set too high:
15912 surface_present_mode_count += 5;
15913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15914 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15915 pass = (err == VK_SUCCESS);
15916 ASSERT_TRUE(pass);
15917 m_errorMonitor->VerifyFound();
15918
15919 // Finally, do a correct 1st and 2nd try:
15920 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15921 pass = (err == VK_SUCCESS);
15922 ASSERT_TRUE(pass);
15923 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15924 pass = (err == VK_SUCCESS);
15925 ASSERT_TRUE(pass);
15926
15927 // Create a swapchain:
15928
15929 // First, try without a pointer to swapchain_create_info:
15930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15931 "specified as NULL");
15932
15933 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15934 pass = (err != VK_SUCCESS);
15935 ASSERT_TRUE(pass);
15936 m_errorMonitor->VerifyFound();
15937
15938 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15939 // sType:
15940 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15942
15943 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15944 pass = (err != VK_SUCCESS);
15945 ASSERT_TRUE(pass);
15946 m_errorMonitor->VerifyFound();
15947
15948 // Next, call with a NULL swapchain pointer:
15949 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15950 swapchain_create_info.pNext = NULL;
15951 swapchain_create_info.flags = 0;
15952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15953 "specified as NULL");
15954
15955 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15956 pass = (err != VK_SUCCESS);
15957 ASSERT_TRUE(pass);
15958 m_errorMonitor->VerifyFound();
15959
15960 // TODO: Enhance swapchain layer so that
15961 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15962
15963 // Next, call with a queue family index that's too large:
15964 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15965 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15966 swapchain_create_info.queueFamilyIndexCount = 2;
15967 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15969 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15970 pass = (err != VK_SUCCESS);
15971 ASSERT_TRUE(pass);
15972 m_errorMonitor->VerifyFound();
15973
15974 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15975 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15976 swapchain_create_info.queueFamilyIndexCount = 1;
15977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15978 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15979 "pCreateInfo->pQueueFamilyIndices).");
15980 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15981 pass = (err != VK_SUCCESS);
15982 ASSERT_TRUE(pass);
15983 m_errorMonitor->VerifyFound();
15984
15985 // Next, call with an invalid imageSharingMode:
15986 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15987 swapchain_create_info.queueFamilyIndexCount = 1;
15988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15989 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15990 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15991 pass = (err != VK_SUCCESS);
15992 ASSERT_TRUE(pass);
15993 m_errorMonitor->VerifyFound();
15994 // Fix for the future:
15995 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15996 // SUPPORTED
15997 swapchain_create_info.queueFamilyIndexCount = 0;
15998 queueFamilyIndex[0] = 0;
15999 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16000
16001 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16002 // Get the images from a swapchain:
16003 // Acquire an image from a swapchain:
16004 // Present an image to a swapchain:
16005 // Destroy the swapchain:
16006
16007 // TODOs:
16008 //
16009 // - Try destroying the device without first destroying the swapchain
16010 //
16011 // - Try destroying the device without first destroying the surface
16012 //
16013 // - Try destroying the surface without first destroying the swapchain
16014
16015 // Destroy the surface:
16016 vkDestroySurfaceKHR(instance(), surface, NULL);
16017
16018 // Tear down the window:
16019 xcb_destroy_window(connection, xcb_window);
16020 xcb_disconnect(connection);
16021
16022#else // VK_USE_PLATFORM_XCB_KHR
16023 return;
16024#endif // VK_USE_PLATFORM_XCB_KHR
16025}
Chris Forbes09368e42016-10-13 11:59:22 +130016026#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016027
16028//
16029// POSITIVE VALIDATION TESTS
16030//
16031// These tests do not expect to encounter ANY validation errors pass only if this is true
16032
Tobin Ehlise0006882016-11-03 10:14:28 -060016033TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
16034 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
16035 "by a transition in the primary.");
16036 VkResult err;
16037 m_errorMonitor->ExpectSuccess();
16038 ASSERT_NO_FATAL_FAILURE(InitState());
16039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16040 // Allocate a secondary and primary cmd buffer
16041 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16042 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16043 command_buffer_allocate_info.commandPool = m_commandPool;
16044 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16045 command_buffer_allocate_info.commandBufferCount = 1;
16046
16047 VkCommandBuffer secondary_command_buffer;
16048 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16049 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16050 VkCommandBuffer primary_command_buffer;
16051 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16052 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16053 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16054 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16055 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16056 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16057 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16058
16059 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16060 ASSERT_VK_SUCCESS(err);
16061 VkImageObj image(m_device);
16062 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16063 ASSERT_TRUE(image.initialized());
16064 VkImageMemoryBarrier img_barrier = {};
16065 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16066 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16067 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16068 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16069 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16070 img_barrier.image = image.handle();
16071 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16072 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16073 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16074 img_barrier.subresourceRange.baseArrayLayer = 0;
16075 img_barrier.subresourceRange.baseMipLevel = 0;
16076 img_barrier.subresourceRange.layerCount = 1;
16077 img_barrier.subresourceRange.levelCount = 1;
16078 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16079 0, nullptr, 1, &img_barrier);
16080 err = vkEndCommandBuffer(secondary_command_buffer);
16081 ASSERT_VK_SUCCESS(err);
16082
16083 // Now update primary cmd buffer to execute secondary and transitions image
16084 command_buffer_begin_info.pInheritanceInfo = nullptr;
16085 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16086 ASSERT_VK_SUCCESS(err);
16087 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16088 VkImageMemoryBarrier img_barrier2 = {};
16089 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16090 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16091 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16092 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16093 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16094 img_barrier2.image = image.handle();
16095 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16096 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16097 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16098 img_barrier2.subresourceRange.baseArrayLayer = 0;
16099 img_barrier2.subresourceRange.baseMipLevel = 0;
16100 img_barrier2.subresourceRange.layerCount = 1;
16101 img_barrier2.subresourceRange.levelCount = 1;
16102 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16103 nullptr, 1, &img_barrier2);
16104 err = vkEndCommandBuffer(primary_command_buffer);
16105 ASSERT_VK_SUCCESS(err);
16106 VkSubmitInfo submit_info = {};
16107 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16108 submit_info.commandBufferCount = 1;
16109 submit_info.pCommandBuffers = &primary_command_buffer;
16110 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16111 ASSERT_VK_SUCCESS(err);
16112 m_errorMonitor->VerifyNotFound();
16113 err = vkDeviceWaitIdle(m_device->device());
16114 ASSERT_VK_SUCCESS(err);
16115 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16116 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16117}
16118
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016119// This is a positive test. No failures are expected.
16120TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16121 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16122 "is ignoring VkWriteDescriptorSet members that are not "
16123 "related to the descriptor type specified by "
16124 "VkWriteDescriptorSet::descriptorType. Correct "
16125 "validation behavior will result in the test running to "
16126 "completion without validation errors.");
16127
16128 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16129
16130 ASSERT_NO_FATAL_FAILURE(InitState());
16131
16132 // Image Case
16133 {
16134 m_errorMonitor->ExpectSuccess();
16135
16136 VkImage image;
16137 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16138 const int32_t tex_width = 32;
16139 const int32_t tex_height = 32;
16140 VkImageCreateInfo image_create_info = {};
16141 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16142 image_create_info.pNext = NULL;
16143 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16144 image_create_info.format = tex_format;
16145 image_create_info.extent.width = tex_width;
16146 image_create_info.extent.height = tex_height;
16147 image_create_info.extent.depth = 1;
16148 image_create_info.mipLevels = 1;
16149 image_create_info.arrayLayers = 1;
16150 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16151 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16152 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16153 image_create_info.flags = 0;
16154 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16155 ASSERT_VK_SUCCESS(err);
16156
16157 VkMemoryRequirements memory_reqs;
16158 VkDeviceMemory image_memory;
16159 bool pass;
16160 VkMemoryAllocateInfo memory_info = {};
16161 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16162 memory_info.pNext = NULL;
16163 memory_info.allocationSize = 0;
16164 memory_info.memoryTypeIndex = 0;
16165 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16166 memory_info.allocationSize = memory_reqs.size;
16167 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16168 ASSERT_TRUE(pass);
16169 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16170 ASSERT_VK_SUCCESS(err);
16171 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16172 ASSERT_VK_SUCCESS(err);
16173
16174 VkImageViewCreateInfo image_view_create_info = {};
16175 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16176 image_view_create_info.image = image;
16177 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16178 image_view_create_info.format = tex_format;
16179 image_view_create_info.subresourceRange.layerCount = 1;
16180 image_view_create_info.subresourceRange.baseMipLevel = 0;
16181 image_view_create_info.subresourceRange.levelCount = 1;
16182 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16183
16184 VkImageView view;
16185 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16186 ASSERT_VK_SUCCESS(err);
16187
16188 VkDescriptorPoolSize ds_type_count = {};
16189 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16190 ds_type_count.descriptorCount = 1;
16191
16192 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16193 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16194 ds_pool_ci.pNext = NULL;
16195 ds_pool_ci.maxSets = 1;
16196 ds_pool_ci.poolSizeCount = 1;
16197 ds_pool_ci.pPoolSizes = &ds_type_count;
16198
16199 VkDescriptorPool ds_pool;
16200 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16201 ASSERT_VK_SUCCESS(err);
16202
16203 VkDescriptorSetLayoutBinding dsl_binding = {};
16204 dsl_binding.binding = 0;
16205 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16206 dsl_binding.descriptorCount = 1;
16207 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16208 dsl_binding.pImmutableSamplers = NULL;
16209
16210 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16211 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16212 ds_layout_ci.pNext = NULL;
16213 ds_layout_ci.bindingCount = 1;
16214 ds_layout_ci.pBindings = &dsl_binding;
16215 VkDescriptorSetLayout ds_layout;
16216 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16217 ASSERT_VK_SUCCESS(err);
16218
16219 VkDescriptorSet descriptor_set;
16220 VkDescriptorSetAllocateInfo alloc_info = {};
16221 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16222 alloc_info.descriptorSetCount = 1;
16223 alloc_info.descriptorPool = ds_pool;
16224 alloc_info.pSetLayouts = &ds_layout;
16225 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16226 ASSERT_VK_SUCCESS(err);
16227
16228 VkDescriptorImageInfo image_info = {};
16229 image_info.imageView = view;
16230 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16231
16232 VkWriteDescriptorSet descriptor_write;
16233 memset(&descriptor_write, 0, sizeof(descriptor_write));
16234 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16235 descriptor_write.dstSet = descriptor_set;
16236 descriptor_write.dstBinding = 0;
16237 descriptor_write.descriptorCount = 1;
16238 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16239 descriptor_write.pImageInfo = &image_info;
16240
16241 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16242 // be
16243 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16244 // This will most likely produce a crash if the parameter_validation
16245 // layer
16246 // does not correctly ignore pBufferInfo.
16247 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16248 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16249
16250 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16251
16252 m_errorMonitor->VerifyNotFound();
16253
16254 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16255 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16256 vkDestroyImageView(m_device->device(), view, NULL);
16257 vkDestroyImage(m_device->device(), image, NULL);
16258 vkFreeMemory(m_device->device(), image_memory, NULL);
16259 }
16260
16261 // Buffer Case
16262 {
16263 m_errorMonitor->ExpectSuccess();
16264
16265 VkBuffer buffer;
16266 uint32_t queue_family_index = 0;
16267 VkBufferCreateInfo buffer_create_info = {};
16268 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16269 buffer_create_info.size = 1024;
16270 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16271 buffer_create_info.queueFamilyIndexCount = 1;
16272 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16273
16274 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16275 ASSERT_VK_SUCCESS(err);
16276
16277 VkMemoryRequirements memory_reqs;
16278 VkDeviceMemory buffer_memory;
16279 bool pass;
16280 VkMemoryAllocateInfo memory_info = {};
16281 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16282 memory_info.pNext = NULL;
16283 memory_info.allocationSize = 0;
16284 memory_info.memoryTypeIndex = 0;
16285
16286 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16287 memory_info.allocationSize = memory_reqs.size;
16288 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16289 ASSERT_TRUE(pass);
16290
16291 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16292 ASSERT_VK_SUCCESS(err);
16293 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16294 ASSERT_VK_SUCCESS(err);
16295
16296 VkDescriptorPoolSize ds_type_count = {};
16297 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16298 ds_type_count.descriptorCount = 1;
16299
16300 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16301 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16302 ds_pool_ci.pNext = NULL;
16303 ds_pool_ci.maxSets = 1;
16304 ds_pool_ci.poolSizeCount = 1;
16305 ds_pool_ci.pPoolSizes = &ds_type_count;
16306
16307 VkDescriptorPool ds_pool;
16308 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16309 ASSERT_VK_SUCCESS(err);
16310
16311 VkDescriptorSetLayoutBinding dsl_binding = {};
16312 dsl_binding.binding = 0;
16313 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16314 dsl_binding.descriptorCount = 1;
16315 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16316 dsl_binding.pImmutableSamplers = NULL;
16317
16318 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16319 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16320 ds_layout_ci.pNext = NULL;
16321 ds_layout_ci.bindingCount = 1;
16322 ds_layout_ci.pBindings = &dsl_binding;
16323 VkDescriptorSetLayout ds_layout;
16324 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16325 ASSERT_VK_SUCCESS(err);
16326
16327 VkDescriptorSet descriptor_set;
16328 VkDescriptorSetAllocateInfo alloc_info = {};
16329 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16330 alloc_info.descriptorSetCount = 1;
16331 alloc_info.descriptorPool = ds_pool;
16332 alloc_info.pSetLayouts = &ds_layout;
16333 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16334 ASSERT_VK_SUCCESS(err);
16335
16336 VkDescriptorBufferInfo buffer_info = {};
16337 buffer_info.buffer = buffer;
16338 buffer_info.offset = 0;
16339 buffer_info.range = 1024;
16340
16341 VkWriteDescriptorSet descriptor_write;
16342 memset(&descriptor_write, 0, sizeof(descriptor_write));
16343 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16344 descriptor_write.dstSet = descriptor_set;
16345 descriptor_write.dstBinding = 0;
16346 descriptor_write.descriptorCount = 1;
16347 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16348 descriptor_write.pBufferInfo = &buffer_info;
16349
16350 // Set pImageInfo and pTexelBufferView to invalid values, which should
16351 // be
16352 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16353 // This will most likely produce a crash if the parameter_validation
16354 // layer
16355 // does not correctly ignore pImageInfo.
16356 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16357 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16358
16359 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16360
16361 m_errorMonitor->VerifyNotFound();
16362
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016363 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16364 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16365 vkDestroyBuffer(m_device->device(), buffer, NULL);
16366 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16367 }
16368
16369 // Texel Buffer Case
16370 {
16371 m_errorMonitor->ExpectSuccess();
16372
16373 VkBuffer buffer;
16374 uint32_t queue_family_index = 0;
16375 VkBufferCreateInfo buffer_create_info = {};
16376 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16377 buffer_create_info.size = 1024;
16378 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16379 buffer_create_info.queueFamilyIndexCount = 1;
16380 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16381
16382 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16383 ASSERT_VK_SUCCESS(err);
16384
16385 VkMemoryRequirements memory_reqs;
16386 VkDeviceMemory buffer_memory;
16387 bool pass;
16388 VkMemoryAllocateInfo memory_info = {};
16389 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16390 memory_info.pNext = NULL;
16391 memory_info.allocationSize = 0;
16392 memory_info.memoryTypeIndex = 0;
16393
16394 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16395 memory_info.allocationSize = memory_reqs.size;
16396 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16397 ASSERT_TRUE(pass);
16398
16399 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16400 ASSERT_VK_SUCCESS(err);
16401 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16402 ASSERT_VK_SUCCESS(err);
16403
16404 VkBufferViewCreateInfo buff_view_ci = {};
16405 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16406 buff_view_ci.buffer = buffer;
16407 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16408 buff_view_ci.range = VK_WHOLE_SIZE;
16409 VkBufferView buffer_view;
16410 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16411
16412 VkDescriptorPoolSize ds_type_count = {};
16413 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16414 ds_type_count.descriptorCount = 1;
16415
16416 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16417 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16418 ds_pool_ci.pNext = NULL;
16419 ds_pool_ci.maxSets = 1;
16420 ds_pool_ci.poolSizeCount = 1;
16421 ds_pool_ci.pPoolSizes = &ds_type_count;
16422
16423 VkDescriptorPool ds_pool;
16424 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16425 ASSERT_VK_SUCCESS(err);
16426
16427 VkDescriptorSetLayoutBinding dsl_binding = {};
16428 dsl_binding.binding = 0;
16429 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16430 dsl_binding.descriptorCount = 1;
16431 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16432 dsl_binding.pImmutableSamplers = NULL;
16433
16434 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16435 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16436 ds_layout_ci.pNext = NULL;
16437 ds_layout_ci.bindingCount = 1;
16438 ds_layout_ci.pBindings = &dsl_binding;
16439 VkDescriptorSetLayout ds_layout;
16440 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16441 ASSERT_VK_SUCCESS(err);
16442
16443 VkDescriptorSet descriptor_set;
16444 VkDescriptorSetAllocateInfo alloc_info = {};
16445 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16446 alloc_info.descriptorSetCount = 1;
16447 alloc_info.descriptorPool = ds_pool;
16448 alloc_info.pSetLayouts = &ds_layout;
16449 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16450 ASSERT_VK_SUCCESS(err);
16451
16452 VkWriteDescriptorSet descriptor_write;
16453 memset(&descriptor_write, 0, sizeof(descriptor_write));
16454 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16455 descriptor_write.dstSet = descriptor_set;
16456 descriptor_write.dstBinding = 0;
16457 descriptor_write.descriptorCount = 1;
16458 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16459 descriptor_write.pTexelBufferView = &buffer_view;
16460
16461 // Set pImageInfo and pBufferInfo to invalid values, which should be
16462 // ignored for descriptorType ==
16463 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16464 // This will most likely produce a crash if the parameter_validation
16465 // layer
16466 // does not correctly ignore pImageInfo and pBufferInfo.
16467 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16468 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16469
16470 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16471
16472 m_errorMonitor->VerifyNotFound();
16473
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016474 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16475 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16476 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16477 vkDestroyBuffer(m_device->device(), buffer, NULL);
16478 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16479 }
16480}
16481
Tobin Ehlisf7428442016-10-25 07:58:24 -060016482TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16483 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16484
16485 ASSERT_NO_FATAL_FAILURE(InitState());
16486 // Create layout where two binding #s are "1"
16487 static const uint32_t NUM_BINDINGS = 3;
16488 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16489 dsl_binding[0].binding = 1;
16490 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16491 dsl_binding[0].descriptorCount = 1;
16492 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16493 dsl_binding[0].pImmutableSamplers = NULL;
16494 dsl_binding[1].binding = 0;
16495 dsl_binding[1].descriptorCount = 1;
16496 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16497 dsl_binding[1].descriptorCount = 1;
16498 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16499 dsl_binding[1].pImmutableSamplers = NULL;
16500 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16501 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16502 dsl_binding[2].descriptorCount = 1;
16503 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16504 dsl_binding[2].pImmutableSamplers = NULL;
16505
16506 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16507 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16508 ds_layout_ci.pNext = NULL;
16509 ds_layout_ci.bindingCount = NUM_BINDINGS;
16510 ds_layout_ci.pBindings = dsl_binding;
16511 VkDescriptorSetLayout ds_layout;
16512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16513 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16514 m_errorMonitor->VerifyFound();
16515}
16516
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016517TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016518 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16519
16520 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016521
16522 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016523
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016524 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16525
16526 {
16527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16528 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16529 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16530 m_errorMonitor->VerifyFound();
16531 }
16532
16533 {
16534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16535 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16536 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16537 m_errorMonitor->VerifyFound();
16538 }
16539
16540 {
16541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16542 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16543 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16544 m_errorMonitor->VerifyFound();
16545 }
16546
16547 {
16548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16549 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16550 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16551 m_errorMonitor->VerifyFound();
16552 }
16553
16554 {
16555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16556 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16557 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16558 m_errorMonitor->VerifyFound();
16559 }
16560
16561 {
16562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16563 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16564 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16565 m_errorMonitor->VerifyFound();
16566 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016567
16568 {
16569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16570 VkRect2D scissor = {{-1, 0}, {16, 16}};
16571 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16572 m_errorMonitor->VerifyFound();
16573 }
16574
16575 {
16576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16577 VkRect2D scissor = {{0, -2}, {16, 16}};
16578 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16579 m_errorMonitor->VerifyFound();
16580 }
16581
16582 {
16583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16584 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16585 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16586 m_errorMonitor->VerifyFound();
16587 }
16588
16589 {
16590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16591 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16592 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16593 m_errorMonitor->VerifyFound();
16594 }
16595
16596 EndCommandBuffer();
16597}
16598
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016599// This is a positive test. No failures are expected.
16600TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16601 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16602 VkResult err;
16603
16604 ASSERT_NO_FATAL_FAILURE(InitState());
16605 m_errorMonitor->ExpectSuccess();
16606 VkDescriptorPoolSize ds_type_count = {};
16607 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16608 ds_type_count.descriptorCount = 2;
16609
16610 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16611 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16612 ds_pool_ci.pNext = NULL;
16613 ds_pool_ci.maxSets = 1;
16614 ds_pool_ci.poolSizeCount = 1;
16615 ds_pool_ci.pPoolSizes = &ds_type_count;
16616
16617 VkDescriptorPool ds_pool;
16618 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16619 ASSERT_VK_SUCCESS(err);
16620
16621 // Create layout with two uniform buffer descriptors w/ empty binding between them
16622 static const uint32_t NUM_BINDINGS = 3;
16623 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16624 dsl_binding[0].binding = 0;
16625 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16626 dsl_binding[0].descriptorCount = 1;
16627 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16628 dsl_binding[0].pImmutableSamplers = NULL;
16629 dsl_binding[1].binding = 1;
16630 dsl_binding[1].descriptorCount = 0; // empty binding
16631 dsl_binding[2].binding = 2;
16632 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16633 dsl_binding[2].descriptorCount = 1;
16634 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16635 dsl_binding[2].pImmutableSamplers = NULL;
16636
16637 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16638 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16639 ds_layout_ci.pNext = NULL;
16640 ds_layout_ci.bindingCount = NUM_BINDINGS;
16641 ds_layout_ci.pBindings = dsl_binding;
16642 VkDescriptorSetLayout ds_layout;
16643 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16644 ASSERT_VK_SUCCESS(err);
16645
16646 VkDescriptorSet descriptor_set = {};
16647 VkDescriptorSetAllocateInfo alloc_info = {};
16648 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16649 alloc_info.descriptorSetCount = 1;
16650 alloc_info.descriptorPool = ds_pool;
16651 alloc_info.pSetLayouts = &ds_layout;
16652 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16653 ASSERT_VK_SUCCESS(err);
16654
16655 // Create a buffer to be used for update
16656 VkBufferCreateInfo buff_ci = {};
16657 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16658 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16659 buff_ci.size = 256;
16660 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16661 VkBuffer buffer;
16662 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16663 ASSERT_VK_SUCCESS(err);
16664 // Have to bind memory to buffer before descriptor update
16665 VkMemoryAllocateInfo mem_alloc = {};
16666 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16667 mem_alloc.pNext = NULL;
16668 mem_alloc.allocationSize = 512; // one allocation for both buffers
16669 mem_alloc.memoryTypeIndex = 0;
16670
16671 VkMemoryRequirements mem_reqs;
16672 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16673 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16674 if (!pass) {
16675 vkDestroyBuffer(m_device->device(), buffer, NULL);
16676 return;
16677 }
16678
16679 VkDeviceMemory mem;
16680 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16681 ASSERT_VK_SUCCESS(err);
16682 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16683 ASSERT_VK_SUCCESS(err);
16684
16685 // Only update the descriptor at binding 2
16686 VkDescriptorBufferInfo buff_info = {};
16687 buff_info.buffer = buffer;
16688 buff_info.offset = 0;
16689 buff_info.range = VK_WHOLE_SIZE;
16690 VkWriteDescriptorSet descriptor_write = {};
16691 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16692 descriptor_write.dstBinding = 2;
16693 descriptor_write.descriptorCount = 1;
16694 descriptor_write.pTexelBufferView = nullptr;
16695 descriptor_write.pBufferInfo = &buff_info;
16696 descriptor_write.pImageInfo = nullptr;
16697 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16698 descriptor_write.dstSet = descriptor_set;
16699
16700 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16701
16702 m_errorMonitor->VerifyNotFound();
16703 // Cleanup
16704 vkFreeMemory(m_device->device(), mem, NULL);
16705 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16706 vkDestroyBuffer(m_device->device(), buffer, NULL);
16707 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16708}
16709
16710// This is a positive test. No failures are expected.
16711TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16712 VkResult err;
16713 bool pass;
16714
16715 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16716 "the buffer, create an image, and bind the same memory to "
16717 "it");
16718
16719 m_errorMonitor->ExpectSuccess();
16720
16721 ASSERT_NO_FATAL_FAILURE(InitState());
16722
16723 VkBuffer buffer;
16724 VkImage image;
16725 VkDeviceMemory mem;
16726 VkMemoryRequirements mem_reqs;
16727
16728 VkBufferCreateInfo buf_info = {};
16729 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16730 buf_info.pNext = NULL;
16731 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16732 buf_info.size = 256;
16733 buf_info.queueFamilyIndexCount = 0;
16734 buf_info.pQueueFamilyIndices = NULL;
16735 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16736 buf_info.flags = 0;
16737 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16738 ASSERT_VK_SUCCESS(err);
16739
16740 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16741
16742 VkMemoryAllocateInfo alloc_info = {};
16743 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16744 alloc_info.pNext = NULL;
16745 alloc_info.memoryTypeIndex = 0;
16746
16747 // Ensure memory is big enough for both bindings
16748 alloc_info.allocationSize = 0x10000;
16749
16750 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16751 if (!pass) {
16752 vkDestroyBuffer(m_device->device(), buffer, NULL);
16753 return;
16754 }
16755
16756 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16757 ASSERT_VK_SUCCESS(err);
16758
16759 uint8_t *pData;
16760 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16761 ASSERT_VK_SUCCESS(err);
16762
16763 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16764
16765 vkUnmapMemory(m_device->device(), mem);
16766
16767 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16768 ASSERT_VK_SUCCESS(err);
16769
16770 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16771 // memory. In fact, it was never used by the GPU.
16772 // Just be be sure, wait for idle.
16773 vkDestroyBuffer(m_device->device(), buffer, NULL);
16774 vkDeviceWaitIdle(m_device->device());
16775
16776 VkImageCreateInfo image_create_info = {};
16777 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16778 image_create_info.pNext = NULL;
16779 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16780 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16781 image_create_info.extent.width = 64;
16782 image_create_info.extent.height = 64;
16783 image_create_info.extent.depth = 1;
16784 image_create_info.mipLevels = 1;
16785 image_create_info.arrayLayers = 1;
16786 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16787 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16788 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16789 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16790 image_create_info.queueFamilyIndexCount = 0;
16791 image_create_info.pQueueFamilyIndices = NULL;
16792 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16793 image_create_info.flags = 0;
16794
16795 VkMemoryAllocateInfo mem_alloc = {};
16796 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16797 mem_alloc.pNext = NULL;
16798 mem_alloc.allocationSize = 0;
16799 mem_alloc.memoryTypeIndex = 0;
16800
16801 /* Create a mappable image. It will be the texture if linear images are ok
16802 * to be textures or it will be the staging image if they are not.
16803 */
16804 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16805 ASSERT_VK_SUCCESS(err);
16806
16807 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16808
16809 mem_alloc.allocationSize = mem_reqs.size;
16810
16811 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16812 if (!pass) {
16813 vkDestroyImage(m_device->device(), image, NULL);
16814 return;
16815 }
16816
16817 // VALIDATION FAILURE:
16818 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16819 ASSERT_VK_SUCCESS(err);
16820
16821 m_errorMonitor->VerifyNotFound();
16822
16823 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016824 vkDestroyImage(m_device->device(), image, NULL);
16825}
16826
Tobin Ehlis953e8392016-11-17 10:54:13 -070016827TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16828 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16829 // We previously had a bug where dynamic offset of inactive bindings was still being used
16830 VkResult err;
16831 m_errorMonitor->ExpectSuccess();
16832
16833 ASSERT_NO_FATAL_FAILURE(InitState());
16834 ASSERT_NO_FATAL_FAILURE(InitViewport());
16835 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16836
16837 VkDescriptorPoolSize ds_type_count = {};
16838 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16839 ds_type_count.descriptorCount = 3;
16840
16841 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16842 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16843 ds_pool_ci.pNext = NULL;
16844 ds_pool_ci.maxSets = 1;
16845 ds_pool_ci.poolSizeCount = 1;
16846 ds_pool_ci.pPoolSizes = &ds_type_count;
16847
16848 VkDescriptorPool ds_pool;
16849 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16850 ASSERT_VK_SUCCESS(err);
16851
16852 const uint32_t BINDING_COUNT = 3;
16853 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016854 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016855 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16856 dsl_binding[0].descriptorCount = 1;
16857 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16858 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016859 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016860 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16861 dsl_binding[1].descriptorCount = 1;
16862 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16863 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016864 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016865 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16866 dsl_binding[2].descriptorCount = 1;
16867 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16868 dsl_binding[2].pImmutableSamplers = NULL;
16869
16870 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16871 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16872 ds_layout_ci.pNext = NULL;
16873 ds_layout_ci.bindingCount = BINDING_COUNT;
16874 ds_layout_ci.pBindings = dsl_binding;
16875 VkDescriptorSetLayout ds_layout;
16876 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16877 ASSERT_VK_SUCCESS(err);
16878
16879 VkDescriptorSet descriptor_set;
16880 VkDescriptorSetAllocateInfo alloc_info = {};
16881 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16882 alloc_info.descriptorSetCount = 1;
16883 alloc_info.descriptorPool = ds_pool;
16884 alloc_info.pSetLayouts = &ds_layout;
16885 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16886 ASSERT_VK_SUCCESS(err);
16887
16888 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16889 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16890 pipeline_layout_ci.pNext = NULL;
16891 pipeline_layout_ci.setLayoutCount = 1;
16892 pipeline_layout_ci.pSetLayouts = &ds_layout;
16893
16894 VkPipelineLayout pipeline_layout;
16895 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16896 ASSERT_VK_SUCCESS(err);
16897
16898 // Create two buffers to update the descriptors with
16899 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16900 uint32_t qfi = 0;
16901 VkBufferCreateInfo buffCI = {};
16902 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16903 buffCI.size = 2048;
16904 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16905 buffCI.queueFamilyIndexCount = 1;
16906 buffCI.pQueueFamilyIndices = &qfi;
16907
16908 VkBuffer dyub1;
16909 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16910 ASSERT_VK_SUCCESS(err);
16911 // buffer2
16912 buffCI.size = 1024;
16913 VkBuffer dyub2;
16914 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16915 ASSERT_VK_SUCCESS(err);
16916 // Allocate memory and bind to buffers
16917 VkMemoryAllocateInfo mem_alloc[2] = {};
16918 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16919 mem_alloc[0].pNext = NULL;
16920 mem_alloc[0].memoryTypeIndex = 0;
16921 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16922 mem_alloc[1].pNext = NULL;
16923 mem_alloc[1].memoryTypeIndex = 0;
16924
16925 VkMemoryRequirements mem_reqs1;
16926 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16927 VkMemoryRequirements mem_reqs2;
16928 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16929 mem_alloc[0].allocationSize = mem_reqs1.size;
16930 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16931 mem_alloc[1].allocationSize = mem_reqs2.size;
16932 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16933 if (!pass) {
16934 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16935 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16936 return;
16937 }
16938
16939 VkDeviceMemory mem1;
16940 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16941 ASSERT_VK_SUCCESS(err);
16942 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16943 ASSERT_VK_SUCCESS(err);
16944 VkDeviceMemory mem2;
16945 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16946 ASSERT_VK_SUCCESS(err);
16947 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16948 ASSERT_VK_SUCCESS(err);
16949 // Update descriptors
16950 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16951 buff_info[0].buffer = dyub1;
16952 buff_info[0].offset = 0;
16953 buff_info[0].range = 256;
16954 buff_info[1].buffer = dyub1;
16955 buff_info[1].offset = 256;
16956 buff_info[1].range = 512;
16957 buff_info[2].buffer = dyub2;
16958 buff_info[2].offset = 0;
16959 buff_info[2].range = 512;
16960
16961 VkWriteDescriptorSet descriptor_write;
16962 memset(&descriptor_write, 0, sizeof(descriptor_write));
16963 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16964 descriptor_write.dstSet = descriptor_set;
16965 descriptor_write.dstBinding = 0;
16966 descriptor_write.descriptorCount = BINDING_COUNT;
16967 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16968 descriptor_write.pBufferInfo = buff_info;
16969
16970 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16971
16972 BeginCommandBuffer();
16973
16974 // Create PSO to be used for draw-time errors below
16975 char const *vsSource = "#version 450\n"
16976 "\n"
16977 "out gl_PerVertex { \n"
16978 " vec4 gl_Position;\n"
16979 "};\n"
16980 "void main(){\n"
16981 " gl_Position = vec4(1);\n"
16982 "}\n";
16983 char const *fsSource = "#version 450\n"
16984 "\n"
16985 "layout(location=0) out vec4 x;\n"
16986 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16987 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16988 "void main(){\n"
16989 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16990 "}\n";
16991 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16992 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16993 VkPipelineObj pipe(m_device);
16994 pipe.SetViewport(m_viewports);
16995 pipe.SetScissor(m_scissors);
16996 pipe.AddShader(&vs);
16997 pipe.AddShader(&fs);
16998 pipe.AddColorAttachment();
16999 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17000
17001 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17002 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17003 // we used to have a bug in this case.
17004 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17005 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17006 &descriptor_set, BINDING_COUNT, dyn_off);
17007 Draw(1, 0, 0, 0);
17008 m_errorMonitor->VerifyNotFound();
17009
17010 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17011 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17012 vkFreeMemory(m_device->device(), mem1, NULL);
17013 vkFreeMemory(m_device->device(), mem2, NULL);
17014
17015 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17016 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17017 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17018}
17019
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017020TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
17021
17022 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
17023 "mapping while using VK_WHOLE_SIZE does not cause access "
17024 "violations");
17025 VkResult err;
17026 uint8_t *pData;
17027 ASSERT_NO_FATAL_FAILURE(InitState());
17028
17029 VkDeviceMemory mem;
17030 VkMemoryRequirements mem_reqs;
17031 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017032 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017033 VkMemoryAllocateInfo alloc_info = {};
17034 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17035 alloc_info.pNext = NULL;
17036 alloc_info.memoryTypeIndex = 0;
17037
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017038 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017039 alloc_info.allocationSize = allocation_size;
17040
17041 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17042 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
17043 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17044 if (!pass) {
17045 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17046 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17047 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17048 if (!pass) {
17049 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17050 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17051 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17052 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17053 if (!pass) {
17054 return;
17055 }
17056 }
17057 }
17058
17059 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17060 ASSERT_VK_SUCCESS(err);
17061
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017062 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017063 m_errorMonitor->ExpectSuccess();
17064 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17065 ASSERT_VK_SUCCESS(err);
17066 VkMappedMemoryRange mmr = {};
17067 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17068 mmr.memory = mem;
17069 mmr.offset = 0;
17070 mmr.size = VK_WHOLE_SIZE;
17071 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17072 ASSERT_VK_SUCCESS(err);
17073 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17074 ASSERT_VK_SUCCESS(err);
17075 m_errorMonitor->VerifyNotFound();
17076 vkUnmapMemory(m_device->device(), mem);
17077
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017078 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017079 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017080 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017081 ASSERT_VK_SUCCESS(err);
17082 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17083 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017084 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017085 mmr.size = VK_WHOLE_SIZE;
17086 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17087 ASSERT_VK_SUCCESS(err);
17088 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17089 ASSERT_VK_SUCCESS(err);
17090 m_errorMonitor->VerifyNotFound();
17091 vkUnmapMemory(m_device->device(), mem);
17092
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017093 // Map with offset and size
17094 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017095 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017096 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017097 ASSERT_VK_SUCCESS(err);
17098 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17099 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017100 mmr.offset = 4 * atom_size;
17101 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017102 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17103 ASSERT_VK_SUCCESS(err);
17104 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17105 ASSERT_VK_SUCCESS(err);
17106 m_errorMonitor->VerifyNotFound();
17107 vkUnmapMemory(m_device->device(), mem);
17108
17109 // Map without offset and flush WHOLE_SIZE with two separate offsets
17110 m_errorMonitor->ExpectSuccess();
17111 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17112 ASSERT_VK_SUCCESS(err);
17113 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17114 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017115 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017116 mmr.size = VK_WHOLE_SIZE;
17117 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17118 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017119 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017120 mmr.size = VK_WHOLE_SIZE;
17121 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17122 ASSERT_VK_SUCCESS(err);
17123 m_errorMonitor->VerifyNotFound();
17124 vkUnmapMemory(m_device->device(), mem);
17125
17126 vkFreeMemory(m_device->device(), mem, NULL);
17127}
17128
17129// This is a positive test. We used to expect error in this case but spec now allows it
17130TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17131 m_errorMonitor->ExpectSuccess();
17132 vk_testing::Fence testFence;
17133 VkFenceCreateInfo fenceInfo = {};
17134 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17135 fenceInfo.pNext = NULL;
17136
17137 ASSERT_NO_FATAL_FAILURE(InitState());
17138 testFence.init(*m_device, fenceInfo);
17139 VkFence fences[1] = { testFence.handle() };
17140 VkResult result = vkResetFences(m_device->device(), 1, fences);
17141 ASSERT_VK_SUCCESS(result);
17142
17143 m_errorMonitor->VerifyNotFound();
17144}
17145
17146TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17147 m_errorMonitor->ExpectSuccess();
17148
17149 ASSERT_NO_FATAL_FAILURE(InitState());
17150 VkResult err;
17151
17152 // Record (empty!) command buffer that can be submitted multiple times
17153 // simultaneously.
17154 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17155 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17156 m_commandBuffer->BeginCommandBuffer(&cbbi);
17157 m_commandBuffer->EndCommandBuffer();
17158
17159 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17160 VkFence fence;
17161 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17162 ASSERT_VK_SUCCESS(err);
17163
17164 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17165 VkSemaphore s1, s2;
17166 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17167 ASSERT_VK_SUCCESS(err);
17168 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17169 ASSERT_VK_SUCCESS(err);
17170
17171 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17172 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17173 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17174 ASSERT_VK_SUCCESS(err);
17175
17176 // Submit CB again, signaling s2.
17177 si.pSignalSemaphores = &s2;
17178 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17179 ASSERT_VK_SUCCESS(err);
17180
17181 // Wait for fence.
17182 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17183 ASSERT_VK_SUCCESS(err);
17184
17185 // CB is still in flight from second submission, but semaphore s1 is no
17186 // longer in flight. delete it.
17187 vkDestroySemaphore(m_device->device(), s1, nullptr);
17188
17189 m_errorMonitor->VerifyNotFound();
17190
17191 // Force device idle and clean up remaining objects
17192 vkDeviceWaitIdle(m_device->device());
17193 vkDestroySemaphore(m_device->device(), s2, nullptr);
17194 vkDestroyFence(m_device->device(), fence, nullptr);
17195}
17196
17197TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17198 m_errorMonitor->ExpectSuccess();
17199
17200 ASSERT_NO_FATAL_FAILURE(InitState());
17201 VkResult err;
17202
17203 // A fence created signaled
17204 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17205 VkFence f1;
17206 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17207 ASSERT_VK_SUCCESS(err);
17208
17209 // A fence created not
17210 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17211 VkFence f2;
17212 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17213 ASSERT_VK_SUCCESS(err);
17214
17215 // Submit the unsignaled fence
17216 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17217 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17218
17219 // Wait on both fences, with signaled first.
17220 VkFence fences[] = { f1, f2 };
17221 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17222
17223 // Should have both retired!
17224 vkDestroyFence(m_device->device(), f1, nullptr);
17225 vkDestroyFence(m_device->device(), f2, nullptr);
17226
17227 m_errorMonitor->VerifyNotFound();
17228}
17229
17230TEST_F(VkPositiveLayerTest, ValidUsage) {
17231 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17232 "doesn't generate validation errors");
17233
17234 ASSERT_NO_FATAL_FAILURE(InitState());
17235
17236 m_errorMonitor->ExpectSuccess();
17237 // Verify that we can create a view with usage INPUT_ATTACHMENT
17238 VkImageObj image(m_device);
17239 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17240 ASSERT_TRUE(image.initialized());
17241 VkImageView imageView;
17242 VkImageViewCreateInfo ivci = {};
17243 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17244 ivci.image = image.handle();
17245 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17246 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17247 ivci.subresourceRange.layerCount = 1;
17248 ivci.subresourceRange.baseMipLevel = 0;
17249 ivci.subresourceRange.levelCount = 1;
17250 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17251
17252 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17253 m_errorMonitor->VerifyNotFound();
17254 vkDestroyImageView(m_device->device(), imageView, NULL);
17255}
17256
17257// This is a positive test. No failures are expected.
17258TEST_F(VkPositiveLayerTest, BindSparse) {
17259 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17260 "and then free the memory");
17261
17262 ASSERT_NO_FATAL_FAILURE(InitState());
17263
17264 auto index = m_device->graphics_queue_node_index_;
17265 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17266 return;
17267
17268 m_errorMonitor->ExpectSuccess();
17269
17270 VkImage image;
17271 VkImageCreateInfo image_create_info = {};
17272 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17273 image_create_info.pNext = NULL;
17274 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17275 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17276 image_create_info.extent.width = 64;
17277 image_create_info.extent.height = 64;
17278 image_create_info.extent.depth = 1;
17279 image_create_info.mipLevels = 1;
17280 image_create_info.arrayLayers = 1;
17281 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17282 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17283 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17284 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17285 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17286 ASSERT_VK_SUCCESS(err);
17287
17288 VkMemoryRequirements memory_reqs;
17289 VkDeviceMemory memory_one, memory_two;
17290 bool pass;
17291 VkMemoryAllocateInfo memory_info = {};
17292 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17293 memory_info.pNext = NULL;
17294 memory_info.allocationSize = 0;
17295 memory_info.memoryTypeIndex = 0;
17296 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17297 // Find an image big enough to allow sparse mapping of 2 memory regions
17298 // Increase the image size until it is at least twice the
17299 // size of the required alignment, to ensure we can bind both
17300 // allocated memory blocks to the image on aligned offsets.
17301 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17302 vkDestroyImage(m_device->device(), image, nullptr);
17303 image_create_info.extent.width *= 2;
17304 image_create_info.extent.height *= 2;
17305 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17306 ASSERT_VK_SUCCESS(err);
17307 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17308 }
17309 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17310 // at the end of the first
17311 memory_info.allocationSize = memory_reqs.alignment;
17312 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17313 ASSERT_TRUE(pass);
17314 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17315 ASSERT_VK_SUCCESS(err);
17316 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17317 ASSERT_VK_SUCCESS(err);
17318 VkSparseMemoryBind binds[2];
17319 binds[0].flags = 0;
17320 binds[0].memory = memory_one;
17321 binds[0].memoryOffset = 0;
17322 binds[0].resourceOffset = 0;
17323 binds[0].size = memory_info.allocationSize;
17324 binds[1].flags = 0;
17325 binds[1].memory = memory_two;
17326 binds[1].memoryOffset = 0;
17327 binds[1].resourceOffset = memory_info.allocationSize;
17328 binds[1].size = memory_info.allocationSize;
17329
17330 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17331 opaqueBindInfo.image = image;
17332 opaqueBindInfo.bindCount = 2;
17333 opaqueBindInfo.pBinds = binds;
17334
17335 VkFence fence = VK_NULL_HANDLE;
17336 VkBindSparseInfo bindSparseInfo = {};
17337 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17338 bindSparseInfo.imageOpaqueBindCount = 1;
17339 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17340
17341 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17342 vkQueueWaitIdle(m_device->m_queue);
17343 vkDestroyImage(m_device->device(), image, NULL);
17344 vkFreeMemory(m_device->device(), memory_one, NULL);
17345 vkFreeMemory(m_device->device(), memory_two, NULL);
17346 m_errorMonitor->VerifyNotFound();
17347}
17348
17349TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17350 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17351 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17352 "the command buffer has prior knowledge of that "
17353 "attachment's layout.");
17354
17355 m_errorMonitor->ExpectSuccess();
17356
17357 ASSERT_NO_FATAL_FAILURE(InitState());
17358
17359 // A renderpass with one color attachment.
17360 VkAttachmentDescription attachment = { 0,
17361 VK_FORMAT_R8G8B8A8_UNORM,
17362 VK_SAMPLE_COUNT_1_BIT,
17363 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17364 VK_ATTACHMENT_STORE_OP_STORE,
17365 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17366 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17367 VK_IMAGE_LAYOUT_UNDEFINED,
17368 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17369
17370 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17371
17372 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17373
17374 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17375
17376 VkRenderPass rp;
17377 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17378 ASSERT_VK_SUCCESS(err);
17379
17380 // A compatible framebuffer.
17381 VkImageObj image(m_device);
17382 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17383 ASSERT_TRUE(image.initialized());
17384
17385 VkImageViewCreateInfo ivci = {
17386 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17387 nullptr,
17388 0,
17389 image.handle(),
17390 VK_IMAGE_VIEW_TYPE_2D,
17391 VK_FORMAT_R8G8B8A8_UNORM,
17392 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17393 VK_COMPONENT_SWIZZLE_IDENTITY },
17394 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17395 };
17396 VkImageView view;
17397 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17398 ASSERT_VK_SUCCESS(err);
17399
17400 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17401 VkFramebuffer fb;
17402 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17403 ASSERT_VK_SUCCESS(err);
17404
17405 // Record a single command buffer which uses this renderpass twice. The
17406 // bug is triggered at the beginning of the second renderpass, when the
17407 // command buffer already has a layout recorded for the attachment.
17408 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17409 BeginCommandBuffer();
17410 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17411 vkCmdEndRenderPass(m_commandBuffer->handle());
17412 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17413
17414 m_errorMonitor->VerifyNotFound();
17415
17416 vkCmdEndRenderPass(m_commandBuffer->handle());
17417 EndCommandBuffer();
17418
17419 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17420 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17421 vkDestroyImageView(m_device->device(), view, nullptr);
17422}
17423
17424TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17425 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17426 "command buffer, bind them together, then destroy "
17427 "command pool and framebuffer and verify there are no "
17428 "errors.");
17429
17430 m_errorMonitor->ExpectSuccess();
17431
17432 ASSERT_NO_FATAL_FAILURE(InitState());
17433
17434 // A renderpass with one color attachment.
17435 VkAttachmentDescription attachment = { 0,
17436 VK_FORMAT_R8G8B8A8_UNORM,
17437 VK_SAMPLE_COUNT_1_BIT,
17438 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17439 VK_ATTACHMENT_STORE_OP_STORE,
17440 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17441 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17442 VK_IMAGE_LAYOUT_UNDEFINED,
17443 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17444
17445 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17446
17447 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17448
17449 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17450
17451 VkRenderPass rp;
17452 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17453 ASSERT_VK_SUCCESS(err);
17454
17455 // A compatible framebuffer.
17456 VkImageObj image(m_device);
17457 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17458 ASSERT_TRUE(image.initialized());
17459
17460 VkImageViewCreateInfo ivci = {
17461 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17462 nullptr,
17463 0,
17464 image.handle(),
17465 VK_IMAGE_VIEW_TYPE_2D,
17466 VK_FORMAT_R8G8B8A8_UNORM,
17467 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17468 VK_COMPONENT_SWIZZLE_IDENTITY },
17469 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17470 };
17471 VkImageView view;
17472 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17473 ASSERT_VK_SUCCESS(err);
17474
17475 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17476 VkFramebuffer fb;
17477 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17478 ASSERT_VK_SUCCESS(err);
17479
17480 // Explicitly create a command buffer to bind the FB to so that we can then
17481 // destroy the command pool in order to implicitly free command buffer
17482 VkCommandPool command_pool;
17483 VkCommandPoolCreateInfo pool_create_info{};
17484 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17485 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17486 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17487 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17488
17489 VkCommandBuffer command_buffer;
17490 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17491 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17492 command_buffer_allocate_info.commandPool = command_pool;
17493 command_buffer_allocate_info.commandBufferCount = 1;
17494 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17495 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17496
17497 // Begin our cmd buffer with renderpass using our framebuffer
17498 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17499 VkCommandBufferBeginInfo begin_info{};
17500 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17501 vkBeginCommandBuffer(command_buffer, &begin_info);
17502
17503 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17504 vkCmdEndRenderPass(command_buffer);
17505 vkEndCommandBuffer(command_buffer);
17506 vkDestroyImageView(m_device->device(), view, nullptr);
17507 // Destroy command pool to implicitly free command buffer
17508 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17509 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17510 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17511 m_errorMonitor->VerifyNotFound();
17512}
17513
17514TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17515 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17516 "transitions for the first subpass");
17517
17518 m_errorMonitor->ExpectSuccess();
17519
17520 ASSERT_NO_FATAL_FAILURE(InitState());
17521
17522 // A renderpass with one color attachment.
17523 VkAttachmentDescription attachment = { 0,
17524 VK_FORMAT_R8G8B8A8_UNORM,
17525 VK_SAMPLE_COUNT_1_BIT,
17526 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17527 VK_ATTACHMENT_STORE_OP_STORE,
17528 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17529 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17530 VK_IMAGE_LAYOUT_UNDEFINED,
17531 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17532
17533 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17534
17535 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17536
17537 VkSubpassDependency dep = { 0,
17538 0,
17539 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17540 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17541 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17542 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17543 VK_DEPENDENCY_BY_REGION_BIT };
17544
17545 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17546
17547 VkResult err;
17548 VkRenderPass rp;
17549 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17550 ASSERT_VK_SUCCESS(err);
17551
17552 // A compatible framebuffer.
17553 VkImageObj image(m_device);
17554 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17555 ASSERT_TRUE(image.initialized());
17556
17557 VkImageViewCreateInfo ivci = {
17558 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17559 nullptr,
17560 0,
17561 image.handle(),
17562 VK_IMAGE_VIEW_TYPE_2D,
17563 VK_FORMAT_R8G8B8A8_UNORM,
17564 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17565 VK_COMPONENT_SWIZZLE_IDENTITY },
17566 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17567 };
17568 VkImageView view;
17569 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17570 ASSERT_VK_SUCCESS(err);
17571
17572 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17573 VkFramebuffer fb;
17574 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17575 ASSERT_VK_SUCCESS(err);
17576
17577 // Record a single command buffer which issues a pipeline barrier w/
17578 // image memory barrier for the attachment. This detects the previously
17579 // missing tracking of the subpass layout by throwing a validation error
17580 // if it doesn't occur.
17581 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17582 BeginCommandBuffer();
17583 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17584
17585 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17586 nullptr,
17587 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17588 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17589 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17590 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17591 VK_QUEUE_FAMILY_IGNORED,
17592 VK_QUEUE_FAMILY_IGNORED,
17593 image.handle(),
17594 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17595 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17596 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17597 &imb);
17598
17599 vkCmdEndRenderPass(m_commandBuffer->handle());
17600 m_errorMonitor->VerifyNotFound();
17601 EndCommandBuffer();
17602
17603 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17604 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17605 vkDestroyImageView(m_device->device(), view, nullptr);
17606}
17607
17608TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17609 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17610 "is used as a depth/stencil framebuffer attachment, the "
17611 "aspectMask is ignored and both depth and stencil image "
17612 "subresources are used.");
17613
17614 VkFormatProperties format_properties;
17615 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17616 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17617 return;
17618 }
17619
17620 m_errorMonitor->ExpectSuccess();
17621
17622 ASSERT_NO_FATAL_FAILURE(InitState());
17623
17624 VkAttachmentDescription attachment = { 0,
17625 VK_FORMAT_D32_SFLOAT_S8_UINT,
17626 VK_SAMPLE_COUNT_1_BIT,
17627 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17628 VK_ATTACHMENT_STORE_OP_STORE,
17629 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17630 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17631 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17632 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17633
17634 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17635
17636 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17637
17638 VkSubpassDependency dep = { 0,
17639 0,
17640 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17641 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17642 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17643 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17644 VK_DEPENDENCY_BY_REGION_BIT};
17645
17646 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17647
17648 VkResult err;
17649 VkRenderPass rp;
17650 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17651 ASSERT_VK_SUCCESS(err);
17652
17653 VkImageObj image(m_device);
17654 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17655 0x26, // usage
17656 VK_IMAGE_TILING_OPTIMAL, 0);
17657 ASSERT_TRUE(image.initialized());
17658 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17659
17660 VkImageViewCreateInfo ivci = {
17661 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17662 nullptr,
17663 0,
17664 image.handle(),
17665 VK_IMAGE_VIEW_TYPE_2D,
17666 VK_FORMAT_D32_SFLOAT_S8_UINT,
17667 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17668 { 0x2, 0, 1, 0, 1 },
17669 };
17670 VkImageView view;
17671 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17672 ASSERT_VK_SUCCESS(err);
17673
17674 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17675 VkFramebuffer fb;
17676 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17677 ASSERT_VK_SUCCESS(err);
17678
17679 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17680 BeginCommandBuffer();
17681 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17682
17683 VkImageMemoryBarrier imb = {};
17684 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17685 imb.pNext = nullptr;
17686 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17687 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17688 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17689 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17690 imb.srcQueueFamilyIndex = 0;
17691 imb.dstQueueFamilyIndex = 0;
17692 imb.image = image.handle();
17693 imb.subresourceRange.aspectMask = 0x6;
17694 imb.subresourceRange.baseMipLevel = 0;
17695 imb.subresourceRange.levelCount = 0x1;
17696 imb.subresourceRange.baseArrayLayer = 0;
17697 imb.subresourceRange.layerCount = 0x1;
17698
17699 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17700 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17701 &imb);
17702
17703 vkCmdEndRenderPass(m_commandBuffer->handle());
17704 EndCommandBuffer();
17705 QueueCommandBuffer(false);
17706 m_errorMonitor->VerifyNotFound();
17707
17708 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17709 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17710 vkDestroyImageView(m_device->device(), view, nullptr);
17711}
17712
17713TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17714 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17715 "errors, when an attachment reference is "
17716 "VK_ATTACHMENT_UNUSED");
17717
17718 m_errorMonitor->ExpectSuccess();
17719
17720 ASSERT_NO_FATAL_FAILURE(InitState());
17721
17722 // A renderpass with no attachments
17723 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17724
17725 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17726
17727 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17728
17729 VkRenderPass rp;
17730 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17731 ASSERT_VK_SUCCESS(err);
17732
17733 // A compatible framebuffer.
17734 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17735 VkFramebuffer fb;
17736 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17737 ASSERT_VK_SUCCESS(err);
17738
17739 // Record a command buffer which just begins and ends the renderpass. The
17740 // bug manifests in BeginRenderPass.
17741 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17742 BeginCommandBuffer();
17743 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17744 vkCmdEndRenderPass(m_commandBuffer->handle());
17745 m_errorMonitor->VerifyNotFound();
17746 EndCommandBuffer();
17747
17748 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17749 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17750}
17751
17752// This is a positive test. No errors are expected.
17753TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17754 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17755 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17756 VkResult result = VK_SUCCESS;
17757 VkImageFormatProperties formatProps;
17758 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17759 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17760 &formatProps);
17761 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17762 return;
17763 }
17764
17765 ASSERT_NO_FATAL_FAILURE(InitState());
17766 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17767 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17768 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17769 VkAttachmentDescription att = {};
17770 VkAttachmentReference ref = {};
17771 att.format = depth_stencil_fmt;
17772 att.samples = VK_SAMPLE_COUNT_1_BIT;
17773 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17774 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17775 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17776 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17777 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17778 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17779
17780 VkClearValue clear;
17781 clear.depthStencil.depth = 1.0;
17782 clear.depthStencil.stencil = 0;
17783 ref.attachment = 0;
17784 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17785
17786 VkSubpassDescription subpass = {};
17787 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17788 subpass.flags = 0;
17789 subpass.inputAttachmentCount = 0;
17790 subpass.pInputAttachments = NULL;
17791 subpass.colorAttachmentCount = 0;
17792 subpass.pColorAttachments = NULL;
17793 subpass.pResolveAttachments = NULL;
17794 subpass.pDepthStencilAttachment = &ref;
17795 subpass.preserveAttachmentCount = 0;
17796 subpass.pPreserveAttachments = NULL;
17797
17798 VkRenderPass rp;
17799 VkRenderPassCreateInfo rp_info = {};
17800 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17801 rp_info.attachmentCount = 1;
17802 rp_info.pAttachments = &att;
17803 rp_info.subpassCount = 1;
17804 rp_info.pSubpasses = &subpass;
17805 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17806 ASSERT_VK_SUCCESS(result);
17807
17808 VkImageView *depthView = m_depthStencil->BindInfo();
17809 VkFramebufferCreateInfo fb_info = {};
17810 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17811 fb_info.pNext = NULL;
17812 fb_info.renderPass = rp;
17813 fb_info.attachmentCount = 1;
17814 fb_info.pAttachments = depthView;
17815 fb_info.width = 100;
17816 fb_info.height = 100;
17817 fb_info.layers = 1;
17818 VkFramebuffer fb;
17819 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17820 ASSERT_VK_SUCCESS(result);
17821
17822 VkRenderPassBeginInfo rpbinfo = {};
17823 rpbinfo.clearValueCount = 1;
17824 rpbinfo.pClearValues = &clear;
17825 rpbinfo.pNext = NULL;
17826 rpbinfo.renderPass = rp;
17827 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17828 rpbinfo.renderArea.extent.width = 100;
17829 rpbinfo.renderArea.extent.height = 100;
17830 rpbinfo.renderArea.offset.x = 0;
17831 rpbinfo.renderArea.offset.y = 0;
17832 rpbinfo.framebuffer = fb;
17833
17834 VkFence fence = {};
17835 VkFenceCreateInfo fence_ci = {};
17836 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17837 fence_ci.pNext = nullptr;
17838 fence_ci.flags = 0;
17839 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17840 ASSERT_VK_SUCCESS(result);
17841
17842 m_commandBuffer->BeginCommandBuffer();
17843 m_commandBuffer->BeginRenderPass(rpbinfo);
17844 m_commandBuffer->EndRenderPass();
17845 m_commandBuffer->EndCommandBuffer();
17846 m_commandBuffer->QueueCommandBuffer(fence);
17847
17848 VkImageObj destImage(m_device);
17849 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17850 VK_IMAGE_TILING_OPTIMAL, 0);
17851 VkImageMemoryBarrier barrier = {};
17852 VkImageSubresourceRange range;
17853 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17854 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17855 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17856 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17857 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17858 barrier.image = m_depthStencil->handle();
17859 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17860 range.baseMipLevel = 0;
17861 range.levelCount = 1;
17862 range.baseArrayLayer = 0;
17863 range.layerCount = 1;
17864 barrier.subresourceRange = range;
17865 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17866 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17867 cmdbuf.BeginCommandBuffer();
17868 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17869 &barrier);
17870 barrier.srcAccessMask = 0;
17871 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17872 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17873 barrier.image = destImage.handle();
17874 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17875 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17876 &barrier);
17877 VkImageCopy cregion;
17878 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17879 cregion.srcSubresource.mipLevel = 0;
17880 cregion.srcSubresource.baseArrayLayer = 0;
17881 cregion.srcSubresource.layerCount = 1;
17882 cregion.srcOffset.x = 0;
17883 cregion.srcOffset.y = 0;
17884 cregion.srcOffset.z = 0;
17885 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17886 cregion.dstSubresource.mipLevel = 0;
17887 cregion.dstSubresource.baseArrayLayer = 0;
17888 cregion.dstSubresource.layerCount = 1;
17889 cregion.dstOffset.x = 0;
17890 cregion.dstOffset.y = 0;
17891 cregion.dstOffset.z = 0;
17892 cregion.extent.width = 100;
17893 cregion.extent.height = 100;
17894 cregion.extent.depth = 1;
17895 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17896 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17897 cmdbuf.EndCommandBuffer();
17898
17899 VkSubmitInfo submit_info;
17900 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17901 submit_info.pNext = NULL;
17902 submit_info.waitSemaphoreCount = 0;
17903 submit_info.pWaitSemaphores = NULL;
17904 submit_info.pWaitDstStageMask = NULL;
17905 submit_info.commandBufferCount = 1;
17906 submit_info.pCommandBuffers = &cmdbuf.handle();
17907 submit_info.signalSemaphoreCount = 0;
17908 submit_info.pSignalSemaphores = NULL;
17909
17910 m_errorMonitor->ExpectSuccess();
17911 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17912 m_errorMonitor->VerifyNotFound();
17913
17914 vkQueueWaitIdle(m_device->m_queue);
17915 vkDestroyFence(m_device->device(), fence, nullptr);
17916 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17917 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17918}
17919
17920// This is a positive test. No errors should be generated.
17921TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17922 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17923
17924 m_errorMonitor->ExpectSuccess();
17925 ASSERT_NO_FATAL_FAILURE(InitState());
17926
17927 VkEvent event;
17928 VkEventCreateInfo event_create_info{};
17929 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17930 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17931
17932 VkCommandPool command_pool;
17933 VkCommandPoolCreateInfo pool_create_info{};
17934 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17935 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17936 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17937 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17938
17939 VkCommandBuffer command_buffer;
17940 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17941 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17942 command_buffer_allocate_info.commandPool = command_pool;
17943 command_buffer_allocate_info.commandBufferCount = 1;
17944 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17945 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17946
17947 VkQueue queue = VK_NULL_HANDLE;
17948 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17949
17950 {
17951 VkCommandBufferBeginInfo begin_info{};
17952 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17953 vkBeginCommandBuffer(command_buffer, &begin_info);
17954
17955 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17956 nullptr, 0, nullptr);
17957 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17958 vkEndCommandBuffer(command_buffer);
17959 }
17960 {
17961 VkSubmitInfo submit_info{};
17962 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17963 submit_info.commandBufferCount = 1;
17964 submit_info.pCommandBuffers = &command_buffer;
17965 submit_info.signalSemaphoreCount = 0;
17966 submit_info.pSignalSemaphores = nullptr;
17967 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17968 }
17969 { vkSetEvent(m_device->device(), event); }
17970
17971 vkQueueWaitIdle(queue);
17972
17973 vkDestroyEvent(m_device->device(), event, nullptr);
17974 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17975 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17976
17977 m_errorMonitor->VerifyNotFound();
17978}
17979// This is a positive test. No errors should be generated.
17980TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17981 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17982
17983 ASSERT_NO_FATAL_FAILURE(InitState());
17984 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17985 return;
17986
17987 m_errorMonitor->ExpectSuccess();
17988
17989 VkQueryPool query_pool;
17990 VkQueryPoolCreateInfo query_pool_create_info{};
17991 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17992 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17993 query_pool_create_info.queryCount = 1;
17994 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17995
17996 VkCommandPool command_pool;
17997 VkCommandPoolCreateInfo pool_create_info{};
17998 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17999 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18000 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18001 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18002
18003 VkCommandBuffer command_buffer;
18004 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18005 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18006 command_buffer_allocate_info.commandPool = command_pool;
18007 command_buffer_allocate_info.commandBufferCount = 1;
18008 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18009 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18010
18011 VkCommandBuffer secondary_command_buffer;
18012 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18013 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18014
18015 VkQueue queue = VK_NULL_HANDLE;
18016 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18017
18018 uint32_t qfi = 0;
18019 VkBufferCreateInfo buff_create_info = {};
18020 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18021 buff_create_info.size = 1024;
18022 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18023 buff_create_info.queueFamilyIndexCount = 1;
18024 buff_create_info.pQueueFamilyIndices = &qfi;
18025
18026 VkResult err;
18027 VkBuffer buffer;
18028 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18029 ASSERT_VK_SUCCESS(err);
18030 VkMemoryAllocateInfo mem_alloc = {};
18031 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18032 mem_alloc.pNext = NULL;
18033 mem_alloc.allocationSize = 1024;
18034 mem_alloc.memoryTypeIndex = 0;
18035
18036 VkMemoryRequirements memReqs;
18037 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18038 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18039 if (!pass) {
18040 vkDestroyBuffer(m_device->device(), buffer, NULL);
18041 return;
18042 }
18043
18044 VkDeviceMemory mem;
18045 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18046 ASSERT_VK_SUCCESS(err);
18047 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18048 ASSERT_VK_SUCCESS(err);
18049
18050 VkCommandBufferInheritanceInfo hinfo = {};
18051 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18052 hinfo.renderPass = VK_NULL_HANDLE;
18053 hinfo.subpass = 0;
18054 hinfo.framebuffer = VK_NULL_HANDLE;
18055 hinfo.occlusionQueryEnable = VK_FALSE;
18056 hinfo.queryFlags = 0;
18057 hinfo.pipelineStatistics = 0;
18058
18059 {
18060 VkCommandBufferBeginInfo begin_info{};
18061 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18062 begin_info.pInheritanceInfo = &hinfo;
18063 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18064
18065 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18066 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18067
18068 vkEndCommandBuffer(secondary_command_buffer);
18069
18070 begin_info.pInheritanceInfo = nullptr;
18071 vkBeginCommandBuffer(command_buffer, &begin_info);
18072
18073 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18074 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18075
18076 vkEndCommandBuffer(command_buffer);
18077 }
18078 {
18079 VkSubmitInfo submit_info{};
18080 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18081 submit_info.commandBufferCount = 1;
18082 submit_info.pCommandBuffers = &command_buffer;
18083 submit_info.signalSemaphoreCount = 0;
18084 submit_info.pSignalSemaphores = nullptr;
18085 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18086 }
18087
18088 vkQueueWaitIdle(queue);
18089
18090 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18091 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18092 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18093 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18094 vkDestroyBuffer(m_device->device(), buffer, NULL);
18095 vkFreeMemory(m_device->device(), mem, NULL);
18096
18097 m_errorMonitor->VerifyNotFound();
18098}
18099
18100// This is a positive test. No errors should be generated.
18101TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18102 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18103
18104 ASSERT_NO_FATAL_FAILURE(InitState());
18105 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18106 return;
18107
18108 m_errorMonitor->ExpectSuccess();
18109
18110 VkQueryPool query_pool;
18111 VkQueryPoolCreateInfo query_pool_create_info{};
18112 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18113 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18114 query_pool_create_info.queryCount = 1;
18115 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18116
18117 VkCommandPool command_pool;
18118 VkCommandPoolCreateInfo pool_create_info{};
18119 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18120 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18121 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18122 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18123
18124 VkCommandBuffer command_buffer[2];
18125 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18126 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18127 command_buffer_allocate_info.commandPool = command_pool;
18128 command_buffer_allocate_info.commandBufferCount = 2;
18129 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18130 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18131
18132 VkQueue queue = VK_NULL_HANDLE;
18133 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18134
18135 uint32_t qfi = 0;
18136 VkBufferCreateInfo buff_create_info = {};
18137 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18138 buff_create_info.size = 1024;
18139 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18140 buff_create_info.queueFamilyIndexCount = 1;
18141 buff_create_info.pQueueFamilyIndices = &qfi;
18142
18143 VkResult err;
18144 VkBuffer buffer;
18145 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18146 ASSERT_VK_SUCCESS(err);
18147 VkMemoryAllocateInfo mem_alloc = {};
18148 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18149 mem_alloc.pNext = NULL;
18150 mem_alloc.allocationSize = 1024;
18151 mem_alloc.memoryTypeIndex = 0;
18152
18153 VkMemoryRequirements memReqs;
18154 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18155 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18156 if (!pass) {
18157 vkDestroyBuffer(m_device->device(), buffer, NULL);
18158 return;
18159 }
18160
18161 VkDeviceMemory mem;
18162 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18163 ASSERT_VK_SUCCESS(err);
18164 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18165 ASSERT_VK_SUCCESS(err);
18166
18167 {
18168 VkCommandBufferBeginInfo begin_info{};
18169 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18170 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18171
18172 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18173 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18174
18175 vkEndCommandBuffer(command_buffer[0]);
18176
18177 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18178
18179 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18180
18181 vkEndCommandBuffer(command_buffer[1]);
18182 }
18183 {
18184 VkSubmitInfo submit_info{};
18185 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18186 submit_info.commandBufferCount = 2;
18187 submit_info.pCommandBuffers = command_buffer;
18188 submit_info.signalSemaphoreCount = 0;
18189 submit_info.pSignalSemaphores = nullptr;
18190 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18191 }
18192
18193 vkQueueWaitIdle(queue);
18194
18195 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18196 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18197 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18198 vkDestroyBuffer(m_device->device(), buffer, NULL);
18199 vkFreeMemory(m_device->device(), mem, NULL);
18200
18201 m_errorMonitor->VerifyNotFound();
18202}
18203
Tony Barbourc46924f2016-11-04 11:49:52 -060018204TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018205 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18206
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018207 ASSERT_NO_FATAL_FAILURE(InitState());
18208 VkEvent event;
18209 VkEventCreateInfo event_create_info{};
18210 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18211 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18212
18213 VkCommandPool command_pool;
18214 VkCommandPoolCreateInfo pool_create_info{};
18215 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18216 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18217 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18218 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18219
18220 VkCommandBuffer command_buffer;
18221 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18222 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18223 command_buffer_allocate_info.commandPool = command_pool;
18224 command_buffer_allocate_info.commandBufferCount = 1;
18225 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18226 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18227
18228 VkQueue queue = VK_NULL_HANDLE;
18229 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18230
18231 {
18232 VkCommandBufferBeginInfo begin_info{};
18233 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18234 vkBeginCommandBuffer(command_buffer, &begin_info);
18235
18236 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018237 vkEndCommandBuffer(command_buffer);
18238 }
18239 {
18240 VkSubmitInfo submit_info{};
18241 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18242 submit_info.commandBufferCount = 1;
18243 submit_info.pCommandBuffers = &command_buffer;
18244 submit_info.signalSemaphoreCount = 0;
18245 submit_info.pSignalSemaphores = nullptr;
18246 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18247 }
18248 {
18249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18250 "command buffer.");
18251 vkSetEvent(m_device->device(), event);
18252 m_errorMonitor->VerifyFound();
18253 }
18254
18255 vkQueueWaitIdle(queue);
18256
18257 vkDestroyEvent(m_device->device(), event, nullptr);
18258 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18259 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18260}
18261
18262// This is a positive test. No errors should be generated.
18263TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18264 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18265 "run through a Submit & WaitForFences cycle 3 times. This "
18266 "previously revealed a bug so running this positive test "
18267 "to prevent a regression.");
18268 m_errorMonitor->ExpectSuccess();
18269
18270 ASSERT_NO_FATAL_FAILURE(InitState());
18271 VkQueue queue = VK_NULL_HANDLE;
18272 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18273
18274 static const uint32_t NUM_OBJECTS = 2;
18275 static const uint32_t NUM_FRAMES = 3;
18276 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18277 VkFence fences[NUM_OBJECTS] = {};
18278
18279 VkCommandPool cmd_pool;
18280 VkCommandPoolCreateInfo cmd_pool_ci = {};
18281 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18282 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18283 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18284 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18285 ASSERT_VK_SUCCESS(err);
18286
18287 VkCommandBufferAllocateInfo cmd_buf_info = {};
18288 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18289 cmd_buf_info.commandPool = cmd_pool;
18290 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18291 cmd_buf_info.commandBufferCount = 1;
18292
18293 VkFenceCreateInfo fence_ci = {};
18294 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18295 fence_ci.pNext = nullptr;
18296 fence_ci.flags = 0;
18297
18298 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18299 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18300 ASSERT_VK_SUCCESS(err);
18301 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18302 ASSERT_VK_SUCCESS(err);
18303 }
18304
18305 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18306 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18307 // Create empty cmd buffer
18308 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18309 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18310
18311 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18312 ASSERT_VK_SUCCESS(err);
18313 err = vkEndCommandBuffer(cmd_buffers[obj]);
18314 ASSERT_VK_SUCCESS(err);
18315
18316 VkSubmitInfo submit_info = {};
18317 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18318 submit_info.commandBufferCount = 1;
18319 submit_info.pCommandBuffers = &cmd_buffers[obj];
18320 // Submit cmd buffer and wait for fence
18321 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18322 ASSERT_VK_SUCCESS(err);
18323 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18324 ASSERT_VK_SUCCESS(err);
18325 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18326 ASSERT_VK_SUCCESS(err);
18327 }
18328 }
18329 m_errorMonitor->VerifyNotFound();
18330 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18331 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18332 vkDestroyFence(m_device->device(), fences[i], nullptr);
18333 }
18334}
18335// This is a positive test. No errors should be generated.
18336TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18337
18338 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18339 "submitted on separate queues followed by a QueueWaitIdle.");
18340
18341 ASSERT_NO_FATAL_FAILURE(InitState());
18342 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18343 return;
18344
18345 m_errorMonitor->ExpectSuccess();
18346
18347 VkSemaphore semaphore;
18348 VkSemaphoreCreateInfo semaphore_create_info{};
18349 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18350 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18351
18352 VkCommandPool command_pool;
18353 VkCommandPoolCreateInfo pool_create_info{};
18354 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18355 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18356 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18357 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18358
18359 VkCommandBuffer command_buffer[2];
18360 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18361 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18362 command_buffer_allocate_info.commandPool = command_pool;
18363 command_buffer_allocate_info.commandBufferCount = 2;
18364 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18365 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18366
18367 VkQueue queue = VK_NULL_HANDLE;
18368 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18369
18370 {
18371 VkCommandBufferBeginInfo begin_info{};
18372 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18373 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18374
18375 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18376 nullptr, 0, nullptr, 0, nullptr);
18377
18378 VkViewport viewport{};
18379 viewport.maxDepth = 1.0f;
18380 viewport.minDepth = 0.0f;
18381 viewport.width = 512;
18382 viewport.height = 512;
18383 viewport.x = 0;
18384 viewport.y = 0;
18385 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18386 vkEndCommandBuffer(command_buffer[0]);
18387 }
18388 {
18389 VkCommandBufferBeginInfo begin_info{};
18390 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18391 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18392
18393 VkViewport viewport{};
18394 viewport.maxDepth = 1.0f;
18395 viewport.minDepth = 0.0f;
18396 viewport.width = 512;
18397 viewport.height = 512;
18398 viewport.x = 0;
18399 viewport.y = 0;
18400 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18401 vkEndCommandBuffer(command_buffer[1]);
18402 }
18403 {
18404 VkSubmitInfo submit_info{};
18405 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18406 submit_info.commandBufferCount = 1;
18407 submit_info.pCommandBuffers = &command_buffer[0];
18408 submit_info.signalSemaphoreCount = 1;
18409 submit_info.pSignalSemaphores = &semaphore;
18410 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18411 }
18412 {
18413 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18414 VkSubmitInfo submit_info{};
18415 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18416 submit_info.commandBufferCount = 1;
18417 submit_info.pCommandBuffers = &command_buffer[1];
18418 submit_info.waitSemaphoreCount = 1;
18419 submit_info.pWaitSemaphores = &semaphore;
18420 submit_info.pWaitDstStageMask = flags;
18421 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18422 }
18423
18424 vkQueueWaitIdle(m_device->m_queue);
18425
18426 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18427 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18428 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18429
18430 m_errorMonitor->VerifyNotFound();
18431}
18432
18433// This is a positive test. No errors should be generated.
18434TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18435
18436 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18437 "submitted on separate queues, the second having a fence"
18438 "followed by a QueueWaitIdle.");
18439
18440 ASSERT_NO_FATAL_FAILURE(InitState());
18441 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18442 return;
18443
18444 m_errorMonitor->ExpectSuccess();
18445
18446 VkFence fence;
18447 VkFenceCreateInfo fence_create_info{};
18448 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18449 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18450
18451 VkSemaphore semaphore;
18452 VkSemaphoreCreateInfo semaphore_create_info{};
18453 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18454 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18455
18456 VkCommandPool command_pool;
18457 VkCommandPoolCreateInfo pool_create_info{};
18458 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18459 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18460 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18461 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18462
18463 VkCommandBuffer command_buffer[2];
18464 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18465 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18466 command_buffer_allocate_info.commandPool = command_pool;
18467 command_buffer_allocate_info.commandBufferCount = 2;
18468 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18469 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18470
18471 VkQueue queue = VK_NULL_HANDLE;
18472 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18473
18474 {
18475 VkCommandBufferBeginInfo begin_info{};
18476 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18477 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18478
18479 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18480 nullptr, 0, nullptr, 0, nullptr);
18481
18482 VkViewport viewport{};
18483 viewport.maxDepth = 1.0f;
18484 viewport.minDepth = 0.0f;
18485 viewport.width = 512;
18486 viewport.height = 512;
18487 viewport.x = 0;
18488 viewport.y = 0;
18489 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18490 vkEndCommandBuffer(command_buffer[0]);
18491 }
18492 {
18493 VkCommandBufferBeginInfo begin_info{};
18494 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18495 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18496
18497 VkViewport viewport{};
18498 viewport.maxDepth = 1.0f;
18499 viewport.minDepth = 0.0f;
18500 viewport.width = 512;
18501 viewport.height = 512;
18502 viewport.x = 0;
18503 viewport.y = 0;
18504 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18505 vkEndCommandBuffer(command_buffer[1]);
18506 }
18507 {
18508 VkSubmitInfo submit_info{};
18509 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18510 submit_info.commandBufferCount = 1;
18511 submit_info.pCommandBuffers = &command_buffer[0];
18512 submit_info.signalSemaphoreCount = 1;
18513 submit_info.pSignalSemaphores = &semaphore;
18514 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18515 }
18516 {
18517 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18518 VkSubmitInfo submit_info{};
18519 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18520 submit_info.commandBufferCount = 1;
18521 submit_info.pCommandBuffers = &command_buffer[1];
18522 submit_info.waitSemaphoreCount = 1;
18523 submit_info.pWaitSemaphores = &semaphore;
18524 submit_info.pWaitDstStageMask = flags;
18525 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18526 }
18527
18528 vkQueueWaitIdle(m_device->m_queue);
18529
18530 vkDestroyFence(m_device->device(), fence, nullptr);
18531 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18532 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18533 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18534
18535 m_errorMonitor->VerifyNotFound();
18536}
18537
18538// This is a positive test. No errors should be generated.
18539TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18540
18541 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18542 "submitted on separate queues, the second having a fence"
18543 "followed by two consecutive WaitForFences calls on the same fence.");
18544
18545 ASSERT_NO_FATAL_FAILURE(InitState());
18546 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18547 return;
18548
18549 m_errorMonitor->ExpectSuccess();
18550
18551 VkFence fence;
18552 VkFenceCreateInfo fence_create_info{};
18553 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18554 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18555
18556 VkSemaphore semaphore;
18557 VkSemaphoreCreateInfo semaphore_create_info{};
18558 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18559 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18560
18561 VkCommandPool command_pool;
18562 VkCommandPoolCreateInfo pool_create_info{};
18563 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18564 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18565 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18566 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18567
18568 VkCommandBuffer command_buffer[2];
18569 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18570 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18571 command_buffer_allocate_info.commandPool = command_pool;
18572 command_buffer_allocate_info.commandBufferCount = 2;
18573 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18574 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18575
18576 VkQueue queue = VK_NULL_HANDLE;
18577 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18578
18579 {
18580 VkCommandBufferBeginInfo begin_info{};
18581 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18582 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18583
18584 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18585 nullptr, 0, nullptr, 0, nullptr);
18586
18587 VkViewport viewport{};
18588 viewport.maxDepth = 1.0f;
18589 viewport.minDepth = 0.0f;
18590 viewport.width = 512;
18591 viewport.height = 512;
18592 viewport.x = 0;
18593 viewport.y = 0;
18594 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18595 vkEndCommandBuffer(command_buffer[0]);
18596 }
18597 {
18598 VkCommandBufferBeginInfo begin_info{};
18599 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18600 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18601
18602 VkViewport viewport{};
18603 viewport.maxDepth = 1.0f;
18604 viewport.minDepth = 0.0f;
18605 viewport.width = 512;
18606 viewport.height = 512;
18607 viewport.x = 0;
18608 viewport.y = 0;
18609 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18610 vkEndCommandBuffer(command_buffer[1]);
18611 }
18612 {
18613 VkSubmitInfo submit_info{};
18614 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18615 submit_info.commandBufferCount = 1;
18616 submit_info.pCommandBuffers = &command_buffer[0];
18617 submit_info.signalSemaphoreCount = 1;
18618 submit_info.pSignalSemaphores = &semaphore;
18619 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18620 }
18621 {
18622 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18623 VkSubmitInfo submit_info{};
18624 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18625 submit_info.commandBufferCount = 1;
18626 submit_info.pCommandBuffers = &command_buffer[1];
18627 submit_info.waitSemaphoreCount = 1;
18628 submit_info.pWaitSemaphores = &semaphore;
18629 submit_info.pWaitDstStageMask = flags;
18630 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18631 }
18632
18633 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18634 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18635
18636 vkDestroyFence(m_device->device(), fence, nullptr);
18637 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18638 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18639 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18640
18641 m_errorMonitor->VerifyNotFound();
18642}
18643
18644TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18645
18646 ASSERT_NO_FATAL_FAILURE(InitState());
18647 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18648 printf("Test requires two queues, skipping\n");
18649 return;
18650 }
18651
18652 VkResult err;
18653
18654 m_errorMonitor->ExpectSuccess();
18655
18656 VkQueue q0 = m_device->m_queue;
18657 VkQueue q1 = nullptr;
18658 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18659 ASSERT_NE(q1, nullptr);
18660
18661 // An (empty) command buffer. We must have work in the first submission --
18662 // the layer treats unfenced work differently from fenced work.
18663 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18664 VkCommandPool pool;
18665 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18666 ASSERT_VK_SUCCESS(err);
18667 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18668 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18669 VkCommandBuffer cb;
18670 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18671 ASSERT_VK_SUCCESS(err);
18672 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18673 err = vkBeginCommandBuffer(cb, &cbbi);
18674 ASSERT_VK_SUCCESS(err);
18675 err = vkEndCommandBuffer(cb);
18676 ASSERT_VK_SUCCESS(err);
18677
18678 // A semaphore
18679 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18680 VkSemaphore s;
18681 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18682 ASSERT_VK_SUCCESS(err);
18683
18684 // First submission, to q0
18685 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18686
18687 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18688 ASSERT_VK_SUCCESS(err);
18689
18690 // Second submission, to q1, waiting on s
18691 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18692 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18693
18694 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18695 ASSERT_VK_SUCCESS(err);
18696
18697 // Wait for q0 idle
18698 err = vkQueueWaitIdle(q0);
18699 ASSERT_VK_SUCCESS(err);
18700
18701 // Command buffer should have been completed (it was on q0); reset the pool.
18702 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18703
18704 m_errorMonitor->VerifyNotFound();
18705
18706 // Force device completely idle and clean up resources
18707 vkDeviceWaitIdle(m_device->device());
18708 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18709 vkDestroySemaphore(m_device->device(), s, nullptr);
18710}
18711
18712// This is a positive test. No errors should be generated.
18713TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18714
18715 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18716 "submitted on separate queues, the second having a fence, "
18717 "followed by a WaitForFences call.");
18718
18719 ASSERT_NO_FATAL_FAILURE(InitState());
18720 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18721 return;
18722
18723 m_errorMonitor->ExpectSuccess();
18724
18725 ASSERT_NO_FATAL_FAILURE(InitState());
18726 VkFence fence;
18727 VkFenceCreateInfo fence_create_info{};
18728 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18729 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18730
18731 VkSemaphore semaphore;
18732 VkSemaphoreCreateInfo semaphore_create_info{};
18733 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18734 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18735
18736 VkCommandPool command_pool;
18737 VkCommandPoolCreateInfo pool_create_info{};
18738 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18739 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18740 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18741 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18742
18743 VkCommandBuffer command_buffer[2];
18744 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18745 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18746 command_buffer_allocate_info.commandPool = command_pool;
18747 command_buffer_allocate_info.commandBufferCount = 2;
18748 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18749 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18750
18751 VkQueue queue = VK_NULL_HANDLE;
18752 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18753
18754 {
18755 VkCommandBufferBeginInfo begin_info{};
18756 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18757 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18758
18759 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18760 nullptr, 0, nullptr, 0, nullptr);
18761
18762 VkViewport viewport{};
18763 viewport.maxDepth = 1.0f;
18764 viewport.minDepth = 0.0f;
18765 viewport.width = 512;
18766 viewport.height = 512;
18767 viewport.x = 0;
18768 viewport.y = 0;
18769 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18770 vkEndCommandBuffer(command_buffer[0]);
18771 }
18772 {
18773 VkCommandBufferBeginInfo begin_info{};
18774 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18775 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18776
18777 VkViewport viewport{};
18778 viewport.maxDepth = 1.0f;
18779 viewport.minDepth = 0.0f;
18780 viewport.width = 512;
18781 viewport.height = 512;
18782 viewport.x = 0;
18783 viewport.y = 0;
18784 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18785 vkEndCommandBuffer(command_buffer[1]);
18786 }
18787 {
18788 VkSubmitInfo submit_info{};
18789 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18790 submit_info.commandBufferCount = 1;
18791 submit_info.pCommandBuffers = &command_buffer[0];
18792 submit_info.signalSemaphoreCount = 1;
18793 submit_info.pSignalSemaphores = &semaphore;
18794 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18795 }
18796 {
18797 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18798 VkSubmitInfo submit_info{};
18799 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18800 submit_info.commandBufferCount = 1;
18801 submit_info.pCommandBuffers = &command_buffer[1];
18802 submit_info.waitSemaphoreCount = 1;
18803 submit_info.pWaitSemaphores = &semaphore;
18804 submit_info.pWaitDstStageMask = flags;
18805 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18806 }
18807
18808 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18809
18810 vkDestroyFence(m_device->device(), fence, nullptr);
18811 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18812 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18813 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18814
18815 m_errorMonitor->VerifyNotFound();
18816}
18817
18818// This is a positive test. No errors should be generated.
18819TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18820
18821 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18822 "on the same queue, sharing a signal/wait semaphore, the "
18823 "second having a fence, "
18824 "followed by a WaitForFences call.");
18825
18826 m_errorMonitor->ExpectSuccess();
18827
18828 ASSERT_NO_FATAL_FAILURE(InitState());
18829 VkFence fence;
18830 VkFenceCreateInfo fence_create_info{};
18831 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18832 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18833
18834 VkSemaphore semaphore;
18835 VkSemaphoreCreateInfo semaphore_create_info{};
18836 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18837 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18838
18839 VkCommandPool command_pool;
18840 VkCommandPoolCreateInfo pool_create_info{};
18841 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18842 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18843 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18844 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18845
18846 VkCommandBuffer command_buffer[2];
18847 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18848 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18849 command_buffer_allocate_info.commandPool = command_pool;
18850 command_buffer_allocate_info.commandBufferCount = 2;
18851 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18852 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18853
18854 {
18855 VkCommandBufferBeginInfo begin_info{};
18856 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18857 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18858
18859 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18860 nullptr, 0, nullptr, 0, nullptr);
18861
18862 VkViewport viewport{};
18863 viewport.maxDepth = 1.0f;
18864 viewport.minDepth = 0.0f;
18865 viewport.width = 512;
18866 viewport.height = 512;
18867 viewport.x = 0;
18868 viewport.y = 0;
18869 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18870 vkEndCommandBuffer(command_buffer[0]);
18871 }
18872 {
18873 VkCommandBufferBeginInfo begin_info{};
18874 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18875 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18876
18877 VkViewport viewport{};
18878 viewport.maxDepth = 1.0f;
18879 viewport.minDepth = 0.0f;
18880 viewport.width = 512;
18881 viewport.height = 512;
18882 viewport.x = 0;
18883 viewport.y = 0;
18884 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18885 vkEndCommandBuffer(command_buffer[1]);
18886 }
18887 {
18888 VkSubmitInfo submit_info{};
18889 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18890 submit_info.commandBufferCount = 1;
18891 submit_info.pCommandBuffers = &command_buffer[0];
18892 submit_info.signalSemaphoreCount = 1;
18893 submit_info.pSignalSemaphores = &semaphore;
18894 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18895 }
18896 {
18897 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18898 VkSubmitInfo submit_info{};
18899 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18900 submit_info.commandBufferCount = 1;
18901 submit_info.pCommandBuffers = &command_buffer[1];
18902 submit_info.waitSemaphoreCount = 1;
18903 submit_info.pWaitSemaphores = &semaphore;
18904 submit_info.pWaitDstStageMask = flags;
18905 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18906 }
18907
18908 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18909
18910 vkDestroyFence(m_device->device(), fence, nullptr);
18911 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18912 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18913 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18914
18915 m_errorMonitor->VerifyNotFound();
18916}
18917
18918// This is a positive test. No errors should be generated.
18919TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18920
18921 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18922 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18923 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18924
18925 m_errorMonitor->ExpectSuccess();
18926
18927 ASSERT_NO_FATAL_FAILURE(InitState());
18928 VkFence fence;
18929 VkFenceCreateInfo fence_create_info{};
18930 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18931 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18932
18933 VkCommandPool command_pool;
18934 VkCommandPoolCreateInfo pool_create_info{};
18935 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18936 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18937 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18938 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18939
18940 VkCommandBuffer command_buffer[2];
18941 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18942 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18943 command_buffer_allocate_info.commandPool = command_pool;
18944 command_buffer_allocate_info.commandBufferCount = 2;
18945 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18946 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18947
18948 {
18949 VkCommandBufferBeginInfo begin_info{};
18950 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18951 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18952
18953 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18954 nullptr, 0, nullptr, 0, nullptr);
18955
18956 VkViewport viewport{};
18957 viewport.maxDepth = 1.0f;
18958 viewport.minDepth = 0.0f;
18959 viewport.width = 512;
18960 viewport.height = 512;
18961 viewport.x = 0;
18962 viewport.y = 0;
18963 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18964 vkEndCommandBuffer(command_buffer[0]);
18965 }
18966 {
18967 VkCommandBufferBeginInfo begin_info{};
18968 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18969 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18970
18971 VkViewport viewport{};
18972 viewport.maxDepth = 1.0f;
18973 viewport.minDepth = 0.0f;
18974 viewport.width = 512;
18975 viewport.height = 512;
18976 viewport.x = 0;
18977 viewport.y = 0;
18978 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18979 vkEndCommandBuffer(command_buffer[1]);
18980 }
18981 {
18982 VkSubmitInfo submit_info{};
18983 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18984 submit_info.commandBufferCount = 1;
18985 submit_info.pCommandBuffers = &command_buffer[0];
18986 submit_info.signalSemaphoreCount = 0;
18987 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18988 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18989 }
18990 {
18991 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18992 VkSubmitInfo submit_info{};
18993 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18994 submit_info.commandBufferCount = 1;
18995 submit_info.pCommandBuffers = &command_buffer[1];
18996 submit_info.waitSemaphoreCount = 0;
18997 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18998 submit_info.pWaitDstStageMask = flags;
18999 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19000 }
19001
19002 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19003
19004 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19005 ASSERT_VK_SUCCESS(err);
19006
19007 vkDestroyFence(m_device->device(), fence, nullptr);
19008 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19009 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19010
19011 m_errorMonitor->VerifyNotFound();
19012}
19013
19014// This is a positive test. No errors should be generated.
19015TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
19016
19017 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19018 "on the same queue, the second having a fence, followed "
19019 "by a WaitForFences call.");
19020
19021 m_errorMonitor->ExpectSuccess();
19022
19023 ASSERT_NO_FATAL_FAILURE(InitState());
19024 VkFence fence;
19025 VkFenceCreateInfo fence_create_info{};
19026 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19027 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19028
19029 VkCommandPool command_pool;
19030 VkCommandPoolCreateInfo pool_create_info{};
19031 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19032 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19033 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19034 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19035
19036 VkCommandBuffer command_buffer[2];
19037 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19038 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19039 command_buffer_allocate_info.commandPool = command_pool;
19040 command_buffer_allocate_info.commandBufferCount = 2;
19041 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19042 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19043
19044 {
19045 VkCommandBufferBeginInfo begin_info{};
19046 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19047 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19048
19049 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19050 nullptr, 0, nullptr, 0, nullptr);
19051
19052 VkViewport viewport{};
19053 viewport.maxDepth = 1.0f;
19054 viewport.minDepth = 0.0f;
19055 viewport.width = 512;
19056 viewport.height = 512;
19057 viewport.x = 0;
19058 viewport.y = 0;
19059 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19060 vkEndCommandBuffer(command_buffer[0]);
19061 }
19062 {
19063 VkCommandBufferBeginInfo begin_info{};
19064 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19065 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19066
19067 VkViewport viewport{};
19068 viewport.maxDepth = 1.0f;
19069 viewport.minDepth = 0.0f;
19070 viewport.width = 512;
19071 viewport.height = 512;
19072 viewport.x = 0;
19073 viewport.y = 0;
19074 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19075 vkEndCommandBuffer(command_buffer[1]);
19076 }
19077 {
19078 VkSubmitInfo submit_info{};
19079 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19080 submit_info.commandBufferCount = 1;
19081 submit_info.pCommandBuffers = &command_buffer[0];
19082 submit_info.signalSemaphoreCount = 0;
19083 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19084 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19085 }
19086 {
19087 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19088 VkSubmitInfo submit_info{};
19089 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19090 submit_info.commandBufferCount = 1;
19091 submit_info.pCommandBuffers = &command_buffer[1];
19092 submit_info.waitSemaphoreCount = 0;
19093 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19094 submit_info.pWaitDstStageMask = flags;
19095 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19096 }
19097
19098 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19099
19100 vkDestroyFence(m_device->device(), fence, nullptr);
19101 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19102 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19103
19104 m_errorMonitor->VerifyNotFound();
19105}
19106
19107// This is a positive test. No errors should be generated.
19108TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19109
19110 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19111 "QueueSubmit call followed by a WaitForFences call.");
19112 ASSERT_NO_FATAL_FAILURE(InitState());
19113
19114 m_errorMonitor->ExpectSuccess();
19115
19116 VkFence fence;
19117 VkFenceCreateInfo fence_create_info{};
19118 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19119 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19120
19121 VkSemaphore semaphore;
19122 VkSemaphoreCreateInfo semaphore_create_info{};
19123 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19124 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19125
19126 VkCommandPool command_pool;
19127 VkCommandPoolCreateInfo pool_create_info{};
19128 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19129 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19130 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19131 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19132
19133 VkCommandBuffer command_buffer[2];
19134 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19135 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19136 command_buffer_allocate_info.commandPool = command_pool;
19137 command_buffer_allocate_info.commandBufferCount = 2;
19138 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19139 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19140
19141 {
19142 VkCommandBufferBeginInfo begin_info{};
19143 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19144 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19145
19146 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19147 nullptr, 0, nullptr, 0, nullptr);
19148
19149 VkViewport viewport{};
19150 viewport.maxDepth = 1.0f;
19151 viewport.minDepth = 0.0f;
19152 viewport.width = 512;
19153 viewport.height = 512;
19154 viewport.x = 0;
19155 viewport.y = 0;
19156 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19157 vkEndCommandBuffer(command_buffer[0]);
19158 }
19159 {
19160 VkCommandBufferBeginInfo begin_info{};
19161 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19162 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19163
19164 VkViewport viewport{};
19165 viewport.maxDepth = 1.0f;
19166 viewport.minDepth = 0.0f;
19167 viewport.width = 512;
19168 viewport.height = 512;
19169 viewport.x = 0;
19170 viewport.y = 0;
19171 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19172 vkEndCommandBuffer(command_buffer[1]);
19173 }
19174 {
19175 VkSubmitInfo submit_info[2];
19176 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19177
19178 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19179 submit_info[0].pNext = NULL;
19180 submit_info[0].commandBufferCount = 1;
19181 submit_info[0].pCommandBuffers = &command_buffer[0];
19182 submit_info[0].signalSemaphoreCount = 1;
19183 submit_info[0].pSignalSemaphores = &semaphore;
19184 submit_info[0].waitSemaphoreCount = 0;
19185 submit_info[0].pWaitSemaphores = NULL;
19186 submit_info[0].pWaitDstStageMask = 0;
19187
19188 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19189 submit_info[1].pNext = NULL;
19190 submit_info[1].commandBufferCount = 1;
19191 submit_info[1].pCommandBuffers = &command_buffer[1];
19192 submit_info[1].waitSemaphoreCount = 1;
19193 submit_info[1].pWaitSemaphores = &semaphore;
19194 submit_info[1].pWaitDstStageMask = flags;
19195 submit_info[1].signalSemaphoreCount = 0;
19196 submit_info[1].pSignalSemaphores = NULL;
19197 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19198 }
19199
19200 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19201
19202 vkDestroyFence(m_device->device(), fence, nullptr);
19203 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19204 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19205 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19206
19207 m_errorMonitor->VerifyNotFound();
19208}
19209
19210TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19211 m_errorMonitor->ExpectSuccess();
19212
19213 ASSERT_NO_FATAL_FAILURE(InitState());
19214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19215
19216 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
19217 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
19218
19219 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19220 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19221 m_errorMonitor->VerifyNotFound();
19222 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19223 m_errorMonitor->VerifyNotFound();
19224 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19225 m_errorMonitor->VerifyNotFound();
19226
19227 m_commandBuffer->EndCommandBuffer();
19228 m_errorMonitor->VerifyNotFound();
19229}
19230
19231TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19232 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19233 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19234 "has a valid layout, and a second subpass then uses a "
19235 "valid *READ_ONLY* layout.");
19236 m_errorMonitor->ExpectSuccess();
19237 ASSERT_NO_FATAL_FAILURE(InitState());
19238
19239 VkAttachmentReference attach[2] = {};
19240 attach[0].attachment = 0;
19241 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19242 attach[1].attachment = 0;
19243 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19244 VkSubpassDescription subpasses[2] = {};
19245 // First subpass clears DS attach on load
19246 subpasses[0].pDepthStencilAttachment = &attach[0];
19247 // 2nd subpass reads in DS as input attachment
19248 subpasses[1].inputAttachmentCount = 1;
19249 subpasses[1].pInputAttachments = &attach[1];
19250 VkAttachmentDescription attach_desc = {};
19251 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19252 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19253 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19254 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19255 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19256 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19257 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19258 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19259 VkRenderPassCreateInfo rpci = {};
19260 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19261 rpci.attachmentCount = 1;
19262 rpci.pAttachments = &attach_desc;
19263 rpci.subpassCount = 2;
19264 rpci.pSubpasses = subpasses;
19265
19266 // Now create RenderPass and verify no errors
19267 VkRenderPass rp;
19268 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19269 m_errorMonitor->VerifyNotFound();
19270
19271 vkDestroyRenderPass(m_device->device(), rp, NULL);
19272}
19273
19274TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19275 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19276 "as vertex attributes");
19277 m_errorMonitor->ExpectSuccess();
19278
19279 ASSERT_NO_FATAL_FAILURE(InitState());
19280 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19281
19282 VkVertexInputBindingDescription input_binding;
19283 memset(&input_binding, 0, sizeof(input_binding));
19284
19285 VkVertexInputAttributeDescription input_attribs[2];
19286 memset(input_attribs, 0, sizeof(input_attribs));
19287
19288 for (int i = 0; i < 2; i++) {
19289 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19290 input_attribs[i].location = i;
19291 }
19292
19293 char const *vsSource = "#version 450\n"
19294 "\n"
19295 "layout(location=0) in mat2x4 x;\n"
19296 "out gl_PerVertex {\n"
19297 " vec4 gl_Position;\n"
19298 "};\n"
19299 "void main(){\n"
19300 " gl_Position = x[0] + x[1];\n"
19301 "}\n";
19302 char const *fsSource = "#version 450\n"
19303 "\n"
19304 "layout(location=0) out vec4 color;\n"
19305 "void main(){\n"
19306 " color = vec4(1);\n"
19307 "}\n";
19308
19309 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19310 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19311
19312 VkPipelineObj pipe(m_device);
19313 pipe.AddColorAttachment();
19314 pipe.AddShader(&vs);
19315 pipe.AddShader(&fs);
19316
19317 pipe.AddVertexInputBindings(&input_binding, 1);
19318 pipe.AddVertexInputAttribs(input_attribs, 2);
19319
19320 VkDescriptorSetObj descriptorSet(m_device);
19321 descriptorSet.AppendDummy();
19322 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19323
19324 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19325
19326 /* expect success */
19327 m_errorMonitor->VerifyNotFound();
19328}
19329
19330TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19331 m_errorMonitor->ExpectSuccess();
19332
19333 ASSERT_NO_FATAL_FAILURE(InitState());
19334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19335
19336 VkVertexInputBindingDescription input_binding;
19337 memset(&input_binding, 0, sizeof(input_binding));
19338
19339 VkVertexInputAttributeDescription input_attribs[2];
19340 memset(input_attribs, 0, sizeof(input_attribs));
19341
19342 for (int i = 0; i < 2; i++) {
19343 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19344 input_attribs[i].location = i;
19345 }
19346
19347 char const *vsSource = "#version 450\n"
19348 "\n"
19349 "layout(location=0) in vec4 x[2];\n"
19350 "out gl_PerVertex {\n"
19351 " vec4 gl_Position;\n"
19352 "};\n"
19353 "void main(){\n"
19354 " gl_Position = x[0] + x[1];\n"
19355 "}\n";
19356 char const *fsSource = "#version 450\n"
19357 "\n"
19358 "layout(location=0) out vec4 color;\n"
19359 "void main(){\n"
19360 " color = vec4(1);\n"
19361 "}\n";
19362
19363 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19364 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19365
19366 VkPipelineObj pipe(m_device);
19367 pipe.AddColorAttachment();
19368 pipe.AddShader(&vs);
19369 pipe.AddShader(&fs);
19370
19371 pipe.AddVertexInputBindings(&input_binding, 1);
19372 pipe.AddVertexInputAttribs(input_attribs, 2);
19373
19374 VkDescriptorSetObj descriptorSet(m_device);
19375 descriptorSet.AppendDummy();
19376 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19377
19378 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19379
19380 m_errorMonitor->VerifyNotFound();
19381}
19382
19383TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19384 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19385 "through multiple vertex shader inputs, each consuming a different "
19386 "subset of the components.");
19387 m_errorMonitor->ExpectSuccess();
19388
19389 ASSERT_NO_FATAL_FAILURE(InitState());
19390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19391
19392 VkVertexInputBindingDescription input_binding;
19393 memset(&input_binding, 0, sizeof(input_binding));
19394
19395 VkVertexInputAttributeDescription input_attribs[3];
19396 memset(input_attribs, 0, sizeof(input_attribs));
19397
19398 for (int i = 0; i < 3; i++) {
19399 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19400 input_attribs[i].location = i;
19401 }
19402
19403 char const *vsSource = "#version 450\n"
19404 "\n"
19405 "layout(location=0) in vec4 x;\n"
19406 "layout(location=1) in vec3 y1;\n"
19407 "layout(location=1, component=3) in float y2;\n"
19408 "layout(location=2) in vec4 z;\n"
19409 "out gl_PerVertex {\n"
19410 " vec4 gl_Position;\n"
19411 "};\n"
19412 "void main(){\n"
19413 " gl_Position = x + vec4(y1, y2) + z;\n"
19414 "}\n";
19415 char const *fsSource = "#version 450\n"
19416 "\n"
19417 "layout(location=0) out vec4 color;\n"
19418 "void main(){\n"
19419 " color = vec4(1);\n"
19420 "}\n";
19421
19422 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19423 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19424
19425 VkPipelineObj pipe(m_device);
19426 pipe.AddColorAttachment();
19427 pipe.AddShader(&vs);
19428 pipe.AddShader(&fs);
19429
19430 pipe.AddVertexInputBindings(&input_binding, 1);
19431 pipe.AddVertexInputAttribs(input_attribs, 3);
19432
19433 VkDescriptorSetObj descriptorSet(m_device);
19434 descriptorSet.AppendDummy();
19435 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19436
19437 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19438
19439 m_errorMonitor->VerifyNotFound();
19440}
19441
19442TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19443 m_errorMonitor->ExpectSuccess();
19444
19445 ASSERT_NO_FATAL_FAILURE(InitState());
19446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19447
19448 char const *vsSource = "#version 450\n"
19449 "out gl_PerVertex {\n"
19450 " vec4 gl_Position;\n"
19451 "};\n"
19452 "void main(){\n"
19453 " gl_Position = vec4(0);\n"
19454 "}\n";
19455 char const *fsSource = "#version 450\n"
19456 "\n"
19457 "layout(location=0) out vec4 color;\n"
19458 "void main(){\n"
19459 " color = vec4(1);\n"
19460 "}\n";
19461
19462 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19463 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19464
19465 VkPipelineObj pipe(m_device);
19466 pipe.AddColorAttachment();
19467 pipe.AddShader(&vs);
19468 pipe.AddShader(&fs);
19469
19470 VkDescriptorSetObj descriptorSet(m_device);
19471 descriptorSet.AppendDummy();
19472 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19473
19474 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19475
19476 m_errorMonitor->VerifyNotFound();
19477}
19478
19479TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19480 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19481 "set out in 14.1.3: fundamental type must match, and producer side must "
19482 "have at least as many components");
19483 m_errorMonitor->ExpectSuccess();
19484
19485 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19486
19487 ASSERT_NO_FATAL_FAILURE(InitState());
19488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19489
19490 char const *vsSource = "#version 450\n"
19491 "out gl_PerVertex {\n"
19492 " vec4 gl_Position;\n"
19493 "};\n"
19494 "layout(location=0) out vec3 x;\n"
19495 "layout(location=1) out ivec3 y;\n"
19496 "layout(location=2) out vec3 z;\n"
19497 "void main(){\n"
19498 " gl_Position = vec4(0);\n"
19499 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19500 "}\n";
19501 char const *fsSource = "#version 450\n"
19502 "\n"
19503 "layout(location=0) out vec4 color;\n"
19504 "layout(location=0) in float x;\n"
19505 "layout(location=1) flat in int y;\n"
19506 "layout(location=2) in vec2 z;\n"
19507 "void main(){\n"
19508 " color = vec4(1 + x + y + z.x);\n"
19509 "}\n";
19510
19511 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19512 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19513
19514 VkPipelineObj pipe(m_device);
19515 pipe.AddColorAttachment();
19516 pipe.AddShader(&vs);
19517 pipe.AddShader(&fs);
19518
19519 VkDescriptorSetObj descriptorSet(m_device);
19520 descriptorSet.AppendDummy();
19521 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19522
19523 VkResult err = VK_SUCCESS;
19524 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19525 ASSERT_VK_SUCCESS(err);
19526
19527 m_errorMonitor->VerifyNotFound();
19528}
19529
19530TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19531 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19532 "passed between the TCS and TES stages");
19533 m_errorMonitor->ExpectSuccess();
19534
19535 ASSERT_NO_FATAL_FAILURE(InitState());
19536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19537
19538 if (!m_device->phy().features().tessellationShader) {
19539 printf("Device does not support tessellation shaders; skipped.\n");
19540 return;
19541 }
19542
19543 char const *vsSource = "#version 450\n"
19544 "void main(){}\n";
19545 char const *tcsSource = "#version 450\n"
19546 "layout(location=0) out int x[];\n"
19547 "layout(vertices=3) out;\n"
19548 "void main(){\n"
19549 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19550 " gl_TessLevelInner[0] = 1;\n"
19551 " x[gl_InvocationID] = gl_InvocationID;\n"
19552 "}\n";
19553 char const *tesSource = "#version 450\n"
19554 "layout(triangles, equal_spacing, cw) in;\n"
19555 "layout(location=0) in int x[];\n"
19556 "out gl_PerVertex { vec4 gl_Position; };\n"
19557 "void main(){\n"
19558 " gl_Position.xyz = gl_TessCoord;\n"
19559 " gl_Position.w = x[0] + x[1] + x[2];\n"
19560 "}\n";
19561 char const *fsSource = "#version 450\n"
19562 "layout(location=0) out vec4 color;\n"
19563 "void main(){\n"
19564 " color = vec4(1);\n"
19565 "}\n";
19566
19567 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19568 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19569 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19570 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19571
19572 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19573 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19574
19575 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19576
19577 VkPipelineObj pipe(m_device);
19578 pipe.SetInputAssembly(&iasci);
19579 pipe.SetTessellation(&tsci);
19580 pipe.AddColorAttachment();
19581 pipe.AddShader(&vs);
19582 pipe.AddShader(&tcs);
19583 pipe.AddShader(&tes);
19584 pipe.AddShader(&fs);
19585
19586 VkDescriptorSetObj descriptorSet(m_device);
19587 descriptorSet.AppendDummy();
19588 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19589
19590 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19591
19592 m_errorMonitor->VerifyNotFound();
19593}
19594
19595TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19596 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19597 "interface block passed into the geometry shader. This "
19598 "is interesting because the 'extra' array level is not "
19599 "present on the member type, but on the block instance.");
19600 m_errorMonitor->ExpectSuccess();
19601
19602 ASSERT_NO_FATAL_FAILURE(InitState());
19603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19604
19605 if (!m_device->phy().features().geometryShader) {
19606 printf("Device does not support geometry shaders; skipped.\n");
19607 return;
19608 }
19609
19610 char const *vsSource = "#version 450\n"
19611 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19612 "void main(){\n"
19613 " vs_out.x = vec4(1);\n"
19614 "}\n";
19615 char const *gsSource = "#version 450\n"
19616 "layout(triangles) in;\n"
19617 "layout(triangle_strip, max_vertices=3) out;\n"
19618 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19619 "out gl_PerVertex { vec4 gl_Position; };\n"
19620 "void main() {\n"
19621 " gl_Position = gs_in[0].x;\n"
19622 " EmitVertex();\n"
19623 "}\n";
19624 char const *fsSource = "#version 450\n"
19625 "layout(location=0) out vec4 color;\n"
19626 "void main(){\n"
19627 " color = vec4(1);\n"
19628 "}\n";
19629
19630 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19631 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19632 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19633
19634 VkPipelineObj pipe(m_device);
19635 pipe.AddColorAttachment();
19636 pipe.AddShader(&vs);
19637 pipe.AddShader(&gs);
19638 pipe.AddShader(&fs);
19639
19640 VkDescriptorSetObj descriptorSet(m_device);
19641 descriptorSet.AppendDummy();
19642 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19643
19644 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19645
19646 m_errorMonitor->VerifyNotFound();
19647}
19648
19649TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19650 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19651 "attributes. This is interesting because they consume multiple "
19652 "locations.");
19653 m_errorMonitor->ExpectSuccess();
19654
19655 ASSERT_NO_FATAL_FAILURE(InitState());
19656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19657
19658 if (!m_device->phy().features().shaderFloat64) {
19659 printf("Device does not support 64bit vertex attributes; skipped.\n");
19660 return;
19661 }
19662
19663 VkVertexInputBindingDescription input_bindings[1];
19664 memset(input_bindings, 0, sizeof(input_bindings));
19665
19666 VkVertexInputAttributeDescription input_attribs[4];
19667 memset(input_attribs, 0, sizeof(input_attribs));
19668 input_attribs[0].location = 0;
19669 input_attribs[0].offset = 0;
19670 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19671 input_attribs[1].location = 2;
19672 input_attribs[1].offset = 32;
19673 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19674 input_attribs[2].location = 4;
19675 input_attribs[2].offset = 64;
19676 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19677 input_attribs[3].location = 6;
19678 input_attribs[3].offset = 96;
19679 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19680
19681 char const *vsSource = "#version 450\n"
19682 "\n"
19683 "layout(location=0) in dmat4 x;\n"
19684 "out gl_PerVertex {\n"
19685 " vec4 gl_Position;\n"
19686 "};\n"
19687 "void main(){\n"
19688 " gl_Position = vec4(x[0][0]);\n"
19689 "}\n";
19690 char const *fsSource = "#version 450\n"
19691 "\n"
19692 "layout(location=0) out vec4 color;\n"
19693 "void main(){\n"
19694 " color = vec4(1);\n"
19695 "}\n";
19696
19697 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19698 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19699
19700 VkPipelineObj pipe(m_device);
19701 pipe.AddColorAttachment();
19702 pipe.AddShader(&vs);
19703 pipe.AddShader(&fs);
19704
19705 pipe.AddVertexInputBindings(input_bindings, 1);
19706 pipe.AddVertexInputAttribs(input_attribs, 4);
19707
19708 VkDescriptorSetObj descriptorSet(m_device);
19709 descriptorSet.AppendDummy();
19710 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19711
19712 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19713
19714 m_errorMonitor->VerifyNotFound();
19715}
19716
19717TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19718 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19719 m_errorMonitor->ExpectSuccess();
19720
19721 ASSERT_NO_FATAL_FAILURE(InitState());
19722
19723 char const *vsSource = "#version 450\n"
19724 "\n"
19725 "out gl_PerVertex {\n"
19726 " vec4 gl_Position;\n"
19727 "};\n"
19728 "void main(){\n"
19729 " gl_Position = vec4(1);\n"
19730 "}\n";
19731 char const *fsSource = "#version 450\n"
19732 "\n"
19733 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19734 "layout(location=0) out vec4 color;\n"
19735 "void main() {\n"
19736 " color = subpassLoad(x);\n"
19737 "}\n";
19738
19739 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19740 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19741
19742 VkPipelineObj pipe(m_device);
19743 pipe.AddShader(&vs);
19744 pipe.AddShader(&fs);
19745 pipe.AddColorAttachment();
19746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19747
19748 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19749 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19750 VkDescriptorSetLayout dsl;
19751 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19752 ASSERT_VK_SUCCESS(err);
19753
19754 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19755 VkPipelineLayout pl;
19756 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19757 ASSERT_VK_SUCCESS(err);
19758
19759 VkAttachmentDescription descs[2] = {
19760 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19761 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19762 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19763 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19764 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19765 };
19766 VkAttachmentReference color = {
19767 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19768 };
19769 VkAttachmentReference input = {
19770 1, VK_IMAGE_LAYOUT_GENERAL,
19771 };
19772
19773 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19774
19775 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19776 VkRenderPass rp;
19777 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19778 ASSERT_VK_SUCCESS(err);
19779
19780 // should be OK. would go wrong here if it's going to...
19781 pipe.CreateVKPipeline(pl, rp);
19782
19783 m_errorMonitor->VerifyNotFound();
19784
19785 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19786 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19787 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19788}
19789
19790TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19791 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19792 "descriptor-backed resource which is not provided, but the shader does not "
19793 "statically use it. This is interesting because it requires compute pipelines "
19794 "to have a proper descriptor use walk, which they didn't for some time.");
19795 m_errorMonitor->ExpectSuccess();
19796
19797 ASSERT_NO_FATAL_FAILURE(InitState());
19798
19799 char const *csSource = "#version 450\n"
19800 "\n"
19801 "layout(local_size_x=1) in;\n"
19802 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19803 "void main(){\n"
19804 " // x is not used.\n"
19805 "}\n";
19806
19807 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19808
19809 VkDescriptorSetObj descriptorSet(m_device);
19810 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19811
19812 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19813 nullptr,
19814 0,
19815 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19816 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19817 descriptorSet.GetPipelineLayout(),
19818 VK_NULL_HANDLE,
19819 -1 };
19820
19821 VkPipeline pipe;
19822 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19823
19824 m_errorMonitor->VerifyNotFound();
19825
19826 if (err == VK_SUCCESS) {
19827 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19828 }
19829}
19830
19831TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19832 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19833 "sampler portion of a combined image + sampler");
19834 m_errorMonitor->ExpectSuccess();
19835
19836 ASSERT_NO_FATAL_FAILURE(InitState());
19837
19838 VkDescriptorSetLayoutBinding bindings[] = {
19839 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19840 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19841 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19842 };
19843 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19844 VkDescriptorSetLayout dsl;
19845 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19846 ASSERT_VK_SUCCESS(err);
19847
19848 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19849 VkPipelineLayout pl;
19850 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19851 ASSERT_VK_SUCCESS(err);
19852
19853 char const *csSource = "#version 450\n"
19854 "\n"
19855 "layout(local_size_x=1) in;\n"
19856 "layout(set=0, binding=0) uniform sampler s;\n"
19857 "layout(set=0, binding=1) uniform texture2D t;\n"
19858 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19859 "void main() {\n"
19860 " x = texture(sampler2D(t, s), vec2(0));\n"
19861 "}\n";
19862 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19863
19864 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19865 nullptr,
19866 0,
19867 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19868 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19869 pl,
19870 VK_NULL_HANDLE,
19871 -1 };
19872
19873 VkPipeline pipe;
19874 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19875
19876 m_errorMonitor->VerifyNotFound();
19877
19878 if (err == VK_SUCCESS) {
19879 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19880 }
19881
19882 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19883 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19884}
19885
19886TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19887 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19888 "image portion of a combined image + sampler");
19889 m_errorMonitor->ExpectSuccess();
19890
19891 ASSERT_NO_FATAL_FAILURE(InitState());
19892
19893 VkDescriptorSetLayoutBinding bindings[] = {
19894 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19895 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19896 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19897 };
19898 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19899 VkDescriptorSetLayout dsl;
19900 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19901 ASSERT_VK_SUCCESS(err);
19902
19903 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19904 VkPipelineLayout pl;
19905 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19906 ASSERT_VK_SUCCESS(err);
19907
19908 char const *csSource = "#version 450\n"
19909 "\n"
19910 "layout(local_size_x=1) in;\n"
19911 "layout(set=0, binding=0) uniform texture2D t;\n"
19912 "layout(set=0, binding=1) uniform sampler s;\n"
19913 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19914 "void main() {\n"
19915 " x = texture(sampler2D(t, s), vec2(0));\n"
19916 "}\n";
19917 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19918
19919 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19920 nullptr,
19921 0,
19922 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19923 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19924 pl,
19925 VK_NULL_HANDLE,
19926 -1 };
19927
19928 VkPipeline pipe;
19929 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19930
19931 m_errorMonitor->VerifyNotFound();
19932
19933 if (err == VK_SUCCESS) {
19934 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19935 }
19936
19937 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19938 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19939}
19940
19941TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19942 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19943 "both the sampler and the image of a combined image+sampler "
19944 "but via separate variables");
19945 m_errorMonitor->ExpectSuccess();
19946
19947 ASSERT_NO_FATAL_FAILURE(InitState());
19948
19949 VkDescriptorSetLayoutBinding bindings[] = {
19950 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19951 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19952 };
19953 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19954 VkDescriptorSetLayout dsl;
19955 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19956 ASSERT_VK_SUCCESS(err);
19957
19958 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19959 VkPipelineLayout pl;
19960 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19961 ASSERT_VK_SUCCESS(err);
19962
19963 char const *csSource = "#version 450\n"
19964 "\n"
19965 "layout(local_size_x=1) in;\n"
19966 "layout(set=0, binding=0) uniform texture2D t;\n"
19967 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19968 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19969 "void main() {\n"
19970 " x = texture(sampler2D(t, s), vec2(0));\n"
19971 "}\n";
19972 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19973
19974 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19975 nullptr,
19976 0,
19977 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19978 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19979 pl,
19980 VK_NULL_HANDLE,
19981 -1 };
19982
19983 VkPipeline pipe;
19984 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19985
19986 m_errorMonitor->VerifyNotFound();
19987
19988 if (err == VK_SUCCESS) {
19989 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19990 }
19991
19992 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19993 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19994}
19995
19996TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19997 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19998
19999 ASSERT_NO_FATAL_FAILURE(InitState());
20000
20001 // Positive test to check parameter_validation and unique_objects support
20002 // for NV_dedicated_allocation
20003 uint32_t extension_count = 0;
20004 bool supports_nv_dedicated_allocation = false;
20005 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20006 ASSERT_VK_SUCCESS(err);
20007
20008 if (extension_count > 0) {
20009 std::vector<VkExtensionProperties> available_extensions(extension_count);
20010
20011 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20012 ASSERT_VK_SUCCESS(err);
20013
20014 for (const auto &extension_props : available_extensions) {
20015 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20016 supports_nv_dedicated_allocation = true;
20017 }
20018 }
20019 }
20020
20021 if (supports_nv_dedicated_allocation) {
20022 m_errorMonitor->ExpectSuccess();
20023
20024 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20025 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20026 dedicated_buffer_create_info.pNext = nullptr;
20027 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20028
20029 uint32_t queue_family_index = 0;
20030 VkBufferCreateInfo buffer_create_info = {};
20031 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20032 buffer_create_info.pNext = &dedicated_buffer_create_info;
20033 buffer_create_info.size = 1024;
20034 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20035 buffer_create_info.queueFamilyIndexCount = 1;
20036 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20037
20038 VkBuffer buffer;
20039 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20040 ASSERT_VK_SUCCESS(err);
20041
20042 VkMemoryRequirements memory_reqs;
20043 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20044
20045 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20046 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20047 dedicated_memory_info.pNext = nullptr;
20048 dedicated_memory_info.buffer = buffer;
20049 dedicated_memory_info.image = VK_NULL_HANDLE;
20050
20051 VkMemoryAllocateInfo memory_info = {};
20052 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20053 memory_info.pNext = &dedicated_memory_info;
20054 memory_info.allocationSize = memory_reqs.size;
20055
20056 bool pass;
20057 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20058 ASSERT_TRUE(pass);
20059
20060 VkDeviceMemory buffer_memory;
20061 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20062 ASSERT_VK_SUCCESS(err);
20063
20064 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20065 ASSERT_VK_SUCCESS(err);
20066
20067 vkDestroyBuffer(m_device->device(), buffer, NULL);
20068 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20069
20070 m_errorMonitor->VerifyNotFound();
20071 }
20072}
20073
20074TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20075 VkResult err;
20076
20077 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20078
20079 ASSERT_NO_FATAL_FAILURE(InitState());
20080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20081
20082 std::vector<const char *> device_extension_names;
20083 auto features = m_device->phy().features();
20084 // Artificially disable support for non-solid fill modes
20085 features.fillModeNonSolid = false;
20086 // The sacrificial device object
20087 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20088
20089 VkRenderpassObj render_pass(&test_device);
20090
20091 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20092 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20093 pipeline_layout_ci.setLayoutCount = 0;
20094 pipeline_layout_ci.pSetLayouts = NULL;
20095
20096 VkPipelineLayout pipeline_layout;
20097 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20098 ASSERT_VK_SUCCESS(err);
20099
20100 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20101 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20102 rs_ci.pNext = nullptr;
20103 rs_ci.lineWidth = 1.0f;
20104 rs_ci.rasterizerDiscardEnable = true;
20105
20106 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20107 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20108
20109 // Set polygonMode=FILL. No error is expected
20110 m_errorMonitor->ExpectSuccess();
20111 {
20112 VkPipelineObj pipe(&test_device);
20113 pipe.AddShader(&vs);
20114 pipe.AddShader(&fs);
20115 pipe.AddColorAttachment();
20116 // Set polygonMode to a good value
20117 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20118 pipe.SetRasterization(&rs_ci);
20119 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20120 }
20121 m_errorMonitor->VerifyNotFound();
20122
20123 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20124}
20125
20126TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20127 VkResult err;
20128 ASSERT_NO_FATAL_FAILURE(InitState());
20129 ASSERT_NO_FATAL_FAILURE(InitViewport());
20130 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20131
20132 VkPipelineLayout pipeline_layout;
20133 VkPushConstantRange pc_range = {};
20134 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20135 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20136 pipeline_layout_ci.pushConstantRangeCount = 1;
20137 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20138
20139 //
20140 // Check for invalid push constant ranges in pipeline layouts.
20141 //
20142 struct PipelineLayoutTestCase {
20143 VkPushConstantRange const range;
20144 char const *msg;
20145 };
20146
20147 // Check for overlapping ranges
20148 const uint32_t ranges_per_test = 5;
20149 struct OverlappingRangeTestCase {
20150 VkPushConstantRange const ranges[ranges_per_test];
20151 char const *msg;
20152 };
20153
20154 // Run some positive tests to make sure overlap checking in the layer is OK
20155 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20156 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20157 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20158 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20159 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20160 "" },
20161 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20162 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20163 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20164 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20165 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20166 "" } } };
20167 for (const auto &iter : overlapping_range_tests_pos) {
20168 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20169 m_errorMonitor->ExpectSuccess();
20170 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20171 m_errorMonitor->VerifyNotFound();
20172 if (VK_SUCCESS == err) {
20173 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20174 }
20175 }
20176
20177 //
20178 // CmdPushConstants tests
20179 //
20180 const uint8_t dummy_values[100] = {};
20181
20182 BeginCommandBuffer();
20183
20184 // positive overlapping range tests with cmd
20185 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20186 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20187 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20188 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20189 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20190 } };
20191
20192 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20193 const VkPushConstantRange pc_range4[] = {
20194 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20195 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20196 };
20197
20198 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20199 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20200 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20201 ASSERT_VK_SUCCESS(err);
20202 for (const auto &iter : cmd_overlap_tests_pos) {
20203 m_errorMonitor->ExpectSuccess();
20204 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20205 iter.range.size, dummy_values);
20206 m_errorMonitor->VerifyNotFound();
20207 }
20208 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20209
20210 EndCommandBuffer();
20211}
20212
20213
20214
20215
20216
20217
20218
20219#if 0 // A few devices have issues with this test so disabling for now
20220TEST_F(VkPositiveLayerTest, LongFenceChain)
20221{
20222 m_errorMonitor->ExpectSuccess();
20223
20224 ASSERT_NO_FATAL_FAILURE(InitState());
20225 VkResult err;
20226
20227 std::vector<VkFence> fences;
20228
20229 const int chainLength = 32768;
20230
20231 for (int i = 0; i < chainLength; i++) {
20232 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20233 VkFence fence;
20234 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20235 ASSERT_VK_SUCCESS(err);
20236
20237 fences.push_back(fence);
20238
20239 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20240 0, nullptr, 0, nullptr };
20241 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20242 ASSERT_VK_SUCCESS(err);
20243
20244 }
20245
20246 // BOOM, stack overflow.
20247 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20248
20249 for (auto fence : fences)
20250 vkDestroyFence(m_device->device(), fence, nullptr);
20251
20252 m_errorMonitor->VerifyNotFound();
20253}
20254#endif
20255
20256
Cody Northrop1242dfd2016-07-13 17:24:59 -060020257#if defined(ANDROID) && defined(VALIDATION_APK)
20258static bool initialized = false;
20259static bool active = false;
20260
20261// Convert Intents to argv
20262// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020263std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020264 std::vector<std::string> args;
20265 JavaVM &vm = *app.activity->vm;
20266 JNIEnv *p_env;
20267 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20268 return args;
20269
20270 JNIEnv &env = *p_env;
20271 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020272 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020273 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020274 jmethodID get_string_extra_method =
20275 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020276 jvalue get_string_extra_args;
20277 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020278 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020279
20280 std::string args_str;
20281 if (extra_str) {
20282 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20283 args_str = extra_utf;
20284 env.ReleaseStringUTFChars(extra_str, extra_utf);
20285 env.DeleteLocalRef(extra_str);
20286 }
20287
20288 env.DeleteLocalRef(get_string_extra_args.l);
20289 env.DeleteLocalRef(intent);
20290 vm.DetachCurrentThread();
20291
20292 // split args_str
20293 std::stringstream ss(args_str);
20294 std::string arg;
20295 while (std::getline(ss, arg, ' ')) {
20296 if (!arg.empty())
20297 args.push_back(arg);
20298 }
20299
20300 return args;
20301}
20302
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020303static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020305static void processCommand(struct android_app *app, int32_t cmd) {
20306 switch (cmd) {
20307 case APP_CMD_INIT_WINDOW: {
20308 if (app->window) {
20309 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020310 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020311 break;
20312 }
20313 case APP_CMD_GAINED_FOCUS: {
20314 active = true;
20315 break;
20316 }
20317 case APP_CMD_LOST_FOCUS: {
20318 active = false;
20319 break;
20320 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020321 }
20322}
20323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020324void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020325 app_dummy();
20326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020327 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020328
20329 int vulkanSupport = InitVulkan();
20330 if (vulkanSupport == 0) {
20331 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20332 return;
20333 }
20334
20335 app->onAppCmd = processCommand;
20336 app->onInputEvent = processInput;
20337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020338 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020339 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020340 struct android_poll_source *source;
20341 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020342 if (source) {
20343 source->process(app, source);
20344 }
20345
20346 if (app->destroyRequested != 0) {
20347 VkTestFramework::Finish();
20348 return;
20349 }
20350 }
20351
20352 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020353 // Use the following key to send arguments to gtest, i.e.
20354 // --es args "--gtest_filter=-VkLayerTest.foo"
20355 const char key[] = "args";
20356 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020358 std::string filter = "";
20359 if (args.size() > 0) {
20360 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20361 filter += args[0];
20362 } else {
20363 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20364 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020366 int argc = 2;
20367 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20368 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020370 // Route output to files until we can override the gtest output
20371 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20372 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020373
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020374 ::testing::InitGoogleTest(&argc, argv);
20375 VkTestFramework::InitArgs(&argc, argv);
20376 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020377
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020378 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020379
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020380 if (result != 0) {
20381 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20382 } else {
20383 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20384 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020385
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020386 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020388 fclose(stdout);
20389 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020391 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020392
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020393 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020394 }
20395 }
20396}
20397#endif
20398
Tony Barbour300a6082015-04-07 13:44:53 -060020399int main(int argc, char **argv) {
20400 int result;
20401
Cody Northrop8e54a402016-03-08 22:25:52 -070020402#ifdef ANDROID
20403 int vulkanSupport = InitVulkan();
20404 if (vulkanSupport == 0)
20405 return 1;
20406#endif
20407
Tony Barbour300a6082015-04-07 13:44:53 -060020408 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020409 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020410
20411 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20412
20413 result = RUN_ALL_TESTS();
20414
Tony Barbour6918cd52015-04-09 12:58:51 -060020415 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020416 return result;
20417}