blob: 013e9b1e13bfe3a0ee5358d029b1c87bfcd3dcd1 [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"
37#include "vkrenderframework.h"
Tobin Ehlise2eeffa2016-09-21 17:32:26 -060038#include <unordered_set>
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060039#include "vk_validation_error_messages.h"
Tony Barbour300a6082015-04-07 13:44:53 -060040
Mark Lobodzinski3780e142015-05-14 15:08:13 -050041#define GLM_FORCE_RADIANS
42#include "glm/glm.hpp"
43#include <glm/gtc/matrix_transform.hpp>
44
Dustin Gravesffa90fa2016-05-06 11:20:38 -060045#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060046#define MEM_TRACKER_TESTS 1
47#define OBJ_TRACKER_TESTS 1
48#define DRAW_STATE_TESTS 1
49#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120050#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060051#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060052#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060053
Mark Lobodzinski3780e142015-05-14 15:08:13 -050054//--------------------------------------------------------------------------------------
55// Mesh and VertexFormat Data
56//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070057struct Vertex {
58 float posX, posY, posZ, posW; // Position data
59 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050060};
61
Karl Schultz6addd812016-02-02 17:17:23 -070062#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050063
64typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070065 BsoFailNone = 0x00000000,
66 BsoFailLineWidth = 0x00000001,
67 BsoFailDepthBias = 0x00000002,
68 BsoFailViewport = 0x00000004,
69 BsoFailScissor = 0x00000008,
70 BsoFailBlend = 0x00000010,
71 BsoFailDepthBounds = 0x00000020,
72 BsoFailStencilReadMask = 0x00000040,
73 BsoFailStencilWriteMask = 0x00000080,
74 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060075 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060076 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050077} BsoFailSelect;
78
79struct vktriangle_vs_uniform {
80 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070081 float mvp[4][4];
82 float position[3][4];
83 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050084};
85
Mark Lobodzinskice751c62016-09-08 10:45:35 -060086static const char bindStateVertShaderText[] = "#version 450\n"
87 "vec2 vertices[3];\n"
88 "out gl_PerVertex {\n"
89 " vec4 gl_Position;\n"
90 "};\n"
91 "void main() {\n"
92 " vertices[0] = vec2(-1.0, -1.0);\n"
93 " vertices[1] = vec2( 1.0, -1.0);\n"
94 " vertices[2] = vec2( 0.0, 1.0);\n"
95 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
96 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060098static const char bindStateFragShaderText[] = "#version 450\n"
99 "\n"
100 "layout(location = 0) out vec4 uFragColor;\n"
101 "void main(){\n"
102 " uFragColor = vec4(0,1,0,1);\n"
103 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500104
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600105static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
106 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
107 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600108
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600109// ErrorMonitor Usage:
110//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600111// Call SetDesiredFailureMsg with: a string to be compared against all
112// encountered log messages, or a validation error enum identifying
113// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
114// will match all log messages. logMsg will return true for skipCall
115// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600116//
117// Call DesiredMsgFound to determine if the desired failure message
118// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600119class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700120 public:
121 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600122 test_platform_thread_create_mutex(&m_mutex);
123 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200124 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700125 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600126 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600127 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600128
Dustin Graves48458142016-04-29 16:11:55 -0600129 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
130
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600131 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700132 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600133 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600134 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600135 m_failure_message_strings.clear();
136 // If we are looking for a matching string, ignore any IDs
137 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600138 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600139 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700140 m_msgFound = VK_FALSE;
141 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600142 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600143 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600144
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600145 // ErrorMonitor will look for a message ID matching the specified one
146 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
147 // Also discard all collected messages to this point
148 test_platform_thread_lock_mutex(&m_mutex);
149 m_failure_message_strings.clear();
150 // If we are looking for IDs don't look for strings
151 m_desired_message_strings.clear();
152 m_otherMsgs.clear();
153 m_desired_message_ids.insert(msg_id);
154 m_msgFound = VK_FALSE;
155 m_msgFlags = msgFlags;
156 test_platform_thread_unlock_mutex(&m_mutex);
157 }
158
159 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600160 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600161 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600162 if (m_bailout != NULL) {
163 *m_bailout = true;
164 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600166 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600167
168 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600169 if (desired_msg.length() == 0) {
170 // An empty desired_msg string "" indicates a positive test - not expecting an error.
171 // Return true to avoid calling layers/driver with this error.
172 // And don't erase the "" string, so it remains if another error is found.
173 result = VK_TRUE;
174 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600175 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600176 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600177 m_msgFound = VK_TRUE;
178 result = VK_TRUE;
179 // We only want one match for each expected error so remove from set here
180 // 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 -0600181 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600182 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600183 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600184 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600185 for (auto desired_id : m_desired_message_ids) {
186 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
187 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
188 // Return true to avoid calling layers/driver with this error.
189 result = VK_TRUE;
190 } else if (desired_id == message_code) {
191 // Double-check that the string matches the error enum
192 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
193 found_expected = true;
194 result = VK_TRUE;
195 m_msgFound = VK_TRUE;
196 m_desired_message_ids.erase(desired_id);
197 break;
198 } else {
199 // Treat this message as a regular unexpected error, but print a warning jic
200 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
201 errorString.c_str(), desired_id, validation_error_map[desired_id]);
202 }
203 }
204 }
205
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600206 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200207 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600208 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600209 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600210 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600211 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600212 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600213
Karl Schultz6addd812016-02-02 17:17:23 -0700214 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600215
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600216 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
217
Karl Schultz6addd812016-02-02 17:17:23 -0700218 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600219
Karl Schultz6addd812016-02-02 17:17:23 -0700220 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600221
Karl Schultz6addd812016-02-02 17:17:23 -0700222 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600223 vector<string> otherMsgs = GetOtherFailureMsgs();
224 cout << "Other error messages logged for this test were:" << endl;
225 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
226 cout << " " << *iter << endl;
227 }
228 }
229
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600230 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200231
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600232 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
233 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
234 m_msgFlags = message_flag_mask;
235 // Match ANY message matching specified type
236 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200237 }
238
239 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600240 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200241 if (!DesiredMsgFound()) {
242 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600243 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600244 FAIL() << "Did not receive expected error '" << desired_msg << "'";
245 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200246 }
247 }
248
249 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600250 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200251 if (DesiredMsgFound()) {
252 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600253 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600254 FAIL() << "Expected to succeed but got error: " << msg;
255 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200256 }
257 }
258
Karl Schultz6addd812016-02-02 17:17:23 -0700259 private:
260 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600261 std::unordered_set<uint32_t>m_desired_message_ids;
262 std::unordered_set<string> m_desired_message_strings;
263 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700264 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600265 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700266 bool *m_bailout;
267 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600268};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500269
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600270static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
271 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
272 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600273 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
274 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600275 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600276 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600277 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600278}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500279
Karl Schultz6addd812016-02-02 17:17:23 -0700280class VkLayerTest : public VkRenderFramework {
281 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800282 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
283 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600284 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
285 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700286 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600287 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
288 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700289 }
Tony Barbour300a6082015-04-07 13:44:53 -0600290
Tony Barbourfe3351b2015-07-28 10:17:20 -0600291 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600292 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800293 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600294 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
295 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700296 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600297 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700298 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600299 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700300 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600301 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
302 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
303 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700304 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
305 }
306 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
307 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
308 }
309
310 protected:
311 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600312 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600313
314 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600315 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600316 std::vector<const char *> instance_extension_names;
317 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600318
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700319 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600320 /*
321 * Since CreateDbgMsgCallback is an instance level extension call
322 * any extension / layer that utilizes that feature also needs
323 * to be enabled at create instance time.
324 */
Karl Schultz6addd812016-02-02 17:17:23 -0700325 // Use Threading layer first to protect others from
326 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700327 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600328 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800329 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700330 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800331 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600332 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700333 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600334
Ian Elliott2c1daf52016-05-12 09:41:46 -0600335 if (m_enableWSI) {
336 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
337 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
338#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
339#if defined(VK_USE_PLATFORM_ANDROID_KHR)
340 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
341#endif // VK_USE_PLATFORM_ANDROID_KHR
342#if defined(VK_USE_PLATFORM_MIR_KHR)
343 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
344#endif // VK_USE_PLATFORM_MIR_KHR
345#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
346 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
347#endif // VK_USE_PLATFORM_WAYLAND_KHR
348#if defined(VK_USE_PLATFORM_WIN32_KHR)
349 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_WIN32_KHR
351#endif // NEED_TO_TEST_THIS_ON_PLATFORM
352#if defined(VK_USE_PLATFORM_XCB_KHR)
353 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
354#elif defined(VK_USE_PLATFORM_XLIB_KHR)
355 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_XLIB_KHR
357 }
358
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600359 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600360 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800361 this->app_info.pApplicationName = "layer_tests";
362 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600363 this->app_info.pEngineName = "unittest";
364 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600365 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600366
Tony Barbour15524c32015-04-29 17:34:29 -0600367 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600368 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600369 }
370
371 virtual void TearDown() {
372 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600373 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600374 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600375 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600376
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600377 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600378};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500379
Karl Schultz6addd812016-02-02 17:17:23 -0700380VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600381 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600382
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800383 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600384
385 /*
386 * For render test all drawing happens in a single render pass
387 * on a single command buffer.
388 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200389 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800390 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600391 }
392
393 return result;
394}
395
Karl Schultz6addd812016-02-02 17:17:23 -0700396VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600397 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600398
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200399 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800400 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200401 }
Tony Barbour300a6082015-04-07 13:44:53 -0600402
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800403 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600404
405 return result;
406}
407
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600408void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500409 // Create identity matrix
410 int i;
411 struct vktriangle_vs_uniform data;
412
413 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700414 glm::mat4 View = glm::mat4(1.0f);
415 glm::mat4 Model = glm::mat4(1.0f);
416 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500417 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700418 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500419
420 memcpy(&data.mvp, &MVP[0][0], matrixSize);
421
Karl Schultz6addd812016-02-02 17:17:23 -0700422 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600423 {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 -0500424 };
425
Karl Schultz6addd812016-02-02 17:17:23 -0700426 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500427 data.position[i][0] = tri_data[i].posX;
428 data.position[i][1] = tri_data[i].posY;
429 data.position[i][2] = tri_data[i].posZ;
430 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700431 data.color[i][0] = tri_data[i].r;
432 data.color[i][1] = tri_data[i].g;
433 data.color[i][2] = tri_data[i].b;
434 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500435 }
436
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500437 ASSERT_NO_FATAL_FAILURE(InitViewport());
438
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200439 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
440 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600443 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444
445 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800446 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447 pipelineobj.AddShader(&vs);
448 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600449 if (failMask & BsoFailLineWidth) {
450 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600451 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600452 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600453 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
454 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 }
456 if (failMask & BsoFailDepthBias) {
457 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600458 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600459 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600460 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600461 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600462 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600463 }
Karl Schultz6addd812016-02-02 17:17:23 -0700464 // Viewport and scissors must stay in synch or other errors will occur than
465 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600466 if (failMask & BsoFailViewport) {
467 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
468 }
469 if (failMask & BsoFailScissor) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
471 }
472 if (failMask & BsoFailBlend) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600474 VkPipelineColorBlendAttachmentState att_state = {};
475 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
476 att_state.blendEnable = VK_TRUE;
477 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600478 }
479 if (failMask & BsoFailDepthBounds) {
480 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
481 }
482 if (failMask & BsoFailStencilReadMask) {
483 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
484 }
485 if (failMask & BsoFailStencilWriteMask) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
487 }
488 if (failMask & BsoFailStencilReference) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
490 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500491
492 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600493 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500494
495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600496 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497
Tony Barbourfe3351b2015-07-28 10:17:20 -0600498 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500499
500 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600501 if (failMask & BsoFailIndexBuffer) {
502 // Use DrawIndexed w/o an index buffer bound
503 DrawIndexed(3, 1, 0, 0, 0);
504 } else {
505 Draw(3, 1, 0, 0);
506 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500507
Mark Muellerd4914412016-06-13 17:52:06 -0600508 if (failMask & BsoFailCmdClearAttachments) {
509 VkClearAttachment color_attachment = {};
510 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
511 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
512 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
513
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600514 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600515 }
516
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500517 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600518 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500519
Tony Barbourfe3351b2015-07-28 10:17:20 -0600520 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500521}
522
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600523void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
524 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600526 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500527 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600528 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500529 }
530
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800531 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700532 // Make sure depthWriteEnable is set so that Depth fail test will work
533 // correctly
534 // Make sure stencilTestEnable is set so that Stencil fail test will work
535 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600536 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800537 stencil.failOp = VK_STENCIL_OP_KEEP;
538 stencil.passOp = VK_STENCIL_OP_KEEP;
539 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
540 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600541
542 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
543 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600544 ds_ci.pNext = NULL;
545 ds_ci.depthTestEnable = VK_FALSE;
546 ds_ci.depthWriteEnable = VK_TRUE;
547 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
548 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600549 if (failMask & BsoFailDepthBounds) {
550 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600551 ds_ci.maxDepthBounds = 0.0f;
552 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600553 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600554 ds_ci.stencilTestEnable = VK_TRUE;
555 ds_ci.front = stencil;
556 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600557
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600558 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600559 pipelineobj.SetViewport(m_viewports);
560 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800561 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600562 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600563 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800564 commandBuffer->BindPipeline(pipelineobj);
565 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500566}
567
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600568class VkPositiveLayerTest : public VkLayerTest {
569 public:
570 protected:
571};
572
Ian Elliott2c1daf52016-05-12 09:41:46 -0600573class VkWsiEnabledLayerTest : public VkLayerTest {
574 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600575 protected:
576 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600577};
578
Mark Muellerdfe37552016-07-07 14:47:42 -0600579class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600580 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600581 enum eTestEnFlags {
582 eDoubleDelete,
583 eInvalidDeviceOffset,
584 eInvalidMemoryOffset,
585 eBindNullBuffer,
586 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600587 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600588 };
589
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600590 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600591
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600592 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
593 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 return true;
595 }
596 VkDeviceSize offset_limit = 0;
597 if (eInvalidMemoryOffset == aTestFlag) {
598 VkBuffer vulkanBuffer;
599 VkBufferCreateInfo buffer_create_info = {};
600 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
601 buffer_create_info.size = 32;
602 buffer_create_info.usage = aBufferUsage;
603
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600604 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600605 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600606
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600607 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600608 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
609 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
611 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600612 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600615 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600616 }
617 if (eOffsetAlignment < offset_limit) {
618 return true;
619 }
620 return false;
621 }
622
623 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
625 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600626
627 if (eBindNullBuffer == aTestFlag) {
628 VulkanMemory = 0;
629 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
630 } else {
631 VkBufferCreateInfo buffer_create_info = {};
632 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
633 buffer_create_info.size = 32;
634 buffer_create_info.usage = aBufferUsage;
635
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600636 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600637
638 CreateCurrent = true;
639
640 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600641 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600642
643 VkMemoryAllocateInfo memory_allocate_info = {};
644 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
645 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600646 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
647 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600648 if (!pass) {
649 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
650 return;
651 }
652
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600653 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 AllocateCurrent = true;
655 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600656 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
657 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600658 BoundCurrent = true;
659
660 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
661 }
662 }
663
664 ~VkBufferTest() {
665 if (CreateCurrent) {
666 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
667 }
668 if (AllocateCurrent) {
669 if (InvalidDeleteEn) {
670 union {
671 VkDeviceMemory device_memory;
672 unsigned long long index_access;
673 } bad_index;
674
675 bad_index.device_memory = VulkanMemory;
676 bad_index.index_access++;
677
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600678 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600679 }
680 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
681 }
682 }
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600685
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600686 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600687
688 void TestDoubleDestroy() {
689 // Destroy the buffer but leave the flag set, which will cause
690 // the buffer to be destroyed again in the destructor.
691 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
692 }
693
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600694 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600695 bool AllocateCurrent;
696 bool BoundCurrent;
697 bool CreateCurrent;
698 bool InvalidDeleteEn;
699
700 VkBuffer VulkanBuffer;
701 VkDevice VulkanDevice;
702 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600703};
704
705class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600706 public:
707 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600708 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600709 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600710 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600711 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
712 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600713 BindIdGenerator++; // NB: This can wrap w/misuse
714
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
716 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600717
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
719 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
720 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
721 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
722 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600723
724 unsigned i = 0;
725 do {
726 VertexInputAttributeDescription[i].binding = BindId;
727 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600728 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
729 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600730 i++;
731 } while (AttributeCount < i);
732
733 i = 0;
734 do {
735 VertexInputBindingDescription[i].binding = BindId;
736 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600738 i++;
739 } while (BindingCount < i);
740 }
741
742 ~VkVerticesObj() {
743 if (VertexInputAttributeDescription) {
744 delete[] VertexInputAttributeDescription;
745 }
746 if (VertexInputBindingDescription) {
747 delete[] VertexInputBindingDescription;
748 }
749 }
750
751 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600752 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
753 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600754 return true;
755 }
756
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600757 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600758 VkDeviceSize *offsetList;
759 unsigned offsetCount;
760
761 if (aOffsetCount) {
762 offsetList = aOffsetList;
763 offsetCount = aOffsetCount;
764 } else {
765 offsetList = new VkDeviceSize[1]();
766 offsetCount = 1;
767 }
768
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600769 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600770 BoundCurrent = true;
771
772 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600773 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600774 }
775 }
776
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600777 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600778 static uint32_t BindIdGenerator;
779
780 bool BoundCurrent;
781 unsigned AttributeCount;
782 unsigned BindingCount;
783 uint32_t BindId;
784
785 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
786 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
787 VkVertexInputBindingDescription *VertexInputBindingDescription;
788 VkConstantBufferObj VulkanMemoryBuffer;
789};
790
791uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500792// ********************************************************************************************************************
793// ********************************************************************************************************************
794// ********************************************************************************************************************
795// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600796#if PARAMETER_VALIDATION_TESTS
797TEST_F(VkLayerTest, RequiredParameter) {
798 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
799 "pointer, array, and array count parameters");
800
801 ASSERT_NO_FATAL_FAILURE(InitState());
802
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600804 // Specify NULL for a pointer to a handle
805 // Expected to trigger an error with
806 // parameter_validation::validate_required_pointer
807 vkGetPhysicalDeviceFeatures(gpu(), NULL);
808 m_errorMonitor->VerifyFound();
809
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
811 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600812 // Specify NULL for pointer to array count
813 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600814 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600815 m_errorMonitor->VerifyFound();
816
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600818 // Specify 0 for a required array count
819 // Expected to trigger an error with parameter_validation::validate_array
820 VkViewport view_port = {};
821 m_commandBuffer->SetViewport(0, 0, &view_port);
822 m_errorMonitor->VerifyFound();
823
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600825 // Specify NULL for a required array
826 // Expected to trigger an error with parameter_validation::validate_array
827 m_commandBuffer->SetViewport(0, 1, NULL);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify VK_NULL_HANDLE for a required handle
832 // Expected to trigger an error with
833 // parameter_validation::validate_required_handle
834 vkUnmapMemory(device(), VK_NULL_HANDLE);
835 m_errorMonitor->VerifyFound();
836
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
838 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600839 // Specify VK_NULL_HANDLE for a required handle array entry
840 // Expected to trigger an error with
841 // parameter_validation::validate_required_handle_array
842 VkFence fence = VK_NULL_HANDLE;
843 vkResetFences(device(), 1, &fence);
844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600847 // Specify NULL for a required struct pointer
848 // Expected to trigger an error with
849 // parameter_validation::validate_struct_type
850 VkDeviceMemory memory = VK_NULL_HANDLE;
851 vkAllocateMemory(device(), NULL, NULL, &memory);
852 m_errorMonitor->VerifyFound();
853
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600855 // Specify 0 for a required VkFlags parameter
856 // Expected to trigger an error with parameter_validation::validate_flags
857 m_commandBuffer->SetStencilReference(0, 0);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 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 -0600861 // Specify 0 for a required VkFlags array entry
862 // Expected to trigger an error with
863 // parameter_validation::validate_flags_array
864 VkSemaphore semaphore = VK_NULL_HANDLE;
865 VkPipelineStageFlags stageFlags = 0;
866 VkSubmitInfo submitInfo = {};
867 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
868 submitInfo.waitSemaphoreCount = 1;
869 submitInfo.pWaitSemaphores = &semaphore;
870 submitInfo.pWaitDstStageMask = &stageFlags;
871 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
872 m_errorMonitor->VerifyFound();
873}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600874
Dustin Gravesfce74c02016-05-10 11:42:58 -0600875TEST_F(VkLayerTest, ReservedParameter) {
876 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
877
878 ASSERT_NO_FATAL_FAILURE(InitState());
879
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600881 // Specify 0 for a reserved VkFlags parameter
882 // Expected to trigger an error with
883 // parameter_validation::validate_reserved_flags
884 VkEvent event_handle = VK_NULL_HANDLE;
885 VkEventCreateInfo event_info = {};
886 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
887 event_info.flags = 1;
888 vkCreateEvent(device(), &event_info, NULL, &event_handle);
889 m_errorMonitor->VerifyFound();
890}
891
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600892TEST_F(VkLayerTest, InvalidStructSType) {
893 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
894 "structure's sType field");
895
896 ASSERT_NO_FATAL_FAILURE(InitState());
897
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600899 // Zero struct memory, effectively setting sType to
900 // VK_STRUCTURE_TYPE_APPLICATION_INFO
901 // Expected to trigger an error with
902 // parameter_validation::validate_struct_type
903 VkMemoryAllocateInfo alloc_info = {};
904 VkDeviceMemory memory = VK_NULL_HANDLE;
905 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
906 m_errorMonitor->VerifyFound();
907
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600909 // Zero struct memory, effectively setting sType to
910 // VK_STRUCTURE_TYPE_APPLICATION_INFO
911 // Expected to trigger an error with
912 // parameter_validation::validate_struct_type_array
913 VkSubmitInfo submit_info = {};
914 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
915 m_errorMonitor->VerifyFound();
916}
917
918TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600919 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600920
921 ASSERT_NO_FATAL_FAILURE(InitState());
922
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600924 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600925 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600926 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600927 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600928 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600929 // Zero-initialization will provide the correct sType
930 VkApplicationInfo app_info = {};
931 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
932 event_alloc_info.pNext = &app_info;
933 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
934 m_errorMonitor->VerifyFound();
935
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
937 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600938 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
939 // a function that has allowed pNext structure types and specify
940 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600941 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600942 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600943 VkMemoryAllocateInfo memory_alloc_info = {};
944 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
945 memory_alloc_info.pNext = &app_info;
946 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600947 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948}
Dustin Graves5d33d532016-05-09 16:21:12 -0600949
950TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600951 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600952
953 ASSERT_NO_FATAL_FAILURE(InitState());
954
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
956 "range of the core VkFormat "
957 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600958 // Specify an invalid VkFormat value
959 // Expected to trigger an error with
960 // parameter_validation::validate_ranged_enum
961 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600962 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600963 m_errorMonitor->VerifyFound();
964
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600965 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 -0600966 // Specify an invalid VkFlags bitmask value
967 // Expected to trigger an error with parameter_validation::validate_flags
968 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600969 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
970 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600971 m_errorMonitor->VerifyFound();
972
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600973 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 -0600974 // Specify an invalid VkFlags array entry
975 // Expected to trigger an error with
976 // parameter_validation::validate_flags_array
977 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600978 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600979 VkSubmitInfo submit_info = {};
980 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
981 submit_info.waitSemaphoreCount = 1;
982 submit_info.pWaitSemaphores = &semaphore;
983 submit_info.pWaitDstStageMask = &stage_flags;
984 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
985 m_errorMonitor->VerifyFound();
986
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600988 // Specify an invalid VkBool32 value
989 // Expected to trigger a warning with
990 // parameter_validation::validate_bool32
991 VkSampler sampler = VK_NULL_HANDLE;
992 VkSamplerCreateInfo sampler_info = {};
993 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
994 sampler_info.pNext = NULL;
995 sampler_info.magFilter = VK_FILTER_NEAREST;
996 sampler_info.minFilter = VK_FILTER_NEAREST;
997 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
998 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
999 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1000 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1001 sampler_info.mipLodBias = 1.0;
1002 sampler_info.maxAnisotropy = 1;
1003 sampler_info.compareEnable = VK_FALSE;
1004 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1005 sampler_info.minLod = 1.0;
1006 sampler_info.maxLod = 1.0;
1007 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1008 sampler_info.unnormalizedCoordinates = VK_FALSE;
1009 // Not VK_TRUE or VK_FALSE
1010 sampler_info.anisotropyEnable = 3;
1011 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1012 m_errorMonitor->VerifyFound();
1013}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001014
1015TEST_F(VkLayerTest, FailedReturnValue) {
1016 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1017
1018 ASSERT_NO_FATAL_FAILURE(InitState());
1019
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001020 // Find an unsupported image format
1021 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1022 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1023 VkFormat format = static_cast<VkFormat>(f);
1024 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001025 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001026 unsupported = format;
1027 break;
1028 }
1029 }
1030
1031 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1033 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001034 // Specify an unsupported VkFormat value to generate a
1035 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1036 // Expected to trigger a warning from
1037 // parameter_validation::validate_result
1038 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001039 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1040 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001041 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1042 m_errorMonitor->VerifyFound();
1043 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001044}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001045
1046TEST_F(VkLayerTest, UpdateBufferAlignment) {
1047 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001048 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001049
1050 ASSERT_NO_FATAL_FAILURE(InitState());
1051
1052 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1053 vk_testing::Buffer buffer;
1054 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1055
1056 BeginCommandBuffer();
1057 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001059 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1060 m_errorMonitor->VerifyFound();
1061
1062 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001064 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1065 m_errorMonitor->VerifyFound();
1066
1067 // Introduce failure by using dataSize that is < 0
1068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Introduce failure by using dataSize that is > 65536
1074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1077 m_errorMonitor->VerifyFound();
1078
1079 EndCommandBuffer();
1080}
1081
1082TEST_F(VkLayerTest, FillBufferAlignment) {
1083 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1084
1085 ASSERT_NO_FATAL_FAILURE(InitState());
1086
1087 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1088 vk_testing::Buffer buffer;
1089 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1090
1091 BeginCommandBuffer();
1092
1093 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001095 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1096 m_errorMonitor->VerifyFound();
1097
1098 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001100 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1101 m_errorMonitor->VerifyFound();
1102
1103 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001105 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1106 m_errorMonitor->VerifyFound();
1107
1108 EndCommandBuffer();
1109}
Dustin Graves40f35822016-06-23 11:12:53 -06001110
Cortd889ff92016-07-27 09:51:27 -07001111TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1112 VkResult err;
1113
1114 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001115 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001116
1117 ASSERT_NO_FATAL_FAILURE(InitState());
1118 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1119
1120 std::vector<const char *> device_extension_names;
1121 auto features = m_device->phy().features();
1122 // Artificially disable support for non-solid fill modes
1123 features.fillModeNonSolid = false;
1124 // The sacrificial device object
1125 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1126
1127 VkRenderpassObj render_pass(&test_device);
1128
1129 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1130 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1131 pipeline_layout_ci.setLayoutCount = 0;
1132 pipeline_layout_ci.pSetLayouts = NULL;
1133
1134 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001135 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001136 ASSERT_VK_SUCCESS(err);
1137
1138 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1139 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1140 rs_ci.pNext = nullptr;
1141 rs_ci.lineWidth = 1.0f;
1142 rs_ci.rasterizerDiscardEnable = true;
1143
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001144 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1145 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001146
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001147 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1149 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001150 {
1151 VkPipelineObj pipe(&test_device);
1152 pipe.AddShader(&vs);
1153 pipe.AddShader(&fs);
1154 pipe.AddColorAttachment();
1155 // Introduce failure by setting unsupported polygon mode
1156 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1157 pipe.SetRasterization(&rs_ci);
1158 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1159 }
1160 m_errorMonitor->VerifyFound();
1161
1162 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1164 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001165 {
1166 VkPipelineObj pipe(&test_device);
1167 pipe.AddShader(&vs);
1168 pipe.AddShader(&fs);
1169 pipe.AddColorAttachment();
1170 // Introduce failure by setting unsupported polygon mode
1171 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1172 pipe.SetRasterization(&rs_ci);
1173 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1174 }
1175 m_errorMonitor->VerifyFound();
1176
Cortd889ff92016-07-27 09:51:27 -07001177 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1178}
1179
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001180#endif // PARAMETER_VALIDATION_TESTS
1181
Tobin Ehlis0788f522015-05-26 16:11:58 -06001182#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001183#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001184TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001185{
1186 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001187 VkFenceCreateInfo fenceInfo = {};
1188 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1189 fenceInfo.pNext = NULL;
1190 fenceInfo.flags = 0;
1191
Mike Weiblencce7ec72016-10-17 19:33:05 -06001192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001193
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001194 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001195
1196 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1197 vk_testing::Buffer buffer;
1198 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001199
Tony Barbourfe3351b2015-07-28 10:17:20 -06001200 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001201 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001202 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001203
1204 testFence.init(*m_device, fenceInfo);
1205
1206 // Bypass framework since it does the waits automatically
1207 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001208 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001209 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1210 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001211 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001212 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001213 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001214 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001215 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001216 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001217 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001218
1219 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001220 ASSERT_VK_SUCCESS( err );
1221
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001223 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001224
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001225 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226}
1227
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001228TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001229{
1230 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001231 VkFenceCreateInfo fenceInfo = {};
1232 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1233 fenceInfo.pNext = NULL;
1234 fenceInfo.flags = 0;
1235
Mike Weiblencce7ec72016-10-17 19:33:05 -06001236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001237
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001238 ASSERT_NO_FATAL_FAILURE(InitState());
1239 ASSERT_NO_FATAL_FAILURE(InitViewport());
1240 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1241
Tony Barbourfe3351b2015-07-28 10:17:20 -06001242 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001243 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001244 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001245
1246 testFence.init(*m_device, fenceInfo);
1247
1248 // Bypass framework since it does the waits automatically
1249 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001250 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001251 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1252 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001253 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001254 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001255 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001256 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001257 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001258 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001259 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001260
1261 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001262 ASSERT_VK_SUCCESS( err );
1263
Jon Ashburnf19916e2016-01-11 13:12:43 -07001264 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001265 VkCommandBufferBeginInfo info = {};
1266 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1267 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001268 info.renderPass = VK_NULL_HANDLE;
1269 info.subpass = 0;
1270 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001271 info.occlusionQueryEnable = VK_FALSE;
1272 info.queryFlags = 0;
1273 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001274
1275 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001276 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001277
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001278 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001279}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001280#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001281
Tobin Ehlisf11be982016-05-11 13:52:53 -06001282TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1283 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1284 "buffer and image to memory such that they will alias.");
1285 VkResult err;
1286 bool pass;
1287 ASSERT_NO_FATAL_FAILURE(InitState());
1288
Tobin Ehlis077ded32016-05-12 17:39:13 -06001289 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001290 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001291 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001292 VkDeviceMemory mem; // buffer will be bound first
1293 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001294 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001295
1296 VkBufferCreateInfo buf_info = {};
1297 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1298 buf_info.pNext = NULL;
1299 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1300 buf_info.size = 256;
1301 buf_info.queueFamilyIndexCount = 0;
1302 buf_info.pQueueFamilyIndices = NULL;
1303 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1304 buf_info.flags = 0;
1305 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1306 ASSERT_VK_SUCCESS(err);
1307
Tobin Ehlis077ded32016-05-12 17:39:13 -06001308 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001309
1310 VkImageCreateInfo image_create_info = {};
1311 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1312 image_create_info.pNext = NULL;
1313 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1314 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1315 image_create_info.extent.width = 64;
1316 image_create_info.extent.height = 64;
1317 image_create_info.extent.depth = 1;
1318 image_create_info.mipLevels = 1;
1319 image_create_info.arrayLayers = 1;
1320 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001321 // Image tiling must be optimal to trigger error when aliasing linear buffer
1322 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001323 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1324 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1325 image_create_info.queueFamilyIndexCount = 0;
1326 image_create_info.pQueueFamilyIndices = NULL;
1327 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1328 image_create_info.flags = 0;
1329
Tobin Ehlisf11be982016-05-11 13:52:53 -06001330 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1331 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001332 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1333 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001334
Tobin Ehlis077ded32016-05-12 17:39:13 -06001335 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1336
1337 VkMemoryAllocateInfo alloc_info = {};
1338 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1339 alloc_info.pNext = NULL;
1340 alloc_info.memoryTypeIndex = 0;
1341 // Ensure memory is big enough for both bindings
1342 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001343 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1344 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001345 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001346 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001347 vkDestroyImage(m_device->device(), image, NULL);
1348 return;
1349 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001350 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1351 ASSERT_VK_SUCCESS(err);
1352 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1353 ASSERT_VK_SUCCESS(err);
1354
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001357 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1358 m_errorMonitor->VerifyFound();
1359
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001360 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001361 // aliasing buffer2
1362 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1363 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001364 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1365 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001366 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001367 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001369 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001370 m_errorMonitor->VerifyFound();
1371
1372 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001373 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001374 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001375 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 vkFreeMemory(m_device->device(), mem, NULL);
1377 vkFreeMemory(m_device->device(), mem_img, NULL);
1378}
1379
Tobin Ehlis35372522016-05-12 08:32:31 -06001380TEST_F(VkLayerTest, InvalidMemoryMapping) {
1381 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1382 VkResult err;
1383 bool pass;
1384 ASSERT_NO_FATAL_FAILURE(InitState());
1385
1386 VkBuffer buffer;
1387 VkDeviceMemory mem;
1388 VkMemoryRequirements mem_reqs;
1389
1390 VkBufferCreateInfo buf_info = {};
1391 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1392 buf_info.pNext = NULL;
1393 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1394 buf_info.size = 256;
1395 buf_info.queueFamilyIndexCount = 0;
1396 buf_info.pQueueFamilyIndices = NULL;
1397 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1398 buf_info.flags = 0;
1399 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1400 ASSERT_VK_SUCCESS(err);
1401
1402 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1403 VkMemoryAllocateInfo alloc_info = {};
1404 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1405 alloc_info.pNext = NULL;
1406 alloc_info.memoryTypeIndex = 0;
1407
1408 // Ensure memory is big enough for both bindings
1409 static const VkDeviceSize allocation_size = 0x10000;
1410 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001411 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 -06001412 if (!pass) {
1413 vkDestroyBuffer(m_device->device(), buffer, NULL);
1414 return;
1415 }
1416 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1417 ASSERT_VK_SUCCESS(err);
1418
1419 uint8_t *pData;
1420 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001421 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 -06001422 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1423 m_errorMonitor->VerifyFound();
1424 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001425 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001426 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1428 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1429 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001430 m_errorMonitor->VerifyFound();
1431
1432 // Unmap the memory to avoid re-map error
1433 vkUnmapMemory(m_device->device(), mem);
1434 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1436 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1437 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001438 m_errorMonitor->VerifyFound();
1439 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1441 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001442 m_errorMonitor->VerifyFound();
1443 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001445 vkUnmapMemory(m_device->device(), mem);
1446 m_errorMonitor->VerifyFound();
1447 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001449 ASSERT_VK_SUCCESS(err);
1450 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001451 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001452 mmr.memory = mem;
1453 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001455 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1456 m_errorMonitor->VerifyFound();
1457 // Now flush range that oversteps mapped range
1458 vkUnmapMemory(m_device->device(), mem);
1459 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1460 ASSERT_VK_SUCCESS(err);
1461 mmr.offset = 16;
1462 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001464 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1465 m_errorMonitor->VerifyFound();
1466
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001467 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1468 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001469 if (!pass) {
1470 vkFreeMemory(m_device->device(), mem, NULL);
1471 vkDestroyBuffer(m_device->device(), buffer, NULL);
1472 return;
1473 }
1474 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1475 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1476
1477 vkDestroyBuffer(m_device->device(), buffer, NULL);
1478 vkFreeMemory(m_device->device(), mem, NULL);
1479}
1480
Ian Elliott1c32c772016-04-28 14:47:13 -06001481TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1482 VkResult err;
1483 bool pass;
1484
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001485 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1486 // following declaration (which is temporarily being moved below):
1487 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001488 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1489 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1490 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001491 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001492 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001493 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001494
1495 ASSERT_NO_FATAL_FAILURE(InitState());
1496
Ian Elliott3f06ce52016-04-29 14:46:21 -06001497#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1498#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1499 // Use the functions from the VK_KHR_android_surface extension without
1500 // enabling that extension:
1501
1502 // Create a surface:
1503 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1505 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001506 pass = (err != VK_SUCCESS);
1507 ASSERT_TRUE(pass);
1508 m_errorMonitor->VerifyFound();
1509#endif // VK_USE_PLATFORM_ANDROID_KHR
1510
Ian Elliott3f06ce52016-04-29 14:46:21 -06001511#if defined(VK_USE_PLATFORM_MIR_KHR)
1512 // Use the functions from the VK_KHR_mir_surface extension without enabling
1513 // that extension:
1514
1515 // Create a surface:
1516 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001518 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1519 pass = (err != VK_SUCCESS);
1520 ASSERT_TRUE(pass);
1521 m_errorMonitor->VerifyFound();
1522
1523 // Tell whether an mir_connection supports presentation:
1524 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1526 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001527 m_errorMonitor->VerifyFound();
1528#endif // VK_USE_PLATFORM_MIR_KHR
1529
Ian Elliott3f06ce52016-04-29 14:46:21 -06001530#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1531 // Use the functions from the VK_KHR_wayland_surface extension without
1532 // enabling that extension:
1533
1534 // Create a surface:
1535 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1537 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001538 pass = (err != VK_SUCCESS);
1539 ASSERT_TRUE(pass);
1540 m_errorMonitor->VerifyFound();
1541
1542 // Tell whether an wayland_display supports presentation:
1543 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1545 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001546 m_errorMonitor->VerifyFound();
1547#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001548#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001549
Ian Elliott3f06ce52016-04-29 14:46:21 -06001550#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001551 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1552 // TO NON-LINUX PLATFORMS:
1553 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001554 // Use the functions from the VK_KHR_win32_surface extension without
1555 // enabling that extension:
1556
1557 // Create a surface:
1558 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1560 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001561 pass = (err != VK_SUCCESS);
1562 ASSERT_TRUE(pass);
1563 m_errorMonitor->VerifyFound();
1564
1565 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001567 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001568 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001569// Set this (for now, until all platforms are supported and tested):
1570#define NEED_TO_TEST_THIS_ON_PLATFORM
1571#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001572
Ian Elliott1c32c772016-04-28 14:47:13 -06001573#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001574 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1575 // TO NON-LINUX PLATFORMS:
1576 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001577 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1578 // that extension:
1579
1580 // Create a surface:
1581 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1584 pass = (err != VK_SUCCESS);
1585 ASSERT_TRUE(pass);
1586 m_errorMonitor->VerifyFound();
1587
1588 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001589 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001590 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1592 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001593 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001594// Set this (for now, until all platforms are supported and tested):
1595#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001596#endif // VK_USE_PLATFORM_XCB_KHR
1597
Ian Elliott12630812016-04-29 14:35:43 -06001598#if defined(VK_USE_PLATFORM_XLIB_KHR)
1599 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1600 // that extension:
1601
1602 // Create a surface:
1603 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001605 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1606 pass = (err != VK_SUCCESS);
1607 ASSERT_TRUE(pass);
1608 m_errorMonitor->VerifyFound();
1609
1610 // Tell whether an Xlib VisualID supports presentation:
1611 Display *dpy = NULL;
1612 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001614 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1615 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001616// Set this (for now, until all platforms are supported and tested):
1617#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001618#endif // VK_USE_PLATFORM_XLIB_KHR
1619
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001620// Use the functions from the VK_KHR_surface extension without enabling
1621// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001622
Ian Elliott489eec02016-05-05 14:12:44 -06001623#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001624 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001626 vkDestroySurfaceKHR(instance(), surface, NULL);
1627 m_errorMonitor->VerifyFound();
1628
1629 // Check if surface supports presentation:
1630 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001632 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1633 pass = (err != VK_SUCCESS);
1634 ASSERT_TRUE(pass);
1635 m_errorMonitor->VerifyFound();
1636
1637 // Check surface capabilities:
1638 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1640 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001641 pass = (err != VK_SUCCESS);
1642 ASSERT_TRUE(pass);
1643 m_errorMonitor->VerifyFound();
1644
1645 // Check surface formats:
1646 uint32_t format_count = 0;
1647 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1649 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001650 pass = (err != VK_SUCCESS);
1651 ASSERT_TRUE(pass);
1652 m_errorMonitor->VerifyFound();
1653
1654 // Check surface present modes:
1655 uint32_t present_mode_count = 0;
1656 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1658 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001659 pass = (err != VK_SUCCESS);
1660 ASSERT_TRUE(pass);
1661 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001662#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001663
Ian Elliott1c32c772016-04-28 14:47:13 -06001664 // Use the functions from the VK_KHR_swapchain extension without enabling
1665 // that extension:
1666
1667 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001669 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1670 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001671 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001672 pass = (err != VK_SUCCESS);
1673 ASSERT_TRUE(pass);
1674 m_errorMonitor->VerifyFound();
1675
1676 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1678 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001679 pass = (err != VK_SUCCESS);
1680 ASSERT_TRUE(pass);
1681 m_errorMonitor->VerifyFound();
1682
Chris Forbeseb7d5502016-09-13 18:19:21 +12001683 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1684 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1685 VkFence fence;
1686 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1687
Ian Elliott1c32c772016-04-28 14:47:13 -06001688 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001690 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001691 pass = (err != VK_SUCCESS);
1692 ASSERT_TRUE(pass);
1693 m_errorMonitor->VerifyFound();
1694
Chris Forbeseb7d5502016-09-13 18:19:21 +12001695 vkDestroyFence(m_device->device(), fence, nullptr);
1696
Ian Elliott1c32c772016-04-28 14:47:13 -06001697 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001698 //
1699 // NOTE: Currently can't test this because a real swapchain is needed (as
1700 // opposed to the fake one we created) in order for the layer to lookup the
1701 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001702
1703 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001705 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1706 m_errorMonitor->VerifyFound();
1707}
1708
Karl Schultz6addd812016-02-02 17:17:23 -07001709TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1710 VkResult err;
1711 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001712
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1714 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001715
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001716 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001717
1718 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001719 VkImage image;
1720 VkDeviceMemory mem;
1721 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001722
Karl Schultz6addd812016-02-02 17:17:23 -07001723 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1724 const int32_t tex_width = 32;
1725 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001726
Tony Barboureb254902015-07-15 12:50:33 -06001727 VkImageCreateInfo image_create_info = {};
1728 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001729 image_create_info.pNext = NULL;
1730 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1731 image_create_info.format = tex_format;
1732 image_create_info.extent.width = tex_width;
1733 image_create_info.extent.height = tex_height;
1734 image_create_info.extent.depth = 1;
1735 image_create_info.mipLevels = 1;
1736 image_create_info.arrayLayers = 1;
1737 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1738 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1739 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1740 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001741 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001742
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001743 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001744 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001745 mem_alloc.pNext = NULL;
1746 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001747
Chia-I Wuf7458c52015-10-26 21:10:41 +08001748 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001749 ASSERT_VK_SUCCESS(err);
1750
Karl Schultz6addd812016-02-02 17:17:23 -07001751 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001752
Mark Lobodzinski23065352015-05-29 09:32:35 -05001753 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001754
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001755 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 -07001756 if (!pass) { // If we can't find any unmappable memory this test doesn't
1757 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001758 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001759 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001760 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001761
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001762 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001763 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001764 ASSERT_VK_SUCCESS(err);
1765
1766 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001767 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001768 ASSERT_VK_SUCCESS(err);
1769
1770 // Map memory as if to initialize the image
1771 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001772 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001773
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001774 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001775
Chia-I Wuf7458c52015-10-26 21:10:41 +08001776 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001777 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001778}
1779
Karl Schultz6addd812016-02-02 17:17:23 -07001780TEST_F(VkLayerTest, RebindMemory) {
1781 VkResult err;
1782 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001783
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001785
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001786 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001787
1788 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001789 VkImage image;
1790 VkDeviceMemory mem1;
1791 VkDeviceMemory mem2;
1792 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001793
Karl Schultz6addd812016-02-02 17:17:23 -07001794 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1795 const int32_t tex_width = 32;
1796 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001797
Tony Barboureb254902015-07-15 12:50:33 -06001798 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001799 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1800 image_create_info.pNext = NULL;
1801 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1802 image_create_info.format = tex_format;
1803 image_create_info.extent.width = tex_width;
1804 image_create_info.extent.height = tex_height;
1805 image_create_info.extent.depth = 1;
1806 image_create_info.mipLevels = 1;
1807 image_create_info.arrayLayers = 1;
1808 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1809 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1810 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1811 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001812
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001813 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001814 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1815 mem_alloc.pNext = NULL;
1816 mem_alloc.allocationSize = 0;
1817 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001818
Karl Schultz6addd812016-02-02 17:17:23 -07001819 // Introduce failure, do NOT set memProps to
1820 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001821 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001822 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001823 ASSERT_VK_SUCCESS(err);
1824
Karl Schultz6addd812016-02-02 17:17:23 -07001825 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001826
1827 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001828 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001829 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001830
1831 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001832 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001833 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001834 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001835 ASSERT_VK_SUCCESS(err);
1836
1837 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001838 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001839 ASSERT_VK_SUCCESS(err);
1840
Karl Schultz6addd812016-02-02 17:17:23 -07001841 // Introduce validation failure, try to bind a different memory object to
1842 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001843 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001844
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001845 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001846
Chia-I Wuf7458c52015-10-26 21:10:41 +08001847 vkDestroyImage(m_device->device(), image, NULL);
1848 vkFreeMemory(m_device->device(), mem1, NULL);
1849 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001850}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001851
Karl Schultz6addd812016-02-02 17:17:23 -07001852TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001853 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1856 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001857
1858 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001859 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1860 fenceInfo.pNext = NULL;
1861 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001862
Tony Barbour300a6082015-04-07 13:44:53 -06001863 ASSERT_NO_FATAL_FAILURE(InitState());
1864 ASSERT_NO_FATAL_FAILURE(InitViewport());
1865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1866
Tony Barbourfe3351b2015-07-28 10:17:20 -06001867 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001868 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001869 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001870
1871 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001872
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001873 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001874 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1875 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001876 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001877 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001878 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001879 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001880 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001881 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001882 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001883
1884 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001885 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001886
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001887 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001888}
Chris Forbes4e44c912016-06-16 10:20:00 +12001889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001890TEST_F(VkLayerTest, InvalidUsageBits) {
1891 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1892 "Initialize buffer with wrong usage then perform copy expecting errors "
1893 "from both the image and the buffer (2 calls)");
1894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001895
1896 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001897 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001898 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001899 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001900 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001901
Tony Barbourf92621a2016-05-02 14:28:12 -06001902 VkImageView dsv;
1903 VkImageViewCreateInfo dsvci = {};
1904 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1905 dsvci.image = image.handle();
1906 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1907 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1908 dsvci.subresourceRange.layerCount = 1;
1909 dsvci.subresourceRange.baseMipLevel = 0;
1910 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001911 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001912
Tony Barbourf92621a2016-05-02 14:28:12 -06001913 // Create a view with depth / stencil aspect for image with different usage
1914 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001915
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001916 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001917
1918 // Initialize buffer with TRANSFER_DST usage
1919 vk_testing::Buffer buffer;
1920 VkMemoryPropertyFlags reqs = 0;
1921 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1922 VkBufferImageCopy region = {};
1923 region.bufferRowLength = 128;
1924 region.bufferImageHeight = 128;
1925 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1926 region.imageSubresource.layerCount = 1;
1927 region.imageExtent.height = 16;
1928 region.imageExtent.width = 16;
1929 region.imageExtent.depth = 1;
1930
Tony Barbourf92621a2016-05-02 14:28:12 -06001931 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1932 // TRANSFER_DST
1933 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001934
Chris Forbesda581202016-10-06 18:25:26 +13001935 // two separate errors from this call:
1936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001939 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1940 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001941 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001942}
Tony Barbour75d79f02016-08-30 09:39:07 -06001943
Tony Barbour75d79f02016-08-30 09:39:07 -06001944
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001945#endif // MEM_TRACKER_TESTS
1946
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001947#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001948
1949TEST_F(VkLayerTest, LeakAnObject) {
1950 VkResult err;
1951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001952 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001953
1954 // Note that we have to create a new device since destroying the
1955 // framework's device causes Teardown() to fail and just calling Teardown
1956 // will destroy the errorMonitor.
1957
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001959
1960 ASSERT_NO_FATAL_FAILURE(InitState());
1961
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001962 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001963 std::vector<VkDeviceQueueCreateInfo> queue_info;
1964 queue_info.reserve(queue_props.size());
1965 std::vector<std::vector<float>> queue_priorities;
1966 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
1967 VkDeviceQueueCreateInfo qi = {};
1968 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
1969 qi.pNext = NULL;
1970 qi.queueFamilyIndex = i;
1971 qi.queueCount = queue_props[i].queueCount;
1972 queue_priorities.emplace_back(qi.queueCount, 0.0f);
1973 qi.pQueuePriorities = queue_priorities[i].data();
1974 queue_info.push_back(qi);
1975 }
1976
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001977 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001978
1979 // The sacrificial device object
1980 VkDevice testDevice;
1981 VkDeviceCreateInfo device_create_info = {};
1982 auto features = m_device->phy().features();
1983 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
1984 device_create_info.pNext = NULL;
1985 device_create_info.queueCreateInfoCount = queue_info.size();
1986 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06001987 device_create_info.enabledLayerCount = 0;
1988 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001989 device_create_info.pEnabledFeatures = &features;
1990 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
1991 ASSERT_VK_SUCCESS(err);
1992
1993 VkFence fence;
1994 VkFenceCreateInfo fence_create_info = {};
1995 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1996 fence_create_info.pNext = NULL;
1997 fence_create_info.flags = 0;
1998 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
1999 ASSERT_VK_SUCCESS(err);
2000
2001 // Induce failure by not calling vkDestroyFence
2002 vkDestroyDevice(testDevice, NULL);
2003 m_errorMonitor->VerifyFound();
2004}
2005
2006TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2007
2008 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2009 "attempt to delete them from another.");
2010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002012
Cody Northropc31a84f2016-08-22 10:41:47 -06002013 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002014 VkCommandPool command_pool_one;
2015 VkCommandPool command_pool_two;
2016
2017 VkCommandPoolCreateInfo pool_create_info{};
2018 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2019 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2020 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2021
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002022 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002024 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002025
2026 VkCommandBuffer command_buffer[9];
2027 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002028 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002029 command_buffer_allocate_info.commandPool = command_pool_one;
2030 command_buffer_allocate_info.commandBufferCount = 9;
2031 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002032 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002034 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002035
2036 m_errorMonitor->VerifyFound();
2037
2038 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2039 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2040}
2041
2042TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2043 VkResult err;
2044
2045 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002046 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002049
2050 ASSERT_NO_FATAL_FAILURE(InitState());
2051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2052
2053 VkDescriptorPoolSize ds_type_count = {};
2054 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2055 ds_type_count.descriptorCount = 1;
2056
2057 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2058 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2059 ds_pool_ci.pNext = NULL;
2060 ds_pool_ci.flags = 0;
2061 ds_pool_ci.maxSets = 1;
2062 ds_pool_ci.poolSizeCount = 1;
2063 ds_pool_ci.pPoolSizes = &ds_type_count;
2064
2065 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002066 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002067 ASSERT_VK_SUCCESS(err);
2068
2069 // Create a second descriptor pool
2070 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002071 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002072 ASSERT_VK_SUCCESS(err);
2073
2074 VkDescriptorSetLayoutBinding dsl_binding = {};
2075 dsl_binding.binding = 0;
2076 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2077 dsl_binding.descriptorCount = 1;
2078 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2079 dsl_binding.pImmutableSamplers = NULL;
2080
2081 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2082 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2083 ds_layout_ci.pNext = NULL;
2084 ds_layout_ci.bindingCount = 1;
2085 ds_layout_ci.pBindings = &dsl_binding;
2086
2087 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002088 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002089 ASSERT_VK_SUCCESS(err);
2090
2091 VkDescriptorSet descriptorSet;
2092 VkDescriptorSetAllocateInfo alloc_info = {};
2093 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2094 alloc_info.descriptorSetCount = 1;
2095 alloc_info.descriptorPool = ds_pool_one;
2096 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002097 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002098 ASSERT_VK_SUCCESS(err);
2099
2100 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2101
2102 m_errorMonitor->VerifyFound();
2103
2104 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2105 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2106 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2107}
2108
2109TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002111
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002112 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002113
2114 ASSERT_NO_FATAL_FAILURE(InitState());
2115
2116 // Pass bogus handle into GetImageMemoryRequirements
2117 VkMemoryRequirements mem_reqs;
2118 uint64_t fakeImageHandle = 0xCADECADE;
2119 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2120
2121 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2122
2123 m_errorMonitor->VerifyFound();
2124}
2125
Karl Schultz6addd812016-02-02 17:17:23 -07002126TEST_F(VkLayerTest, PipelineNotBound) {
2127 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002129 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002130
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002132
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002133 ASSERT_NO_FATAL_FAILURE(InitState());
2134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002135
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002136 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002137 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2138 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002139
2140 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002141 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2142 ds_pool_ci.pNext = NULL;
2143 ds_pool_ci.maxSets = 1;
2144 ds_pool_ci.poolSizeCount = 1;
2145 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002146
2147 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002148 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002149 ASSERT_VK_SUCCESS(err);
2150
2151 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002152 dsl_binding.binding = 0;
2153 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2154 dsl_binding.descriptorCount = 1;
2155 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2156 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002157
2158 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002159 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2160 ds_layout_ci.pNext = NULL;
2161 ds_layout_ci.bindingCount = 1;
2162 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002163
2164 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002165 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002166 ASSERT_VK_SUCCESS(err);
2167
2168 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002169 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002170 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002171 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002172 alloc_info.descriptorPool = ds_pool;
2173 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002174 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002175 ASSERT_VK_SUCCESS(err);
2176
2177 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002178 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2179 pipeline_layout_ci.pNext = NULL;
2180 pipeline_layout_ci.setLayoutCount = 1;
2181 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002182
2183 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002184 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002185 ASSERT_VK_SUCCESS(err);
2186
Mark Youngad779052016-01-06 14:26:04 -07002187 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002188
2189 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002190 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002191
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002192 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002193
Chia-I Wuf7458c52015-10-26 21:10:41 +08002194 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2195 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2196 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002197}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002198
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002199TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2200 VkResult err;
2201
2202 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2203 "during bind[Buffer|Image]Memory time");
2204
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002205 ASSERT_NO_FATAL_FAILURE(InitState());
2206
2207 // Create an image, allocate memory, set a bad typeIndex and then try to
2208 // bind it
2209 VkImage image;
2210 VkDeviceMemory mem;
2211 VkMemoryRequirements mem_reqs;
2212 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2213 const int32_t tex_width = 32;
2214 const int32_t tex_height = 32;
2215
2216 VkImageCreateInfo image_create_info = {};
2217 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2218 image_create_info.pNext = NULL;
2219 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2220 image_create_info.format = tex_format;
2221 image_create_info.extent.width = tex_width;
2222 image_create_info.extent.height = tex_height;
2223 image_create_info.extent.depth = 1;
2224 image_create_info.mipLevels = 1;
2225 image_create_info.arrayLayers = 1;
2226 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2227 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2228 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2229 image_create_info.flags = 0;
2230
2231 VkMemoryAllocateInfo mem_alloc = {};
2232 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2233 mem_alloc.pNext = NULL;
2234 mem_alloc.allocationSize = 0;
2235 mem_alloc.memoryTypeIndex = 0;
2236
2237 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2238 ASSERT_VK_SUCCESS(err);
2239
2240 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2241 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002242
2243 // Introduce Failure, select invalid TypeIndex
2244 VkPhysicalDeviceMemoryProperties memory_info;
2245
2246 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2247 unsigned int i;
2248 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2249 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2250 mem_alloc.memoryTypeIndex = i;
2251 break;
2252 }
2253 }
2254 if (i >= memory_info.memoryTypeCount) {
2255 printf("No invalid memory type index could be found; skipped.\n");
2256 vkDestroyImage(m_device->device(), image, NULL);
2257 return;
2258 }
2259
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002260 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 -06002261
2262 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2263 ASSERT_VK_SUCCESS(err);
2264
2265 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2266 (void)err;
2267
2268 m_errorMonitor->VerifyFound();
2269
2270 vkDestroyImage(m_device->device(), image, NULL);
2271 vkFreeMemory(m_device->device(), mem, NULL);
2272}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002273
Karl Schultz6addd812016-02-02 17:17:23 -07002274TEST_F(VkLayerTest, BindInvalidMemory) {
2275 VkResult err;
2276 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002279
Tobin Ehlisec598302015-09-15 15:02:17 -06002280 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002281
2282 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002283 VkImage image;
2284 VkDeviceMemory mem;
2285 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002286
Karl Schultz6addd812016-02-02 17:17:23 -07002287 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2288 const int32_t tex_width = 32;
2289 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002290
2291 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002292 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2293 image_create_info.pNext = NULL;
2294 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2295 image_create_info.format = tex_format;
2296 image_create_info.extent.width = tex_width;
2297 image_create_info.extent.height = tex_height;
2298 image_create_info.extent.depth = 1;
2299 image_create_info.mipLevels = 1;
2300 image_create_info.arrayLayers = 1;
2301 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2302 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2303 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2304 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002305
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002306 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002307 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2308 mem_alloc.pNext = NULL;
2309 mem_alloc.allocationSize = 0;
2310 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002311
Chia-I Wuf7458c52015-10-26 21:10:41 +08002312 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002313 ASSERT_VK_SUCCESS(err);
2314
Karl Schultz6addd812016-02-02 17:17:23 -07002315 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002316
2317 mem_alloc.allocationSize = mem_reqs.size;
2318
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002319 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002320 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002321
2322 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002323 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002324 ASSERT_VK_SUCCESS(err);
2325
2326 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002327 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002328
2329 // Try to bind free memory that has been freed
2330 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2331 // This may very well return an error.
2332 (void)err;
2333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002334 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002335
Chia-I Wuf7458c52015-10-26 21:10:41 +08002336 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002337}
2338
Karl Schultz6addd812016-02-02 17:17:23 -07002339TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2340 VkResult err;
2341 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002342
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002344
Tobin Ehlisec598302015-09-15 15:02:17 -06002345 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002346
Karl Schultz6addd812016-02-02 17:17:23 -07002347 // Create an image object, allocate memory, destroy the object and then try
2348 // to bind it
2349 VkImage image;
2350 VkDeviceMemory mem;
2351 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002352
Karl Schultz6addd812016-02-02 17:17:23 -07002353 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2354 const int32_t tex_width = 32;
2355 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002356
2357 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002358 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2359 image_create_info.pNext = NULL;
2360 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2361 image_create_info.format = tex_format;
2362 image_create_info.extent.width = tex_width;
2363 image_create_info.extent.height = tex_height;
2364 image_create_info.extent.depth = 1;
2365 image_create_info.mipLevels = 1;
2366 image_create_info.arrayLayers = 1;
2367 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2368 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2369 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2370 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002371
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002372 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002373 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2374 mem_alloc.pNext = NULL;
2375 mem_alloc.allocationSize = 0;
2376 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002377
Chia-I Wuf7458c52015-10-26 21:10:41 +08002378 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002379 ASSERT_VK_SUCCESS(err);
2380
Karl Schultz6addd812016-02-02 17:17:23 -07002381 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002382
2383 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002384 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002385 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002386
2387 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002388 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002389 ASSERT_VK_SUCCESS(err);
2390
2391 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002392 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002393 ASSERT_VK_SUCCESS(err);
2394
2395 // Now Try to bind memory to this destroyed object
2396 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2397 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002398 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002399
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002400 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002401
Chia-I Wuf7458c52015-10-26 21:10:41 +08002402 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002403}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002404
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002405#endif // OBJ_TRACKER_TESTS
2406
Tobin Ehlis0788f522015-05-26 16:11:58 -06002407#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002408
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002409TEST_F(VkLayerTest, ImageSampleCounts) {
2410
2411 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2412 "validation errors.");
2413 ASSERT_NO_FATAL_FAILURE(InitState());
2414
2415 VkMemoryPropertyFlags reqs = 0;
2416 VkImageCreateInfo image_create_info = {};
2417 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2418 image_create_info.pNext = NULL;
2419 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2420 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2421 image_create_info.extent.width = 256;
2422 image_create_info.extent.height = 256;
2423 image_create_info.extent.depth = 1;
2424 image_create_info.mipLevels = 1;
2425 image_create_info.arrayLayers = 1;
2426 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2427 image_create_info.flags = 0;
2428
2429 VkImageBlit blit_region = {};
2430 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2431 blit_region.srcSubresource.baseArrayLayer = 0;
2432 blit_region.srcSubresource.layerCount = 1;
2433 blit_region.srcSubresource.mipLevel = 0;
2434 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2435 blit_region.dstSubresource.baseArrayLayer = 0;
2436 blit_region.dstSubresource.layerCount = 1;
2437 blit_region.dstSubresource.mipLevel = 0;
2438
2439 // Create two images, the source with sampleCount = 2, and attempt to blit
2440 // between them
2441 {
2442 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002443 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002444 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002445 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002446 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002447 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002448 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002449 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002450 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2452 "of VK_SAMPLE_COUNT_2_BIT but "
2453 "must be VK_SAMPLE_COUNT_1_BIT");
2454 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2455 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002456 m_errorMonitor->VerifyFound();
2457 m_commandBuffer->EndCommandBuffer();
2458 }
2459
2460 // Create two images, the dest with sampleCount = 4, and attempt to blit
2461 // between them
2462 {
2463 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002464 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002465 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002466 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002467 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002468 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002469 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002471 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2473 "of VK_SAMPLE_COUNT_4_BIT but "
2474 "must be VK_SAMPLE_COUNT_1_BIT");
2475 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2476 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002477 m_errorMonitor->VerifyFound();
2478 m_commandBuffer->EndCommandBuffer();
2479 }
2480
2481 VkBufferImageCopy copy_region = {};
2482 copy_region.bufferRowLength = 128;
2483 copy_region.bufferImageHeight = 128;
2484 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2485 copy_region.imageSubresource.layerCount = 1;
2486 copy_region.imageExtent.height = 64;
2487 copy_region.imageExtent.width = 64;
2488 copy_region.imageExtent.depth = 1;
2489
2490 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2491 // buffer to image
2492 {
2493 vk_testing::Buffer src_buffer;
2494 VkMemoryPropertyFlags reqs = 0;
2495 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2496 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002497 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002498 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002499 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002500 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2502 "of VK_SAMPLE_COUNT_8_BIT but "
2503 "must be VK_SAMPLE_COUNT_1_BIT");
2504 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2505 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002506 m_errorMonitor->VerifyFound();
2507 m_commandBuffer->EndCommandBuffer();
2508 }
2509
2510 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2511 // image to buffer
2512 {
2513 vk_testing::Buffer dst_buffer;
2514 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2515 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002516 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002517 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002518 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002519 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2521 "of VK_SAMPLE_COUNT_2_BIT but "
2522 "must be VK_SAMPLE_COUNT_1_BIT");
2523 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002524 dst_buffer.handle(), 1, &copy_region);
2525 m_errorMonitor->VerifyFound();
2526 m_commandBuffer->EndCommandBuffer();
2527 }
2528}
2529
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002530TEST_F(VkLayerTest, BlitImageFormats) {
2531
2532 // Image blit with mismatched formats
2533 const char * expected_message =
2534 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2535 " the other one must also have signed/unsigned integer format";
2536
2537 ASSERT_NO_FATAL_FAILURE(InitState());
2538
2539 VkImageObj src_image(m_device);
2540 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2541 VkImageObj dst_image(m_device);
2542 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2543 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002544 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 -06002545
2546 VkImageBlit blitRegion = {};
2547 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2548 blitRegion.srcSubresource.baseArrayLayer = 0;
2549 blitRegion.srcSubresource.layerCount = 1;
2550 blitRegion.srcSubresource.mipLevel = 0;
2551 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2552 blitRegion.dstSubresource.baseArrayLayer = 0;
2553 blitRegion.dstSubresource.layerCount = 1;
2554 blitRegion.dstSubresource.mipLevel = 0;
2555
2556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2557
2558 // Unsigned int vs not an int
2559 BeginCommandBuffer();
2560 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2561 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2562
2563 m_errorMonitor->VerifyFound();
2564
2565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2566
2567 // Unsigned int vs signed int
2568 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2569 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2570
2571 m_errorMonitor->VerifyFound();
2572
2573 EndCommandBuffer();
2574}
2575
2576
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002577TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2578 VkResult err;
2579 bool pass;
2580
2581 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2582 ASSERT_NO_FATAL_FAILURE(InitState());
2583
2584 // If w/d/h granularity is 1, test is not meaningful
2585 // TODO: When virtual device limits are available, create a set of limits for this test that
2586 // will always have a granularity of > 1 for w, h, and d
2587 auto index = m_device->graphics_queue_node_index_;
2588 auto queue_family_properties = m_device->phy().queue_properties();
2589
2590 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2591 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2592 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2593 return;
2594 }
2595
2596 // Create two images of different types and try to copy between them
2597 VkImage srcImage;
2598 VkImage dstImage;
2599 VkDeviceMemory srcMem;
2600 VkDeviceMemory destMem;
2601 VkMemoryRequirements memReqs;
2602
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002603 VkImageCreateInfo image_create_info = {};
2604 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2605 image_create_info.pNext = NULL;
2606 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2607 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2608 image_create_info.extent.width = 32;
2609 image_create_info.extent.height = 32;
2610 image_create_info.extent.depth = 1;
2611 image_create_info.mipLevels = 1;
2612 image_create_info.arrayLayers = 4;
2613 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2614 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2615 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2616 image_create_info.flags = 0;
2617
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002618 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002619 ASSERT_VK_SUCCESS(err);
2620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002622 ASSERT_VK_SUCCESS(err);
2623
2624 // Allocate memory
2625 VkMemoryAllocateInfo memAlloc = {};
2626 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2627 memAlloc.pNext = NULL;
2628 memAlloc.allocationSize = 0;
2629 memAlloc.memoryTypeIndex = 0;
2630
2631 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2632 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002633 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002634 ASSERT_TRUE(pass);
2635 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2636 ASSERT_VK_SUCCESS(err);
2637
2638 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2639 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002640 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002641 ASSERT_VK_SUCCESS(err);
2642 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2643 ASSERT_VK_SUCCESS(err);
2644
2645 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2646 ASSERT_VK_SUCCESS(err);
2647 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2648 ASSERT_VK_SUCCESS(err);
2649
2650 BeginCommandBuffer();
2651 VkImageCopy copyRegion;
2652 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2653 copyRegion.srcSubresource.mipLevel = 0;
2654 copyRegion.srcSubresource.baseArrayLayer = 0;
2655 copyRegion.srcSubresource.layerCount = 1;
2656 copyRegion.srcOffset.x = 0;
2657 copyRegion.srcOffset.y = 0;
2658 copyRegion.srcOffset.z = 0;
2659 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2660 copyRegion.dstSubresource.mipLevel = 0;
2661 copyRegion.dstSubresource.baseArrayLayer = 0;
2662 copyRegion.dstSubresource.layerCount = 1;
2663 copyRegion.dstOffset.x = 0;
2664 copyRegion.dstOffset.y = 0;
2665 copyRegion.dstOffset.z = 0;
2666 copyRegion.extent.width = 1;
2667 copyRegion.extent.height = 1;
2668 copyRegion.extent.depth = 1;
2669
2670 // Introduce failure by setting srcOffset to a bad granularity value
2671 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2673 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002674 m_errorMonitor->VerifyFound();
2675
2676 // Introduce failure by setting extent to a bad granularity value
2677 copyRegion.srcOffset.y = 0;
2678 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2680 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002681 m_errorMonitor->VerifyFound();
2682
2683 // Now do some buffer/image copies
2684 vk_testing::Buffer buffer;
2685 VkMemoryPropertyFlags reqs = 0;
2686 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2687 VkBufferImageCopy region = {};
2688 region.bufferOffset = 0;
2689 region.bufferRowLength = 3;
2690 region.bufferImageHeight = 128;
2691 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2692 region.imageSubresource.layerCount = 1;
2693 region.imageExtent.height = 16;
2694 region.imageExtent.width = 16;
2695 region.imageExtent.depth = 1;
2696 region.imageOffset.x = 0;
2697 region.imageOffset.y = 0;
2698 region.imageOffset.z = 0;
2699
2700 // Introduce failure by setting bufferRowLength to a bad granularity value
2701 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2703 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2704 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002705 m_errorMonitor->VerifyFound();
2706 region.bufferRowLength = 128;
2707
2708 // Introduce failure by setting bufferOffset to a bad granularity value
2709 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2711 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2712 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002713 m_errorMonitor->VerifyFound();
2714 region.bufferOffset = 0;
2715
2716 // Introduce failure by setting bufferImageHeight to a bad granularity value
2717 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2719 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2720 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002721 m_errorMonitor->VerifyFound();
2722 region.bufferImageHeight = 128;
2723
2724 // Introduce failure by setting imageExtent to a bad granularity value
2725 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2727 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2728 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002729 m_errorMonitor->VerifyFound();
2730 region.imageExtent.width = 16;
2731
2732 // Introduce failure by setting imageOffset to a bad granularity value
2733 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2735 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2736 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002737 m_errorMonitor->VerifyFound();
2738
2739 EndCommandBuffer();
2740
2741 vkDestroyImage(m_device->device(), srcImage, NULL);
2742 vkDestroyImage(m_device->device(), dstImage, NULL);
2743 vkFreeMemory(m_device->device(), srcMem, NULL);
2744 vkFreeMemory(m_device->device(), destMem, NULL);
2745}
2746
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002747TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002748 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2749 "attempt to submit them on a queue created in a different "
2750 "queue family.");
2751
Cody Northropc31a84f2016-08-22 10:41:47 -06002752 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002753 // This test is meaningless unless we have multiple queue families
2754 auto queue_family_properties = m_device->phy().queue_properties();
2755 if (queue_family_properties.size() < 2) {
2756 return;
2757 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002759 // Get safe index of another queue family
2760 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2761 ASSERT_NO_FATAL_FAILURE(InitState());
2762 // Create a second queue using a different queue family
2763 VkQueue other_queue;
2764 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2765
2766 // Record an empty cmd buffer
2767 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2768 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2769 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2770 vkEndCommandBuffer(m_commandBuffer->handle());
2771
2772 // And submit on the wrong queue
2773 VkSubmitInfo submit_info = {};
2774 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2775 submit_info.commandBufferCount = 1;
2776 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002777 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002778
2779 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002780}
2781
Chris Forbesa58c4522016-09-28 15:19:39 +13002782TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2783 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2784 ASSERT_NO_FATAL_FAILURE(InitState());
2785
2786 // A renderpass with two subpasses, both writing the same attachment.
2787 VkAttachmentDescription attach[] = {
2788 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2789 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2790 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2791 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2792 },
2793 };
2794 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2795 VkSubpassDescription subpasses[] = {
2796 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2797 1, &ref, nullptr, nullptr, 0, nullptr },
2798 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2799 1, &ref, nullptr, nullptr, 0, nullptr },
2800 };
2801 VkSubpassDependency dep = {
2802 0, 1,
2803 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2804 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2805 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2806 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2807 VK_DEPENDENCY_BY_REGION_BIT
2808 };
2809 VkRenderPassCreateInfo rpci = {
2810 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2811 0, 1, attach, 2, subpasses, 1, &dep
2812 };
2813 VkRenderPass rp;
2814 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2815 ASSERT_VK_SUCCESS(err);
2816
2817 VkImageObj image(m_device);
2818 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2819 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2820 VK_IMAGE_TILING_OPTIMAL, 0);
2821 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2822
2823 VkFramebufferCreateInfo fbci = {
2824 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2825 0, rp, 1, &imageView, 32, 32, 1
2826 };
2827 VkFramebuffer fb;
2828 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2829 ASSERT_VK_SUCCESS(err);
2830
2831 char const *vsSource =
2832 "#version 450\n"
2833 "void main() { gl_Position = vec4(1); }\n";
2834 char const *fsSource =
2835 "#version 450\n"
2836 "layout(location=0) out vec4 color;\n"
2837 "void main() { color = vec4(1); }\n";
2838
2839 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2840 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2841 VkPipelineObj pipe(m_device);
2842 pipe.AddColorAttachment();
2843 pipe.AddShader(&vs);
2844 pipe.AddShader(&fs);
2845 VkViewport view_port = {};
2846 m_viewports.push_back(view_port);
2847 pipe.SetViewport(m_viewports);
2848 VkRect2D rect = {};
2849 m_scissors.push_back(rect);
2850 pipe.SetScissor(m_scissors);
2851
2852 VkPipelineLayoutCreateInfo plci = {
2853 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2854 0, 0, nullptr, 0, nullptr
2855 };
2856 VkPipelineLayout pl;
2857 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2858 ASSERT_VK_SUCCESS(err);
2859 pipe.CreateVKPipeline(pl, rp);
2860
2861 BeginCommandBuffer();
2862
2863 VkRenderPassBeginInfo rpbi = {
2864 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2865 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2866 };
2867
2868 // subtest 1: bind in the wrong subpass
2869 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2870 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2872 "built for subpass 0 but used in subpass 1");
2873 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2874 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2875 m_errorMonitor->VerifyFound();
2876
2877 vkCmdEndRenderPass(m_commandBuffer->handle());
2878
2879 // subtest 2: bind in correct subpass, then transition to next subpass
2880 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2881 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2882 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2884 "built for subpass 0 but used in subpass 1");
2885 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2886 m_errorMonitor->VerifyFound();
2887
2888 vkCmdEndRenderPass(m_commandBuffer->handle());
2889
2890 EndCommandBuffer();
2891
2892 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
2893 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
2894 vkDestroyRenderPass(m_device->device(), rp, nullptr);
2895}
2896
Tony Barbour4e919972016-08-09 13:27:40 -06002897TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
2898 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
2899 "with extent outside of framebuffer");
2900 ASSERT_NO_FATAL_FAILURE(InitState());
2901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2902
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
2904 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06002905
2906 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
2907 m_renderPassBeginInfo.renderArea.extent.width = 257;
2908 m_renderPassBeginInfo.renderArea.extent.height = 257;
2909 BeginCommandBuffer();
2910 m_errorMonitor->VerifyFound();
2911}
2912
2913TEST_F(VkLayerTest, DisabledIndependentBlend) {
2914 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
2915 "blend and then specifying different blend states for two "
2916 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06002917 VkPhysicalDeviceFeatures features = {};
2918 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06002919 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06002920
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2922 "Invalid Pipeline CreateInfo: If independent blend feature not "
2923 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06002924
Cody Northropc31a84f2016-08-22 10:41:47 -06002925 VkDescriptorSetObj descriptorSet(m_device);
2926 descriptorSet.AppendDummy();
2927 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06002928
Cody Northropc31a84f2016-08-22 10:41:47 -06002929 VkPipelineObj pipeline(m_device);
2930 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002931 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06002932 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06002933
Cody Northropc31a84f2016-08-22 10:41:47 -06002934 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
2935 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
2936 att_state1.blendEnable = VK_TRUE;
2937 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
2938 att_state2.blendEnable = VK_FALSE;
2939 pipeline.AddColorAttachment(0, &att_state1);
2940 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002941 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06002942 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06002943}
2944
2945TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
2946 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
2947 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06002948 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06002949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2951 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06002952
2953 // Create a renderPass with a single color attachment
2954 VkAttachmentReference attach = {};
2955 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2956 VkSubpassDescription subpass = {};
2957 VkRenderPassCreateInfo rpci = {};
2958 rpci.subpassCount = 1;
2959 rpci.pSubpasses = &subpass;
2960 rpci.attachmentCount = 1;
2961 VkAttachmentDescription attach_desc = {};
2962 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
2963 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
2964 rpci.pAttachments = &attach_desc;
2965 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
2966 VkRenderPass rp;
2967 subpass.pDepthStencilAttachment = &attach;
2968 subpass.pColorAttachments = NULL;
2969 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
2970 m_errorMonitor->VerifyFound();
2971}
2972
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06002973TEST_F(VkLayerTest, UnusedPreserveAttachment) {
2974 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
2975 "attachment reference of VK_ATTACHMENT_UNUSED");
2976
2977 ASSERT_NO_FATAL_FAILURE(InitState());
2978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06002981
2982 VkAttachmentReference color_attach = {};
2983 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
2984 color_attach.attachment = 0;
2985 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
2986 VkSubpassDescription subpass = {};
2987 subpass.colorAttachmentCount = 1;
2988 subpass.pColorAttachments = &color_attach;
2989 subpass.preserveAttachmentCount = 1;
2990 subpass.pPreserveAttachments = &preserve_attachment;
2991
2992 VkRenderPassCreateInfo rpci = {};
2993 rpci.subpassCount = 1;
2994 rpci.pSubpasses = &subpass;
2995 rpci.attachmentCount = 1;
2996 VkAttachmentDescription attach_desc = {};
2997 attach_desc.format = VK_FORMAT_UNDEFINED;
2998 rpci.pAttachments = &attach_desc;
2999 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3000 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003001 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003002
3003 m_errorMonitor->VerifyFound();
3004
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003005 if (result == VK_SUCCESS) {
3006 vkDestroyRenderPass(m_device->device(), rp, NULL);
3007 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003008}
3009
Chris Forbesc5389742016-06-29 11:49:23 +12003010TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003011 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3012 "when the source of a subpass multisample resolve "
3013 "does not have multiple samples.");
3014
Chris Forbesc5389742016-06-29 11:49:23 +12003015 ASSERT_NO_FATAL_FAILURE(InitState());
3016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3018 "Subpass 0 requests multisample resolve from attachment 0 which has "
3019 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003020
3021 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003022 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3023 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3024 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3025 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3026 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3027 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003028 };
3029
3030 VkAttachmentReference color = {
3031 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3032 };
3033
3034 VkAttachmentReference resolve = {
3035 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3036 };
3037
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003038 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003039
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003040 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003041
3042 VkRenderPass rp;
3043 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3044
3045 m_errorMonitor->VerifyFound();
3046
3047 if (err == VK_SUCCESS)
3048 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3049}
3050
3051TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003052 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3053 "when a subpass multisample resolve operation is "
3054 "requested, and the destination of that resolve has "
3055 "multiple samples.");
3056
Chris Forbesc5389742016-06-29 11:49:23 +12003057 ASSERT_NO_FATAL_FAILURE(InitState());
3058
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3060 "Subpass 0 requests multisample resolve into attachment 1, which "
3061 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003062
3063 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003064 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3065 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3066 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3067 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3068 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3069 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003070 };
3071
3072 VkAttachmentReference color = {
3073 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3074 };
3075
3076 VkAttachmentReference resolve = {
3077 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3078 };
3079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003080 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003081
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003082 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003083
3084 VkRenderPass rp;
3085 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3086
3087 m_errorMonitor->VerifyFound();
3088
3089 if (err == VK_SUCCESS)
3090 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3091}
3092
Chris Forbes3f128ef2016-06-29 14:58:53 +12003093TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003094 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3095 "when the color and depth attachments used by a subpass "
3096 "have inconsistent sample counts");
3097
Chris Forbes3f128ef2016-06-29 14:58:53 +12003098 ASSERT_NO_FATAL_FAILURE(InitState());
3099
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3101 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003102
3103 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003104 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3105 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3106 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3107 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3108 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3109 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003110 };
3111
3112 VkAttachmentReference color[] = {
3113 {
3114 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3115 },
3116 {
3117 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3118 },
3119 };
3120
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003121 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003123 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003124
3125 VkRenderPass rp;
3126 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3127
3128 m_errorMonitor->VerifyFound();
3129
3130 if (err == VK_SUCCESS)
3131 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3132}
3133
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003134TEST_F(VkLayerTest, FramebufferCreateErrors) {
3135 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003136 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003137 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003138 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3139 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3140 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3141 " 6. Framebuffer attachment where dimensions don't match\n"
3142 " 7. Framebuffer attachment w/o identity swizzle\n"
3143 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003144
3145 ASSERT_NO_FATAL_FAILURE(InitState());
3146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3149 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3150 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003151
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003152 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003153 VkAttachmentReference attach = {};
3154 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3155 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003156 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003157 VkRenderPassCreateInfo rpci = {};
3158 rpci.subpassCount = 1;
3159 rpci.pSubpasses = &subpass;
3160 rpci.attachmentCount = 1;
3161 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003162 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003163 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003164 rpci.pAttachments = &attach_desc;
3165 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3166 VkRenderPass rp;
3167 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3168 ASSERT_VK_SUCCESS(err);
3169
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003170 VkImageView ivs[2];
3171 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3172 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003173 VkFramebufferCreateInfo fb_info = {};
3174 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3175 fb_info.pNext = NULL;
3176 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003177 // Set mis-matching attachmentCount
3178 fb_info.attachmentCount = 2;
3179 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003180 fb_info.width = 100;
3181 fb_info.height = 100;
3182 fb_info.layers = 1;
3183
3184 VkFramebuffer fb;
3185 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3186
3187 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003188 if (err == VK_SUCCESS) {
3189 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3190 }
3191 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003192
3193 // Create a renderPass with a depth-stencil attachment created with
3194 // IMAGE_USAGE_COLOR_ATTACHMENT
3195 // Add our color attachment to pDepthStencilAttachment
3196 subpass.pDepthStencilAttachment = &attach;
3197 subpass.pColorAttachments = NULL;
3198 VkRenderPass rp_ds;
3199 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3200 ASSERT_VK_SUCCESS(err);
3201 // Set correct attachment count, but attachment has COLOR usage bit set
3202 fb_info.attachmentCount = 1;
3203 fb_info.renderPass = rp_ds;
3204
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003206 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3207
3208 m_errorMonitor->VerifyFound();
3209 if (err == VK_SUCCESS) {
3210 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3211 }
3212 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003213
3214 // Create new renderpass with alternate attachment format from fb
3215 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3216 subpass.pDepthStencilAttachment = NULL;
3217 subpass.pColorAttachments = &attach;
3218 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3219 ASSERT_VK_SUCCESS(err);
3220
3221 // Cause error due to mis-matched formats between rp & fb
3222 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3223 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3225 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003226 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3227
3228 m_errorMonitor->VerifyFound();
3229 if (err == VK_SUCCESS) {
3230 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3231 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003232 vkDestroyRenderPass(m_device->device(), rp, NULL);
3233
3234 // Create new renderpass with alternate sample count from fb
3235 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3236 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3237 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3238 ASSERT_VK_SUCCESS(err);
3239
3240 // Cause error due to mis-matched sample count between rp & fb
3241 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3243 "that do not match the "
3244 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003245 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3246
3247 m_errorMonitor->VerifyFound();
3248 if (err == VK_SUCCESS) {
3249 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3250 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003251
3252 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003253
3254 // Create a custom imageView with non-1 mip levels
3255 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003256 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 -06003257 ASSERT_TRUE(image.initialized());
3258
3259 VkImageView view;
3260 VkImageViewCreateInfo ivci = {};
3261 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3262 ivci.image = image.handle();
3263 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3264 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3265 ivci.subresourceRange.layerCount = 1;
3266 ivci.subresourceRange.baseMipLevel = 0;
3267 // Set level count 2 (only 1 is allowed for FB attachment)
3268 ivci.subresourceRange.levelCount = 2;
3269 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3270 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3271 ASSERT_VK_SUCCESS(err);
3272 // Re-create renderpass to have matching sample count
3273 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3274 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3275 ASSERT_VK_SUCCESS(err);
3276
3277 fb_info.renderPass = rp;
3278 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003280 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3281
3282 m_errorMonitor->VerifyFound();
3283 if (err == VK_SUCCESS) {
3284 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3285 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003286 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003287 // Update view to original color buffer and grow FB dimensions too big
3288 fb_info.pAttachments = ivs;
3289 fb_info.height = 1024;
3290 fb_info.width = 1024;
3291 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3293 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003294 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3295
3296 m_errorMonitor->VerifyFound();
3297 if (err == VK_SUCCESS) {
3298 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3299 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003300 // Create view attachment with non-identity swizzle
3301 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3302 ivci.image = image.handle();
3303 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3304 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3305 ivci.subresourceRange.layerCount = 1;
3306 ivci.subresourceRange.baseMipLevel = 0;
3307 ivci.subresourceRange.levelCount = 1;
3308 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3309 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3310 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3311 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3312 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3313 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3314 ASSERT_VK_SUCCESS(err);
3315
3316 fb_info.pAttachments = &view;
3317 fb_info.height = 100;
3318 fb_info.width = 100;
3319 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3321 "framebuffer attachments must have "
3322 "been created with the identity "
3323 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003324 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3325
3326 m_errorMonitor->VerifyFound();
3327 if (err == VK_SUCCESS) {
3328 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3329 }
3330 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003331 // Request fb that exceeds max dimensions
3332 // reset attachment to color attachment
3333 fb_info.pAttachments = ivs;
3334 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3335 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3336 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3338 "dimensions exceed physical device "
3339 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003340 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3341
3342 m_errorMonitor->VerifyFound();
3343 if (err == VK_SUCCESS) {
3344 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3345 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003346
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003347 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003348}
3349
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003350TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003351 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3352 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003353
Cody Northropc31a84f2016-08-22 10:41:47 -06003354 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003355 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3357 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003358 m_errorMonitor->VerifyFound();
3359}
3360
3361TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003362 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3363 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003364
Cody Northropc31a84f2016-08-22 10:41:47 -06003365 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003366 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3368 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003369 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003370}
3371
3372TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3374 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003375
Cody Northropc31a84f2016-08-22 10:41:47 -06003376 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003377 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003378 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 -06003379 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003380 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003381}
3382
3383TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003384 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3385 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003386
Cody Northropc31a84f2016-08-22 10:41:47 -06003387 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003388 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003389 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 -06003390 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003391 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003392}
3393
Cortd713fe82016-07-27 09:51:27 -07003394TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003395 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3396 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003397
3398 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003399 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3401 "Dynamic blend constants state not set for this command buffer");
3402 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003403 m_errorMonitor->VerifyFound();
3404}
3405
3406TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003407 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3408 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003409
3410 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003411 if (!m_device->phy().features().depthBounds) {
3412 printf("Device does not support depthBounds test; skipped.\n");
3413 return;
3414 }
3415 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3417 "Dynamic depth bounds state not set for this command buffer");
3418 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003419 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003420}
3421
3422TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003423 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3424 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003425
3426 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003427 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3429 "Dynamic stencil read mask state not set for this command buffer");
3430 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003431 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003432}
3433
3434TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003435 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3436 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003437
3438 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003439 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3441 "Dynamic stencil write mask state not set for this command buffer");
3442 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003443 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003444}
3445
3446TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003447 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3448 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003449
3450 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003451 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3453 "Dynamic stencil reference state not set for this command buffer");
3454 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003455 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003456}
3457
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003458TEST_F(VkLayerTest, IndexBufferNotBound) {
3459 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003460
3461 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3463 "Index buffer object not bound to this command buffer when Indexed ");
3464 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003465 m_errorMonitor->VerifyFound();
3466}
3467
Karl Schultz6addd812016-02-02 17:17:23 -07003468TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3470 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3471 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003472
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003473 ASSERT_NO_FATAL_FAILURE(InitState());
3474 ASSERT_NO_FATAL_FAILURE(InitViewport());
3475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3476
Karl Schultz6addd812016-02-02 17:17:23 -07003477 // We luck out b/c by default the framework creates CB w/ the
3478 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003479 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003480 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003481 EndCommandBuffer();
3482
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003483 // Bypass framework since it does the waits automatically
3484 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003485 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003486 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3487 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003488 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003489 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003490 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003491 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003492 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003493 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003494 submit_info.pSignalSemaphores = NULL;
3495
Chris Forbes40028e22016-06-13 09:59:34 +12003496 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003497 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003498
Karl Schultz6addd812016-02-02 17:17:23 -07003499 // Cause validation error by re-submitting cmd buffer that should only be
3500 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003501 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003502
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003503 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003504}
3505
Karl Schultz6addd812016-02-02 17:17:23 -07003506TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003507 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003508 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3511 "type "
3512 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003513
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003514 ASSERT_NO_FATAL_FAILURE(InitState());
3515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003516
Karl Schultz6addd812016-02-02 17:17:23 -07003517 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3518 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003519 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003520 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3521 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003522
3523 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003524 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3525 ds_pool_ci.pNext = NULL;
3526 ds_pool_ci.flags = 0;
3527 ds_pool_ci.maxSets = 1;
3528 ds_pool_ci.poolSizeCount = 1;
3529 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003530
3531 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003532 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003533 ASSERT_VK_SUCCESS(err);
3534
3535 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003536 dsl_binding.binding = 0;
3537 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3538 dsl_binding.descriptorCount = 1;
3539 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3540 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003541
3542 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003543 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3544 ds_layout_ci.pNext = NULL;
3545 ds_layout_ci.bindingCount = 1;
3546 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003547
3548 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003549 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003550 ASSERT_VK_SUCCESS(err);
3551
3552 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003553 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003554 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003555 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003556 alloc_info.descriptorPool = ds_pool;
3557 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003558 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003559
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003560 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003561
Chia-I Wuf7458c52015-10-26 21:10:41 +08003562 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3563 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003564}
3565
Karl Schultz6addd812016-02-02 17:17:23 -07003566TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3567 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003568
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3570 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3571 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003572
Tobin Ehlise735c692015-10-08 13:13:50 -06003573 ASSERT_NO_FATAL_FAILURE(InitState());
3574 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003575
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003576 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003577 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3578 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003579
3580 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003581 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3582 ds_pool_ci.pNext = NULL;
3583 ds_pool_ci.maxSets = 1;
3584 ds_pool_ci.poolSizeCount = 1;
3585 ds_pool_ci.flags = 0;
3586 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3587 // app can only call vkResetDescriptorPool on this pool.;
3588 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003589
3590 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003591 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003592 ASSERT_VK_SUCCESS(err);
3593
3594 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003595 dsl_binding.binding = 0;
3596 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3597 dsl_binding.descriptorCount = 1;
3598 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3599 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003600
3601 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003602 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3603 ds_layout_ci.pNext = NULL;
3604 ds_layout_ci.bindingCount = 1;
3605 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003606
3607 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003608 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003609 ASSERT_VK_SUCCESS(err);
3610
3611 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003612 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003613 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003614 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003615 alloc_info.descriptorPool = ds_pool;
3616 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003617 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003618 ASSERT_VK_SUCCESS(err);
3619
3620 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003621 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003622
Chia-I Wuf7458c52015-10-26 21:10:41 +08003623 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3624 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003625}
3626
Karl Schultz6addd812016-02-02 17:17:23 -07003627TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003628 // Attempt to clear Descriptor Pool with bad object.
3629 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003630
3631 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003633 uint64_t fake_pool_handle = 0xbaad6001;
3634 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3635 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003636 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003637}
3638
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003639TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003640 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3641 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003642 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003643 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003644
3645 uint64_t fake_set_handle = 0xbaad6001;
3646 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003647 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003649
3650 ASSERT_NO_FATAL_FAILURE(InitState());
3651
3652 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3653 layout_bindings[0].binding = 0;
3654 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3655 layout_bindings[0].descriptorCount = 1;
3656 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3657 layout_bindings[0].pImmutableSamplers = NULL;
3658
3659 VkDescriptorSetLayout descriptor_set_layout;
3660 VkDescriptorSetLayoutCreateInfo dslci = {};
3661 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3662 dslci.pNext = NULL;
3663 dslci.bindingCount = 1;
3664 dslci.pBindings = layout_bindings;
3665 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003666 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003667
3668 VkPipelineLayout pipeline_layout;
3669 VkPipelineLayoutCreateInfo plci = {};
3670 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3671 plci.pNext = NULL;
3672 plci.setLayoutCount = 1;
3673 plci.pSetLayouts = &descriptor_set_layout;
3674 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003675 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003676
3677 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003678 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3679 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003680 m_errorMonitor->VerifyFound();
3681 EndCommandBuffer();
3682 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3683 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003684}
3685
Karl Schultz6addd812016-02-02 17:17:23 -07003686TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003687 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3688 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003689 uint64_t fake_layout_handle = 0xbaad6001;
3690 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003692 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003693 VkPipelineLayout pipeline_layout;
3694 VkPipelineLayoutCreateInfo plci = {};
3695 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3696 plci.pNext = NULL;
3697 plci.setLayoutCount = 1;
3698 plci.pSetLayouts = &bad_layout;
3699 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3700
3701 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003702}
3703
Mark Muellerd4914412016-06-13 17:52:06 -06003704TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3705 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3706 "1) A uniform buffer update must have a valid buffer index."
3707 "2) When using an array of descriptors in a single WriteDescriptor,"
3708 " the descriptor types and stageflags must all be the same."
3709 "3) Immutable Sampler state must match across descriptors");
3710
3711 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003712 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3713 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3714 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3715 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3716 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003717
Mark Muellerd4914412016-06-13 17:52:06 -06003718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3719
3720 ASSERT_NO_FATAL_FAILURE(InitState());
3721 VkDescriptorPoolSize ds_type_count[4] = {};
3722 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3723 ds_type_count[0].descriptorCount = 1;
3724 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3725 ds_type_count[1].descriptorCount = 1;
3726 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3727 ds_type_count[2].descriptorCount = 1;
3728 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3729 ds_type_count[3].descriptorCount = 1;
3730
3731 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3732 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3733 ds_pool_ci.maxSets = 1;
3734 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3735 ds_pool_ci.pPoolSizes = ds_type_count;
3736
3737 VkDescriptorPool ds_pool;
3738 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3739 ASSERT_VK_SUCCESS(err);
3740
Mark Muellerb9896722016-06-16 09:54:29 -06003741 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003742 layout_binding[0].binding = 0;
3743 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3744 layout_binding[0].descriptorCount = 1;
3745 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3746 layout_binding[0].pImmutableSamplers = NULL;
3747
3748 layout_binding[1].binding = 1;
3749 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3750 layout_binding[1].descriptorCount = 1;
3751 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3752 layout_binding[1].pImmutableSamplers = NULL;
3753
3754 VkSamplerCreateInfo sampler_ci = {};
3755 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3756 sampler_ci.pNext = NULL;
3757 sampler_ci.magFilter = VK_FILTER_NEAREST;
3758 sampler_ci.minFilter = VK_FILTER_NEAREST;
3759 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3760 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3761 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3762 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3763 sampler_ci.mipLodBias = 1.0;
3764 sampler_ci.anisotropyEnable = VK_FALSE;
3765 sampler_ci.maxAnisotropy = 1;
3766 sampler_ci.compareEnable = VK_FALSE;
3767 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3768 sampler_ci.minLod = 1.0;
3769 sampler_ci.maxLod = 1.0;
3770 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3771 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3772 VkSampler sampler;
3773
3774 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3775 ASSERT_VK_SUCCESS(err);
3776
3777 layout_binding[2].binding = 2;
3778 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3779 layout_binding[2].descriptorCount = 1;
3780 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3781 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3782
Mark Muellerd4914412016-06-13 17:52:06 -06003783 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3784 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3785 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3786 ds_layout_ci.pBindings = layout_binding;
3787 VkDescriptorSetLayout ds_layout;
3788 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3789 ASSERT_VK_SUCCESS(err);
3790
3791 VkDescriptorSetAllocateInfo alloc_info = {};
3792 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3793 alloc_info.descriptorSetCount = 1;
3794 alloc_info.descriptorPool = ds_pool;
3795 alloc_info.pSetLayouts = &ds_layout;
3796 VkDescriptorSet descriptorSet;
3797 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3798 ASSERT_VK_SUCCESS(err);
3799
3800 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3801 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3802 pipeline_layout_ci.pNext = NULL;
3803 pipeline_layout_ci.setLayoutCount = 1;
3804 pipeline_layout_ci.pSetLayouts = &ds_layout;
3805
3806 VkPipelineLayout pipeline_layout;
3807 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3808 ASSERT_VK_SUCCESS(err);
3809
Mark Mueller5c838ce2016-06-16 09:54:29 -06003810 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003811 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3812 descriptor_write.dstSet = descriptorSet;
3813 descriptor_write.dstBinding = 0;
3814 descriptor_write.descriptorCount = 1;
3815 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3816
Mark Mueller5c838ce2016-06-16 09:54:29 -06003817 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003818 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3819 m_errorMonitor->VerifyFound();
3820
3821 // Create a buffer to update the descriptor with
3822 uint32_t qfi = 0;
3823 VkBufferCreateInfo buffCI = {};
3824 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3825 buffCI.size = 1024;
3826 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3827 buffCI.queueFamilyIndexCount = 1;
3828 buffCI.pQueueFamilyIndices = &qfi;
3829
3830 VkBuffer dyub;
3831 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3832 ASSERT_VK_SUCCESS(err);
3833 VkDescriptorBufferInfo buffInfo = {};
3834 buffInfo.buffer = dyub;
3835 buffInfo.offset = 0;
3836 buffInfo.range = 1024;
3837
3838 descriptor_write.pBufferInfo = &buffInfo;
3839 descriptor_write.descriptorCount = 2;
3840
Mark Mueller5c838ce2016-06-16 09:54:29 -06003841 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3843 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3844 m_errorMonitor->VerifyFound();
3845
Mark Mueller5c838ce2016-06-16 09:54:29 -06003846 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3847 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003848 descriptor_write.dstBinding = 1;
3849 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003850
Mark Mueller5c838ce2016-06-16 09:54:29 -06003851 // Make pImageInfo index non-null to avoid complaints of it missing
3852 VkDescriptorImageInfo imageInfo = {};
3853 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3854 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3856 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3857 m_errorMonitor->VerifyFound();
3858
Mark Muellerd4914412016-06-13 17:52:06 -06003859 vkDestroyBuffer(m_device->device(), dyub, NULL);
3860 vkDestroySampler(m_device->device(), sampler, NULL);
3861 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3862 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3863 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3864}
3865
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003866TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
3867 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
3868 "due to a buffer dependency being destroyed.");
3869 ASSERT_NO_FATAL_FAILURE(InitState());
3870
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003871 VkBuffer buffer;
3872 VkDeviceMemory mem;
3873 VkMemoryRequirements mem_reqs;
3874
3875 VkBufferCreateInfo buf_info = {};
3876 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12003877 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003878 buf_info.size = 256;
3879 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
3880 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
3881 ASSERT_VK_SUCCESS(err);
3882
3883 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
3884
3885 VkMemoryAllocateInfo alloc_info = {};
3886 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3887 alloc_info.allocationSize = 256;
3888 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003889 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 -06003890 if (!pass) {
3891 vkDestroyBuffer(m_device->device(), buffer, NULL);
3892 return;
3893 }
3894 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
3895 ASSERT_VK_SUCCESS(err);
3896
3897 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3898 ASSERT_VK_SUCCESS(err);
3899
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003900 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12003901 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003902 m_commandBuffer->EndCommandBuffer();
3903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003905 // Destroy buffer dependency prior to submit to cause ERROR
3906 vkDestroyBuffer(m_device->device(), buffer, NULL);
3907
3908 VkSubmitInfo submit_info = {};
3909 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3910 submit_info.commandBufferCount = 1;
3911 submit_info.pCommandBuffers = &m_commandBuffer->handle();
3912 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3913
3914 m_errorMonitor->VerifyFound();
3915 vkFreeMemory(m_device->handle(), mem, NULL);
3916}
3917
Tobin Ehlisea413442016-09-28 10:23:59 -06003918TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
3919 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
3920
3921 ASSERT_NO_FATAL_FAILURE(InitState());
3922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3923
3924 VkDescriptorPoolSize ds_type_count;
3925 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3926 ds_type_count.descriptorCount = 1;
3927
3928 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3929 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3930 ds_pool_ci.maxSets = 1;
3931 ds_pool_ci.poolSizeCount = 1;
3932 ds_pool_ci.pPoolSizes = &ds_type_count;
3933
3934 VkDescriptorPool ds_pool;
3935 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3936 ASSERT_VK_SUCCESS(err);
3937
3938 VkDescriptorSetLayoutBinding layout_binding;
3939 layout_binding.binding = 0;
3940 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3941 layout_binding.descriptorCount = 1;
3942 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3943 layout_binding.pImmutableSamplers = NULL;
3944
3945 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3946 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3947 ds_layout_ci.bindingCount = 1;
3948 ds_layout_ci.pBindings = &layout_binding;
3949 VkDescriptorSetLayout ds_layout;
3950 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3951 ASSERT_VK_SUCCESS(err);
3952
3953 VkDescriptorSetAllocateInfo alloc_info = {};
3954 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3955 alloc_info.descriptorSetCount = 1;
3956 alloc_info.descriptorPool = ds_pool;
3957 alloc_info.pSetLayouts = &ds_layout;
3958 VkDescriptorSet descriptor_set;
3959 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
3960 ASSERT_VK_SUCCESS(err);
3961
3962 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3963 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3964 pipeline_layout_ci.pNext = NULL;
3965 pipeline_layout_ci.setLayoutCount = 1;
3966 pipeline_layout_ci.pSetLayouts = &ds_layout;
3967
3968 VkPipelineLayout pipeline_layout;
3969 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3970 ASSERT_VK_SUCCESS(err);
3971
3972 VkBuffer buffer;
3973 uint32_t queue_family_index = 0;
3974 VkBufferCreateInfo buffer_create_info = {};
3975 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3976 buffer_create_info.size = 1024;
3977 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
3978 buffer_create_info.queueFamilyIndexCount = 1;
3979 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
3980
3981 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
3982 ASSERT_VK_SUCCESS(err);
3983
3984 VkMemoryRequirements memory_reqs;
3985 VkDeviceMemory buffer_memory;
3986
3987 VkMemoryAllocateInfo memory_info = {};
3988 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3989 memory_info.allocationSize = 0;
3990 memory_info.memoryTypeIndex = 0;
3991
3992 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
3993 memory_info.allocationSize = memory_reqs.size;
3994 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
3995 ASSERT_TRUE(pass);
3996
3997 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
3998 ASSERT_VK_SUCCESS(err);
3999 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4000 ASSERT_VK_SUCCESS(err);
4001
4002 VkBufferView view;
4003 VkBufferViewCreateInfo bvci = {};
4004 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4005 bvci.buffer = buffer;
4006 bvci.format = VK_FORMAT_R8_UNORM;
4007 bvci.range = VK_WHOLE_SIZE;
4008
4009 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4010 ASSERT_VK_SUCCESS(err);
4011
4012 VkWriteDescriptorSet descriptor_write = {};
4013 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4014 descriptor_write.dstSet = descriptor_set;
4015 descriptor_write.dstBinding = 0;
4016 descriptor_write.descriptorCount = 1;
4017 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4018 descriptor_write.pTexelBufferView = &view;
4019
4020 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4021
4022 char const *vsSource = "#version 450\n"
4023 "\n"
4024 "out gl_PerVertex { \n"
4025 " vec4 gl_Position;\n"
4026 "};\n"
4027 "void main(){\n"
4028 " gl_Position = vec4(1);\n"
4029 "}\n";
4030 char const *fsSource = "#version 450\n"
4031 "\n"
4032 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4033 "layout(location=0) out vec4 x;\n"
4034 "void main(){\n"
4035 " x = imageLoad(s, 0);\n"
4036 "}\n";
4037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4039 VkPipelineObj pipe(m_device);
4040 pipe.AddShader(&vs);
4041 pipe.AddShader(&fs);
4042 pipe.AddColorAttachment();
4043 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4044
4045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4047
4048 BeginCommandBuffer();
4049 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4050 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4051 VkRect2D scissor = {{0, 0}, {16, 16}};
4052 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4053 // Bind pipeline to cmd buffer
4054 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4055 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4056 &descriptor_set, 0, nullptr);
4057 Draw(1, 0, 0, 0);
4058 EndCommandBuffer();
4059
4060 // Delete BufferView in order to invalidate cmd buffer
4061 vkDestroyBufferView(m_device->device(), view, NULL);
4062 // Now attempt submit of cmd buffer
4063 VkSubmitInfo submit_info = {};
4064 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4065 submit_info.commandBufferCount = 1;
4066 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4067 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4068 m_errorMonitor->VerifyFound();
4069
4070 // Clean-up
4071 vkDestroyBuffer(m_device->device(), buffer, NULL);
4072 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4073 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4074 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4075 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4076}
4077
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004078TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4079 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4080 "due to an image dependency being destroyed.");
4081 ASSERT_NO_FATAL_FAILURE(InitState());
4082
4083 VkImage image;
4084 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4085 VkImageCreateInfo image_create_info = {};
4086 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4087 image_create_info.pNext = NULL;
4088 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4089 image_create_info.format = tex_format;
4090 image_create_info.extent.width = 32;
4091 image_create_info.extent.height = 32;
4092 image_create_info.extent.depth = 1;
4093 image_create_info.mipLevels = 1;
4094 image_create_info.arrayLayers = 1;
4095 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4096 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004097 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004098 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004099 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004100 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004101 // Have to bind memory to image before recording cmd in cmd buffer using it
4102 VkMemoryRequirements mem_reqs;
4103 VkDeviceMemory image_mem;
4104 bool pass;
4105 VkMemoryAllocateInfo mem_alloc = {};
4106 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4107 mem_alloc.pNext = NULL;
4108 mem_alloc.memoryTypeIndex = 0;
4109 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4110 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004111 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004112 ASSERT_TRUE(pass);
4113 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4114 ASSERT_VK_SUCCESS(err);
4115 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4116 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004117
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004118 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004119 VkClearColorValue ccv;
4120 ccv.float32[0] = 1.0f;
4121 ccv.float32[1] = 1.0f;
4122 ccv.float32[2] = 1.0f;
4123 ccv.float32[3] = 1.0f;
4124 VkImageSubresourceRange isr = {};
4125 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004126 isr.baseArrayLayer = 0;
4127 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004128 isr.layerCount = 1;
4129 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004131 m_commandBuffer->EndCommandBuffer();
4132
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004134 // Destroy image dependency prior to submit to cause ERROR
4135 vkDestroyImage(m_device->device(), image, NULL);
4136
4137 VkSubmitInfo submit_info = {};
4138 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4139 submit_info.commandBufferCount = 1;
4140 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4141 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4142
4143 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004144 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004145}
4146
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004147TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4148 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4149 "due to a framebuffer image dependency being destroyed.");
4150 VkFormatProperties format_properties;
4151 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004152 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4153 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004154 return;
4155 }
4156
4157 ASSERT_NO_FATAL_FAILURE(InitState());
4158 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4159
4160 VkImageCreateInfo image_ci = {};
4161 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4162 image_ci.pNext = NULL;
4163 image_ci.imageType = VK_IMAGE_TYPE_2D;
4164 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4165 image_ci.extent.width = 32;
4166 image_ci.extent.height = 32;
4167 image_ci.extent.depth = 1;
4168 image_ci.mipLevels = 1;
4169 image_ci.arrayLayers = 1;
4170 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4171 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004172 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004173 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4174 image_ci.flags = 0;
4175 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004176 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004177
4178 VkMemoryRequirements memory_reqs;
4179 VkDeviceMemory image_memory;
4180 bool pass;
4181 VkMemoryAllocateInfo memory_info = {};
4182 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4183 memory_info.pNext = NULL;
4184 memory_info.allocationSize = 0;
4185 memory_info.memoryTypeIndex = 0;
4186 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4187 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004188 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004189 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004190 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004191 ASSERT_VK_SUCCESS(err);
4192 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4193 ASSERT_VK_SUCCESS(err);
4194
4195 VkImageViewCreateInfo ivci = {
4196 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4197 nullptr,
4198 0,
4199 image,
4200 VK_IMAGE_VIEW_TYPE_2D,
4201 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004202 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004203 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4204 };
4205 VkImageView view;
4206 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4207 ASSERT_VK_SUCCESS(err);
4208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004209 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004210 VkFramebuffer fb;
4211 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4212 ASSERT_VK_SUCCESS(err);
4213
4214 // Just use default renderpass with our framebuffer
4215 m_renderPassBeginInfo.framebuffer = fb;
4216 // Create Null cmd buffer for submit
4217 BeginCommandBuffer();
4218 EndCommandBuffer();
4219 // Destroy image attached to framebuffer to invalidate cmd buffer
4220 vkDestroyImage(m_device->device(), image, NULL);
4221 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004223 QueueCommandBuffer(false);
4224 m_errorMonitor->VerifyFound();
4225
4226 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4227 vkDestroyImageView(m_device->device(), view, nullptr);
4228 vkFreeMemory(m_device->device(), image_memory, nullptr);
4229}
4230
Tobin Ehlisb329f992016-10-12 13:20:29 -06004231TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4232 TEST_DESCRIPTION("Delete in-use framebuffer.");
4233 VkFormatProperties format_properties;
4234 VkResult err = VK_SUCCESS;
4235 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4236
4237 ASSERT_NO_FATAL_FAILURE(InitState());
4238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4239
4240 VkImageObj image(m_device);
4241 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4242 ASSERT_TRUE(image.initialized());
4243 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4244
4245 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4246 VkFramebuffer fb;
4247 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4248 ASSERT_VK_SUCCESS(err);
4249
4250 // Just use default renderpass with our framebuffer
4251 m_renderPassBeginInfo.framebuffer = fb;
4252 // Create Null cmd buffer for submit
4253 BeginCommandBuffer();
4254 EndCommandBuffer();
4255 // Submit cmd buffer to put it in-flight
4256 VkSubmitInfo submit_info = {};
4257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4258 submit_info.commandBufferCount = 1;
4259 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4260 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4261 // Destroy framebuffer while in-flight
4262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4263 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4264 m_errorMonitor->VerifyFound();
4265 // Wait for queue to complete so we can safely destroy everything
4266 vkQueueWaitIdle(m_device->m_queue);
4267 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4268}
4269
Tobin Ehlis88becd72016-09-21 14:33:41 -06004270TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4271 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4272 VkFormatProperties format_properties;
4273 VkResult err = VK_SUCCESS;
4274 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004275
4276 ASSERT_NO_FATAL_FAILURE(InitState());
4277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4278
4279 VkImageCreateInfo image_ci = {};
4280 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4281 image_ci.pNext = NULL;
4282 image_ci.imageType = VK_IMAGE_TYPE_2D;
4283 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4284 image_ci.extent.width = 256;
4285 image_ci.extent.height = 256;
4286 image_ci.extent.depth = 1;
4287 image_ci.mipLevels = 1;
4288 image_ci.arrayLayers = 1;
4289 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4290 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004291 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004292 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4293 image_ci.flags = 0;
4294 VkImage image;
4295 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4296
4297 VkMemoryRequirements memory_reqs;
4298 VkDeviceMemory image_memory;
4299 bool pass;
4300 VkMemoryAllocateInfo memory_info = {};
4301 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4302 memory_info.pNext = NULL;
4303 memory_info.allocationSize = 0;
4304 memory_info.memoryTypeIndex = 0;
4305 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4306 memory_info.allocationSize = memory_reqs.size;
4307 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4308 ASSERT_TRUE(pass);
4309 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4310 ASSERT_VK_SUCCESS(err);
4311 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4312 ASSERT_VK_SUCCESS(err);
4313
4314 VkImageViewCreateInfo ivci = {
4315 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4316 nullptr,
4317 0,
4318 image,
4319 VK_IMAGE_VIEW_TYPE_2D,
4320 VK_FORMAT_B8G8R8A8_UNORM,
4321 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4322 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4323 };
4324 VkImageView view;
4325 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4326 ASSERT_VK_SUCCESS(err);
4327
4328 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4329 VkFramebuffer fb;
4330 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4331 ASSERT_VK_SUCCESS(err);
4332
4333 // Just use default renderpass with our framebuffer
4334 m_renderPassBeginInfo.framebuffer = fb;
4335 // Create Null cmd buffer for submit
4336 BeginCommandBuffer();
4337 EndCommandBuffer();
4338 // Submit cmd buffer to put it (and attached imageView) in-flight
4339 VkSubmitInfo submit_info = {};
4340 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4341 submit_info.commandBufferCount = 1;
4342 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4343 // Submit cmd buffer to put framebuffer and children in-flight
4344 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4345 // Destroy image attached to framebuffer while in-flight
4346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4347 vkDestroyImage(m_device->device(), image, NULL);
4348 m_errorMonitor->VerifyFound();
4349 // Wait for queue to complete so we can safely destroy image and other objects
4350 vkQueueWaitIdle(m_device->m_queue);
4351 vkDestroyImage(m_device->device(), image, NULL);
4352 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4353 vkDestroyImageView(m_device->device(), view, nullptr);
4354 vkFreeMemory(m_device->device(), image_memory, nullptr);
4355}
4356
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004357TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004358 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004359 ASSERT_NO_FATAL_FAILURE(InitState());
4360
4361 VkImage image;
4362 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4363 VkImageCreateInfo image_create_info = {};
4364 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4365 image_create_info.pNext = NULL;
4366 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4367 image_create_info.format = tex_format;
4368 image_create_info.extent.width = 32;
4369 image_create_info.extent.height = 32;
4370 image_create_info.extent.depth = 1;
4371 image_create_info.mipLevels = 1;
4372 image_create_info.arrayLayers = 1;
4373 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4374 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004375 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004376 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004377 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004378 ASSERT_VK_SUCCESS(err);
4379 // Have to bind memory to image before recording cmd in cmd buffer using it
4380 VkMemoryRequirements mem_reqs;
4381 VkDeviceMemory image_mem;
4382 bool pass;
4383 VkMemoryAllocateInfo mem_alloc = {};
4384 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4385 mem_alloc.pNext = NULL;
4386 mem_alloc.memoryTypeIndex = 0;
4387 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4388 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004389 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004390 ASSERT_TRUE(pass);
4391 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4392 ASSERT_VK_SUCCESS(err);
4393
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004394 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004396 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004397
4398 m_commandBuffer->BeginCommandBuffer();
4399 VkClearColorValue ccv;
4400 ccv.float32[0] = 1.0f;
4401 ccv.float32[1] = 1.0f;
4402 ccv.float32[2] = 1.0f;
4403 ccv.float32[3] = 1.0f;
4404 VkImageSubresourceRange isr = {};
4405 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4406 isr.baseArrayLayer = 0;
4407 isr.baseMipLevel = 0;
4408 isr.layerCount = 1;
4409 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004410 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004411 m_commandBuffer->EndCommandBuffer();
4412
4413 m_errorMonitor->VerifyFound();
4414 vkDestroyImage(m_device->device(), image, NULL);
4415 vkFreeMemory(m_device->device(), image_mem, nullptr);
4416}
4417
4418TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004419 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004420 ASSERT_NO_FATAL_FAILURE(InitState());
4421
4422 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004423 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 -06004424 VK_IMAGE_TILING_OPTIMAL, 0);
4425 ASSERT_TRUE(image.initialized());
4426
4427 VkBuffer buffer;
4428 VkDeviceMemory mem;
4429 VkMemoryRequirements mem_reqs;
4430
4431 VkBufferCreateInfo buf_info = {};
4432 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004433 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004434 buf_info.size = 256;
4435 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4436 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4437 ASSERT_VK_SUCCESS(err);
4438
4439 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4440
4441 VkMemoryAllocateInfo alloc_info = {};
4442 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4443 alloc_info.allocationSize = 256;
4444 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004445 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 -06004446 if (!pass) {
4447 vkDestroyBuffer(m_device->device(), buffer, NULL);
4448 return;
4449 }
4450 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4451 ASSERT_VK_SUCCESS(err);
4452
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004453 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004455 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004456 VkBufferImageCopy region = {};
4457 region.bufferRowLength = 128;
4458 region.bufferImageHeight = 128;
4459 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4460
4461 region.imageSubresource.layerCount = 1;
4462 region.imageExtent.height = 4;
4463 region.imageExtent.width = 4;
4464 region.imageExtent.depth = 1;
4465 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004466 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4467 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004468 m_commandBuffer->EndCommandBuffer();
4469
4470 m_errorMonitor->VerifyFound();
4471
4472 vkDestroyBuffer(m_device->device(), buffer, NULL);
4473 vkFreeMemory(m_device->handle(), mem, NULL);
4474}
4475
Tobin Ehlis85940f52016-07-07 16:57:21 -06004476TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4477 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4478 "due to an event dependency being destroyed.");
4479 ASSERT_NO_FATAL_FAILURE(InitState());
4480
4481 VkEvent event;
4482 VkEventCreateInfo evci = {};
4483 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4484 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4485 ASSERT_VK_SUCCESS(result);
4486
4487 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004488 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004489 m_commandBuffer->EndCommandBuffer();
4490
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004492 // Destroy event dependency prior to submit to cause ERROR
4493 vkDestroyEvent(m_device->device(), event, NULL);
4494
4495 VkSubmitInfo submit_info = {};
4496 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4497 submit_info.commandBufferCount = 1;
4498 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4499 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4500
4501 m_errorMonitor->VerifyFound();
4502}
4503
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004504TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4505 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4506 "due to a query pool dependency being destroyed.");
4507 ASSERT_NO_FATAL_FAILURE(InitState());
4508
4509 VkQueryPool query_pool;
4510 VkQueryPoolCreateInfo qpci{};
4511 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4512 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4513 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004514 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004515 ASSERT_VK_SUCCESS(result);
4516
4517 m_commandBuffer->BeginCommandBuffer();
4518 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4519 m_commandBuffer->EndCommandBuffer();
4520
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004522 // Destroy query pool dependency prior to submit to cause ERROR
4523 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4524
4525 VkSubmitInfo submit_info = {};
4526 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4527 submit_info.commandBufferCount = 1;
4528 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4529 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4530
4531 m_errorMonitor->VerifyFound();
4532}
4533
Tobin Ehlis24130d92016-07-08 15:50:53 -06004534TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4535 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4536 "due to a pipeline dependency being destroyed.");
4537 ASSERT_NO_FATAL_FAILURE(InitState());
4538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4539
4540 VkResult err;
4541
4542 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4543 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4544
4545 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004546 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004547 ASSERT_VK_SUCCESS(err);
4548
4549 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4550 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4551 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004552 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004553 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004554 vp_state_ci.scissorCount = 1;
4555 VkRect2D scissors = {}; // Dummy scissors to point to
4556 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004557
4558 VkPipelineShaderStageCreateInfo shaderStages[2];
4559 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4560
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004561 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4562 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4563 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004564 shaderStages[0] = vs.GetStageCreateInfo();
4565 shaderStages[1] = fs.GetStageCreateInfo();
4566
4567 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4568 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4569
4570 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4571 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4572 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4573
4574 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4575 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004576 rs_ci.rasterizerDiscardEnable = true;
4577 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004578
4579 VkPipelineColorBlendAttachmentState att = {};
4580 att.blendEnable = VK_FALSE;
4581 att.colorWriteMask = 0xf;
4582
4583 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4584 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4585 cb_ci.attachmentCount = 1;
4586 cb_ci.pAttachments = &att;
4587
4588 VkGraphicsPipelineCreateInfo gp_ci = {};
4589 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4590 gp_ci.stageCount = 2;
4591 gp_ci.pStages = shaderStages;
4592 gp_ci.pVertexInputState = &vi_ci;
4593 gp_ci.pInputAssemblyState = &ia_ci;
4594 gp_ci.pViewportState = &vp_state_ci;
4595 gp_ci.pRasterizationState = &rs_ci;
4596 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004597 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4598 gp_ci.layout = pipeline_layout;
4599 gp_ci.renderPass = renderPass();
4600
4601 VkPipelineCacheCreateInfo pc_ci = {};
4602 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4603
4604 VkPipeline pipeline;
4605 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004606 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004607 ASSERT_VK_SUCCESS(err);
4608
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004609 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004610 ASSERT_VK_SUCCESS(err);
4611
4612 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004613 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004614 m_commandBuffer->EndCommandBuffer();
4615 // Now destroy pipeline in order to cause error when submitting
4616 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4617
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004619
4620 VkSubmitInfo submit_info = {};
4621 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4622 submit_info.commandBufferCount = 1;
4623 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4624 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4625
4626 m_errorMonitor->VerifyFound();
4627 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4628 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4629}
4630
Tobin Ehlis31289162016-08-17 14:57:58 -06004631TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4632 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4633 "due to a bound descriptor set with a buffer dependency "
4634 "being destroyed.");
4635 ASSERT_NO_FATAL_FAILURE(InitState());
4636 ASSERT_NO_FATAL_FAILURE(InitViewport());
4637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4638
4639 VkDescriptorPoolSize ds_type_count = {};
4640 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4641 ds_type_count.descriptorCount = 1;
4642
4643 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4644 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4645 ds_pool_ci.pNext = NULL;
4646 ds_pool_ci.maxSets = 1;
4647 ds_pool_ci.poolSizeCount = 1;
4648 ds_pool_ci.pPoolSizes = &ds_type_count;
4649
4650 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004651 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004652 ASSERT_VK_SUCCESS(err);
4653
4654 VkDescriptorSetLayoutBinding dsl_binding = {};
4655 dsl_binding.binding = 0;
4656 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4657 dsl_binding.descriptorCount = 1;
4658 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4659 dsl_binding.pImmutableSamplers = NULL;
4660
4661 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4662 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4663 ds_layout_ci.pNext = NULL;
4664 ds_layout_ci.bindingCount = 1;
4665 ds_layout_ci.pBindings = &dsl_binding;
4666 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004667 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004668 ASSERT_VK_SUCCESS(err);
4669
4670 VkDescriptorSet descriptorSet;
4671 VkDescriptorSetAllocateInfo alloc_info = {};
4672 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4673 alloc_info.descriptorSetCount = 1;
4674 alloc_info.descriptorPool = ds_pool;
4675 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004676 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004677 ASSERT_VK_SUCCESS(err);
4678
4679 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4680 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4681 pipeline_layout_ci.pNext = NULL;
4682 pipeline_layout_ci.setLayoutCount = 1;
4683 pipeline_layout_ci.pSetLayouts = &ds_layout;
4684
4685 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004686 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004687 ASSERT_VK_SUCCESS(err);
4688
4689 // Create a buffer to update the descriptor with
4690 uint32_t qfi = 0;
4691 VkBufferCreateInfo buffCI = {};
4692 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4693 buffCI.size = 1024;
4694 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4695 buffCI.queueFamilyIndexCount = 1;
4696 buffCI.pQueueFamilyIndices = &qfi;
4697
4698 VkBuffer buffer;
4699 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4700 ASSERT_VK_SUCCESS(err);
4701 // Allocate memory and bind to buffer so we can make it to the appropriate
4702 // error
4703 VkMemoryAllocateInfo mem_alloc = {};
4704 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4705 mem_alloc.pNext = NULL;
4706 mem_alloc.allocationSize = 1024;
4707 mem_alloc.memoryTypeIndex = 0;
4708
4709 VkMemoryRequirements memReqs;
4710 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004711 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004712 if (!pass) {
4713 vkDestroyBuffer(m_device->device(), buffer, NULL);
4714 return;
4715 }
4716
4717 VkDeviceMemory mem;
4718 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4719 ASSERT_VK_SUCCESS(err);
4720 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4721 ASSERT_VK_SUCCESS(err);
4722 // Correctly update descriptor to avoid "NOT_UPDATED" error
4723 VkDescriptorBufferInfo buffInfo = {};
4724 buffInfo.buffer = buffer;
4725 buffInfo.offset = 0;
4726 buffInfo.range = 1024;
4727
4728 VkWriteDescriptorSet descriptor_write;
4729 memset(&descriptor_write, 0, sizeof(descriptor_write));
4730 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4731 descriptor_write.dstSet = descriptorSet;
4732 descriptor_write.dstBinding = 0;
4733 descriptor_write.descriptorCount = 1;
4734 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4735 descriptor_write.pBufferInfo = &buffInfo;
4736
4737 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4738
4739 // Create PSO to be used for draw-time errors below
4740 char const *vsSource = "#version 450\n"
4741 "\n"
4742 "out gl_PerVertex { \n"
4743 " vec4 gl_Position;\n"
4744 "};\n"
4745 "void main(){\n"
4746 " gl_Position = vec4(1);\n"
4747 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004748 char const *fsSource = "#version 450\n"
4749 "\n"
4750 "layout(location=0) out vec4 x;\n"
4751 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4752 "void main(){\n"
4753 " x = vec4(bar.y);\n"
4754 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06004755 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4756 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4757 VkPipelineObj pipe(m_device);
4758 pipe.AddShader(&vs);
4759 pipe.AddShader(&fs);
4760 pipe.AddColorAttachment();
4761 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4762
4763 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004764 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4765 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4766 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06004767 Draw(1, 0, 0, 0);
4768 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06004770 // Destroy buffer should invalidate the cmd buffer, causing error on submit
4771 vkDestroyBuffer(m_device->device(), buffer, NULL);
4772 // Attempt to submit cmd buffer
4773 VkSubmitInfo submit_info = {};
4774 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4775 submit_info.commandBufferCount = 1;
4776 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4777 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4778 m_errorMonitor->VerifyFound();
4779 // Cleanup
4780 vkFreeMemory(m_device->device(), mem, NULL);
4781
4782 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4783 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4784 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4785}
4786
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004787TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
4788 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4789 "due to a bound descriptor sets with a combined image "
4790 "sampler having their image, sampler, and descriptor set "
4791 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06004792 "submit associated cmd buffers. Attempt to destroy a "
4793 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004794 ASSERT_NO_FATAL_FAILURE(InitState());
4795 ASSERT_NO_FATAL_FAILURE(InitViewport());
4796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4797
4798 VkDescriptorPoolSize ds_type_count = {};
4799 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4800 ds_type_count.descriptorCount = 1;
4801
4802 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4803 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4804 ds_pool_ci.pNext = NULL;
4805 ds_pool_ci.maxSets = 1;
4806 ds_pool_ci.poolSizeCount = 1;
4807 ds_pool_ci.pPoolSizes = &ds_type_count;
4808
4809 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004810 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004811 ASSERT_VK_SUCCESS(err);
4812
4813 VkDescriptorSetLayoutBinding dsl_binding = {};
4814 dsl_binding.binding = 0;
4815 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4816 dsl_binding.descriptorCount = 1;
4817 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4818 dsl_binding.pImmutableSamplers = NULL;
4819
4820 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4821 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4822 ds_layout_ci.pNext = NULL;
4823 ds_layout_ci.bindingCount = 1;
4824 ds_layout_ci.pBindings = &dsl_binding;
4825 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004826 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004827 ASSERT_VK_SUCCESS(err);
4828
4829 VkDescriptorSet descriptorSet;
4830 VkDescriptorSetAllocateInfo alloc_info = {};
4831 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4832 alloc_info.descriptorSetCount = 1;
4833 alloc_info.descriptorPool = ds_pool;
4834 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004835 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004836 ASSERT_VK_SUCCESS(err);
4837
4838 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4839 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4840 pipeline_layout_ci.pNext = NULL;
4841 pipeline_layout_ci.setLayoutCount = 1;
4842 pipeline_layout_ci.pSetLayouts = &ds_layout;
4843
4844 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004845 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004846 ASSERT_VK_SUCCESS(err);
4847
4848 // Create images to update the descriptor with
4849 VkImage image;
4850 VkImage image2;
4851 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4852 const int32_t tex_width = 32;
4853 const int32_t tex_height = 32;
4854 VkImageCreateInfo image_create_info = {};
4855 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4856 image_create_info.pNext = NULL;
4857 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4858 image_create_info.format = tex_format;
4859 image_create_info.extent.width = tex_width;
4860 image_create_info.extent.height = tex_height;
4861 image_create_info.extent.depth = 1;
4862 image_create_info.mipLevels = 1;
4863 image_create_info.arrayLayers = 1;
4864 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4865 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
4866 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4867 image_create_info.flags = 0;
4868 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
4869 ASSERT_VK_SUCCESS(err);
4870 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
4871 ASSERT_VK_SUCCESS(err);
4872
4873 VkMemoryRequirements memory_reqs;
4874 VkDeviceMemory image_memory;
4875 bool pass;
4876 VkMemoryAllocateInfo memory_info = {};
4877 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4878 memory_info.pNext = NULL;
4879 memory_info.allocationSize = 0;
4880 memory_info.memoryTypeIndex = 0;
4881 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4882 // Allocate enough memory for both images
4883 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004884 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004885 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004886 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004887 ASSERT_VK_SUCCESS(err);
4888 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4889 ASSERT_VK_SUCCESS(err);
4890 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004891 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004892 ASSERT_VK_SUCCESS(err);
4893
4894 VkImageViewCreateInfo image_view_create_info = {};
4895 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4896 image_view_create_info.image = image;
4897 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4898 image_view_create_info.format = tex_format;
4899 image_view_create_info.subresourceRange.layerCount = 1;
4900 image_view_create_info.subresourceRange.baseMipLevel = 0;
4901 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004902 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004903
4904 VkImageView view;
4905 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004906 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004907 ASSERT_VK_SUCCESS(err);
4908 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004909 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004910 ASSERT_VK_SUCCESS(err);
4911 // Create Samplers
4912 VkSamplerCreateInfo sampler_ci = {};
4913 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4914 sampler_ci.pNext = NULL;
4915 sampler_ci.magFilter = VK_FILTER_NEAREST;
4916 sampler_ci.minFilter = VK_FILTER_NEAREST;
4917 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4918 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4919 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4920 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4921 sampler_ci.mipLodBias = 1.0;
4922 sampler_ci.anisotropyEnable = VK_FALSE;
4923 sampler_ci.maxAnisotropy = 1;
4924 sampler_ci.compareEnable = VK_FALSE;
4925 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4926 sampler_ci.minLod = 1.0;
4927 sampler_ci.maxLod = 1.0;
4928 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4929 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4930 VkSampler sampler;
4931 VkSampler sampler2;
4932 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4933 ASSERT_VK_SUCCESS(err);
4934 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
4935 ASSERT_VK_SUCCESS(err);
4936 // Update descriptor with image and sampler
4937 VkDescriptorImageInfo img_info = {};
4938 img_info.sampler = sampler;
4939 img_info.imageView = view;
4940 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4941
4942 VkWriteDescriptorSet descriptor_write;
4943 memset(&descriptor_write, 0, sizeof(descriptor_write));
4944 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4945 descriptor_write.dstSet = descriptorSet;
4946 descriptor_write.dstBinding = 0;
4947 descriptor_write.descriptorCount = 1;
4948 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4949 descriptor_write.pImageInfo = &img_info;
4950
4951 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4952
4953 // Create PSO to be used for draw-time errors below
4954 char const *vsSource = "#version 450\n"
4955 "\n"
4956 "out gl_PerVertex { \n"
4957 " vec4 gl_Position;\n"
4958 "};\n"
4959 "void main(){\n"
4960 " gl_Position = vec4(1);\n"
4961 "}\n";
4962 char const *fsSource = "#version 450\n"
4963 "\n"
4964 "layout(set=0, binding=0) uniform sampler2D s;\n"
4965 "layout(location=0) out vec4 x;\n"
4966 "void main(){\n"
4967 " x = texture(s, vec2(1));\n"
4968 "}\n";
4969 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4970 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4971 VkPipelineObj pipe(m_device);
4972 pipe.AddShader(&vs);
4973 pipe.AddShader(&fs);
4974 pipe.AddColorAttachment();
4975 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4976
4977 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004979 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004980 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4981 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4982 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004983 Draw(1, 0, 0, 0);
4984 EndCommandBuffer();
4985 // Destroy sampler invalidates the cmd buffer, causing error on submit
4986 vkDestroySampler(m_device->device(), sampler, NULL);
4987 // Attempt to submit cmd buffer
4988 VkSubmitInfo submit_info = {};
4989 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4990 submit_info.commandBufferCount = 1;
4991 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4992 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4993 m_errorMonitor->VerifyFound();
4994 // Now re-update descriptor with valid sampler and delete image
4995 img_info.sampler = sampler2;
4996 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004998 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004999 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5000 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5001 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005002 Draw(1, 0, 0, 0);
5003 EndCommandBuffer();
5004 // Destroy image invalidates the cmd buffer, causing error on submit
5005 vkDestroyImage(m_device->device(), image, NULL);
5006 // Attempt to submit cmd buffer
5007 submit_info = {};
5008 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5009 submit_info.commandBufferCount = 1;
5010 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5011 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5012 m_errorMonitor->VerifyFound();
5013 // Now update descriptor to be valid, but then free descriptor
5014 img_info.imageView = view2;
5015 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005017 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005018 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5019 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5020 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005021 Draw(1, 0, 0, 0);
5022 EndCommandBuffer();
5023 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005025 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005026 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005027 // Attempt to submit cmd buffer
5028 submit_info = {};
5029 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5030 submit_info.commandBufferCount = 1;
5031 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5032 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5033 m_errorMonitor->VerifyFound();
5034 // Cleanup
5035 vkFreeMemory(m_device->device(), image_memory, NULL);
5036 vkDestroySampler(m_device->device(), sampler2, NULL);
5037 vkDestroyImage(m_device->device(), image2, NULL);
5038 vkDestroyImageView(m_device->device(), view, NULL);
5039 vkDestroyImageView(m_device->device(), view2, NULL);
5040 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5041 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5042 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5043}
5044
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005045TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5046 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5047 ASSERT_NO_FATAL_FAILURE(InitState());
5048 ASSERT_NO_FATAL_FAILURE(InitViewport());
5049 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5050
5051 VkDescriptorPoolSize ds_type_count = {};
5052 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5053 ds_type_count.descriptorCount = 1;
5054
5055 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5056 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5057 ds_pool_ci.pNext = NULL;
5058 ds_pool_ci.maxSets = 1;
5059 ds_pool_ci.poolSizeCount = 1;
5060 ds_pool_ci.pPoolSizes = &ds_type_count;
5061
5062 VkDescriptorPool ds_pool;
5063 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5064 ASSERT_VK_SUCCESS(err);
5065
5066 VkDescriptorSetLayoutBinding dsl_binding = {};
5067 dsl_binding.binding = 0;
5068 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5069 dsl_binding.descriptorCount = 1;
5070 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5071 dsl_binding.pImmutableSamplers = NULL;
5072
5073 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5074 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5075 ds_layout_ci.pNext = NULL;
5076 ds_layout_ci.bindingCount = 1;
5077 ds_layout_ci.pBindings = &dsl_binding;
5078 VkDescriptorSetLayout ds_layout;
5079 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5080 ASSERT_VK_SUCCESS(err);
5081
5082 VkDescriptorSet descriptor_set;
5083 VkDescriptorSetAllocateInfo alloc_info = {};
5084 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5085 alloc_info.descriptorSetCount = 1;
5086 alloc_info.descriptorPool = ds_pool;
5087 alloc_info.pSetLayouts = &ds_layout;
5088 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5089 ASSERT_VK_SUCCESS(err);
5090
5091 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5092 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5093 pipeline_layout_ci.pNext = NULL;
5094 pipeline_layout_ci.setLayoutCount = 1;
5095 pipeline_layout_ci.pSetLayouts = &ds_layout;
5096
5097 VkPipelineLayout pipeline_layout;
5098 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5099 ASSERT_VK_SUCCESS(err);
5100
5101 // Create image to update the descriptor with
5102 VkImageObj image(m_device);
5103 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5104 ASSERT_TRUE(image.initialized());
5105
5106 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5107 // Create Sampler
5108 VkSamplerCreateInfo sampler_ci = {};
5109 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5110 sampler_ci.pNext = NULL;
5111 sampler_ci.magFilter = VK_FILTER_NEAREST;
5112 sampler_ci.minFilter = VK_FILTER_NEAREST;
5113 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5114 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5115 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5116 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5117 sampler_ci.mipLodBias = 1.0;
5118 sampler_ci.anisotropyEnable = VK_FALSE;
5119 sampler_ci.maxAnisotropy = 1;
5120 sampler_ci.compareEnable = VK_FALSE;
5121 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5122 sampler_ci.minLod = 1.0;
5123 sampler_ci.maxLod = 1.0;
5124 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5125 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5126 VkSampler sampler;
5127 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5128 ASSERT_VK_SUCCESS(err);
5129 // Update descriptor with image and sampler
5130 VkDescriptorImageInfo img_info = {};
5131 img_info.sampler = sampler;
5132 img_info.imageView = view;
5133 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5134
5135 VkWriteDescriptorSet descriptor_write;
5136 memset(&descriptor_write, 0, sizeof(descriptor_write));
5137 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5138 descriptor_write.dstSet = descriptor_set;
5139 descriptor_write.dstBinding = 0;
5140 descriptor_write.descriptorCount = 1;
5141 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5142 descriptor_write.pImageInfo = &img_info;
5143
5144 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5145
5146 // Create PSO to be used for draw-time errors below
5147 char const *vsSource = "#version 450\n"
5148 "\n"
5149 "out gl_PerVertex { \n"
5150 " vec4 gl_Position;\n"
5151 "};\n"
5152 "void main(){\n"
5153 " gl_Position = vec4(1);\n"
5154 "}\n";
5155 char const *fsSource = "#version 450\n"
5156 "\n"
5157 "layout(set=0, binding=0) uniform sampler2D s;\n"
5158 "layout(location=0) out vec4 x;\n"
5159 "void main(){\n"
5160 " x = texture(s, vec2(1));\n"
5161 "}\n";
5162 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5163 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5164 VkPipelineObj pipe(m_device);
5165 pipe.AddShader(&vs);
5166 pipe.AddShader(&fs);
5167 pipe.AddColorAttachment();
5168 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5169
5170 BeginCommandBuffer();
5171 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5172 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5173 &descriptor_set, 0, NULL);
5174 Draw(1, 0, 0, 0);
5175 EndCommandBuffer();
5176 // Submit cmd buffer to put pool in-flight
5177 VkSubmitInfo submit_info = {};
5178 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5179 submit_info.commandBufferCount = 1;
5180 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5181 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5182 // Destroy pool while in-flight, causing error
5183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5184 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5185 m_errorMonitor->VerifyFound();
5186 vkQueueWaitIdle(m_device->m_queue);
5187 // Cleanup
5188 vkDestroySampler(m_device->device(), sampler, NULL);
5189 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5190 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5191 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5192}
5193
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005194TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5195 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5196 ASSERT_NO_FATAL_FAILURE(InitState());
5197 ASSERT_NO_FATAL_FAILURE(InitViewport());
5198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5199
5200 VkDescriptorPoolSize ds_type_count = {};
5201 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5202 ds_type_count.descriptorCount = 1;
5203
5204 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5205 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5206 ds_pool_ci.pNext = NULL;
5207 ds_pool_ci.maxSets = 1;
5208 ds_pool_ci.poolSizeCount = 1;
5209 ds_pool_ci.pPoolSizes = &ds_type_count;
5210
5211 VkDescriptorPool ds_pool;
5212 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5213 ASSERT_VK_SUCCESS(err);
5214
5215 VkDescriptorSetLayoutBinding dsl_binding = {};
5216 dsl_binding.binding = 0;
5217 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5218 dsl_binding.descriptorCount = 1;
5219 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5220 dsl_binding.pImmutableSamplers = NULL;
5221
5222 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5223 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5224 ds_layout_ci.pNext = NULL;
5225 ds_layout_ci.bindingCount = 1;
5226 ds_layout_ci.pBindings = &dsl_binding;
5227 VkDescriptorSetLayout ds_layout;
5228 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5229 ASSERT_VK_SUCCESS(err);
5230
5231 VkDescriptorSet descriptorSet;
5232 VkDescriptorSetAllocateInfo alloc_info = {};
5233 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5234 alloc_info.descriptorSetCount = 1;
5235 alloc_info.descriptorPool = ds_pool;
5236 alloc_info.pSetLayouts = &ds_layout;
5237 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5238 ASSERT_VK_SUCCESS(err);
5239
5240 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5241 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5242 pipeline_layout_ci.pNext = NULL;
5243 pipeline_layout_ci.setLayoutCount = 1;
5244 pipeline_layout_ci.pSetLayouts = &ds_layout;
5245
5246 VkPipelineLayout pipeline_layout;
5247 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5248 ASSERT_VK_SUCCESS(err);
5249
5250 // Create images to update the descriptor with
5251 VkImage image;
5252 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5253 const int32_t tex_width = 32;
5254 const int32_t tex_height = 32;
5255 VkImageCreateInfo image_create_info = {};
5256 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5257 image_create_info.pNext = NULL;
5258 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5259 image_create_info.format = tex_format;
5260 image_create_info.extent.width = tex_width;
5261 image_create_info.extent.height = tex_height;
5262 image_create_info.extent.depth = 1;
5263 image_create_info.mipLevels = 1;
5264 image_create_info.arrayLayers = 1;
5265 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5266 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5267 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5268 image_create_info.flags = 0;
5269 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5270 ASSERT_VK_SUCCESS(err);
5271 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5272 VkMemoryRequirements memory_reqs;
5273 VkDeviceMemory image_memory;
5274 bool pass;
5275 VkMemoryAllocateInfo memory_info = {};
5276 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5277 memory_info.pNext = NULL;
5278 memory_info.allocationSize = 0;
5279 memory_info.memoryTypeIndex = 0;
5280 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5281 // Allocate enough memory for image
5282 memory_info.allocationSize = memory_reqs.size;
5283 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5284 ASSERT_TRUE(pass);
5285 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5286 ASSERT_VK_SUCCESS(err);
5287 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5288 ASSERT_VK_SUCCESS(err);
5289
5290 VkImageViewCreateInfo image_view_create_info = {};
5291 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5292 image_view_create_info.image = image;
5293 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5294 image_view_create_info.format = tex_format;
5295 image_view_create_info.subresourceRange.layerCount = 1;
5296 image_view_create_info.subresourceRange.baseMipLevel = 0;
5297 image_view_create_info.subresourceRange.levelCount = 1;
5298 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5299
5300 VkImageView view;
5301 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5302 ASSERT_VK_SUCCESS(err);
5303 // Create Samplers
5304 VkSamplerCreateInfo sampler_ci = {};
5305 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5306 sampler_ci.pNext = NULL;
5307 sampler_ci.magFilter = VK_FILTER_NEAREST;
5308 sampler_ci.minFilter = VK_FILTER_NEAREST;
5309 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5310 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5311 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5312 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5313 sampler_ci.mipLodBias = 1.0;
5314 sampler_ci.anisotropyEnable = VK_FALSE;
5315 sampler_ci.maxAnisotropy = 1;
5316 sampler_ci.compareEnable = VK_FALSE;
5317 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5318 sampler_ci.minLod = 1.0;
5319 sampler_ci.maxLod = 1.0;
5320 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5321 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5322 VkSampler sampler;
5323 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5324 ASSERT_VK_SUCCESS(err);
5325 // Update descriptor with image and sampler
5326 VkDescriptorImageInfo img_info = {};
5327 img_info.sampler = sampler;
5328 img_info.imageView = view;
5329 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5330
5331 VkWriteDescriptorSet descriptor_write;
5332 memset(&descriptor_write, 0, sizeof(descriptor_write));
5333 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5334 descriptor_write.dstSet = descriptorSet;
5335 descriptor_write.dstBinding = 0;
5336 descriptor_write.descriptorCount = 1;
5337 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5338 descriptor_write.pImageInfo = &img_info;
5339 // Break memory binding and attempt update
5340 vkFreeMemory(m_device->device(), image_memory, nullptr);
5341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005342 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5344 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5345 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5346 m_errorMonitor->VerifyFound();
5347 // Cleanup
5348 vkDestroyImage(m_device->device(), image, NULL);
5349 vkDestroySampler(m_device->device(), sampler, NULL);
5350 vkDestroyImageView(m_device->device(), view, NULL);
5351 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5352 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5353 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5354}
5355
Karl Schultz6addd812016-02-02 17:17:23 -07005356TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005357 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5358 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005359 // Create a valid cmd buffer
5360 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005361 uint64_t fake_pipeline_handle = 0xbaad6001;
5362 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005363 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005364 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5365
5366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005367 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005368 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005369 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005370
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005371 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005372 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 -06005373 Draw(1, 0, 0, 0);
5374 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005375
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005376 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005377 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 +12005378 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005379 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5380 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005381}
5382
Karl Schultz6addd812016-02-02 17:17:23 -07005383TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005384 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005385 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005388
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005389 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005390 ASSERT_NO_FATAL_FAILURE(InitViewport());
5391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005392 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005393 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5394 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005395
5396 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005397 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5398 ds_pool_ci.pNext = NULL;
5399 ds_pool_ci.maxSets = 1;
5400 ds_pool_ci.poolSizeCount = 1;
5401 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005402
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005403 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005404 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005405 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005406
Tony Barboureb254902015-07-15 12:50:33 -06005407 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005408 dsl_binding.binding = 0;
5409 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5410 dsl_binding.descriptorCount = 1;
5411 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5412 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005413
Tony Barboureb254902015-07-15 12:50:33 -06005414 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005415 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5416 ds_layout_ci.pNext = NULL;
5417 ds_layout_ci.bindingCount = 1;
5418 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005419 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005421 ASSERT_VK_SUCCESS(err);
5422
5423 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005424 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005425 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005426 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005427 alloc_info.descriptorPool = ds_pool;
5428 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005429 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005430 ASSERT_VK_SUCCESS(err);
5431
Tony Barboureb254902015-07-15 12:50:33 -06005432 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005433 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5434 pipeline_layout_ci.pNext = NULL;
5435 pipeline_layout_ci.setLayoutCount = 1;
5436 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005437
5438 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005439 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005440 ASSERT_VK_SUCCESS(err);
5441
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005442 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005443 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005444 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005445 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005446
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005447 VkPipelineObj pipe(m_device);
5448 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005449 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005450 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005451 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005452
5453 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005454 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5455 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5456 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005457
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005458 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005459
Chia-I Wuf7458c52015-10-26 21:10:41 +08005460 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005463}
5464
Karl Schultz6addd812016-02-02 17:17:23 -07005465TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005466 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005467 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005468
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5470 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005471
5472 ASSERT_NO_FATAL_FAILURE(InitState());
5473 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005474 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5475 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005476
5477 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005478 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5479 ds_pool_ci.pNext = NULL;
5480 ds_pool_ci.maxSets = 1;
5481 ds_pool_ci.poolSizeCount = 1;
5482 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005483
5484 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005485 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005486 ASSERT_VK_SUCCESS(err);
5487
5488 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005489 dsl_binding.binding = 0;
5490 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5491 dsl_binding.descriptorCount = 1;
5492 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5493 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005494
5495 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005496 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5497 ds_layout_ci.pNext = NULL;
5498 ds_layout_ci.bindingCount = 1;
5499 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005500 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005501 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005502 ASSERT_VK_SUCCESS(err);
5503
5504 VkDescriptorSet descriptorSet;
5505 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005506 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005507 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005508 alloc_info.descriptorPool = ds_pool;
5509 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005510 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005511 ASSERT_VK_SUCCESS(err);
5512
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005513 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005514 VkWriteDescriptorSet descriptor_write;
5515 memset(&descriptor_write, 0, sizeof(descriptor_write));
5516 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5517 descriptor_write.dstSet = descriptorSet;
5518 descriptor_write.dstBinding = 0;
5519 descriptor_write.descriptorCount = 1;
5520 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5521 descriptor_write.pTexelBufferView = &view;
5522
5523 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5524
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005525 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005526
5527 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5528 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5529}
5530
Mark Youngd339ba32016-05-30 13:28:35 -06005531TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005532 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 -06005533
5534 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005536 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005537
5538 ASSERT_NO_FATAL_FAILURE(InitState());
5539
5540 // Create a buffer with no bound memory and then attempt to create
5541 // a buffer view.
5542 VkBufferCreateInfo buff_ci = {};
5543 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005544 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005545 buff_ci.size = 256;
5546 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5547 VkBuffer buffer;
5548 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5549 ASSERT_VK_SUCCESS(err);
5550
5551 VkBufferViewCreateInfo buff_view_ci = {};
5552 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5553 buff_view_ci.buffer = buffer;
5554 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5555 buff_view_ci.range = VK_WHOLE_SIZE;
5556 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005557 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005558
5559 m_errorMonitor->VerifyFound();
5560 vkDestroyBuffer(m_device->device(), buffer, NULL);
5561 // If last error is success, it still created the view, so delete it.
5562 if (err == VK_SUCCESS) {
5563 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5564 }
5565}
5566
Karl Schultz6addd812016-02-02 17:17:23 -07005567TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5568 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5569 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005570 // 1. No dynamicOffset supplied
5571 // 2. Too many dynamicOffsets supplied
5572 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005573 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5575 "0 dynamicOffsets are left in "
5576 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005577
5578 ASSERT_NO_FATAL_FAILURE(InitState());
5579 ASSERT_NO_FATAL_FAILURE(InitViewport());
5580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5581
5582 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005583 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5584 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005585
5586 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005587 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5588 ds_pool_ci.pNext = NULL;
5589 ds_pool_ci.maxSets = 1;
5590 ds_pool_ci.poolSizeCount = 1;
5591 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005592
5593 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005594 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005595 ASSERT_VK_SUCCESS(err);
5596
5597 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005598 dsl_binding.binding = 0;
5599 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5600 dsl_binding.descriptorCount = 1;
5601 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5602 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005603
5604 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005605 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5606 ds_layout_ci.pNext = NULL;
5607 ds_layout_ci.bindingCount = 1;
5608 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005609 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005610 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005611 ASSERT_VK_SUCCESS(err);
5612
5613 VkDescriptorSet descriptorSet;
5614 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005615 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005616 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005617 alloc_info.descriptorPool = ds_pool;
5618 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005619 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005620 ASSERT_VK_SUCCESS(err);
5621
5622 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005623 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5624 pipeline_layout_ci.pNext = NULL;
5625 pipeline_layout_ci.setLayoutCount = 1;
5626 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005627
5628 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005629 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005630 ASSERT_VK_SUCCESS(err);
5631
5632 // Create a buffer to update the descriptor with
5633 uint32_t qfi = 0;
5634 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005635 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5636 buffCI.size = 1024;
5637 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5638 buffCI.queueFamilyIndexCount = 1;
5639 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005640
5641 VkBuffer dyub;
5642 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5643 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005644 // Allocate memory and bind to buffer so we can make it to the appropriate
5645 // error
5646 VkMemoryAllocateInfo mem_alloc = {};
5647 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5648 mem_alloc.pNext = NULL;
5649 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005650 mem_alloc.memoryTypeIndex = 0;
5651
5652 VkMemoryRequirements memReqs;
5653 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005654 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005655 if (!pass) {
5656 vkDestroyBuffer(m_device->device(), dyub, NULL);
5657 return;
5658 }
5659
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005660 VkDeviceMemory mem;
5661 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5662 ASSERT_VK_SUCCESS(err);
5663 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5664 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005665 // Correctly update descriptor to avoid "NOT_UPDATED" error
5666 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005667 buffInfo.buffer = dyub;
5668 buffInfo.offset = 0;
5669 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005670
5671 VkWriteDescriptorSet descriptor_write;
5672 memset(&descriptor_write, 0, sizeof(descriptor_write));
5673 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5674 descriptor_write.dstSet = descriptorSet;
5675 descriptor_write.dstBinding = 0;
5676 descriptor_write.descriptorCount = 1;
5677 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5678 descriptor_write.pBufferInfo = &buffInfo;
5679
5680 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5681
5682 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005683 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5684 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005685 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005686 uint32_t pDynOff[2] = {512, 756};
5687 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5689 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5690 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5691 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005692 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005693 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5695 "offset 0 and range 1024 that "
5696 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005697 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005698 char const *vsSource = "#version 450\n"
5699 "\n"
5700 "out gl_PerVertex { \n"
5701 " vec4 gl_Position;\n"
5702 "};\n"
5703 "void main(){\n"
5704 " gl_Position = vec4(1);\n"
5705 "}\n";
5706 char const *fsSource = "#version 450\n"
5707 "\n"
5708 "layout(location=0) out vec4 x;\n"
5709 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5710 "void main(){\n"
5711 " x = vec4(bar.y);\n"
5712 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005713 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5714 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5715 VkPipelineObj pipe(m_device);
5716 pipe.AddShader(&vs);
5717 pipe.AddShader(&fs);
5718 pipe.AddColorAttachment();
5719 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005721 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005722 // This update should succeed, but offset size of 512 will overstep buffer
5723 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005724 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5725 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005726 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005727 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005728
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005729 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005730 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005731
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005732 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005733 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005734 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5735}
5736
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005737TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5738 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5739 "that doesn't have memory bound");
5740 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005742 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5744 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005745
5746 ASSERT_NO_FATAL_FAILURE(InitState());
5747 ASSERT_NO_FATAL_FAILURE(InitViewport());
5748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5749
5750 VkDescriptorPoolSize ds_type_count = {};
5751 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5752 ds_type_count.descriptorCount = 1;
5753
5754 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5755 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5756 ds_pool_ci.pNext = NULL;
5757 ds_pool_ci.maxSets = 1;
5758 ds_pool_ci.poolSizeCount = 1;
5759 ds_pool_ci.pPoolSizes = &ds_type_count;
5760
5761 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005762 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005763 ASSERT_VK_SUCCESS(err);
5764
5765 VkDescriptorSetLayoutBinding dsl_binding = {};
5766 dsl_binding.binding = 0;
5767 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5768 dsl_binding.descriptorCount = 1;
5769 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5770 dsl_binding.pImmutableSamplers = NULL;
5771
5772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5774 ds_layout_ci.pNext = NULL;
5775 ds_layout_ci.bindingCount = 1;
5776 ds_layout_ci.pBindings = &dsl_binding;
5777 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005779 ASSERT_VK_SUCCESS(err);
5780
5781 VkDescriptorSet descriptorSet;
5782 VkDescriptorSetAllocateInfo alloc_info = {};
5783 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5784 alloc_info.descriptorSetCount = 1;
5785 alloc_info.descriptorPool = ds_pool;
5786 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005787 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005788 ASSERT_VK_SUCCESS(err);
5789
5790 // Create a buffer to update the descriptor with
5791 uint32_t qfi = 0;
5792 VkBufferCreateInfo buffCI = {};
5793 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5794 buffCI.size = 1024;
5795 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5796 buffCI.queueFamilyIndexCount = 1;
5797 buffCI.pQueueFamilyIndices = &qfi;
5798
5799 VkBuffer dyub;
5800 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5801 ASSERT_VK_SUCCESS(err);
5802
5803 // Attempt to update descriptor without binding memory to it
5804 VkDescriptorBufferInfo buffInfo = {};
5805 buffInfo.buffer = dyub;
5806 buffInfo.offset = 0;
5807 buffInfo.range = 1024;
5808
5809 VkWriteDescriptorSet descriptor_write;
5810 memset(&descriptor_write, 0, sizeof(descriptor_write));
5811 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5812 descriptor_write.dstSet = descriptorSet;
5813 descriptor_write.dstBinding = 0;
5814 descriptor_write.descriptorCount = 1;
5815 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5816 descriptor_write.pBufferInfo = &buffInfo;
5817
5818 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5819 m_errorMonitor->VerifyFound();
5820
5821 vkDestroyBuffer(m_device->device(), dyub, NULL);
5822 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5823 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5824}
5825
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005826TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005827 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005828 ASSERT_NO_FATAL_FAILURE(InitState());
5829 ASSERT_NO_FATAL_FAILURE(InitViewport());
5830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5831
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005832 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005833 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005834 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5835 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5836 pipeline_layout_ci.pushConstantRangeCount = 1;
5837 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5838
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005839 //
5840 // Check for invalid push constant ranges in pipeline layouts.
5841 //
5842 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005843 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005844 char const *msg;
5845 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005846
Karl Schultzc81037d2016-05-12 08:11:23 -06005847 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5848 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5849 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5850 "vkCreatePipelineLayout() call has push constants index 0 with "
5851 "size 0."},
5852 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5853 "vkCreatePipelineLayout() call has push constants index 0 with "
5854 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005855 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06005856 "vkCreatePipelineLayout() call has push constants index 0 with "
5857 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005858 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06005859 "vkCreatePipelineLayout() call has push constants index 0 with "
5860 "size 0."},
5861 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5862 "vkCreatePipelineLayout() call has push constants index 0 with "
5863 "offset 1. Offset must"},
5864 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5865 "vkCreatePipelineLayout() call has push constants index 0 "
5866 "with offset "},
5867 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5868 "vkCreatePipelineLayout() call has push constants "
5869 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005870 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06005871 "vkCreatePipelineLayout() call has push constants index 0 "
5872 "with offset "},
5873 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5874 "vkCreatePipelineLayout() call has push "
5875 "constants index 0 with offset "},
5876 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
5877 "vkCreatePipelineLayout() call has push "
5878 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005879 }};
5880
5881 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06005882 for (const auto &iter : range_tests) {
5883 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
5885 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005886 m_errorMonitor->VerifyFound();
5887 if (VK_SUCCESS == err) {
5888 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5889 }
5890 }
5891
5892 // Check for invalid stage flag
5893 pc_range.offset = 0;
5894 pc_range.size = 16;
5895 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005896 m_errorMonitor->SetDesiredFailureMsg(
5897 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5898 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005899 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005900 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005901 if (VK_SUCCESS == err) {
5902 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5903 }
5904
5905 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06005906 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005907 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005908 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005909 char const *msg;
5910 };
5911
Karl Schultzc81037d2016-05-12 08:11:23 -06005912 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005913 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5914 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5915 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5916 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5917 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005918 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005919 {
5920 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5921 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5922 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5923 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5924 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005925 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005926 },
5927 {
5928 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5929 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5930 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5931 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5932 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005933 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005934 },
5935 {
5936 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5937 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5938 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5939 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5940 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005941 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005942 },
5943 {
5944 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5945 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
5946 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
5947 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
5948 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005949 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005950 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005951
Karl Schultzc81037d2016-05-12 08:11:23 -06005952 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005953 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06005954 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
5956 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005957 m_errorMonitor->VerifyFound();
5958 if (VK_SUCCESS == err) {
5959 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5960 }
5961 }
5962
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005963 //
5964 // CmdPushConstants tests
5965 //
Karl Schultzc81037d2016-05-12 08:11:23 -06005966 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005967
5968 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005969 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
5970 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06005971 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5972 "vkCmdPushConstants() call has push constants with size 1. Size "
5973 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005974 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06005975 "vkCmdPushConstants() call has push constants with size 1. Size "
5976 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005977 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06005978 "vkCmdPushConstants() call has push constants with offset 1. "
5979 "Offset must be a multiple of 4."},
5980 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5981 "vkCmdPushConstants() call has push constants with offset 1. "
5982 "Offset must be a multiple of 4."},
5983 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5984 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5985 "0x1 not within flag-matching ranges in pipeline layout"},
5986 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
5987 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
5988 "0x1 not within flag-matching ranges in pipeline layout"},
5989 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
5990 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
5991 "0x1 not within flag-matching ranges in pipeline layout"},
5992 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
5993 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
5994 "0x1 not within flag-matching ranges in pipeline layout"},
5995 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
5996 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
5997 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005998 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06005999 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6000 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006001 }};
6002
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006003 BeginCommandBuffer();
6004
6005 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006006 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006007 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006008 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006009 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006010 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006011 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006012 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006013 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6015 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006016 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006017 m_errorMonitor->VerifyFound();
6018 }
6019
6020 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006022 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006023 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006024 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006025
Karl Schultzc81037d2016-05-12 08:11:23 -06006026 // overlapping range tests with cmd
6027 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6028 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6029 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6030 "0x1 not within flag-matching ranges in pipeline layout"},
6031 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6032 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6033 "0x1 not within flag-matching ranges in pipeline layout"},
6034 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6035 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6036 "0x1 not within flag-matching ranges in pipeline layout"},
6037 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006038 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006039 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006040 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6041 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006042 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006043 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006044 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006045 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006046 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006047 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6049 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006050 iter.range.size, dummy_values);
6051 m_errorMonitor->VerifyFound();
6052 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006053 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6054
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006055 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006056}
6057
Karl Schultz6addd812016-02-02 17:17:23 -07006058TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006059 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006060 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006061
6062 ASSERT_NO_FATAL_FAILURE(InitState());
6063 ASSERT_NO_FATAL_FAILURE(InitViewport());
6064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6065
Mike Stroyanb8a61002016-06-20 16:00:28 -06006066 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6067 VkImageTiling tiling;
6068 VkFormatProperties format_properties;
6069 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006070 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006071 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006072 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006073 tiling = VK_IMAGE_TILING_OPTIMAL;
6074 } else {
6075 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6076 "skipped.\n");
6077 return;
6078 }
6079
Tobin Ehlis559c6382015-11-05 09:52:49 -07006080 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6081 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006082 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6083 ds_type_count[0].descriptorCount = 10;
6084 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6085 ds_type_count[1].descriptorCount = 2;
6086 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6087 ds_type_count[2].descriptorCount = 2;
6088 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6089 ds_type_count[3].descriptorCount = 5;
6090 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6091 // type
6092 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6093 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6094 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006095
6096 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006097 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6098 ds_pool_ci.pNext = NULL;
6099 ds_pool_ci.maxSets = 5;
6100 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6101 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006102
6103 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006104 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006105 ASSERT_VK_SUCCESS(err);
6106
6107 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6108 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006109 dsl_binding[0].binding = 0;
6110 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6111 dsl_binding[0].descriptorCount = 5;
6112 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6113 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006114
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006115 // Create layout identical to set0 layout but w/ different stageFlags
6116 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006117 dsl_fs_stage_only.binding = 0;
6118 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6119 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006120 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6121 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006122 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006123 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006124 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6125 ds_layout_ci.pNext = NULL;
6126 ds_layout_ci.bindingCount = 1;
6127 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006128 static const uint32_t NUM_LAYOUTS = 4;
6129 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006130 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006131 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6132 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006133 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006134 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006135 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006136 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006137 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006138 dsl_binding[0].binding = 0;
6139 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006140 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006141 dsl_binding[1].binding = 1;
6142 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6143 dsl_binding[1].descriptorCount = 2;
6144 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6145 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006146 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006147 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006148 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006149 ASSERT_VK_SUCCESS(err);
6150 dsl_binding[0].binding = 0;
6151 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006152 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006153 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006154 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006155 ASSERT_VK_SUCCESS(err);
6156 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006157 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006158 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006159 ASSERT_VK_SUCCESS(err);
6160
6161 static const uint32_t NUM_SETS = 4;
6162 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6163 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006164 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006165 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006166 alloc_info.descriptorPool = ds_pool;
6167 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006168 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006169 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006170 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006171 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006172 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006173 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006174 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006175
6176 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006177 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6178 pipeline_layout_ci.pNext = NULL;
6179 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6180 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006181
6182 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006183 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006184 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006185 // Create pipelineLayout with only one setLayout
6186 pipeline_layout_ci.setLayoutCount = 1;
6187 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006188 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006189 ASSERT_VK_SUCCESS(err);
6190 // Create pipelineLayout with 2 descriptor setLayout at index 0
6191 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6192 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006193 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006194 ASSERT_VK_SUCCESS(err);
6195 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6196 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6197 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006198 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006199 ASSERT_VK_SUCCESS(err);
6200 // Create pipelineLayout with UB type, but stageFlags for FS only
6201 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6202 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006203 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006204 ASSERT_VK_SUCCESS(err);
6205 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6206 VkDescriptorSetLayout pl_bad_s0[2] = {};
6207 pl_bad_s0[0] = ds_layout_fs_only;
6208 pl_bad_s0[1] = ds_layout[1];
6209 pipeline_layout_ci.setLayoutCount = 2;
6210 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6211 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006212 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006213 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006214
6215 // Create a buffer to update the descriptor with
6216 uint32_t qfi = 0;
6217 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006218 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6219 buffCI.size = 1024;
6220 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6221 buffCI.queueFamilyIndexCount = 1;
6222 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006223
6224 VkBuffer dyub;
6225 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6226 ASSERT_VK_SUCCESS(err);
6227 // Correctly update descriptor to avoid "NOT_UPDATED" error
6228 static const uint32_t NUM_BUFFS = 5;
6229 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006230 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006231 buffInfo[i].buffer = dyub;
6232 buffInfo[i].offset = 0;
6233 buffInfo[i].range = 1024;
6234 }
Karl Schultz6addd812016-02-02 17:17:23 -07006235 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006236 const int32_t tex_width = 32;
6237 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006238 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006239 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6240 image_create_info.pNext = NULL;
6241 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6242 image_create_info.format = tex_format;
6243 image_create_info.extent.width = tex_width;
6244 image_create_info.extent.height = tex_height;
6245 image_create_info.extent.depth = 1;
6246 image_create_info.mipLevels = 1;
6247 image_create_info.arrayLayers = 1;
6248 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006249 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006250 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006251 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006252 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6253 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006254
Karl Schultz6addd812016-02-02 17:17:23 -07006255 VkMemoryRequirements memReqs;
6256 VkDeviceMemory imageMem;
6257 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006258 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006259 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6260 memAlloc.pNext = NULL;
6261 memAlloc.allocationSize = 0;
6262 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006263 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6264 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006265 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006266 ASSERT_TRUE(pass);
6267 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6268 ASSERT_VK_SUCCESS(err);
6269 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6270 ASSERT_VK_SUCCESS(err);
6271
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006272 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006273 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6274 image_view_create_info.image = image;
6275 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6276 image_view_create_info.format = tex_format;
6277 image_view_create_info.subresourceRange.layerCount = 1;
6278 image_view_create_info.subresourceRange.baseMipLevel = 0;
6279 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006280 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006281
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006282 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006283 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006284 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006285 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006286 imageInfo[0].imageView = view;
6287 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6288 imageInfo[1].imageView = view;
6289 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006290 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006291 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006292 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006293 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006294
6295 static const uint32_t NUM_SET_UPDATES = 3;
6296 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6297 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6298 descriptor_write[0].dstSet = descriptorSet[0];
6299 descriptor_write[0].dstBinding = 0;
6300 descriptor_write[0].descriptorCount = 5;
6301 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6302 descriptor_write[0].pBufferInfo = buffInfo;
6303 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6304 descriptor_write[1].dstSet = descriptorSet[1];
6305 descriptor_write[1].dstBinding = 0;
6306 descriptor_write[1].descriptorCount = 2;
6307 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6308 descriptor_write[1].pImageInfo = imageInfo;
6309 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6310 descriptor_write[2].dstSet = descriptorSet[1];
6311 descriptor_write[2].dstBinding = 1;
6312 descriptor_write[2].descriptorCount = 2;
6313 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006314 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006315
6316 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006317
Tobin Ehlis88452832015-12-03 09:40:56 -07006318 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006319 char const *vsSource = "#version 450\n"
6320 "\n"
6321 "out gl_PerVertex {\n"
6322 " vec4 gl_Position;\n"
6323 "};\n"
6324 "void main(){\n"
6325 " gl_Position = vec4(1);\n"
6326 "}\n";
6327 char const *fsSource = "#version 450\n"
6328 "\n"
6329 "layout(location=0) out vec4 x;\n"
6330 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6331 "void main(){\n"
6332 " x = vec4(bar.y);\n"
6333 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006334 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6335 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006336 VkPipelineObj pipe(m_device);
6337 pipe.AddShader(&vs);
6338 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006339 pipe.AddColorAttachment();
6340 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006341
6342 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006343
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006344 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006345 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6346 // of PSO
6347 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6348 // cmd_pipeline.c
6349 // due to the fact that cmd_alloc_dset_data() has not been called in
6350 // cmd_bind_graphics_pipeline()
6351 // TODO : Want to cause various binding incompatibility issues here to test
6352 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006353 // First cause various verify_layout_compatibility() fails
6354 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006355 // verify_set_layout_compatibility fail cases:
6356 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6358 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6359 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006360 m_errorMonitor->VerifyFound();
6361
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006362 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6364 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6365 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006366 m_errorMonitor->VerifyFound();
6367
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006368 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006369 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6370 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6372 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6373 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006374 m_errorMonitor->VerifyFound();
6375
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006376 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6377 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6379 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6380 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006381 m_errorMonitor->VerifyFound();
6382
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006383 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6384 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6386 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6387 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6388 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006389 m_errorMonitor->VerifyFound();
6390
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006391 // Cause INFO messages due to disturbing previously bound Sets
6392 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006393 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6394 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006395 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6397 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6398 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006399 m_errorMonitor->VerifyFound();
6400
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006401 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6402 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006403 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6405 "any subsequent sets were disturbed ");
6406 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6407 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006408 m_errorMonitor->VerifyFound();
6409
Tobin Ehlis10fad692016-07-07 12:00:36 -06006410 // Now that we're done actively using the pipelineLayout that gfx pipeline
6411 // was created with, we should be able to delete it. Do that now to verify
6412 // that validation obeys pipelineLayout lifetime
6413 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6414
Tobin Ehlis88452832015-12-03 09:40:56 -07006415 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006416 // 1. Error due to not binding required set (we actually use same code as
6417 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6419 &descriptorSet[0], 0, NULL);
6420 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6421 &descriptorSet[1], 0, NULL);
6422 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 -07006423 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006424 m_errorMonitor->VerifyFound();
6425
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006426 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006427 // 2. Error due to bound set not being compatible with PSO's
6428 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006429 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6430 &descriptorSet[0], 0, NULL);
6431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006432 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006433 m_errorMonitor->VerifyFound();
6434
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006435 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006436 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006437 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6438 }
6439 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006440 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006441 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6442 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006443 vkFreeMemory(m_device->device(), imageMem, NULL);
6444 vkDestroyImage(m_device->device(), image, NULL);
6445 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006446}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006447
Karl Schultz6addd812016-02-02 17:17:23 -07006448TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006449
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6451 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006452
6453 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006454 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006455 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006456 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006457
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006458 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006459}
6460
Karl Schultz6addd812016-02-02 17:17:23 -07006461TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6462 VkResult err;
6463 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006464
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006466
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006467 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006468
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006469 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006470 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006471 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006472 cmd.commandPool = m_commandPool;
6473 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006474 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006475
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006476 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006477 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006478
6479 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006480 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006481 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006482 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006483 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006484 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 -07006485 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006486
6487 // The error should be caught by validation of the BeginCommandBuffer call
6488 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6489
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006490 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006491 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006492}
6493
Karl Schultz6addd812016-02-02 17:17:23 -07006494TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006495 // Cause error due to Begin while recording CB
6496 // Then cause 2 errors for attempting to reset CB w/o having
6497 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6498 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006500
6501 ASSERT_NO_FATAL_FAILURE(InitState());
6502
6503 // Calls AllocateCommandBuffers
6504 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6505
Karl Schultz6addd812016-02-02 17:17:23 -07006506 // Force the failure by setting the Renderpass and Framebuffer fields with
6507 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006508 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006509 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006510 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6511 cmd_buf_info.pNext = NULL;
6512 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006513 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006514
6515 // Begin CB to transition to recording state
6516 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6517 // Can't re-begin. This should trigger error
6518 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006519 m_errorMonitor->VerifyFound();
6520
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006522 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6523 // Reset attempt will trigger error due to incorrect CommandPool state
6524 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006525 m_errorMonitor->VerifyFound();
6526
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006528 // Transition CB to RECORDED state
6529 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6530 // Now attempting to Begin will implicitly reset, which triggers error
6531 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006532 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006533}
6534
Karl Schultz6addd812016-02-02 17:17:23 -07006535TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006536 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006537 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006538
Mike Weiblencce7ec72016-10-17 19:33:05 -06006539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006540
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006541 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006543
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006544 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006545 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6546 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006547
6548 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006549 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6550 ds_pool_ci.pNext = NULL;
6551 ds_pool_ci.maxSets = 1;
6552 ds_pool_ci.poolSizeCount = 1;
6553 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006554
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006555 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006556 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006557 ASSERT_VK_SUCCESS(err);
6558
Tony Barboureb254902015-07-15 12:50:33 -06006559 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006560 dsl_binding.binding = 0;
6561 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6562 dsl_binding.descriptorCount = 1;
6563 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6564 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006565
Tony Barboureb254902015-07-15 12:50:33 -06006566 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006567 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6568 ds_layout_ci.pNext = NULL;
6569 ds_layout_ci.bindingCount = 1;
6570 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006571
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006572 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006573 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006574 ASSERT_VK_SUCCESS(err);
6575
6576 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006577 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006578 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006579 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006580 alloc_info.descriptorPool = ds_pool;
6581 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006582 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006583 ASSERT_VK_SUCCESS(err);
6584
Tony Barboureb254902015-07-15 12:50:33 -06006585 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006586 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6587 pipeline_layout_ci.setLayoutCount = 1;
6588 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006589
6590 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006591 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006592 ASSERT_VK_SUCCESS(err);
6593
Tobin Ehlise68360f2015-10-01 11:15:13 -06006594 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006595 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006596
6597 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006598 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6599 vp_state_ci.scissorCount = 1;
6600 vp_state_ci.pScissors = &sc;
6601 vp_state_ci.viewportCount = 1;
6602 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006603
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006604 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6605 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6606 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6607 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6608 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6609 rs_state_ci.depthClampEnable = VK_FALSE;
6610 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6611 rs_state_ci.depthBiasEnable = VK_FALSE;
6612
Tony Barboureb254902015-07-15 12:50:33 -06006613 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006614 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6615 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006616 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006617 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6618 gp_ci.layout = pipeline_layout;
6619 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006620
6621 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006622 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6623 pc_ci.initialDataSize = 0;
6624 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006625
6626 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006627 VkPipelineCache pipelineCache;
6628
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006629 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006630 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006631 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006632
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006633 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006634
Chia-I Wuf7458c52015-10-26 21:10:41 +08006635 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6636 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6637 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6638 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006639}
Tobin Ehlis912df022015-09-17 08:46:18 -06006640/*// TODO : This test should be good, but needs Tess support in compiler to run
6641TEST_F(VkLayerTest, InvalidPatchControlPoints)
6642{
6643 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006644 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006645
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006647 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6648primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006649
Tobin Ehlis912df022015-09-17 08:46:18 -06006650 ASSERT_NO_FATAL_FAILURE(InitState());
6651 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006652
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006653 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006654 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006655 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006656
6657 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6658 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6659 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006660 ds_pool_ci.poolSizeCount = 1;
6661 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006662
6663 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006664 err = vkCreateDescriptorPool(m_device->device(),
6665VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006666 ASSERT_VK_SUCCESS(err);
6667
6668 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006669 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006670 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006671 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006672 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6673 dsl_binding.pImmutableSamplers = NULL;
6674
6675 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006676 ds_layout_ci.sType =
6677VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006678 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006679 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006680 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006681
6682 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006683 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6684&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006685 ASSERT_VK_SUCCESS(err);
6686
6687 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006688 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6689VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006690 ASSERT_VK_SUCCESS(err);
6691
6692 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006693 pipeline_layout_ci.sType =
6694VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006695 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006696 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006697 pipeline_layout_ci.pSetLayouts = &ds_layout;
6698
6699 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006700 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6701&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006702 ASSERT_VK_SUCCESS(err);
6703
6704 VkPipelineShaderStageCreateInfo shaderStages[3];
6705 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6706
Karl Schultz6addd812016-02-02 17:17:23 -07006707 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6708this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006709 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006710 VkShaderObj
6711tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6712this);
6713 VkShaderObj
6714te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6715this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006716
Karl Schultz6addd812016-02-02 17:17:23 -07006717 shaderStages[0].sType =
6718VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006719 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006720 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006721 shaderStages[1].sType =
6722VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006723 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006724 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006725 shaderStages[2].sType =
6726VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006727 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006728 shaderStages[2].shader = te.handle();
6729
6730 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006731 iaCI.sType =
6732VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006733 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006734
6735 VkPipelineTessellationStateCreateInfo tsCI = {};
6736 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6737 tsCI.patchControlPoints = 0; // This will cause an error
6738
6739 VkGraphicsPipelineCreateInfo gp_ci = {};
6740 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6741 gp_ci.pNext = NULL;
6742 gp_ci.stageCount = 3;
6743 gp_ci.pStages = shaderStages;
6744 gp_ci.pVertexInputState = NULL;
6745 gp_ci.pInputAssemblyState = &iaCI;
6746 gp_ci.pTessellationState = &tsCI;
6747 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006748 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006749 gp_ci.pMultisampleState = NULL;
6750 gp_ci.pDepthStencilState = NULL;
6751 gp_ci.pColorBlendState = NULL;
6752 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6753 gp_ci.layout = pipeline_layout;
6754 gp_ci.renderPass = renderPass();
6755
6756 VkPipelineCacheCreateInfo pc_ci = {};
6757 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6758 pc_ci.pNext = NULL;
6759 pc_ci.initialSize = 0;
6760 pc_ci.initialData = 0;
6761 pc_ci.maxSize = 0;
6762
6763 VkPipeline pipeline;
6764 VkPipelineCache pipelineCache;
6765
Karl Schultz6addd812016-02-02 17:17:23 -07006766 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6767&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006768 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006769 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6770&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006771
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006772 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006773
Chia-I Wuf7458c52015-10-26 21:10:41 +08006774 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6775 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6776 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6777 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006778}
6779*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006780// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006781TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006782 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006783
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6785 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006786
Tobin Ehlise68360f2015-10-01 11:15:13 -06006787 ASSERT_NO_FATAL_FAILURE(InitState());
6788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006789
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006790 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006791 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6792 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006793
6794 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006795 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6796 ds_pool_ci.maxSets = 1;
6797 ds_pool_ci.poolSizeCount = 1;
6798 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006799
6800 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006801 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006802 ASSERT_VK_SUCCESS(err);
6803
6804 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006805 dsl_binding.binding = 0;
6806 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6807 dsl_binding.descriptorCount = 1;
6808 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006809
6810 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006811 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6812 ds_layout_ci.bindingCount = 1;
6813 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006814
6815 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006816 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006817 ASSERT_VK_SUCCESS(err);
6818
6819 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006820 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006821 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006822 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006823 alloc_info.descriptorPool = ds_pool;
6824 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006825 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006826 ASSERT_VK_SUCCESS(err);
6827
6828 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006829 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6830 pipeline_layout_ci.setLayoutCount = 1;
6831 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006832
6833 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006834 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006835 ASSERT_VK_SUCCESS(err);
6836
6837 VkViewport vp = {}; // Just need dummy vp to point to
6838
6839 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006840 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6841 vp_state_ci.scissorCount = 0;
6842 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6843 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006844
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006845 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6846 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6847 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6848 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6849 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6850 rs_state_ci.depthClampEnable = VK_FALSE;
6851 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6852 rs_state_ci.depthBiasEnable = VK_FALSE;
6853
Cody Northropeb3a6c12015-10-05 14:44:45 -06006854 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006855 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006856
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006857 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
6858 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
6859 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006860 shaderStages[0] = vs.GetStageCreateInfo();
6861 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006862
6863 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006864 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6865 gp_ci.stageCount = 2;
6866 gp_ci.pStages = shaderStages;
6867 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006868 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006869 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6870 gp_ci.layout = pipeline_layout;
6871 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006872
6873 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006874 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006875
6876 VkPipeline pipeline;
6877 VkPipelineCache pipelineCache;
6878
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006879 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006880 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006881 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006882
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006883 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006884
Chia-I Wuf7458c52015-10-26 21:10:41 +08006885 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6886 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006889}
Karl Schultz6addd812016-02-02 17:17:23 -07006890// Don't set viewport state in PSO. This is an error b/c we always need this
6891// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06006892// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07006893TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06006894 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006895 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006896
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006898
Tobin Ehlise68360f2015-10-01 11:15:13 -06006899 ASSERT_NO_FATAL_FAILURE(InitState());
6900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006901
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006902 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006903 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6904 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006905
6906 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006907 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6908 ds_pool_ci.maxSets = 1;
6909 ds_pool_ci.poolSizeCount = 1;
6910 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006911
6912 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006913 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006914 ASSERT_VK_SUCCESS(err);
6915
6916 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006917 dsl_binding.binding = 0;
6918 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6919 dsl_binding.descriptorCount = 1;
6920 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006921
6922 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006923 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6924 ds_layout_ci.bindingCount = 1;
6925 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006926
6927 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006928 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006929 ASSERT_VK_SUCCESS(err);
6930
6931 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006932 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006933 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006934 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006935 alloc_info.descriptorPool = ds_pool;
6936 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006937 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006938 ASSERT_VK_SUCCESS(err);
6939
6940 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006941 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6942 pipeline_layout_ci.setLayoutCount = 1;
6943 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006944
6945 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006946 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006947 ASSERT_VK_SUCCESS(err);
6948
6949 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6950 // Set scissor as dynamic to avoid second error
6951 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006952 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6953 dyn_state_ci.dynamicStateCount = 1;
6954 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006955
Cody Northropeb3a6c12015-10-05 14:44:45 -06006956 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006957 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006959 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
6960 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
6961 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006962 shaderStages[0] = vs.GetStageCreateInfo();
6963 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006964
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006965 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6966 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6967 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6968 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6969 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6970 rs_state_ci.depthClampEnable = VK_FALSE;
6971 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6972 rs_state_ci.depthBiasEnable = VK_FALSE;
6973
Tobin Ehlise68360f2015-10-01 11:15:13 -06006974 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006975 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6976 gp_ci.stageCount = 2;
6977 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006978 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006979 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
6980 // should cause validation error
6981 gp_ci.pDynamicState = &dyn_state_ci;
6982 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6983 gp_ci.layout = pipeline_layout;
6984 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006985
6986 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006987 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006988
6989 VkPipeline pipeline;
6990 VkPipelineCache pipelineCache;
6991
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006992 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006993 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006994 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006995
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006996 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006997
Chia-I Wuf7458c52015-10-26 21:10:41 +08006998 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6999 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7000 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7001 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007002}
7003// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007004// Then run second test where dynamic scissor count doesn't match PSO scissor
7005// count
7006TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7007 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007008
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7010 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007011
Tobin Ehlise68360f2015-10-01 11:15:13 -06007012 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007013
7014 if (!m_device->phy().features().multiViewport) {
7015 printf("Device does not support multiple viewports/scissors; skipped.\n");
7016 return;
7017 }
7018
Tobin Ehlise68360f2015-10-01 11:15:13 -06007019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007020
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007021 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007022 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7023 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007024
7025 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007026 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7027 ds_pool_ci.maxSets = 1;
7028 ds_pool_ci.poolSizeCount = 1;
7029 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007030
7031 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007032 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007033 ASSERT_VK_SUCCESS(err);
7034
7035 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007036 dsl_binding.binding = 0;
7037 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7038 dsl_binding.descriptorCount = 1;
7039 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007040
7041 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007042 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7043 ds_layout_ci.bindingCount = 1;
7044 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007045
7046 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007047 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007048 ASSERT_VK_SUCCESS(err);
7049
7050 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007051 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007052 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007053 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007054 alloc_info.descriptorPool = ds_pool;
7055 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007056 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007057 ASSERT_VK_SUCCESS(err);
7058
7059 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007060 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7061 pipeline_layout_ci.setLayoutCount = 1;
7062 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007063
7064 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007065 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007066 ASSERT_VK_SUCCESS(err);
7067
7068 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007069 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7070 vp_state_ci.viewportCount = 1;
7071 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7072 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007073 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007074
7075 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7076 // Set scissor as dynamic to avoid that error
7077 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007078 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7079 dyn_state_ci.dynamicStateCount = 1;
7080 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007081
Cody Northropeb3a6c12015-10-05 14:44:45 -06007082 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007083 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007084
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007085 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7086 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7087 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007088 shaderStages[0] = vs.GetStageCreateInfo();
7089 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007090
Cody Northropf6622dc2015-10-06 10:33:21 -06007091 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7092 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7093 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007094 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007095 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007096 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007097 vi_ci.pVertexAttributeDescriptions = nullptr;
7098
7099 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7100 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7101 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7102
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007103 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007104 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007105 rs_ci.pNext = nullptr;
7106
Mark Youngc89c6312016-03-31 16:03:20 -06007107 VkPipelineColorBlendAttachmentState att = {};
7108 att.blendEnable = VK_FALSE;
7109 att.colorWriteMask = 0xf;
7110
Cody Northropf6622dc2015-10-06 10:33:21 -06007111 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7112 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7113 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007114 cb_ci.attachmentCount = 1;
7115 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007116
Tobin Ehlise68360f2015-10-01 11:15:13 -06007117 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007118 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7119 gp_ci.stageCount = 2;
7120 gp_ci.pStages = shaderStages;
7121 gp_ci.pVertexInputState = &vi_ci;
7122 gp_ci.pInputAssemblyState = &ia_ci;
7123 gp_ci.pViewportState = &vp_state_ci;
7124 gp_ci.pRasterizationState = &rs_ci;
7125 gp_ci.pColorBlendState = &cb_ci;
7126 gp_ci.pDynamicState = &dyn_state_ci;
7127 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7128 gp_ci.layout = pipeline_layout;
7129 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007130
7131 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007132 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007133
7134 VkPipeline pipeline;
7135 VkPipelineCache pipelineCache;
7136
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007137 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007138 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007139 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007140
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007141 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007142
Tobin Ehlisd332f282015-10-02 11:00:56 -06007143 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007144 // First need to successfully create the PSO from above by setting
7145 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007146 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 -07007147
7148 VkViewport vp = {}; // Just need dummy vp to point to
7149 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007150 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007151 ASSERT_VK_SUCCESS(err);
7152 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007153 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007154 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007155 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007156 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007157 Draw(1, 0, 0, 0);
7158
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007159 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007160
7161 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7162 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7163 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7164 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007165 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007166}
7167// Create PSO w/o non-zero scissorCount but no scissor data
7168// Then run second test where dynamic viewportCount doesn't match PSO
7169// viewportCount
7170TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7171 VkResult err;
7172
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
Karl Schultz6addd812016-02-02 17:17:23 -07007174
7175 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007176
7177 if (!m_device->phy().features().multiViewport) {
7178 printf("Device does not support multiple viewports/scissors; skipped.\n");
7179 return;
7180 }
7181
Karl Schultz6addd812016-02-02 17:17:23 -07007182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7183
7184 VkDescriptorPoolSize ds_type_count = {};
7185 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7186 ds_type_count.descriptorCount = 1;
7187
7188 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7189 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7190 ds_pool_ci.maxSets = 1;
7191 ds_pool_ci.poolSizeCount = 1;
7192 ds_pool_ci.pPoolSizes = &ds_type_count;
7193
7194 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007195 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007196 ASSERT_VK_SUCCESS(err);
7197
7198 VkDescriptorSetLayoutBinding dsl_binding = {};
7199 dsl_binding.binding = 0;
7200 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7201 dsl_binding.descriptorCount = 1;
7202 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7203
7204 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7205 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7206 ds_layout_ci.bindingCount = 1;
7207 ds_layout_ci.pBindings = &dsl_binding;
7208
7209 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007210 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007211 ASSERT_VK_SUCCESS(err);
7212
7213 VkDescriptorSet descriptorSet;
7214 VkDescriptorSetAllocateInfo alloc_info = {};
7215 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7216 alloc_info.descriptorSetCount = 1;
7217 alloc_info.descriptorPool = ds_pool;
7218 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007219 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007220 ASSERT_VK_SUCCESS(err);
7221
7222 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7223 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7224 pipeline_layout_ci.setLayoutCount = 1;
7225 pipeline_layout_ci.pSetLayouts = &ds_layout;
7226
7227 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007229 ASSERT_VK_SUCCESS(err);
7230
7231 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7232 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7233 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007234 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007235 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007236 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007237
7238 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7239 // Set scissor as dynamic to avoid that error
7240 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7241 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7242 dyn_state_ci.dynamicStateCount = 1;
7243 dyn_state_ci.pDynamicStates = &vp_state;
7244
7245 VkPipelineShaderStageCreateInfo shaderStages[2];
7246 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7247
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007248 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7249 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7250 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007251 shaderStages[0] = vs.GetStageCreateInfo();
7252 shaderStages[1] = fs.GetStageCreateInfo();
7253
7254 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7255 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7256 vi_ci.pNext = nullptr;
7257 vi_ci.vertexBindingDescriptionCount = 0;
7258 vi_ci.pVertexBindingDescriptions = nullptr;
7259 vi_ci.vertexAttributeDescriptionCount = 0;
7260 vi_ci.pVertexAttributeDescriptions = nullptr;
7261
7262 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7263 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7264 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7265
7266 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7267 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7268 rs_ci.pNext = nullptr;
7269
Mark Youngc89c6312016-03-31 16:03:20 -06007270 VkPipelineColorBlendAttachmentState att = {};
7271 att.blendEnable = VK_FALSE;
7272 att.colorWriteMask = 0xf;
7273
Karl Schultz6addd812016-02-02 17:17:23 -07007274 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7275 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7276 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007277 cb_ci.attachmentCount = 1;
7278 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007279
7280 VkGraphicsPipelineCreateInfo gp_ci = {};
7281 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7282 gp_ci.stageCount = 2;
7283 gp_ci.pStages = shaderStages;
7284 gp_ci.pVertexInputState = &vi_ci;
7285 gp_ci.pInputAssemblyState = &ia_ci;
7286 gp_ci.pViewportState = &vp_state_ci;
7287 gp_ci.pRasterizationState = &rs_ci;
7288 gp_ci.pColorBlendState = &cb_ci;
7289 gp_ci.pDynamicState = &dyn_state_ci;
7290 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7291 gp_ci.layout = pipeline_layout;
7292 gp_ci.renderPass = renderPass();
7293
7294 VkPipelineCacheCreateInfo pc_ci = {};
7295 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7296
7297 VkPipeline pipeline;
7298 VkPipelineCache pipelineCache;
7299
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007300 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007301 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007302 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007304 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007305
7306 // Now hit second fail case where we set scissor w/ different count than PSO
7307 // First need to successfully create the PSO from above by setting
7308 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007309 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 -06007310
Tobin Ehlisd332f282015-10-02 11:00:56 -06007311 VkRect2D sc = {}; // Just need dummy vp to point to
7312 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007313 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007314 ASSERT_VK_SUCCESS(err);
7315 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007316 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007317 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007318 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007319 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007320 Draw(1, 0, 0, 0);
7321
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007322 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007323
Chia-I Wuf7458c52015-10-26 21:10:41 +08007324 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7325 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7326 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7327 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007328 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007329}
7330
Mark Young7394fdd2016-03-31 14:56:43 -06007331TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7332 VkResult err;
7333
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007335
7336 ASSERT_NO_FATAL_FAILURE(InitState());
7337 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7338
7339 VkDescriptorPoolSize ds_type_count = {};
7340 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7341 ds_type_count.descriptorCount = 1;
7342
7343 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7344 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7345 ds_pool_ci.maxSets = 1;
7346 ds_pool_ci.poolSizeCount = 1;
7347 ds_pool_ci.pPoolSizes = &ds_type_count;
7348
7349 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007350 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007351 ASSERT_VK_SUCCESS(err);
7352
7353 VkDescriptorSetLayoutBinding dsl_binding = {};
7354 dsl_binding.binding = 0;
7355 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7356 dsl_binding.descriptorCount = 1;
7357 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7358
7359 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7360 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7361 ds_layout_ci.bindingCount = 1;
7362 ds_layout_ci.pBindings = &dsl_binding;
7363
7364 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007365 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007366 ASSERT_VK_SUCCESS(err);
7367
7368 VkDescriptorSet descriptorSet;
7369 VkDescriptorSetAllocateInfo alloc_info = {};
7370 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7371 alloc_info.descriptorSetCount = 1;
7372 alloc_info.descriptorPool = ds_pool;
7373 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007374 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007375 ASSERT_VK_SUCCESS(err);
7376
7377 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7378 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7379 pipeline_layout_ci.setLayoutCount = 1;
7380 pipeline_layout_ci.pSetLayouts = &ds_layout;
7381
7382 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007383 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007384 ASSERT_VK_SUCCESS(err);
7385
7386 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7387 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7388 vp_state_ci.scissorCount = 1;
7389 vp_state_ci.pScissors = NULL;
7390 vp_state_ci.viewportCount = 1;
7391 vp_state_ci.pViewports = NULL;
7392
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007393 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007394 // Set scissor as dynamic to avoid that error
7395 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7396 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7397 dyn_state_ci.dynamicStateCount = 2;
7398 dyn_state_ci.pDynamicStates = dynamic_states;
7399
7400 VkPipelineShaderStageCreateInfo shaderStages[2];
7401 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7402
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007403 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7404 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007405 this); // TODO - We shouldn't need a fragment shader
7406 // but add it to be able to run on more devices
7407 shaderStages[0] = vs.GetStageCreateInfo();
7408 shaderStages[1] = fs.GetStageCreateInfo();
7409
7410 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7411 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7412 vi_ci.pNext = nullptr;
7413 vi_ci.vertexBindingDescriptionCount = 0;
7414 vi_ci.pVertexBindingDescriptions = nullptr;
7415 vi_ci.vertexAttributeDescriptionCount = 0;
7416 vi_ci.pVertexAttributeDescriptions = nullptr;
7417
7418 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7419 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7420 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7421
7422 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7423 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7424 rs_ci.pNext = nullptr;
7425
Mark Young47107952016-05-02 15:59:55 -06007426 // Check too low (line width of -1.0f).
7427 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007428
7429 VkPipelineColorBlendAttachmentState att = {};
7430 att.blendEnable = VK_FALSE;
7431 att.colorWriteMask = 0xf;
7432
7433 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7434 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7435 cb_ci.pNext = nullptr;
7436 cb_ci.attachmentCount = 1;
7437 cb_ci.pAttachments = &att;
7438
7439 VkGraphicsPipelineCreateInfo gp_ci = {};
7440 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7441 gp_ci.stageCount = 2;
7442 gp_ci.pStages = shaderStages;
7443 gp_ci.pVertexInputState = &vi_ci;
7444 gp_ci.pInputAssemblyState = &ia_ci;
7445 gp_ci.pViewportState = &vp_state_ci;
7446 gp_ci.pRasterizationState = &rs_ci;
7447 gp_ci.pColorBlendState = &cb_ci;
7448 gp_ci.pDynamicState = &dyn_state_ci;
7449 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7450 gp_ci.layout = pipeline_layout;
7451 gp_ci.renderPass = renderPass();
7452
7453 VkPipelineCacheCreateInfo pc_ci = {};
7454 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7455
7456 VkPipeline pipeline;
7457 VkPipelineCache pipelineCache;
7458
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007459 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007460 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007461 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007462
7463 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007464 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007465
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007467
7468 // Check too high (line width of 65536.0f).
7469 rs_ci.lineWidth = 65536.0f;
7470
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007471 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007472 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007473 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007474
7475 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007476 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007477
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007479
7480 dyn_state_ci.dynamicStateCount = 3;
7481
7482 rs_ci.lineWidth = 1.0f;
7483
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007484 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007485 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007486 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007487 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007488 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007489
7490 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007491 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007492 m_errorMonitor->VerifyFound();
7493
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007495
7496 // Check too high with dynamic setting.
7497 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7498 m_errorMonitor->VerifyFound();
7499 EndCommandBuffer();
7500
7501 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7502 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7503 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7504 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007505 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007506}
7507
Karl Schultz6addd812016-02-02 17:17:23 -07007508TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007509 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7511 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007512
7513 ASSERT_NO_FATAL_FAILURE(InitState());
7514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007515
Tony Barbourfe3351b2015-07-28 10:17:20 -06007516 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007517 // Don't care about RenderPass handle b/c error should be flagged before
7518 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007519 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007520
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007521 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007522}
7523
Karl Schultz6addd812016-02-02 17:17:23 -07007524TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007525 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7527 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007528
7529 ASSERT_NO_FATAL_FAILURE(InitState());
7530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007531
Tony Barbourfe3351b2015-07-28 10:17:20 -06007532 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007533 // Just create a dummy Renderpass that's non-NULL so we can get to the
7534 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007535 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007536
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007537 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007538}
7539
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007540TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7541 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7542 "the number of renderPass attachments that use loadOp"
7543 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7544
7545 ASSERT_NO_FATAL_FAILURE(InitState());
7546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7547
7548 // Create a renderPass with a single attachment that uses loadOp CLEAR
7549 VkAttachmentReference attach = {};
7550 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7551 VkSubpassDescription subpass = {};
7552 subpass.inputAttachmentCount = 1;
7553 subpass.pInputAttachments = &attach;
7554 VkRenderPassCreateInfo rpci = {};
7555 rpci.subpassCount = 1;
7556 rpci.pSubpasses = &subpass;
7557 rpci.attachmentCount = 1;
7558 VkAttachmentDescription attach_desc = {};
7559 attach_desc.format = VK_FORMAT_UNDEFINED;
7560 // Set loadOp to CLEAR
7561 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7562 rpci.pAttachments = &attach_desc;
7563 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7564 VkRenderPass rp;
7565 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7566
7567 VkCommandBufferInheritanceInfo hinfo = {};
7568 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7569 hinfo.renderPass = VK_NULL_HANDLE;
7570 hinfo.subpass = 0;
7571 hinfo.framebuffer = VK_NULL_HANDLE;
7572 hinfo.occlusionQueryEnable = VK_FALSE;
7573 hinfo.queryFlags = 0;
7574 hinfo.pipelineStatistics = 0;
7575 VkCommandBufferBeginInfo info = {};
7576 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7577 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7578 info.pInheritanceInfo = &hinfo;
7579
7580 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7581 VkRenderPassBeginInfo rp_begin = {};
7582 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7583 rp_begin.pNext = NULL;
7584 rp_begin.renderPass = renderPass();
7585 rp_begin.framebuffer = framebuffer();
7586 rp_begin.clearValueCount = 0; // Should be 1
7587
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7589 "there must be at least 1 entries in "
7590 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007591
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007592 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007593
7594 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007595
7596 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007597}
7598
Cody Northrop3bb4d962016-05-09 16:15:57 -06007599TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7600
7601 TEST_DESCRIPTION("End a command buffer with an active render pass");
7602
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7604 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007605
7606 ASSERT_NO_FATAL_FAILURE(InitState());
7607 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7608
7609 // The framework's BeginCommandBuffer calls CreateRenderPass
7610 BeginCommandBuffer();
7611
7612 // Call directly into vkEndCommandBuffer instead of the
7613 // the framework's EndCommandBuffer, which inserts a
7614 // vkEndRenderPass
7615 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7616
7617 m_errorMonitor->VerifyFound();
7618
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007619 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7620 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007621}
7622
Karl Schultz6addd812016-02-02 17:17:23 -07007623TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007624 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7626 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007627
7628 ASSERT_NO_FATAL_FAILURE(InitState());
7629 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007630
7631 // Renderpass is started here
7632 BeginCommandBuffer();
7633
7634 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007635 vk_testing::Buffer dstBuffer;
7636 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007637
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007638 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007639
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007640 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007641}
7642
Karl Schultz6addd812016-02-02 17:17:23 -07007643TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007644 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7646 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007647
7648 ASSERT_NO_FATAL_FAILURE(InitState());
7649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007650
7651 // Renderpass is started here
7652 BeginCommandBuffer();
7653
7654 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007655 vk_testing::Buffer dstBuffer;
7656 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007657
Karl Schultz6addd812016-02-02 17:17:23 -07007658 VkDeviceSize dstOffset = 0;
7659 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007660 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007661
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007662 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007663
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007664 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007665}
7666
Karl Schultz6addd812016-02-02 17:17:23 -07007667TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007668 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7670 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007671
7672 ASSERT_NO_FATAL_FAILURE(InitState());
7673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007674
7675 // Renderpass is started here
7676 BeginCommandBuffer();
7677
Michael Lentine0a369f62016-02-03 16:51:46 -06007678 VkClearColorValue clear_color;
7679 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007680 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7681 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7682 const int32_t tex_width = 32;
7683 const int32_t tex_height = 32;
7684 VkImageCreateInfo image_create_info = {};
7685 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7686 image_create_info.pNext = NULL;
7687 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7688 image_create_info.format = tex_format;
7689 image_create_info.extent.width = tex_width;
7690 image_create_info.extent.height = tex_height;
7691 image_create_info.extent.depth = 1;
7692 image_create_info.mipLevels = 1;
7693 image_create_info.arrayLayers = 1;
7694 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7695 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7696 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007697
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007698 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007699 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007700
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007701 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007702
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007703 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007704
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007705 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007706}
7707
Karl Schultz6addd812016-02-02 17:17:23 -07007708TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007709 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7711 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007712
7713 ASSERT_NO_FATAL_FAILURE(InitState());
7714 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007715
7716 // Renderpass is started here
7717 BeginCommandBuffer();
7718
7719 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007720 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007721 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7722 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7723 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7724 image_create_info.extent.width = 64;
7725 image_create_info.extent.height = 64;
7726 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7727 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007728
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007729 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007730 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007731
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007732 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007734 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7735 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007736
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007737 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007738}
7739
Karl Schultz6addd812016-02-02 17:17:23 -07007740TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007741 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007742 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7745 "must be issued inside an active "
7746 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007747
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007748 ASSERT_NO_FATAL_FAILURE(InitState());
7749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007750
7751 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007752 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007753 ASSERT_VK_SUCCESS(err);
7754
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007755 VkClearAttachment color_attachment;
7756 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7757 color_attachment.clearValue.color.float32[0] = 0;
7758 color_attachment.clearValue.color.float32[1] = 0;
7759 color_attachment.clearValue.color.float32[2] = 0;
7760 color_attachment.clearValue.color.float32[3] = 0;
7761 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007762 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007763 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007764
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007765 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007766}
7767
Chris Forbes3b97e932016-09-07 11:29:24 +12007768TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
7769 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
7770 "called too many times in a renderpass instance");
7771
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
7773 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12007774
7775 ASSERT_NO_FATAL_FAILURE(InitState());
7776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7777
7778 BeginCommandBuffer();
7779
7780 // error here.
7781 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
7782 m_errorMonitor->VerifyFound();
7783
7784 EndCommandBuffer();
7785}
7786
Chris Forbes6d624702016-09-07 13:57:05 +12007787TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
7788 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
7789 "called before the final subpass has been reached");
7790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
7792 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12007793
7794 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007795 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
7796 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12007797
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007798 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12007799
7800 VkRenderPass rp;
7801 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
7802 ASSERT_VK_SUCCESS(err);
7803
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007804 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12007805
7806 VkFramebuffer fb;
7807 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
7808 ASSERT_VK_SUCCESS(err);
7809
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007810 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12007811
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007812 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 +12007813
7814 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
7815
7816 // Error here.
7817 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7818 m_errorMonitor->VerifyFound();
7819
7820 // Clean up.
7821 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
7822 vkDestroyRenderPass(m_device->device(), rp, nullptr);
7823}
7824
Karl Schultz9e66a292016-04-21 15:57:51 -06007825TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7826 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7828 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06007829
7830 ASSERT_NO_FATAL_FAILURE(InitState());
7831 BeginCommandBuffer();
7832
7833 VkBufferMemoryBarrier buf_barrier = {};
7834 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7835 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7836 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7837 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7838 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7839 buf_barrier.buffer = VK_NULL_HANDLE;
7840 buf_barrier.offset = 0;
7841 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007842 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7843 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06007844
7845 m_errorMonitor->VerifyFound();
7846}
7847
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007848TEST_F(VkLayerTest, InvalidBarriers) {
7849 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7850
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007852
7853 ASSERT_NO_FATAL_FAILURE(InitState());
7854 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7855
7856 VkMemoryBarrier mem_barrier = {};
7857 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7858 mem_barrier.pNext = NULL;
7859 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7860 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7861 BeginCommandBuffer();
7862 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007863 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007864 &mem_barrier, 0, nullptr, 0, nullptr);
7865 m_errorMonitor->VerifyFound();
7866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007868 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007869 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 -06007870 ASSERT_TRUE(image.initialized());
7871 VkImageMemoryBarrier img_barrier = {};
7872 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7873 img_barrier.pNext = NULL;
7874 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7875 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7876 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7877 // New layout can't be UNDEFINED
7878 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7879 img_barrier.image = image.handle();
7880 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7881 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7882 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7883 img_barrier.subresourceRange.baseArrayLayer = 0;
7884 img_barrier.subresourceRange.baseMipLevel = 0;
7885 img_barrier.subresourceRange.layerCount = 1;
7886 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007887 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7888 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007889 m_errorMonitor->VerifyFound();
7890 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7891
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
7893 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007894 // baseArrayLayer + layerCount must be <= image's arrayLayers
7895 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007896 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7897 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007898 m_errorMonitor->VerifyFound();
7899 img_barrier.subresourceRange.baseArrayLayer = 0;
7900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007902 // baseMipLevel + levelCount must be <= image's mipLevels
7903 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007904 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7905 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007906 m_errorMonitor->VerifyFound();
7907 img_barrier.subresourceRange.baseMipLevel = 0;
7908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 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 -06007910 vk_testing::Buffer buffer;
7911 buffer.init(*m_device, 256);
7912 VkBufferMemoryBarrier buf_barrier = {};
7913 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7914 buf_barrier.pNext = NULL;
7915 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7916 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7917 buf_barrier.buffer = buffer.handle();
7918 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7919 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7920 buf_barrier.offset = 0;
7921 buf_barrier.size = VK_WHOLE_SIZE;
7922 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007923 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7924 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007925 m_errorMonitor->VerifyFound();
7926 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7927
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007929 buf_barrier.offset = 257;
7930 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007931 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7932 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007933 m_errorMonitor->VerifyFound();
7934 buf_barrier.offset = 0;
7935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007937 buf_barrier.size = 257;
7938 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007939 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7940 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007941 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007942
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007943 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06007944 m_errorMonitor->SetDesiredFailureMsg(
7945 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7946 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
7947 m_errorMonitor->SetDesiredFailureMsg(
7948 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7949 "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 -06007950 VkDepthStencilObj ds_image(m_device);
7951 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
7952 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06007953 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
7954 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007955 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06007956 // Use of COLOR aspect on DS image is error
7957 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007958 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7959 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007960 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007961 // Now test depth-only
7962 VkFormatProperties format_props;
7963
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007964 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
7965 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06007966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7967 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
7968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7969 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007970 VkDepthStencilObj d_image(m_device);
7971 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
7972 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007973 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06007974 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007975 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06007976 // Use of COLOR aspect on depth image is error
7977 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007978 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
7979 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007980 m_errorMonitor->VerifyFound();
7981 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007982 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
7983 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007984 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06007985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7986 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007987 VkDepthStencilObj s_image(m_device);
7988 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
7989 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007990 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06007991 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007992 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06007993 // Use of COLOR aspect on depth image is error
7994 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007995 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
7996 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007997 m_errorMonitor->VerifyFound();
7998 }
7999 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8001 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8003 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008004 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008005 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 -06008006 ASSERT_TRUE(c_image.initialized());
8007 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8008 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8009 img_barrier.image = c_image.handle();
8010 // Set aspect to depth (non-color)
8011 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008012 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8013 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008014 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008015}
8016
Tony Barbour18ba25c2016-09-29 13:42:40 -06008017TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8018 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8019
8020 m_errorMonitor->SetDesiredFailureMsg(
8021 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8022 "must have required access bit");
8023 ASSERT_NO_FATAL_FAILURE(InitState());
8024 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008025 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 -06008026 ASSERT_TRUE(image.initialized());
8027
8028 VkImageMemoryBarrier barrier = {};
8029 VkImageSubresourceRange range;
8030 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8031 barrier.srcAccessMask = 0;
8032 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8033 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8034 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8035 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8036 barrier.image = image.handle();
8037 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8038 range.baseMipLevel = 0;
8039 range.levelCount = 1;
8040 range.baseArrayLayer = 0;
8041 range.layerCount = 1;
8042 barrier.subresourceRange = range;
8043 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8044 cmdbuf.BeginCommandBuffer();
8045 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8046 &barrier);
8047 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8048 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8049 barrier.srcAccessMask = 0;
8050 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8051 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8052 &barrier);
8053
8054 m_errorMonitor->VerifyFound();
8055}
8056
Karl Schultz6addd812016-02-02 17:17:23 -07008057TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008058 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008059 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008060
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008062
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008063 ASSERT_NO_FATAL_FAILURE(InitState());
8064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008065 uint32_t qfi = 0;
8066 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008067 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8068 buffCI.size = 1024;
8069 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8070 buffCI.queueFamilyIndexCount = 1;
8071 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008072
8073 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008074 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008075 ASSERT_VK_SUCCESS(err);
8076
8077 BeginCommandBuffer();
8078 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008079 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8080 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008081 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008082 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008083
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008084 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008085
Chia-I Wuf7458c52015-10-26 21:10:41 +08008086 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008087}
8088
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008089TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8090 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8092 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8093 "of the indices specified when the device was created, via the "
8094 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008095
8096 ASSERT_NO_FATAL_FAILURE(InitState());
8097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8098 VkBufferCreateInfo buffCI = {};
8099 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8100 buffCI.size = 1024;
8101 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8102 buffCI.queueFamilyIndexCount = 1;
8103 // Introduce failure by specifying invalid queue_family_index
8104 uint32_t qfi = 777;
8105 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008106 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008107
8108 VkBuffer ib;
8109 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8110
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008111 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008112 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008113}
8114
Karl Schultz6addd812016-02-02 17:17:23 -07008115TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008116TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008117 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008118
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008119 ASSERT_NO_FATAL_FAILURE(InitState());
8120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008121
Chris Forbesf29a84f2016-10-06 18:39:28 +13008122 // An empty primary command buffer
8123 VkCommandBufferObj cb(m_device, m_commandPool);
8124 cb.BeginCommandBuffer();
8125 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008126
Chris Forbesf29a84f2016-10-06 18:39:28 +13008127 m_commandBuffer->BeginCommandBuffer();
8128 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8129 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008130
Chris Forbesf29a84f2016-10-06 18:39:28 +13008131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8132 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008133 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008134}
8135
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008136TEST_F(VkLayerTest, DSUsageBitsErrors) {
8137 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8138 "that do not have correct usage bits sets.");
8139 VkResult err;
8140
8141 ASSERT_NO_FATAL_FAILURE(InitState());
8142 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8143 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8144 ds_type_count[i].type = VkDescriptorType(i);
8145 ds_type_count[i].descriptorCount = 1;
8146 }
8147 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8148 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8149 ds_pool_ci.pNext = NULL;
8150 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8151 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8152 ds_pool_ci.pPoolSizes = ds_type_count;
8153
8154 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008155 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008156 ASSERT_VK_SUCCESS(err);
8157
8158 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008159 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008160 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8161 dsl_binding[i].binding = 0;
8162 dsl_binding[i].descriptorType = VkDescriptorType(i);
8163 dsl_binding[i].descriptorCount = 1;
8164 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8165 dsl_binding[i].pImmutableSamplers = NULL;
8166 }
8167
8168 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8169 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8170 ds_layout_ci.pNext = NULL;
8171 ds_layout_ci.bindingCount = 1;
8172 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8173 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8174 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008175 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008176 ASSERT_VK_SUCCESS(err);
8177 }
8178 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8179 VkDescriptorSetAllocateInfo alloc_info = {};
8180 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8181 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8182 alloc_info.descriptorPool = ds_pool;
8183 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008184 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008185 ASSERT_VK_SUCCESS(err);
8186
8187 // Create a buffer & bufferView to be used for invalid updates
8188 VkBufferCreateInfo buff_ci = {};
8189 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8190 // This usage is not valid for any descriptor type
8191 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8192 buff_ci.size = 256;
8193 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8194 VkBuffer buffer;
8195 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8196 ASSERT_VK_SUCCESS(err);
8197
8198 VkBufferViewCreateInfo buff_view_ci = {};
8199 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8200 buff_view_ci.buffer = buffer;
8201 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8202 buff_view_ci.range = VK_WHOLE_SIZE;
8203 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008204 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008205 ASSERT_VK_SUCCESS(err);
8206
8207 // Create an image to be used for invalid updates
8208 VkImageCreateInfo image_ci = {};
8209 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8210 image_ci.imageType = VK_IMAGE_TYPE_2D;
8211 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8212 image_ci.extent.width = 64;
8213 image_ci.extent.height = 64;
8214 image_ci.extent.depth = 1;
8215 image_ci.mipLevels = 1;
8216 image_ci.arrayLayers = 1;
8217 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8218 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8219 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8220 // This usage is not valid for any descriptor type
8221 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8222 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8223 VkImage image;
8224 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8225 ASSERT_VK_SUCCESS(err);
8226 // Bind memory to image
8227 VkMemoryRequirements mem_reqs;
8228 VkDeviceMemory image_mem;
8229 bool pass;
8230 VkMemoryAllocateInfo mem_alloc = {};
8231 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8232 mem_alloc.pNext = NULL;
8233 mem_alloc.allocationSize = 0;
8234 mem_alloc.memoryTypeIndex = 0;
8235 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8236 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008237 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008238 ASSERT_TRUE(pass);
8239 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8240 ASSERT_VK_SUCCESS(err);
8241 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8242 ASSERT_VK_SUCCESS(err);
8243 // Now create view for image
8244 VkImageViewCreateInfo image_view_ci = {};
8245 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8246 image_view_ci.image = image;
8247 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8248 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8249 image_view_ci.subresourceRange.layerCount = 1;
8250 image_view_ci.subresourceRange.baseArrayLayer = 0;
8251 image_view_ci.subresourceRange.levelCount = 1;
8252 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8253 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008254 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008255 ASSERT_VK_SUCCESS(err);
8256
8257 VkDescriptorBufferInfo buff_info = {};
8258 buff_info.buffer = buffer;
8259 VkDescriptorImageInfo img_info = {};
8260 img_info.imageView = image_view;
8261 VkWriteDescriptorSet descriptor_write = {};
8262 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8263 descriptor_write.dstBinding = 0;
8264 descriptor_write.descriptorCount = 1;
8265 descriptor_write.pTexelBufferView = &buff_view;
8266 descriptor_write.pBufferInfo = &buff_info;
8267 descriptor_write.pImageInfo = &img_info;
8268
8269 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008270 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8271 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8272 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8273 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8274 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8275 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8276 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8277 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8278 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8279 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8280 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008281 // Start loop at 1 as SAMPLER desc type has no usage bit error
8282 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8283 descriptor_write.descriptorType = VkDescriptorType(i);
8284 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008287 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008288
8289 m_errorMonitor->VerifyFound();
8290 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8291 }
8292 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8293 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008294 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008295 vkDestroyImageView(m_device->device(), image_view, NULL);
8296 vkDestroyBuffer(m_device->device(), buffer, NULL);
8297 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008298 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008299 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8300}
8301
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008302TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008303 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8304 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8305 "1. offset value greater than buffer size\n"
8306 "2. range value of 0\n"
8307 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008308 VkResult err;
8309
8310 ASSERT_NO_FATAL_FAILURE(InitState());
8311 VkDescriptorPoolSize ds_type_count = {};
8312 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8313 ds_type_count.descriptorCount = 1;
8314
8315 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8316 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8317 ds_pool_ci.pNext = NULL;
8318 ds_pool_ci.maxSets = 1;
8319 ds_pool_ci.poolSizeCount = 1;
8320 ds_pool_ci.pPoolSizes = &ds_type_count;
8321
8322 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008323 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008324 ASSERT_VK_SUCCESS(err);
8325
8326 // Create layout with single uniform buffer descriptor
8327 VkDescriptorSetLayoutBinding dsl_binding = {};
8328 dsl_binding.binding = 0;
8329 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8330 dsl_binding.descriptorCount = 1;
8331 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8332 dsl_binding.pImmutableSamplers = NULL;
8333
8334 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8335 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8336 ds_layout_ci.pNext = NULL;
8337 ds_layout_ci.bindingCount = 1;
8338 ds_layout_ci.pBindings = &dsl_binding;
8339 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008340 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008341 ASSERT_VK_SUCCESS(err);
8342
8343 VkDescriptorSet descriptor_set = {};
8344 VkDescriptorSetAllocateInfo alloc_info = {};
8345 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8346 alloc_info.descriptorSetCount = 1;
8347 alloc_info.descriptorPool = ds_pool;
8348 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008349 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008350 ASSERT_VK_SUCCESS(err);
8351
8352 // Create a buffer to be used for invalid updates
8353 VkBufferCreateInfo buff_ci = {};
8354 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8355 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8356 buff_ci.size = 256;
8357 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8358 VkBuffer buffer;
8359 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8360 ASSERT_VK_SUCCESS(err);
8361 // Have to bind memory to buffer before descriptor update
8362 VkMemoryAllocateInfo mem_alloc = {};
8363 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8364 mem_alloc.pNext = NULL;
8365 mem_alloc.allocationSize = 256;
8366 mem_alloc.memoryTypeIndex = 0;
8367
8368 VkMemoryRequirements mem_reqs;
8369 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008370 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008371 if (!pass) {
8372 vkDestroyBuffer(m_device->device(), buffer, NULL);
8373 return;
8374 }
8375
8376 VkDeviceMemory mem;
8377 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8378 ASSERT_VK_SUCCESS(err);
8379 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8380 ASSERT_VK_SUCCESS(err);
8381
8382 VkDescriptorBufferInfo buff_info = {};
8383 buff_info.buffer = buffer;
8384 // First make offset 1 larger than buffer size
8385 buff_info.offset = 257;
8386 buff_info.range = VK_WHOLE_SIZE;
8387 VkWriteDescriptorSet descriptor_write = {};
8388 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8389 descriptor_write.dstBinding = 0;
8390 descriptor_write.descriptorCount = 1;
8391 descriptor_write.pTexelBufferView = nullptr;
8392 descriptor_write.pBufferInfo = &buff_info;
8393 descriptor_write.pImageInfo = nullptr;
8394
8395 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8396 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008398
8399 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8400
8401 m_errorMonitor->VerifyFound();
8402 // Now cause error due to range of 0
8403 buff_info.offset = 0;
8404 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8406 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008407
8408 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8409
8410 m_errorMonitor->VerifyFound();
8411 // Now cause error due to range exceeding buffer size - offset
8412 buff_info.offset = 128;
8413 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008414 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 -06008415
8416 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8417
8418 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008419 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008420 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8421 vkDestroyBuffer(m_device->device(), buffer, NULL);
8422 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8423 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8424}
8425
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008426TEST_F(VkLayerTest, DSAspectBitsErrors) {
8427 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8428 // are set, but could expand this test to hit more cases.
8429 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8430 "that do not have correct aspect bits sets.");
8431 VkResult err;
8432
8433 ASSERT_NO_FATAL_FAILURE(InitState());
8434 VkDescriptorPoolSize ds_type_count = {};
8435 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8436 ds_type_count.descriptorCount = 1;
8437
8438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8440 ds_pool_ci.pNext = NULL;
8441 ds_pool_ci.maxSets = 5;
8442 ds_pool_ci.poolSizeCount = 1;
8443 ds_pool_ci.pPoolSizes = &ds_type_count;
8444
8445 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008446 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008447 ASSERT_VK_SUCCESS(err);
8448
8449 VkDescriptorSetLayoutBinding dsl_binding = {};
8450 dsl_binding.binding = 0;
8451 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8452 dsl_binding.descriptorCount = 1;
8453 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8454 dsl_binding.pImmutableSamplers = NULL;
8455
8456 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8457 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8458 ds_layout_ci.pNext = NULL;
8459 ds_layout_ci.bindingCount = 1;
8460 ds_layout_ci.pBindings = &dsl_binding;
8461 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008462 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008463 ASSERT_VK_SUCCESS(err);
8464
8465 VkDescriptorSet descriptor_set = {};
8466 VkDescriptorSetAllocateInfo alloc_info = {};
8467 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8468 alloc_info.descriptorSetCount = 1;
8469 alloc_info.descriptorPool = ds_pool;
8470 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008471 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008472 ASSERT_VK_SUCCESS(err);
8473
8474 // Create an image to be used for invalid updates
8475 VkImageCreateInfo image_ci = {};
8476 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8477 image_ci.imageType = VK_IMAGE_TYPE_2D;
8478 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8479 image_ci.extent.width = 64;
8480 image_ci.extent.height = 64;
8481 image_ci.extent.depth = 1;
8482 image_ci.mipLevels = 1;
8483 image_ci.arrayLayers = 1;
8484 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8485 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8486 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8487 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8488 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8489 VkImage image;
8490 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8491 ASSERT_VK_SUCCESS(err);
8492 // Bind memory to image
8493 VkMemoryRequirements mem_reqs;
8494 VkDeviceMemory image_mem;
8495 bool pass;
8496 VkMemoryAllocateInfo mem_alloc = {};
8497 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8498 mem_alloc.pNext = NULL;
8499 mem_alloc.allocationSize = 0;
8500 mem_alloc.memoryTypeIndex = 0;
8501 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8502 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008503 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008504 ASSERT_TRUE(pass);
8505 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8506 ASSERT_VK_SUCCESS(err);
8507 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8508 ASSERT_VK_SUCCESS(err);
8509 // Now create view for image
8510 VkImageViewCreateInfo image_view_ci = {};
8511 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8512 image_view_ci.image = image;
8513 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8514 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8515 image_view_ci.subresourceRange.layerCount = 1;
8516 image_view_ci.subresourceRange.baseArrayLayer = 0;
8517 image_view_ci.subresourceRange.levelCount = 1;
8518 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008519 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008520
8521 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008522 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008523 ASSERT_VK_SUCCESS(err);
8524
8525 VkDescriptorImageInfo img_info = {};
8526 img_info.imageView = image_view;
8527 VkWriteDescriptorSet descriptor_write = {};
8528 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8529 descriptor_write.dstBinding = 0;
8530 descriptor_write.descriptorCount = 1;
8531 descriptor_write.pTexelBufferView = NULL;
8532 descriptor_write.pBufferInfo = NULL;
8533 descriptor_write.pImageInfo = &img_info;
8534 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8535 descriptor_write.dstSet = descriptor_set;
8536 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8537 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008539
8540 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8541
8542 m_errorMonitor->VerifyFound();
8543 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8544 vkDestroyImage(m_device->device(), image, NULL);
8545 vkFreeMemory(m_device->device(), image_mem, NULL);
8546 vkDestroyImageView(m_device->device(), image_view, NULL);
8547 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8548 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8549}
8550
Karl Schultz6addd812016-02-02 17:17:23 -07008551TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008552 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008553 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008554
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8556 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8557 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008558
Tobin Ehlis3b780662015-05-28 12:11:26 -06008559 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008560 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008561 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008562 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8563 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008564
8565 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008566 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8567 ds_pool_ci.pNext = NULL;
8568 ds_pool_ci.maxSets = 1;
8569 ds_pool_ci.poolSizeCount = 1;
8570 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008571
Tobin Ehlis3b780662015-05-28 12:11:26 -06008572 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008573 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008574 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008575 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008576 dsl_binding.binding = 0;
8577 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8578 dsl_binding.descriptorCount = 1;
8579 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8580 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008581
Tony Barboureb254902015-07-15 12:50:33 -06008582 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008583 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8584 ds_layout_ci.pNext = NULL;
8585 ds_layout_ci.bindingCount = 1;
8586 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008587
Tobin Ehlis3b780662015-05-28 12:11:26 -06008588 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008589 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008590 ASSERT_VK_SUCCESS(err);
8591
8592 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008593 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008594 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008595 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008596 alloc_info.descriptorPool = ds_pool;
8597 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008598 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008599 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008600
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008601 VkSamplerCreateInfo sampler_ci = {};
8602 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8603 sampler_ci.pNext = NULL;
8604 sampler_ci.magFilter = VK_FILTER_NEAREST;
8605 sampler_ci.minFilter = VK_FILTER_NEAREST;
8606 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8607 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8608 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8609 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8610 sampler_ci.mipLodBias = 1.0;
8611 sampler_ci.anisotropyEnable = VK_FALSE;
8612 sampler_ci.maxAnisotropy = 1;
8613 sampler_ci.compareEnable = VK_FALSE;
8614 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8615 sampler_ci.minLod = 1.0;
8616 sampler_ci.maxLod = 1.0;
8617 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8618 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8619 VkSampler sampler;
8620 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8621 ASSERT_VK_SUCCESS(err);
8622
8623 VkDescriptorImageInfo info = {};
8624 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008625
8626 VkWriteDescriptorSet descriptor_write;
8627 memset(&descriptor_write, 0, sizeof(descriptor_write));
8628 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008629 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008630 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008631 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008632 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008633 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008634
8635 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8636
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008637 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008638
Chia-I Wuf7458c52015-10-26 21:10:41 +08008639 vkDestroySampler(m_device->device(), sampler, NULL);
8640 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8641 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008642}
8643
Karl Schultz6addd812016-02-02 17:17:23 -07008644TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008645 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008646 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008647
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8649 " binding #0 with 1 total descriptors but update of 1 descriptors "
8650 "starting at binding offset of 0 combined with update array element "
8651 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008652
Tobin Ehlis3b780662015-05-28 12:11:26 -06008653 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008654 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008655 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008656 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8657 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008658
8659 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008660 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8661 ds_pool_ci.pNext = NULL;
8662 ds_pool_ci.maxSets = 1;
8663 ds_pool_ci.poolSizeCount = 1;
8664 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008665
Tobin Ehlis3b780662015-05-28 12:11:26 -06008666 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008667 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008668 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008669
Tony Barboureb254902015-07-15 12:50:33 -06008670 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008671 dsl_binding.binding = 0;
8672 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8673 dsl_binding.descriptorCount = 1;
8674 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8675 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008676
8677 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008678 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8679 ds_layout_ci.pNext = NULL;
8680 ds_layout_ci.bindingCount = 1;
8681 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008682
Tobin Ehlis3b780662015-05-28 12:11:26 -06008683 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008684 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008685 ASSERT_VK_SUCCESS(err);
8686
8687 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008688 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008689 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008690 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008691 alloc_info.descriptorPool = ds_pool;
8692 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008693 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008694 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008695
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008696 // Correctly update descriptor to avoid "NOT_UPDATED" error
8697 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008698 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008699 buff_info.offset = 0;
8700 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008701
8702 VkWriteDescriptorSet descriptor_write;
8703 memset(&descriptor_write, 0, sizeof(descriptor_write));
8704 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008705 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008706 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008707 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008708 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8709 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008710
8711 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8712
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008713 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008714
Chia-I Wuf7458c52015-10-26 21:10:41 +08008715 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8716 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008717}
8718
Karl Schultz6addd812016-02-02 17:17:23 -07008719TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8720 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8721 // index 2
8722 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008725
Tobin Ehlis3b780662015-05-28 12:11:26 -06008726 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008727 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008728 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008729 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8730 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008731
8732 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008733 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8734 ds_pool_ci.pNext = NULL;
8735 ds_pool_ci.maxSets = 1;
8736 ds_pool_ci.poolSizeCount = 1;
8737 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008738
Tobin Ehlis3b780662015-05-28 12:11:26 -06008739 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008740 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008741 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008742
Tony Barboureb254902015-07-15 12:50:33 -06008743 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008744 dsl_binding.binding = 0;
8745 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8746 dsl_binding.descriptorCount = 1;
8747 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8748 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008749
8750 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008751 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8752 ds_layout_ci.pNext = NULL;
8753 ds_layout_ci.bindingCount = 1;
8754 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008755 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008756 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008757 ASSERT_VK_SUCCESS(err);
8758
8759 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008760 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008761 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008762 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008763 alloc_info.descriptorPool = ds_pool;
8764 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008765 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008766 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008767
Tony Barboureb254902015-07-15 12:50:33 -06008768 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008769 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8770 sampler_ci.pNext = NULL;
8771 sampler_ci.magFilter = VK_FILTER_NEAREST;
8772 sampler_ci.minFilter = VK_FILTER_NEAREST;
8773 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8774 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8775 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8776 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8777 sampler_ci.mipLodBias = 1.0;
8778 sampler_ci.anisotropyEnable = VK_FALSE;
8779 sampler_ci.maxAnisotropy = 1;
8780 sampler_ci.compareEnable = VK_FALSE;
8781 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8782 sampler_ci.minLod = 1.0;
8783 sampler_ci.maxLod = 1.0;
8784 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8785 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008786
Tobin Ehlis3b780662015-05-28 12:11:26 -06008787 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008788 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008789 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008790
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008791 VkDescriptorImageInfo info = {};
8792 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008793
8794 VkWriteDescriptorSet descriptor_write;
8795 memset(&descriptor_write, 0, sizeof(descriptor_write));
8796 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008797 descriptor_write.dstSet = descriptorSet;
8798 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008799 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008800 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008801 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008802 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008803
8804 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8805
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008806 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008807
Chia-I Wuf7458c52015-10-26 21:10:41 +08008808 vkDestroySampler(m_device->device(), sampler, NULL);
8809 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8810 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008811}
8812
Karl Schultz6addd812016-02-02 17:17:23 -07008813TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8814 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8815 // types
8816 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008817
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008818 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 -06008819
Tobin Ehlis3b780662015-05-28 12:11:26 -06008820 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008821
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008822 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008823 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8824 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008825
8826 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008827 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8828 ds_pool_ci.pNext = NULL;
8829 ds_pool_ci.maxSets = 1;
8830 ds_pool_ci.poolSizeCount = 1;
8831 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008832
Tobin Ehlis3b780662015-05-28 12:11:26 -06008833 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008834 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008835 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008836 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008837 dsl_binding.binding = 0;
8838 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8839 dsl_binding.descriptorCount = 1;
8840 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8841 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008842
Tony Barboureb254902015-07-15 12:50:33 -06008843 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008844 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8845 ds_layout_ci.pNext = NULL;
8846 ds_layout_ci.bindingCount = 1;
8847 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008848
Tobin Ehlis3b780662015-05-28 12:11:26 -06008849 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008850 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008851 ASSERT_VK_SUCCESS(err);
8852
8853 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008854 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008855 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008856 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008857 alloc_info.descriptorPool = ds_pool;
8858 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008859 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008860 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008861
Tony Barboureb254902015-07-15 12:50:33 -06008862 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008863 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8864 sampler_ci.pNext = NULL;
8865 sampler_ci.magFilter = VK_FILTER_NEAREST;
8866 sampler_ci.minFilter = VK_FILTER_NEAREST;
8867 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8868 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8869 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8870 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8871 sampler_ci.mipLodBias = 1.0;
8872 sampler_ci.anisotropyEnable = VK_FALSE;
8873 sampler_ci.maxAnisotropy = 1;
8874 sampler_ci.compareEnable = VK_FALSE;
8875 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8876 sampler_ci.minLod = 1.0;
8877 sampler_ci.maxLod = 1.0;
8878 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8879 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008880 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008881 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008882 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008883
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008884 VkDescriptorImageInfo info = {};
8885 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008886
8887 VkWriteDescriptorSet descriptor_write;
8888 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008889 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008890 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008891 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008892 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008893 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008894 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008895
8896 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8897
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008898 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008899
Chia-I Wuf7458c52015-10-26 21:10:41 +08008900 vkDestroySampler(m_device->device(), sampler, NULL);
8901 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8902 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008903}
8904
Karl Schultz6addd812016-02-02 17:17:23 -07008905TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008906 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07008907 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8910 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008911
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008912 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008913 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
8914 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008915 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008916 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
8917 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008918
8919 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008920 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8921 ds_pool_ci.pNext = NULL;
8922 ds_pool_ci.maxSets = 1;
8923 ds_pool_ci.poolSizeCount = 1;
8924 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008925
8926 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008927 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008928 ASSERT_VK_SUCCESS(err);
8929
8930 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008931 dsl_binding.binding = 0;
8932 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8933 dsl_binding.descriptorCount = 1;
8934 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8935 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008936
8937 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008938 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8939 ds_layout_ci.pNext = NULL;
8940 ds_layout_ci.bindingCount = 1;
8941 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008942 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008943 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008944 ASSERT_VK_SUCCESS(err);
8945
8946 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008947 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008948 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008949 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008950 alloc_info.descriptorPool = ds_pool;
8951 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008952 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008953 ASSERT_VK_SUCCESS(err);
8954
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008955 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008956
8957 VkDescriptorImageInfo descriptor_info;
8958 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8959 descriptor_info.sampler = sampler;
8960
8961 VkWriteDescriptorSet descriptor_write;
8962 memset(&descriptor_write, 0, sizeof(descriptor_write));
8963 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008964 descriptor_write.dstSet = descriptorSet;
8965 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008966 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008967 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8968 descriptor_write.pImageInfo = &descriptor_info;
8969
8970 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8971
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008972 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008973
Chia-I Wuf7458c52015-10-26 21:10:41 +08008974 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8975 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008976}
8977
Karl Schultz6addd812016-02-02 17:17:23 -07008978TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
8979 // Create a single combined Image/Sampler descriptor and send it an invalid
8980 // imageView
8981 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
8984 "image sampler descriptor failed due "
8985 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008986
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008987 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008988 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008989 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8990 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008991
8992 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008993 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8994 ds_pool_ci.pNext = NULL;
8995 ds_pool_ci.maxSets = 1;
8996 ds_pool_ci.poolSizeCount = 1;
8997 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008998
8999 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009000 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009001 ASSERT_VK_SUCCESS(err);
9002
9003 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009004 dsl_binding.binding = 0;
9005 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9006 dsl_binding.descriptorCount = 1;
9007 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9008 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009009
9010 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009011 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9012 ds_layout_ci.pNext = NULL;
9013 ds_layout_ci.bindingCount = 1;
9014 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009015 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009016 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009017 ASSERT_VK_SUCCESS(err);
9018
9019 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009020 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009021 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009022 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009023 alloc_info.descriptorPool = ds_pool;
9024 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009025 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009026 ASSERT_VK_SUCCESS(err);
9027
9028 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009029 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9030 sampler_ci.pNext = NULL;
9031 sampler_ci.magFilter = VK_FILTER_NEAREST;
9032 sampler_ci.minFilter = VK_FILTER_NEAREST;
9033 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9034 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9035 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9036 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9037 sampler_ci.mipLodBias = 1.0;
9038 sampler_ci.anisotropyEnable = VK_FALSE;
9039 sampler_ci.maxAnisotropy = 1;
9040 sampler_ci.compareEnable = VK_FALSE;
9041 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9042 sampler_ci.minLod = 1.0;
9043 sampler_ci.maxLod = 1.0;
9044 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9045 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009046
9047 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009048 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009049 ASSERT_VK_SUCCESS(err);
9050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009051 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009052
9053 VkDescriptorImageInfo descriptor_info;
9054 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9055 descriptor_info.sampler = sampler;
9056 descriptor_info.imageView = view;
9057
9058 VkWriteDescriptorSet descriptor_write;
9059 memset(&descriptor_write, 0, sizeof(descriptor_write));
9060 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009061 descriptor_write.dstSet = descriptorSet;
9062 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009063 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009064 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9065 descriptor_write.pImageInfo = &descriptor_info;
9066
9067 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9068
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009069 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009070
Chia-I Wuf7458c52015-10-26 21:10:41 +08009071 vkDestroySampler(m_device->device(), sampler, NULL);
9072 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9073 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009074}
9075
Karl Schultz6addd812016-02-02 17:17:23 -07009076TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9077 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9078 // into the other
9079 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9082 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9083 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009084
Tobin Ehlis04356f92015-10-27 16:35:27 -06009085 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009086 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009087 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009088 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9089 ds_type_count[0].descriptorCount = 1;
9090 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9091 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009092
9093 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009094 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9095 ds_pool_ci.pNext = NULL;
9096 ds_pool_ci.maxSets = 1;
9097 ds_pool_ci.poolSizeCount = 2;
9098 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009099
9100 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009101 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009102 ASSERT_VK_SUCCESS(err);
9103 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009104 dsl_binding[0].binding = 0;
9105 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9106 dsl_binding[0].descriptorCount = 1;
9107 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9108 dsl_binding[0].pImmutableSamplers = NULL;
9109 dsl_binding[1].binding = 1;
9110 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9111 dsl_binding[1].descriptorCount = 1;
9112 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9113 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009114
9115 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009116 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9117 ds_layout_ci.pNext = NULL;
9118 ds_layout_ci.bindingCount = 2;
9119 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009120
9121 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009122 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009123 ASSERT_VK_SUCCESS(err);
9124
9125 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009126 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009127 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009128 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009129 alloc_info.descriptorPool = ds_pool;
9130 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009131 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009132 ASSERT_VK_SUCCESS(err);
9133
9134 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009135 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9136 sampler_ci.pNext = NULL;
9137 sampler_ci.magFilter = VK_FILTER_NEAREST;
9138 sampler_ci.minFilter = VK_FILTER_NEAREST;
9139 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9140 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9141 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9142 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9143 sampler_ci.mipLodBias = 1.0;
9144 sampler_ci.anisotropyEnable = VK_FALSE;
9145 sampler_ci.maxAnisotropy = 1;
9146 sampler_ci.compareEnable = VK_FALSE;
9147 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9148 sampler_ci.minLod = 1.0;
9149 sampler_ci.maxLod = 1.0;
9150 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9151 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009152
9153 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009154 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009155 ASSERT_VK_SUCCESS(err);
9156
9157 VkDescriptorImageInfo info = {};
9158 info.sampler = sampler;
9159
9160 VkWriteDescriptorSet descriptor_write;
9161 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9162 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009163 descriptor_write.dstSet = descriptorSet;
9164 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009165 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009166 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9167 descriptor_write.pImageInfo = &info;
9168 // This write update should succeed
9169 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9170 // Now perform a copy update that fails due to type mismatch
9171 VkCopyDescriptorSet copy_ds_update;
9172 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9173 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9174 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009175 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009176 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009177 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009178 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009179 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9180
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009181 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009182 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009183 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 -06009184 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9185 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9186 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009187 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009188 copy_ds_update.dstSet = descriptorSet;
9189 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009190 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009191 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9192
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009193 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009194
Tobin Ehlis04356f92015-10-27 16:35:27 -06009195 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9197 "update array offset of 0 and update of "
9198 "5 descriptors oversteps total number "
9199 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009200
Tobin Ehlis04356f92015-10-27 16:35:27 -06009201 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9202 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9203 copy_ds_update.srcSet = descriptorSet;
9204 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009205 copy_ds_update.dstSet = descriptorSet;
9206 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009207 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009208 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9209
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009210 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009211
Chia-I Wuf7458c52015-10-26 21:10:41 +08009212 vkDestroySampler(m_device->device(), sampler, NULL);
9213 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9214 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009215}
9216
Karl Schultz6addd812016-02-02 17:17:23 -07009217TEST_F(VkLayerTest, NumSamplesMismatch) {
9218 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9219 // sampleCount
9220 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009223
Tobin Ehlis3b780662015-05-28 12:11:26 -06009224 ASSERT_NO_FATAL_FAILURE(InitState());
9225 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009226 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009227 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009228 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 = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009242 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009243 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009244 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009245 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9246 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009247
Tony Barboureb254902015-07-15 12:50:33 -06009248 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9249 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9250 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009251 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009252 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009253
Tobin Ehlis3b780662015-05-28 12:11:26 -06009254 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009255 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009256 ASSERT_VK_SUCCESS(err);
9257
9258 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009259 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009260 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009261 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009262 alloc_info.descriptorPool = ds_pool;
9263 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009264 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009265 ASSERT_VK_SUCCESS(err);
9266
Tony Barboureb254902015-07-15 12:50:33 -06009267 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009268 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009269 pipe_ms_state_ci.pNext = NULL;
9270 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9271 pipe_ms_state_ci.sampleShadingEnable = 0;
9272 pipe_ms_state_ci.minSampleShading = 1.0;
9273 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009274
Tony Barboureb254902015-07-15 12:50:33 -06009275 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009276 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9277 pipeline_layout_ci.pNext = NULL;
9278 pipeline_layout_ci.setLayoutCount = 1;
9279 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009280
9281 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009282 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009283 ASSERT_VK_SUCCESS(err);
9284
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009285 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9286 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9287 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009288 VkPipelineObj pipe(m_device);
9289 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009290 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009291 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009292 pipe.SetMSAA(&pipe_ms_state_ci);
9293 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009294
Tony Barbourfe3351b2015-07-28 10:17:20 -06009295 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009296 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009297
Mark Young29927482016-05-04 14:38:51 -06009298 // Render triangle (the error should trigger on the attempt to draw).
9299 Draw(3, 1, 0, 0);
9300
9301 // Finalize recording of the command buffer
9302 EndCommandBuffer();
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 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, 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}
Mark Young29927482016-05-04 14:38:51 -06009310
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009311TEST_F(VkLayerTest, RenderPassIncompatible) {
9312 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9313 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009314 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009315 VkResult err;
9316
9317 ASSERT_NO_FATAL_FAILURE(InitState());
9318 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9319
9320 VkDescriptorSetLayoutBinding dsl_binding = {};
9321 dsl_binding.binding = 0;
9322 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9323 dsl_binding.descriptorCount = 1;
9324 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9325 dsl_binding.pImmutableSamplers = NULL;
9326
9327 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9328 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9329 ds_layout_ci.pNext = NULL;
9330 ds_layout_ci.bindingCount = 1;
9331 ds_layout_ci.pBindings = &dsl_binding;
9332
9333 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009334 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009335 ASSERT_VK_SUCCESS(err);
9336
9337 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9338 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9339 pipeline_layout_ci.pNext = NULL;
9340 pipeline_layout_ci.setLayoutCount = 1;
9341 pipeline_layout_ci.pSetLayouts = &ds_layout;
9342
9343 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009344 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009345 ASSERT_VK_SUCCESS(err);
9346
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009347 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9348 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9349 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009350 // Create a renderpass that will be incompatible with default renderpass
9351 VkAttachmentReference attach = {};
9352 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9353 VkAttachmentReference color_att = {};
9354 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9355 VkSubpassDescription subpass = {};
9356 subpass.inputAttachmentCount = 1;
9357 subpass.pInputAttachments = &attach;
9358 subpass.colorAttachmentCount = 1;
9359 subpass.pColorAttachments = &color_att;
9360 VkRenderPassCreateInfo rpci = {};
9361 rpci.subpassCount = 1;
9362 rpci.pSubpasses = &subpass;
9363 rpci.attachmentCount = 1;
9364 VkAttachmentDescription attach_desc = {};
9365 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009366 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9367 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009368 rpci.pAttachments = &attach_desc;
9369 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9370 VkRenderPass rp;
9371 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9372 VkPipelineObj pipe(m_device);
9373 pipe.AddShader(&vs);
9374 pipe.AddShader(&fs);
9375 pipe.AddColorAttachment();
9376 VkViewport view_port = {};
9377 m_viewports.push_back(view_port);
9378 pipe.SetViewport(m_viewports);
9379 VkRect2D rect = {};
9380 m_scissors.push_back(rect);
9381 pipe.SetScissor(m_scissors);
9382 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9383
9384 VkCommandBufferInheritanceInfo cbii = {};
9385 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9386 cbii.renderPass = rp;
9387 cbii.subpass = 0;
9388 VkCommandBufferBeginInfo cbbi = {};
9389 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9390 cbbi.pInheritanceInfo = &cbii;
9391 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9392 VkRenderPassBeginInfo rpbi = {};
9393 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9394 rpbi.framebuffer = m_framebuffer;
9395 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009396 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9397 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009398
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009400 // Render triangle (the error should trigger on the attempt to draw).
9401 Draw(3, 1, 0, 0);
9402
9403 // Finalize recording of the command buffer
9404 EndCommandBuffer();
9405
9406 m_errorMonitor->VerifyFound();
9407
9408 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9409 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9410 vkDestroyRenderPass(m_device->device(), rp, NULL);
9411}
9412
Mark Youngc89c6312016-03-31 16:03:20 -06009413TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9414 // Create Pipeline where the number of blend attachments doesn't match the
9415 // number of color attachments. In this case, we don't add any color
9416 // blend attachments even though we have a color attachment.
9417 VkResult err;
9418
9419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009420 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009421
9422 ASSERT_NO_FATAL_FAILURE(InitState());
9423 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9424 VkDescriptorPoolSize ds_type_count = {};
9425 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9426 ds_type_count.descriptorCount = 1;
9427
9428 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9429 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9430 ds_pool_ci.pNext = NULL;
9431 ds_pool_ci.maxSets = 1;
9432 ds_pool_ci.poolSizeCount = 1;
9433 ds_pool_ci.pPoolSizes = &ds_type_count;
9434
9435 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009436 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009437 ASSERT_VK_SUCCESS(err);
9438
9439 VkDescriptorSetLayoutBinding dsl_binding = {};
9440 dsl_binding.binding = 0;
9441 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9442 dsl_binding.descriptorCount = 1;
9443 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9444 dsl_binding.pImmutableSamplers = NULL;
9445
9446 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9447 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9448 ds_layout_ci.pNext = NULL;
9449 ds_layout_ci.bindingCount = 1;
9450 ds_layout_ci.pBindings = &dsl_binding;
9451
9452 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009453 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009454 ASSERT_VK_SUCCESS(err);
9455
9456 VkDescriptorSet descriptorSet;
9457 VkDescriptorSetAllocateInfo alloc_info = {};
9458 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9459 alloc_info.descriptorSetCount = 1;
9460 alloc_info.descriptorPool = ds_pool;
9461 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009462 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009463 ASSERT_VK_SUCCESS(err);
9464
9465 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009466 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009467 pipe_ms_state_ci.pNext = NULL;
9468 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9469 pipe_ms_state_ci.sampleShadingEnable = 0;
9470 pipe_ms_state_ci.minSampleShading = 1.0;
9471 pipe_ms_state_ci.pSampleMask = NULL;
9472
9473 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9474 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9475 pipeline_layout_ci.pNext = NULL;
9476 pipeline_layout_ci.setLayoutCount = 1;
9477 pipeline_layout_ci.pSetLayouts = &ds_layout;
9478
9479 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009480 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009481 ASSERT_VK_SUCCESS(err);
9482
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009483 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9484 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9485 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009486 VkPipelineObj pipe(m_device);
9487 pipe.AddShader(&vs);
9488 pipe.AddShader(&fs);
9489 pipe.SetMSAA(&pipe_ms_state_ci);
9490 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9491
9492 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009493 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009494
Mark Young29927482016-05-04 14:38:51 -06009495 // Render triangle (the error should trigger on the attempt to draw).
9496 Draw(3, 1, 0, 0);
9497
9498 // Finalize recording of the command buffer
9499 EndCommandBuffer();
9500
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009501 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009502
9503 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9504 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9505 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9506}
Mark Young29927482016-05-04 14:38:51 -06009507
Mark Muellerd4914412016-06-13 17:52:06 -06009508TEST_F(VkLayerTest, MissingClearAttachment) {
9509 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9510 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009511 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +12009513 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -06009514
9515 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9516 m_errorMonitor->VerifyFound();
9517}
9518
Karl Schultz6addd812016-02-02 17:17:23 -07009519TEST_F(VkLayerTest, ClearCmdNoDraw) {
9520 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9521 // to issuing a Draw
9522 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009523
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009525 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009526
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009527 ASSERT_NO_FATAL_FAILURE(InitState());
9528 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009529
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009530 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009531 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9532 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009533
9534 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009535 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9536 ds_pool_ci.pNext = NULL;
9537 ds_pool_ci.maxSets = 1;
9538 ds_pool_ci.poolSizeCount = 1;
9539 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009540
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009541 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009542 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009543 ASSERT_VK_SUCCESS(err);
9544
Tony Barboureb254902015-07-15 12:50:33 -06009545 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009546 dsl_binding.binding = 0;
9547 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9548 dsl_binding.descriptorCount = 1;
9549 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9550 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009551
Tony Barboureb254902015-07-15 12:50:33 -06009552 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009553 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9554 ds_layout_ci.pNext = NULL;
9555 ds_layout_ci.bindingCount = 1;
9556 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009557
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009558 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009559 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009560 ASSERT_VK_SUCCESS(err);
9561
9562 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009563 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009564 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009565 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009566 alloc_info.descriptorPool = ds_pool;
9567 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009568 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009569 ASSERT_VK_SUCCESS(err);
9570
Tony Barboureb254902015-07-15 12:50:33 -06009571 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009572 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009573 pipe_ms_state_ci.pNext = NULL;
9574 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9575 pipe_ms_state_ci.sampleShadingEnable = 0;
9576 pipe_ms_state_ci.minSampleShading = 1.0;
9577 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009578
Tony Barboureb254902015-07-15 12:50:33 -06009579 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009580 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9581 pipeline_layout_ci.pNext = NULL;
9582 pipeline_layout_ci.setLayoutCount = 1;
9583 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009584
9585 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009586 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009587 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009588
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009589 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009590 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009591 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009592 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009593
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009594 VkPipelineObj pipe(m_device);
9595 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009596 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009597 pipe.SetMSAA(&pipe_ms_state_ci);
9598 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009599
9600 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009601
Karl Schultz6addd812016-02-02 17:17:23 -07009602 // Main thing we care about for this test is that the VkImage obj we're
9603 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009604 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009605 VkClearAttachment color_attachment;
9606 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9607 color_attachment.clearValue.color.float32[0] = 1.0;
9608 color_attachment.clearValue.color.float32[1] = 1.0;
9609 color_attachment.clearValue.color.float32[2] = 1.0;
9610 color_attachment.clearValue.color.float32[3] = 1.0;
9611 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009612 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009613
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009614 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009615
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009616 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009617
Chia-I Wuf7458c52015-10-26 21:10:41 +08009618 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9619 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9620 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009621}
9622
Karl Schultz6addd812016-02-02 17:17:23 -07009623TEST_F(VkLayerTest, VtxBufferBadIndex) {
9624 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009625
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9627 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009628
Tobin Ehlis502480b2015-06-24 15:53:07 -06009629 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009630 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009631 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009632
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009633 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009634 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9635 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009636
9637 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009638 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9639 ds_pool_ci.pNext = NULL;
9640 ds_pool_ci.maxSets = 1;
9641 ds_pool_ci.poolSizeCount = 1;
9642 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009643
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009644 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009645 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009646 ASSERT_VK_SUCCESS(err);
9647
Tony Barboureb254902015-07-15 12:50:33 -06009648 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009649 dsl_binding.binding = 0;
9650 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9651 dsl_binding.descriptorCount = 1;
9652 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9653 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009654
Tony Barboureb254902015-07-15 12:50:33 -06009655 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009656 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9657 ds_layout_ci.pNext = NULL;
9658 ds_layout_ci.bindingCount = 1;
9659 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009660
Tobin Ehlis502480b2015-06-24 15:53:07 -06009661 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009662 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009663 ASSERT_VK_SUCCESS(err);
9664
9665 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009666 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009667 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009668 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009669 alloc_info.descriptorPool = ds_pool;
9670 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009671 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009672 ASSERT_VK_SUCCESS(err);
9673
Tony Barboureb254902015-07-15 12:50:33 -06009674 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009675 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009676 pipe_ms_state_ci.pNext = NULL;
9677 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9678 pipe_ms_state_ci.sampleShadingEnable = 0;
9679 pipe_ms_state_ci.minSampleShading = 1.0;
9680 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009681
Tony Barboureb254902015-07-15 12:50:33 -06009682 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009683 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9684 pipeline_layout_ci.pNext = NULL;
9685 pipeline_layout_ci.setLayoutCount = 1;
9686 pipeline_layout_ci.pSetLayouts = &ds_layout;
9687 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009688
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009689 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009690 ASSERT_VK_SUCCESS(err);
9691
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009692 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9693 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9694 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009695 VkPipelineObj pipe(m_device);
9696 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009697 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009698 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009699 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009700 pipe.SetViewport(m_viewports);
9701 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009702 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009703
9704 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009705 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009706 // Don't care about actual data, just need to get to draw to flag error
9707 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009708 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009709 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009710 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009711
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009712 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009713
Chia-I Wuf7458c52015-10-26 21:10:41 +08009714 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9715 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9716 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009717}
Mark Muellerdfe37552016-07-07 14:47:42 -06009718
Mark Mueller2ee294f2016-08-04 12:59:48 -06009719TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9720 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9721 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009722 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009724 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9725 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009726
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009727 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9728 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009729
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009730 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009731
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009733 // The following test fails with recent NVidia drivers.
9734 // By the time core_validation is reached, the NVidia
9735 // driver has sanitized the invalid condition and core_validation
9736 // is not introduced to the failure condition. This is not the case
9737 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009738 // uint32_t count = static_cast<uint32_t>(~0);
9739 // VkPhysicalDevice physical_device;
9740 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9741 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009742
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009744 float queue_priority = 0.0;
9745
9746 VkDeviceQueueCreateInfo queue_create_info = {};
9747 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9748 queue_create_info.queueCount = 1;
9749 queue_create_info.pQueuePriorities = &queue_priority;
9750 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
9751
9752 VkPhysicalDeviceFeatures features = m_device->phy().features();
9753 VkDevice testDevice;
9754 VkDeviceCreateInfo device_create_info = {};
9755 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
9756 device_create_info.queueCreateInfoCount = 1;
9757 device_create_info.pQueueCreateInfos = &queue_create_info;
9758 device_create_info.pEnabledFeatures = &features;
9759 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9760 m_errorMonitor->VerifyFound();
9761
9762 queue_create_info.queueFamilyIndex = 1;
9763
9764 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
9765 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
9766 for (unsigned i = 0; i < feature_count; i++) {
9767 if (VK_FALSE == feature_array[i]) {
9768 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009770 device_create_info.pEnabledFeatures = &features;
9771 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9772 m_errorMonitor->VerifyFound();
9773 break;
9774 }
9775 }
9776}
9777
9778TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
9779 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
9780 "End a command buffer with a query still in progress.");
9781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009782 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
9783 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
9784 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009785
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009786 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009787
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009789
9790 ASSERT_NO_FATAL_FAILURE(InitState());
9791
9792 VkEvent event;
9793 VkEventCreateInfo event_create_info{};
9794 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9795 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9796
Mark Mueller2ee294f2016-08-04 12:59:48 -06009797 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009798 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009799
9800 BeginCommandBuffer();
9801
9802 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009803 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 -06009804 ASSERT_TRUE(image.initialized());
9805 VkImageMemoryBarrier img_barrier = {};
9806 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9807 img_barrier.pNext = NULL;
9808 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9809 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9810 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9811 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9812 img_barrier.image = image.handle();
9813 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -06009814
9815 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
9816 // that layer validation catches the case when it is not.
9817 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -06009818 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9819 img_barrier.subresourceRange.baseArrayLayer = 0;
9820 img_barrier.subresourceRange.baseMipLevel = 0;
9821 img_barrier.subresourceRange.layerCount = 1;
9822 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009823 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
9824 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009825 m_errorMonitor->VerifyFound();
9826
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009828
9829 VkQueryPool query_pool;
9830 VkQueryPoolCreateInfo query_pool_create_info = {};
9831 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
9832 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
9833 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009834 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009835
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009836 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009837 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
9838
9839 vkEndCommandBuffer(m_commandBuffer->handle());
9840 m_errorMonitor->VerifyFound();
9841
9842 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
9843 vkDestroyEvent(m_device->device(), event, nullptr);
9844}
9845
Mark Muellerdfe37552016-07-07 14:47:42 -06009846TEST_F(VkLayerTest, VertexBufferInvalid) {
9847 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
9848 "delete a buffer twice, use an invalid offset for each "
9849 "buffer type, and attempt to bind a null buffer");
9850
9851 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
9852 "using deleted buffer ";
9853 const char *double_destroy_message = "Cannot free buffer 0x";
9854 const char *invalid_offset_message = "vkBindBufferMemory(): "
9855 "memoryOffset is 0x";
9856 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
9857 "storage memoryOffset "
9858 "is 0x";
9859 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
9860 "texel memoryOffset "
9861 "is 0x";
9862 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
9863 "uniform memoryOffset "
9864 "is 0x";
9865 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
9866 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -06009867 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -06009868
9869 ASSERT_NO_FATAL_FAILURE(InitState());
9870 ASSERT_NO_FATAL_FAILURE(InitViewport());
9871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9872
9873 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009874 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -06009875 pipe_ms_state_ci.pNext = NULL;
9876 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9877 pipe_ms_state_ci.sampleShadingEnable = 0;
9878 pipe_ms_state_ci.minSampleShading = 1.0;
9879 pipe_ms_state_ci.pSampleMask = nullptr;
9880
9881 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9882 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9883 VkPipelineLayout pipeline_layout;
9884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009885 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -06009886 ASSERT_VK_SUCCESS(err);
9887
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009888 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9889 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -06009890 VkPipelineObj pipe(m_device);
9891 pipe.AddShader(&vs);
9892 pipe.AddShader(&fs);
9893 pipe.AddColorAttachment();
9894 pipe.SetMSAA(&pipe_ms_state_ci);
9895 pipe.SetViewport(m_viewports);
9896 pipe.SetScissor(m_scissors);
9897 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9898
9899 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009900 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -06009901
9902 {
9903 // Create and bind a vertex buffer in a reduced scope, which will cause
9904 // it to be deleted upon leaving this scope
9905 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009906 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -06009907 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
9908 draw_verticies.AddVertexInputToPipe(pipe);
9909 }
9910
9911 Draw(1, 0, 0, 0);
9912
9913 EndCommandBuffer();
9914
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -06009916 QueueCommandBuffer(false);
9917 m_errorMonitor->VerifyFound();
9918
9919 {
9920 // Create and bind a vertex buffer in a reduced scope, and delete it
9921 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009922 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
9923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -06009924 buffer_test.TestDoubleDestroy();
9925 }
9926 m_errorMonitor->VerifyFound();
9927
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009928 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -06009929 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
9931 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
9932 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -06009933 m_errorMonitor->VerifyFound();
9934 }
9935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009936 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
9937 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -06009938 // Create and bind a memory buffer with an invalid offset again,
9939 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
9941 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
9942 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -06009943 m_errorMonitor->VerifyFound();
9944 }
9945
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009946 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -06009947 // Create and bind a memory buffer with an invalid offset again, but
9948 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
9950 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
9951 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -06009952 m_errorMonitor->VerifyFound();
9953 }
9954
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009955 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -06009956 // Create and bind a memory buffer with an invalid offset again, but
9957 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
9959 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
9960 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -06009961 m_errorMonitor->VerifyFound();
9962 }
9963
9964 {
9965 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
9967 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
9968 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -06009969 m_errorMonitor->VerifyFound();
9970 }
9971
9972 {
9973 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
9975 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
9976 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -06009977 }
9978 m_errorMonitor->VerifyFound();
9979
9980 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9981}
9982
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009983// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
9984TEST_F(VkLayerTest, InvalidImageLayout) {
9985 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009986 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
9987 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009988 // 3 in ValidateCmdBufImageLayouts
9989 // * -1 Attempt to submit cmd buf w/ deleted image
9990 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
9991 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9993 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009994
9995 ASSERT_NO_FATAL_FAILURE(InitState());
9996 // Create src & dst images to use for copy operations
9997 VkImage src_image;
9998 VkImage dst_image;
9999
10000 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10001 const int32_t tex_width = 32;
10002 const int32_t tex_height = 32;
10003
10004 VkImageCreateInfo image_create_info = {};
10005 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10006 image_create_info.pNext = NULL;
10007 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10008 image_create_info.format = tex_format;
10009 image_create_info.extent.width = tex_width;
10010 image_create_info.extent.height = tex_height;
10011 image_create_info.extent.depth = 1;
10012 image_create_info.mipLevels = 1;
10013 image_create_info.arrayLayers = 4;
10014 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10015 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10016 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10017 image_create_info.flags = 0;
10018
10019 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10020 ASSERT_VK_SUCCESS(err);
10021 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10022 ASSERT_VK_SUCCESS(err);
10023
10024 BeginCommandBuffer();
10025 VkImageCopy copyRegion;
10026 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10027 copyRegion.srcSubresource.mipLevel = 0;
10028 copyRegion.srcSubresource.baseArrayLayer = 0;
10029 copyRegion.srcSubresource.layerCount = 1;
10030 copyRegion.srcOffset.x = 0;
10031 copyRegion.srcOffset.y = 0;
10032 copyRegion.srcOffset.z = 0;
10033 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10034 copyRegion.dstSubresource.mipLevel = 0;
10035 copyRegion.dstSubresource.baseArrayLayer = 0;
10036 copyRegion.dstSubresource.layerCount = 1;
10037 copyRegion.dstOffset.x = 0;
10038 copyRegion.dstOffset.y = 0;
10039 copyRegion.dstOffset.z = 0;
10040 copyRegion.extent.width = 1;
10041 copyRegion.extent.height = 1;
10042 copyRegion.extent.depth = 1;
10043 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10044 m_errorMonitor->VerifyFound();
10045 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10047 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10048 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010049 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10050 m_errorMonitor->VerifyFound();
10051 // Final src error is due to bad layout type
10052 m_errorMonitor->SetDesiredFailureMsg(
10053 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10054 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10055 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10056 m_errorMonitor->VerifyFound();
10057 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10059 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010060 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10061 m_errorMonitor->VerifyFound();
10062 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10064 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10065 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010066 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10067 m_errorMonitor->VerifyFound();
10068 m_errorMonitor->SetDesiredFailureMsg(
10069 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10070 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10071 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10072 m_errorMonitor->VerifyFound();
10073 // Now cause error due to bad image layout transition in PipelineBarrier
10074 VkImageMemoryBarrier image_barrier[1] = {};
10075 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10076 image_barrier[0].image = src_image;
10077 image_barrier[0].subresourceRange.layerCount = 2;
10078 image_barrier[0].subresourceRange.levelCount = 2;
10079 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10081 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10082 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10083 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10084 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010085 m_errorMonitor->VerifyFound();
10086
10087 // Finally some layout errors at RenderPass create time
10088 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10089 VkAttachmentReference attach = {};
10090 // perf warning for GENERAL layout w/ non-DS input attachment
10091 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10092 VkSubpassDescription subpass = {};
10093 subpass.inputAttachmentCount = 1;
10094 subpass.pInputAttachments = &attach;
10095 VkRenderPassCreateInfo rpci = {};
10096 rpci.subpassCount = 1;
10097 rpci.pSubpasses = &subpass;
10098 rpci.attachmentCount = 1;
10099 VkAttachmentDescription attach_desc = {};
10100 attach_desc.format = VK_FORMAT_UNDEFINED;
10101 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010102 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010103 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10105 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010106 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10107 m_errorMonitor->VerifyFound();
10108 // error w/ non-general layout
10109 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10110
10111 m_errorMonitor->SetDesiredFailureMsg(
10112 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10113 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10114 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10115 m_errorMonitor->VerifyFound();
10116 subpass.inputAttachmentCount = 0;
10117 subpass.colorAttachmentCount = 1;
10118 subpass.pColorAttachments = &attach;
10119 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10120 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10122 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010123 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10124 m_errorMonitor->VerifyFound();
10125 // error w/ non-color opt or GENERAL layout for color attachment
10126 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10127 m_errorMonitor->SetDesiredFailureMsg(
10128 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10129 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10130 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10131 m_errorMonitor->VerifyFound();
10132 subpass.colorAttachmentCount = 0;
10133 subpass.pDepthStencilAttachment = &attach;
10134 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10135 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10137 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010138 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10139 m_errorMonitor->VerifyFound();
10140 // error w/ non-ds opt or GENERAL layout for color attachment
10141 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10143 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10144 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010145 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10146 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010147 // For this error we need a valid renderpass so create default one
10148 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10149 attach.attachment = 0;
10150 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10151 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10152 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10153 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10154 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10155 // Can't do a CLEAR load on READ_ONLY initialLayout
10156 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10157 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10158 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10160 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10161 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010162 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10163 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010164
10165 vkDestroyImage(m_device->device(), src_image, NULL);
10166 vkDestroyImage(m_device->device(), dst_image, NULL);
10167}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010168
Tobin Ehlise0936662016-10-11 08:10:51 -060010169TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10170 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10171 VkResult err;
10172
10173 ASSERT_NO_FATAL_FAILURE(InitState());
10174
10175 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10176 VkImageTiling tiling;
10177 VkFormatProperties format_properties;
10178 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10179 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10180 tiling = VK_IMAGE_TILING_LINEAR;
10181 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10182 tiling = VK_IMAGE_TILING_OPTIMAL;
10183 } else {
10184 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10185 "skipped.\n");
10186 return;
10187 }
10188
10189 VkDescriptorPoolSize ds_type = {};
10190 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10191 ds_type.descriptorCount = 1;
10192
10193 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10194 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10195 ds_pool_ci.maxSets = 1;
10196 ds_pool_ci.poolSizeCount = 1;
10197 ds_pool_ci.pPoolSizes = &ds_type;
10198 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10199
10200 VkDescriptorPool ds_pool;
10201 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10202 ASSERT_VK_SUCCESS(err);
10203
10204 VkDescriptorSetLayoutBinding dsl_binding = {};
10205 dsl_binding.binding = 0;
10206 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10207 dsl_binding.descriptorCount = 1;
10208 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10209 dsl_binding.pImmutableSamplers = NULL;
10210
10211 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10212 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10213 ds_layout_ci.pNext = NULL;
10214 ds_layout_ci.bindingCount = 1;
10215 ds_layout_ci.pBindings = &dsl_binding;
10216
10217 VkDescriptorSetLayout ds_layout;
10218 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10219 ASSERT_VK_SUCCESS(err);
10220
10221 VkDescriptorSetAllocateInfo alloc_info = {};
10222 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10223 alloc_info.descriptorSetCount = 1;
10224 alloc_info.descriptorPool = ds_pool;
10225 alloc_info.pSetLayouts = &ds_layout;
10226 VkDescriptorSet descriptor_set;
10227 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10228 ASSERT_VK_SUCCESS(err);
10229
10230 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10231 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10232 pipeline_layout_ci.pNext = NULL;
10233 pipeline_layout_ci.setLayoutCount = 1;
10234 pipeline_layout_ci.pSetLayouts = &ds_layout;
10235 VkPipelineLayout pipeline_layout;
10236 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10237 ASSERT_VK_SUCCESS(err);
10238
10239 VkImageObj image(m_device);
10240 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10241 ASSERT_TRUE(image.initialized());
10242 VkImageView view = image.targetView(tex_format);
10243
10244 VkDescriptorImageInfo image_info = {};
10245 image_info.imageView = view;
10246 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10247
10248 VkWriteDescriptorSet descriptor_write = {};
10249 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10250 descriptor_write.dstSet = descriptor_set;
10251 descriptor_write.dstBinding = 0;
10252 descriptor_write.descriptorCount = 1;
10253 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10254 descriptor_write.pImageInfo = &image_info;
10255
10256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10257 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10258 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10259 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10260 m_errorMonitor->VerifyFound();
10261
10262 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10263 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10264 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10265 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10266}
10267
Mark Mueller93b938f2016-08-18 10:27:40 -060010268TEST_F(VkLayerTest, SimultaneousUse) {
10269 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10270 "in primary and secondary command buffers.");
10271
10272 ASSERT_NO_FATAL_FAILURE(InitState());
10273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10274
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010275 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010276 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10277 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010278
10279 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010280 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010281 command_buffer_allocate_info.commandPool = m_commandPool;
10282 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10283 command_buffer_allocate_info.commandBufferCount = 1;
10284
10285 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010286 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010287 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10288 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010289 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010290 command_buffer_inheritance_info.renderPass = m_renderPass;
10291 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10292 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010293 command_buffer_begin_info.flags =
10294 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010295 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10296
10297 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010298 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10299 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010300 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010301 vkEndCommandBuffer(secondary_command_buffer);
10302
Mark Mueller93b938f2016-08-18 10:27:40 -060010303 VkSubmitInfo submit_info = {};
10304 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10305 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010306 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010307 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010308
Mark Mueller4042b652016-09-05 22:52:21 -060010309 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010310 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10312 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010313 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010314 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10315 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010316
10317 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010318 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10319
Mark Mueller4042b652016-09-05 22:52:21 -060010320 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010321 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010322 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10325 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010326 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010327 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10328 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010329}
10330
Mark Mueller917f6bc2016-08-30 10:57:19 -060010331TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10332 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10333 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010334 "Delete objects that are inuse. Call VkQueueSubmit "
10335 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010336
10337 ASSERT_NO_FATAL_FAILURE(InitState());
10338 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010340 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10341 const char *cannot_delete_event_message = "Cannot delete event 0x";
10342 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10343 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010344
10345 BeginCommandBuffer();
10346
10347 VkEvent event;
10348 VkEventCreateInfo event_create_info = {};
10349 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10350 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010351 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010352
Mark Muellerc8d441e2016-08-23 17:36:00 -060010353 EndCommandBuffer();
10354 vkDestroyEvent(m_device->device(), event, nullptr);
10355
10356 VkSubmitInfo submit_info = {};
10357 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10358 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010359 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010361 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10362 m_errorMonitor->VerifyFound();
10363
10364 m_errorMonitor->SetDesiredFailureMsg(0, "");
10365 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10366
10367 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10368
Mark Mueller917f6bc2016-08-30 10:57:19 -060010369 VkSemaphoreCreateInfo semaphore_create_info = {};
10370 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10371 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010372 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010373 VkFenceCreateInfo fence_create_info = {};
10374 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10375 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010376 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010377
10378 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010379 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010380 descriptor_pool_type_count.descriptorCount = 1;
10381
10382 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10383 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10384 descriptor_pool_create_info.maxSets = 1;
10385 descriptor_pool_create_info.poolSizeCount = 1;
10386 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010387 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010388
10389 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010390 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010391
10392 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010393 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010394 descriptorset_layout_binding.descriptorCount = 1;
10395 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10396
10397 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010398 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010399 descriptorset_layout_create_info.bindingCount = 1;
10400 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10401
10402 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010403 ASSERT_VK_SUCCESS(
10404 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010405
10406 VkDescriptorSet descriptorset;
10407 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010408 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010409 descriptorset_allocate_info.descriptorSetCount = 1;
10410 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10411 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010412 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010413
Mark Mueller4042b652016-09-05 22:52:21 -060010414 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10415
10416 VkDescriptorBufferInfo buffer_info = {};
10417 buffer_info.buffer = buffer_test.GetBuffer();
10418 buffer_info.offset = 0;
10419 buffer_info.range = 1024;
10420
10421 VkWriteDescriptorSet write_descriptor_set = {};
10422 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10423 write_descriptor_set.dstSet = descriptorset;
10424 write_descriptor_set.descriptorCount = 1;
10425 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10426 write_descriptor_set.pBufferInfo = &buffer_info;
10427
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010428 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010430 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10431 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010432
10433 VkPipelineObj pipe(m_device);
10434 pipe.AddColorAttachment();
10435 pipe.AddShader(&vs);
10436 pipe.AddShader(&fs);
10437
10438 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010439 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010440 pipeline_layout_create_info.setLayoutCount = 1;
10441 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10442
10443 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010444 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010445
10446 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10447
Mark Muellerc8d441e2016-08-23 17:36:00 -060010448 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010449 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010450
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010451 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10452 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10453 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010454
Mark Muellerc8d441e2016-08-23 17:36:00 -060010455 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010456
Mark Mueller917f6bc2016-08-30 10:57:19 -060010457 submit_info.signalSemaphoreCount = 1;
10458 submit_info.pSignalSemaphores = &semaphore;
10459 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010460
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010462 vkDestroyEvent(m_device->device(), event, nullptr);
10463 m_errorMonitor->VerifyFound();
10464
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010466 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10467 m_errorMonitor->VerifyFound();
10468
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010470 vkDestroyFence(m_device->device(), fence, nullptr);
10471 m_errorMonitor->VerifyFound();
10472
Tobin Ehlis122207b2016-09-01 08:50:06 -070010473 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010474 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10475 vkDestroyFence(m_device->device(), fence, nullptr);
10476 vkDestroyEvent(m_device->device(), event, nullptr);
10477 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010478 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010479 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10480}
10481
Tobin Ehlis2adda372016-09-01 08:51:06 -070010482TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10483 TEST_DESCRIPTION("Delete in-use query pool.");
10484
10485 ASSERT_NO_FATAL_FAILURE(InitState());
10486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10487
10488 VkQueryPool query_pool;
10489 VkQueryPoolCreateInfo query_pool_ci{};
10490 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10491 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10492 query_pool_ci.queryCount = 1;
10493 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10494 BeginCommandBuffer();
10495 // Reset query pool to create binding with cmd buffer
10496 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10497
10498 EndCommandBuffer();
10499
10500 VkSubmitInfo submit_info = {};
10501 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10502 submit_info.commandBufferCount = 1;
10503 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10504 // Submit cmd buffer and then destroy query pool while in-flight
10505 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10506
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010508 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10509 m_errorMonitor->VerifyFound();
10510
10511 vkQueueWaitIdle(m_device->m_queue);
10512 // Now that cmd buffer done we can safely destroy query_pool
10513 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10514}
10515
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010516TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10517 TEST_DESCRIPTION("Delete in-use pipeline.");
10518
10519 ASSERT_NO_FATAL_FAILURE(InitState());
10520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10521
10522 // Empty pipeline layout used for binding PSO
10523 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10524 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10525 pipeline_layout_ci.setLayoutCount = 0;
10526 pipeline_layout_ci.pSetLayouts = NULL;
10527
10528 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010529 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010530 ASSERT_VK_SUCCESS(err);
10531
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010533 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10535 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010536 // Store pipeline handle so we can actually delete it before test finishes
10537 VkPipeline delete_this_pipeline;
10538 { // Scope pipeline so it will be auto-deleted
10539 VkPipelineObj pipe(m_device);
10540 pipe.AddShader(&vs);
10541 pipe.AddShader(&fs);
10542 pipe.AddColorAttachment();
10543 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10544 delete_this_pipeline = pipe.handle();
10545
10546 BeginCommandBuffer();
10547 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010548 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010549
10550 EndCommandBuffer();
10551
10552 VkSubmitInfo submit_info = {};
10553 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10554 submit_info.commandBufferCount = 1;
10555 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10556 // Submit cmd buffer and then pipeline destroyed while in-flight
10557 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10558 } // Pipeline deletion triggered here
10559 m_errorMonitor->VerifyFound();
10560 // Make sure queue finished and then actually delete pipeline
10561 vkQueueWaitIdle(m_device->m_queue);
10562 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10563 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10564}
10565
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010566TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10567 TEST_DESCRIPTION("Delete in-use imageView.");
10568
10569 ASSERT_NO_FATAL_FAILURE(InitState());
10570 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10571
10572 VkDescriptorPoolSize ds_type_count;
10573 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10574 ds_type_count.descriptorCount = 1;
10575
10576 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10577 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10578 ds_pool_ci.maxSets = 1;
10579 ds_pool_ci.poolSizeCount = 1;
10580 ds_pool_ci.pPoolSizes = &ds_type_count;
10581
10582 VkDescriptorPool ds_pool;
10583 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10584 ASSERT_VK_SUCCESS(err);
10585
10586 VkSamplerCreateInfo sampler_ci = {};
10587 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10588 sampler_ci.pNext = NULL;
10589 sampler_ci.magFilter = VK_FILTER_NEAREST;
10590 sampler_ci.minFilter = VK_FILTER_NEAREST;
10591 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10592 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10593 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10594 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10595 sampler_ci.mipLodBias = 1.0;
10596 sampler_ci.anisotropyEnable = VK_FALSE;
10597 sampler_ci.maxAnisotropy = 1;
10598 sampler_ci.compareEnable = VK_FALSE;
10599 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10600 sampler_ci.minLod = 1.0;
10601 sampler_ci.maxLod = 1.0;
10602 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10603 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10604 VkSampler sampler;
10605
10606 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10607 ASSERT_VK_SUCCESS(err);
10608
10609 VkDescriptorSetLayoutBinding layout_binding;
10610 layout_binding.binding = 0;
10611 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10612 layout_binding.descriptorCount = 1;
10613 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10614 layout_binding.pImmutableSamplers = NULL;
10615
10616 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10617 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10618 ds_layout_ci.bindingCount = 1;
10619 ds_layout_ci.pBindings = &layout_binding;
10620 VkDescriptorSetLayout ds_layout;
10621 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10622 ASSERT_VK_SUCCESS(err);
10623
10624 VkDescriptorSetAllocateInfo alloc_info = {};
10625 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10626 alloc_info.descriptorSetCount = 1;
10627 alloc_info.descriptorPool = ds_pool;
10628 alloc_info.pSetLayouts = &ds_layout;
10629 VkDescriptorSet descriptor_set;
10630 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10631 ASSERT_VK_SUCCESS(err);
10632
10633 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10634 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10635 pipeline_layout_ci.pNext = NULL;
10636 pipeline_layout_ci.setLayoutCount = 1;
10637 pipeline_layout_ci.pSetLayouts = &ds_layout;
10638
10639 VkPipelineLayout pipeline_layout;
10640 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10641 ASSERT_VK_SUCCESS(err);
10642
10643 VkImageObj image(m_device);
10644 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10645 ASSERT_TRUE(image.initialized());
10646
10647 VkImageView view;
10648 VkImageViewCreateInfo ivci = {};
10649 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10650 ivci.image = image.handle();
10651 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10652 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10653 ivci.subresourceRange.layerCount = 1;
10654 ivci.subresourceRange.baseMipLevel = 0;
10655 ivci.subresourceRange.levelCount = 1;
10656 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10657
10658 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10659 ASSERT_VK_SUCCESS(err);
10660
10661 VkDescriptorImageInfo image_info{};
10662 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10663 image_info.imageView = view;
10664 image_info.sampler = sampler;
10665
10666 VkWriteDescriptorSet descriptor_write = {};
10667 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10668 descriptor_write.dstSet = descriptor_set;
10669 descriptor_write.dstBinding = 0;
10670 descriptor_write.descriptorCount = 1;
10671 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10672 descriptor_write.pImageInfo = &image_info;
10673
10674 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10675
10676 // Create PSO to use the sampler
10677 char const *vsSource = "#version 450\n"
10678 "\n"
10679 "out gl_PerVertex { \n"
10680 " vec4 gl_Position;\n"
10681 "};\n"
10682 "void main(){\n"
10683 " gl_Position = vec4(1);\n"
10684 "}\n";
10685 char const *fsSource = "#version 450\n"
10686 "\n"
10687 "layout(set=0, binding=0) uniform sampler2D s;\n"
10688 "layout(location=0) out vec4 x;\n"
10689 "void main(){\n"
10690 " x = texture(s, vec2(1));\n"
10691 "}\n";
10692 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10693 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10694 VkPipelineObj pipe(m_device);
10695 pipe.AddShader(&vs);
10696 pipe.AddShader(&fs);
10697 pipe.AddColorAttachment();
10698 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10699
10700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10701
10702 BeginCommandBuffer();
10703 // Bind pipeline to cmd buffer
10704 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10705 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10706 &descriptor_set, 0, nullptr);
10707 Draw(1, 0, 0, 0);
10708 EndCommandBuffer();
10709 // Submit cmd buffer then destroy sampler
10710 VkSubmitInfo submit_info = {};
10711 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10712 submit_info.commandBufferCount = 1;
10713 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10714 // Submit cmd buffer and then destroy imageView while in-flight
10715 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10716
10717 vkDestroyImageView(m_device->device(), view, nullptr);
10718 m_errorMonitor->VerifyFound();
10719 vkQueueWaitIdle(m_device->m_queue);
10720 // Now we can actually destroy imageView
10721 vkDestroyImageView(m_device->device(), view, NULL);
10722 vkDestroySampler(m_device->device(), sampler, nullptr);
10723 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10724 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10725 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10726}
10727
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010728TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10729 TEST_DESCRIPTION("Delete in-use bufferView.");
10730
10731 ASSERT_NO_FATAL_FAILURE(InitState());
10732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10733
10734 VkDescriptorPoolSize ds_type_count;
10735 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10736 ds_type_count.descriptorCount = 1;
10737
10738 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10739 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10740 ds_pool_ci.maxSets = 1;
10741 ds_pool_ci.poolSizeCount = 1;
10742 ds_pool_ci.pPoolSizes = &ds_type_count;
10743
10744 VkDescriptorPool ds_pool;
10745 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10746 ASSERT_VK_SUCCESS(err);
10747
10748 VkDescriptorSetLayoutBinding layout_binding;
10749 layout_binding.binding = 0;
10750 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10751 layout_binding.descriptorCount = 1;
10752 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10753 layout_binding.pImmutableSamplers = NULL;
10754
10755 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10756 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10757 ds_layout_ci.bindingCount = 1;
10758 ds_layout_ci.pBindings = &layout_binding;
10759 VkDescriptorSetLayout ds_layout;
10760 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10761 ASSERT_VK_SUCCESS(err);
10762
10763 VkDescriptorSetAllocateInfo alloc_info = {};
10764 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10765 alloc_info.descriptorSetCount = 1;
10766 alloc_info.descriptorPool = ds_pool;
10767 alloc_info.pSetLayouts = &ds_layout;
10768 VkDescriptorSet descriptor_set;
10769 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10770 ASSERT_VK_SUCCESS(err);
10771
10772 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10773 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10774 pipeline_layout_ci.pNext = NULL;
10775 pipeline_layout_ci.setLayoutCount = 1;
10776 pipeline_layout_ci.pSetLayouts = &ds_layout;
10777
10778 VkPipelineLayout pipeline_layout;
10779 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10780 ASSERT_VK_SUCCESS(err);
10781
10782 VkBuffer buffer;
10783 uint32_t queue_family_index = 0;
10784 VkBufferCreateInfo buffer_create_info = {};
10785 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10786 buffer_create_info.size = 1024;
10787 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10788 buffer_create_info.queueFamilyIndexCount = 1;
10789 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
10790
10791 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
10792 ASSERT_VK_SUCCESS(err);
10793
10794 VkMemoryRequirements memory_reqs;
10795 VkDeviceMemory buffer_memory;
10796
10797 VkMemoryAllocateInfo memory_info = {};
10798 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10799 memory_info.allocationSize = 0;
10800 memory_info.memoryTypeIndex = 0;
10801
10802 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
10803 memory_info.allocationSize = memory_reqs.size;
10804 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
10805 ASSERT_TRUE(pass);
10806
10807 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
10808 ASSERT_VK_SUCCESS(err);
10809 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
10810 ASSERT_VK_SUCCESS(err);
10811
10812 VkBufferView view;
10813 VkBufferViewCreateInfo bvci = {};
10814 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10815 bvci.buffer = buffer;
10816 bvci.format = VK_FORMAT_R8_UNORM;
10817 bvci.range = VK_WHOLE_SIZE;
10818
10819 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
10820 ASSERT_VK_SUCCESS(err);
10821
10822 VkWriteDescriptorSet descriptor_write = {};
10823 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10824 descriptor_write.dstSet = descriptor_set;
10825 descriptor_write.dstBinding = 0;
10826 descriptor_write.descriptorCount = 1;
10827 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10828 descriptor_write.pTexelBufferView = &view;
10829
10830 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10831
10832 char const *vsSource = "#version 450\n"
10833 "\n"
10834 "out gl_PerVertex { \n"
10835 " vec4 gl_Position;\n"
10836 "};\n"
10837 "void main(){\n"
10838 " gl_Position = vec4(1);\n"
10839 "}\n";
10840 char const *fsSource = "#version 450\n"
10841 "\n"
10842 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
10843 "layout(location=0) out vec4 x;\n"
10844 "void main(){\n"
10845 " x = imageLoad(s, 0);\n"
10846 "}\n";
10847 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10848 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10849 VkPipelineObj pipe(m_device);
10850 pipe.AddShader(&vs);
10851 pipe.AddShader(&fs);
10852 pipe.AddColorAttachment();
10853 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10854
10855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
10856
10857 BeginCommandBuffer();
10858 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10859 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10860 VkRect2D scissor = {{0, 0}, {16, 16}};
10861 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10862 // Bind pipeline to cmd buffer
10863 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10864 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10865 &descriptor_set, 0, nullptr);
10866 Draw(1, 0, 0, 0);
10867 EndCommandBuffer();
10868
10869 VkSubmitInfo submit_info = {};
10870 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10871 submit_info.commandBufferCount = 1;
10872 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10873 // Submit cmd buffer and then destroy bufferView while in-flight
10874 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10875
10876 vkDestroyBufferView(m_device->device(), view, nullptr);
10877 m_errorMonitor->VerifyFound();
10878 vkQueueWaitIdle(m_device->m_queue);
10879 // Now we can actually destroy bufferView
10880 vkDestroyBufferView(m_device->device(), view, NULL);
10881 vkDestroyBuffer(m_device->device(), buffer, NULL);
10882 vkFreeMemory(m_device->device(), buffer_memory, NULL);
10883 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10884 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10885 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10886}
10887
Tobin Ehlis209532e2016-09-07 13:52:18 -060010888TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
10889 TEST_DESCRIPTION("Delete in-use sampler.");
10890
10891 ASSERT_NO_FATAL_FAILURE(InitState());
10892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10893
10894 VkDescriptorPoolSize ds_type_count;
10895 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10896 ds_type_count.descriptorCount = 1;
10897
10898 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10899 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10900 ds_pool_ci.maxSets = 1;
10901 ds_pool_ci.poolSizeCount = 1;
10902 ds_pool_ci.pPoolSizes = &ds_type_count;
10903
10904 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010905 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060010906 ASSERT_VK_SUCCESS(err);
10907
10908 VkSamplerCreateInfo sampler_ci = {};
10909 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10910 sampler_ci.pNext = NULL;
10911 sampler_ci.magFilter = VK_FILTER_NEAREST;
10912 sampler_ci.minFilter = VK_FILTER_NEAREST;
10913 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10914 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10915 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10916 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10917 sampler_ci.mipLodBias = 1.0;
10918 sampler_ci.anisotropyEnable = VK_FALSE;
10919 sampler_ci.maxAnisotropy = 1;
10920 sampler_ci.compareEnable = VK_FALSE;
10921 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10922 sampler_ci.minLod = 1.0;
10923 sampler_ci.maxLod = 1.0;
10924 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10925 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10926 VkSampler sampler;
10927
10928 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10929 ASSERT_VK_SUCCESS(err);
10930
10931 VkDescriptorSetLayoutBinding layout_binding;
10932 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060010933 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060010934 layout_binding.descriptorCount = 1;
10935 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10936 layout_binding.pImmutableSamplers = NULL;
10937
10938 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10939 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10940 ds_layout_ci.bindingCount = 1;
10941 ds_layout_ci.pBindings = &layout_binding;
10942 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010943 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060010944 ASSERT_VK_SUCCESS(err);
10945
10946 VkDescriptorSetAllocateInfo alloc_info = {};
10947 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10948 alloc_info.descriptorSetCount = 1;
10949 alloc_info.descriptorPool = ds_pool;
10950 alloc_info.pSetLayouts = &ds_layout;
10951 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010952 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060010953 ASSERT_VK_SUCCESS(err);
10954
10955 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10956 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10957 pipeline_layout_ci.pNext = NULL;
10958 pipeline_layout_ci.setLayoutCount = 1;
10959 pipeline_layout_ci.pSetLayouts = &ds_layout;
10960
10961 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010962 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060010963 ASSERT_VK_SUCCESS(err);
10964
10965 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010966 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 -060010967 ASSERT_TRUE(image.initialized());
10968
10969 VkImageView view;
10970 VkImageViewCreateInfo ivci = {};
10971 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10972 ivci.image = image.handle();
10973 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10974 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10975 ivci.subresourceRange.layerCount = 1;
10976 ivci.subresourceRange.baseMipLevel = 0;
10977 ivci.subresourceRange.levelCount = 1;
10978 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10979
10980 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10981 ASSERT_VK_SUCCESS(err);
10982
10983 VkDescriptorImageInfo image_info{};
10984 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10985 image_info.imageView = view;
10986 image_info.sampler = sampler;
10987
10988 VkWriteDescriptorSet descriptor_write = {};
10989 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10990 descriptor_write.dstSet = descriptor_set;
10991 descriptor_write.dstBinding = 0;
10992 descriptor_write.descriptorCount = 1;
10993 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10994 descriptor_write.pImageInfo = &image_info;
10995
10996 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10997
10998 // Create PSO to use the sampler
10999 char const *vsSource = "#version 450\n"
11000 "\n"
11001 "out gl_PerVertex { \n"
11002 " vec4 gl_Position;\n"
11003 "};\n"
11004 "void main(){\n"
11005 " gl_Position = vec4(1);\n"
11006 "}\n";
11007 char const *fsSource = "#version 450\n"
11008 "\n"
11009 "layout(set=0, binding=0) uniform sampler2D s;\n"
11010 "layout(location=0) out vec4 x;\n"
11011 "void main(){\n"
11012 " x = texture(s, vec2(1));\n"
11013 "}\n";
11014 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11015 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11016 VkPipelineObj pipe(m_device);
11017 pipe.AddShader(&vs);
11018 pipe.AddShader(&fs);
11019 pipe.AddColorAttachment();
11020 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011023
11024 BeginCommandBuffer();
11025 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011026 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11027 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11028 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011029 Draw(1, 0, 0, 0);
11030 EndCommandBuffer();
11031 // Submit cmd buffer then destroy sampler
11032 VkSubmitInfo submit_info = {};
11033 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11034 submit_info.commandBufferCount = 1;
11035 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11036 // Submit cmd buffer and then destroy sampler while in-flight
11037 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11038
11039 vkDestroySampler(m_device->device(), sampler, nullptr);
11040 m_errorMonitor->VerifyFound();
11041 vkQueueWaitIdle(m_device->m_queue);
11042 // Now we can actually destroy sampler
11043 vkDestroySampler(m_device->device(), sampler, nullptr);
11044 vkDestroyImageView(m_device->device(), view, NULL);
11045 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11046 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11047 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11048}
11049
Mark Mueller1cd9f412016-08-25 13:23:52 -060011050TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011051 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011052 "signaled but not waited on by the queue. Wait on a "
11053 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011054
11055 ASSERT_NO_FATAL_FAILURE(InitState());
11056 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11057
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011058 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11059 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11060 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011061
11062 BeginCommandBuffer();
11063 EndCommandBuffer();
11064
11065 VkSemaphoreCreateInfo semaphore_create_info = {};
11066 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11067 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011068 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011069 VkSubmitInfo submit_info = {};
11070 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11071 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011072 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011073 submit_info.signalSemaphoreCount = 1;
11074 submit_info.pSignalSemaphores = &semaphore;
11075 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11076 m_errorMonitor->SetDesiredFailureMsg(0, "");
11077 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11078 BeginCommandBuffer();
11079 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011081 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11082 m_errorMonitor->VerifyFound();
11083
Mark Mueller1cd9f412016-08-25 13:23:52 -060011084 VkFenceCreateInfo fence_create_info = {};
11085 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11086 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011087 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011090 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11091 m_errorMonitor->VerifyFound();
11092
Mark Mueller4042b652016-09-05 22:52:21 -060011093 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011094 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011095 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11096}
11097
Tobin Ehlis4af23302016-07-19 10:50:30 -060011098TEST_F(VkLayerTest, FramebufferIncompatible) {
11099 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11100 "that does not match the framebuffer for the active "
11101 "renderpass.");
11102 ASSERT_NO_FATAL_FAILURE(InitState());
11103 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11104
11105 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011106 VkAttachmentDescription attachment = {0,
11107 VK_FORMAT_B8G8R8A8_UNORM,
11108 VK_SAMPLE_COUNT_1_BIT,
11109 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11110 VK_ATTACHMENT_STORE_OP_STORE,
11111 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11112 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11113 VK_IMAGE_LAYOUT_UNDEFINED,
11114 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011116 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011118 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011120 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011121
11122 VkRenderPass rp;
11123 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11124 ASSERT_VK_SUCCESS(err);
11125
11126 // A compatible framebuffer.
11127 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011128 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 -060011129 ASSERT_TRUE(image.initialized());
11130
11131 VkImageViewCreateInfo ivci = {
11132 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11133 nullptr,
11134 0,
11135 image.handle(),
11136 VK_IMAGE_VIEW_TYPE_2D,
11137 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011138 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11139 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011140 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11141 };
11142 VkImageView view;
11143 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11144 ASSERT_VK_SUCCESS(err);
11145
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011146 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011147 VkFramebuffer fb;
11148 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11149 ASSERT_VK_SUCCESS(err);
11150
11151 VkCommandBufferAllocateInfo cbai = {};
11152 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11153 cbai.commandPool = m_commandPool;
11154 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11155 cbai.commandBufferCount = 1;
11156
11157 VkCommandBuffer sec_cb;
11158 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11159 ASSERT_VK_SUCCESS(err);
11160 VkCommandBufferBeginInfo cbbi = {};
11161 VkCommandBufferInheritanceInfo cbii = {};
11162 cbii.renderPass = renderPass();
11163 cbii.framebuffer = fb;
11164 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11165 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011166 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 -060011167 cbbi.pInheritanceInfo = &cbii;
11168 vkBeginCommandBuffer(sec_cb, &cbbi);
11169 vkEndCommandBuffer(sec_cb);
11170
Chris Forbes3400bc52016-09-13 18:10:34 +120011171 VkCommandBufferBeginInfo cbbi2 = {
11172 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11173 0, nullptr
11174 };
11175 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11176 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011179 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011180 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11181 m_errorMonitor->VerifyFound();
11182 // Cleanup
11183 vkDestroyImageView(m_device->device(), view, NULL);
11184 vkDestroyRenderPass(m_device->device(), rp, NULL);
11185 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11186}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011187
11188TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11189 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11190 "invalid value. If logicOp is not available, attempt to "
11191 "use it and verify that we see the correct error.");
11192 ASSERT_NO_FATAL_FAILURE(InitState());
11193 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11194
11195 auto features = m_device->phy().features();
11196 // Set the expected error depending on whether or not logicOp available
11197 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11199 "enabled, logicOpEnable must be "
11200 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011201 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011203 }
11204 // Create a pipeline using logicOp
11205 VkResult err;
11206
11207 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11208 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11209
11210 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011211 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011212 ASSERT_VK_SUCCESS(err);
11213
11214 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11215 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11216 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011217 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011218 vp_state_ci.pViewports = &vp;
11219 vp_state_ci.scissorCount = 1;
11220 VkRect2D scissors = {}; // Dummy scissors to point to
11221 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011222
11223 VkPipelineShaderStageCreateInfo shaderStages[2];
11224 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11225
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011226 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11227 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011228 shaderStages[0] = vs.GetStageCreateInfo();
11229 shaderStages[1] = fs.GetStageCreateInfo();
11230
11231 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11232 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11233
11234 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11235 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11236 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11237
11238 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11239 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011240 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011241
11242 VkPipelineColorBlendAttachmentState att = {};
11243 att.blendEnable = VK_FALSE;
11244 att.colorWriteMask = 0xf;
11245
11246 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11247 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11248 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11249 cb_ci.logicOpEnable = VK_TRUE;
11250 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11251 cb_ci.attachmentCount = 1;
11252 cb_ci.pAttachments = &att;
11253
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011254 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11255 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11256 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11257
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011258 VkGraphicsPipelineCreateInfo gp_ci = {};
11259 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11260 gp_ci.stageCount = 2;
11261 gp_ci.pStages = shaderStages;
11262 gp_ci.pVertexInputState = &vi_ci;
11263 gp_ci.pInputAssemblyState = &ia_ci;
11264 gp_ci.pViewportState = &vp_state_ci;
11265 gp_ci.pRasterizationState = &rs_ci;
11266 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011267 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011268 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11269 gp_ci.layout = pipeline_layout;
11270 gp_ci.renderPass = renderPass();
11271
11272 VkPipelineCacheCreateInfo pc_ci = {};
11273 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11274
11275 VkPipeline pipeline;
11276 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011277 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011278 ASSERT_VK_SUCCESS(err);
11279
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011280 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011281 m_errorMonitor->VerifyFound();
11282 if (VK_SUCCESS == err) {
11283 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11284 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011285 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11286 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11287}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011288#endif // DRAW_STATE_TESTS
11289
Tobin Ehlis0788f522015-05-26 16:11:58 -060011290#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011291#if GTEST_IS_THREADSAFE
11292struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011293 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011294 VkEvent event;
11295 bool bailout;
11296};
11297
Karl Schultz6addd812016-02-02 17:17:23 -070011298extern "C" void *AddToCommandBuffer(void *arg) {
11299 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011300
Mike Stroyana6d14942016-07-13 15:10:05 -060011301 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011302 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011303 if (data->bailout) {
11304 break;
11305 }
11306 }
11307 return NULL;
11308}
11309
Karl Schultz6addd812016-02-02 17:17:23 -070011310TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011311 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011314
Mike Stroyanaccf7692015-05-12 16:00:45 -060011315 ASSERT_NO_FATAL_FAILURE(InitState());
11316 ASSERT_NO_FATAL_FAILURE(InitViewport());
11317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11318
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011319 // Calls AllocateCommandBuffers
11320 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011321
11322 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011323 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011324
11325 VkEventCreateInfo event_info;
11326 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011327 VkResult err;
11328
11329 memset(&event_info, 0, sizeof(event_info));
11330 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11331
Chia-I Wuf7458c52015-10-26 21:10:41 +080011332 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011333 ASSERT_VK_SUCCESS(err);
11334
Mike Stroyanaccf7692015-05-12 16:00:45 -060011335 err = vkResetEvent(device(), event);
11336 ASSERT_VK_SUCCESS(err);
11337
11338 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011339 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011340 data.event = event;
11341 data.bailout = false;
11342 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011343
11344 // First do some correct operations using multiple threads.
11345 // Add many entries to command buffer from another thread.
11346 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11347 // Make non-conflicting calls from this thread at the same time.
11348 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011349 uint32_t count;
11350 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011351 }
11352 test_platform_thread_join(thread, NULL);
11353
11354 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011355 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011356 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011357 // Add many entries to command buffer from this thread at the same time.
11358 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011359
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011360 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011361 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011362
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011363 m_errorMonitor->SetBailout(NULL);
11364
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011365 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011366
Chia-I Wuf7458c52015-10-26 21:10:41 +080011367 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011368}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011369#endif // GTEST_IS_THREADSAFE
11370#endif // THREADING_TESTS
11371
Chris Forbes9f7ff632015-05-25 11:13:08 +120011372#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011373TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011374 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11375 "with an impossible code size");
11376
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011378
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011379 ASSERT_NO_FATAL_FAILURE(InitState());
11380 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11381
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011382 VkShaderModule module;
11383 VkShaderModuleCreateInfo moduleCreateInfo;
11384 struct icd_spv_header spv;
11385
11386 spv.magic = ICD_SPV_MAGIC;
11387 spv.version = ICD_SPV_VERSION;
11388 spv.gen_magic = 0;
11389
11390 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11391 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011392 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011393 moduleCreateInfo.codeSize = 4;
11394 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011395 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011396
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011397 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011398}
11399
Karl Schultz6addd812016-02-02 17:17:23 -070011400TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011401 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11402 "with a bad magic number");
11403
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011405
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011406 ASSERT_NO_FATAL_FAILURE(InitState());
11407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11408
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011409 VkShaderModule module;
11410 VkShaderModuleCreateInfo moduleCreateInfo;
11411 struct icd_spv_header spv;
11412
11413 spv.magic = ~ICD_SPV_MAGIC;
11414 spv.version = ICD_SPV_VERSION;
11415 spv.gen_magic = 0;
11416
11417 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11418 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011419 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011420 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11421 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011422 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011423
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011424 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011425}
11426
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011427#if 0
11428// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011429TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011431 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011432
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011433 ASSERT_NO_FATAL_FAILURE(InitState());
11434 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11435
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011436 VkShaderModule module;
11437 VkShaderModuleCreateInfo moduleCreateInfo;
11438 struct icd_spv_header spv;
11439
11440 spv.magic = ICD_SPV_MAGIC;
11441 spv.version = ~ICD_SPV_VERSION;
11442 spv.gen_magic = 0;
11443
11444 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11445 moduleCreateInfo.pNext = NULL;
11446
Karl Schultz6addd812016-02-02 17:17:23 -070011447 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011448 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11449 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011450 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011451
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011452 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011453}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011454#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011455
Karl Schultz6addd812016-02-02 17:17:23 -070011456TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011457 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11458 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011460
Chris Forbes9f7ff632015-05-25 11:13:08 +120011461 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011462 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011463
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011464 char const *vsSource = "#version 450\n"
11465 "\n"
11466 "layout(location=0) out float x;\n"
11467 "out gl_PerVertex {\n"
11468 " vec4 gl_Position;\n"
11469 "};\n"
11470 "void main(){\n"
11471 " gl_Position = vec4(1);\n"
11472 " x = 0;\n"
11473 "}\n";
11474 char const *fsSource = "#version 450\n"
11475 "\n"
11476 "layout(location=0) out vec4 color;\n"
11477 "void main(){\n"
11478 " color = vec4(1);\n"
11479 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011480
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011481 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11482 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011483
11484 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011485 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011486 pipe.AddShader(&vs);
11487 pipe.AddShader(&fs);
11488
Chris Forbes9f7ff632015-05-25 11:13:08 +120011489 VkDescriptorSetObj descriptorSet(m_device);
11490 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011491 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011492
Tony Barbour5781e8f2015-08-04 16:23:11 -060011493 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011494
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011495 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011496}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011497
Mark Mueller098c9cb2016-09-08 09:01:57 -060011498TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11499 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11500
11501 ASSERT_NO_FATAL_FAILURE(InitState());
11502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11503
11504 const char *bad_specialization_message =
11505 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11506
11507 char const *vsSource =
11508 "#version 450\n"
11509 "\n"
11510 "out gl_PerVertex {\n"
11511 " vec4 gl_Position;\n"
11512 "};\n"
11513 "void main(){\n"
11514 " gl_Position = vec4(1);\n"
11515 "}\n";
11516
11517 char const *fsSource =
11518 "#version 450\n"
11519 "\n"
11520 "layout (constant_id = 0) const float r = 0.0f;\n"
11521 "layout(location = 0) out vec4 uFragColor;\n"
11522 "void main(){\n"
11523 " uFragColor = vec4(r,1,0,1);\n"
11524 "}\n";
11525
11526 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11527 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11528
11529 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11530 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11531
11532 VkPipelineLayout pipeline_layout;
11533 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11534
11535 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11536 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11537 vp_state_create_info.viewportCount = 1;
11538 VkViewport viewport = {};
11539 vp_state_create_info.pViewports = &viewport;
11540 vp_state_create_info.scissorCount = 1;
11541 VkRect2D scissors = {};
11542 vp_state_create_info.pScissors = &scissors;
11543
11544 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11545
11546 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11547 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11548 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11549 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11550
11551 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11552 vs.GetStageCreateInfo(),
11553 fs.GetStageCreateInfo()
11554 };
11555
11556 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11557 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11558
11559 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11560 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11561 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11562
11563 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11564 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11565 rasterization_state_create_info.pNext = nullptr;
11566 rasterization_state_create_info.lineWidth = 1.0f;
11567 rasterization_state_create_info.rasterizerDiscardEnable = true;
11568
11569 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11570 color_blend_attachment_state.blendEnable = VK_FALSE;
11571 color_blend_attachment_state.colorWriteMask = 0xf;
11572
11573 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11574 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11575 color_blend_state_create_info.attachmentCount = 1;
11576 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11577
11578 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11579 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11580 graphicspipe_create_info.stageCount = 2;
11581 graphicspipe_create_info.pStages = shader_stage_create_info;
11582 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11583 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11584 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11585 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11586 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11587 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11588 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11589 graphicspipe_create_info.layout = pipeline_layout;
11590 graphicspipe_create_info.renderPass = renderPass();
11591
11592 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11593 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11594
11595 VkPipelineCache pipelineCache;
11596 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11597
11598 // This structure maps constant ids to data locations.
11599 const VkSpecializationMapEntry entry =
11600 // id, offset, size
11601 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11602
11603 uint32_t data = 1;
11604
11605 // Set up the info describing spec map and data
11606 const VkSpecializationInfo specialization_info = {
11607 1,
11608 &entry,
11609 1 * sizeof(float),
11610 &data,
11611 };
11612 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11613
11614 VkPipeline pipeline;
11615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11616 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11617 m_errorMonitor->VerifyFound();
11618
11619 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11620 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11621}
11622
11623TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11624 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11625
11626 ASSERT_NO_FATAL_FAILURE(InitState());
11627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11628
11629 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11630
11631 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11632 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11633 descriptor_pool_type_count[0].descriptorCount = 1;
11634 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11635 descriptor_pool_type_count[1].descriptorCount = 1;
11636
11637 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11638 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11639 descriptor_pool_create_info.maxSets = 1;
11640 descriptor_pool_create_info.poolSizeCount = 2;
11641 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11642 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11643
11644 VkDescriptorPool descriptorset_pool;
11645 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11646
11647 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11648 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11649 descriptorset_layout_binding.descriptorCount = 1;
11650 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11651
11652 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11653 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11654 descriptorset_layout_create_info.bindingCount = 1;
11655 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11656
11657 VkDescriptorSetLayout descriptorset_layout;
11658 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11659
11660 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11661 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11662 descriptorset_allocate_info.descriptorSetCount = 1;
11663 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11664 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11665 VkDescriptorSet descriptorset;
11666 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11667
11668 // Challenge core_validation with a non uniform buffer type.
11669 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11670
Mark Mueller098c9cb2016-09-08 09:01:57 -060011671 char const *vsSource =
11672 "#version 450\n"
11673 "\n"
11674 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11675 " mat4 mvp;\n"
11676 "} ubuf;\n"
11677 "out gl_PerVertex {\n"
11678 " vec4 gl_Position;\n"
11679 "};\n"
11680 "void main(){\n"
11681 " gl_Position = ubuf.mvp * vec4(1);\n"
11682 "}\n";
11683
11684 char const *fsSource =
11685 "#version 450\n"
11686 "\n"
11687 "layout(location = 0) out vec4 uFragColor;\n"
11688 "void main(){\n"
11689 " uFragColor = vec4(0,1,0,1);\n"
11690 "}\n";
11691
11692 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11693 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11694
11695 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11696 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11697 pipeline_layout_create_info.setLayoutCount = 1;
11698 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11699
11700 VkPipelineLayout pipeline_layout;
11701 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11702
11703 VkPipelineObj pipe(m_device);
11704 pipe.AddColorAttachment();
11705 pipe.AddShader(&vs);
11706 pipe.AddShader(&fs);
11707
11708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11709 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11710 m_errorMonitor->VerifyFound();
11711
11712 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11713 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11714 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11715}
11716
11717TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11718 TEST_DESCRIPTION(
11719 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11720
11721 ASSERT_NO_FATAL_FAILURE(InitState());
11722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11723
11724 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11725
11726 VkDescriptorPoolSize descriptor_pool_type_count = {};
11727 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11728 descriptor_pool_type_count.descriptorCount = 1;
11729
11730 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11731 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11732 descriptor_pool_create_info.maxSets = 1;
11733 descriptor_pool_create_info.poolSizeCount = 1;
11734 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11735 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11736
11737 VkDescriptorPool descriptorset_pool;
11738 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11739
11740 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11741 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11742 descriptorset_layout_binding.descriptorCount = 1;
11743 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11744 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11745
11746 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11747 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11748 descriptorset_layout_create_info.bindingCount = 1;
11749 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11750
11751 VkDescriptorSetLayout descriptorset_layout;
11752 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
11753 nullptr, &descriptorset_layout));
11754
11755 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11756 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11757 descriptorset_allocate_info.descriptorSetCount = 1;
11758 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11759 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11760 VkDescriptorSet descriptorset;
11761 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11762
11763 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11764
Mark Mueller098c9cb2016-09-08 09:01:57 -060011765 char const *vsSource =
11766 "#version 450\n"
11767 "\n"
11768 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11769 " mat4 mvp;\n"
11770 "} ubuf;\n"
11771 "out gl_PerVertex {\n"
11772 " vec4 gl_Position;\n"
11773 "};\n"
11774 "void main(){\n"
11775 " gl_Position = ubuf.mvp * vec4(1);\n"
11776 "}\n";
11777
11778 char const *fsSource =
11779 "#version 450\n"
11780 "\n"
11781 "layout(location = 0) out vec4 uFragColor;\n"
11782 "void main(){\n"
11783 " uFragColor = vec4(0,1,0,1);\n"
11784 "}\n";
11785
11786 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11787 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11788
11789 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11790 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11791 pipeline_layout_create_info.setLayoutCount = 1;
11792 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11793
11794 VkPipelineLayout pipeline_layout;
11795 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11796
11797 VkPipelineObj pipe(m_device);
11798 pipe.AddColorAttachment();
11799 pipe.AddShader(&vs);
11800 pipe.AddShader(&fs);
11801
11802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
11803 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11804 m_errorMonitor->VerifyFound();
11805
11806 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11807 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11808 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11809}
11810
11811TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
11812 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
11813 "accessible from the current shader stage.");
11814
11815 ASSERT_NO_FATAL_FAILURE(InitState());
11816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11817
11818 const char *push_constant_not_accessible_message =
11819 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
11820
11821 char const *vsSource =
11822 "#version 450\n"
11823 "\n"
11824 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
11825 "out gl_PerVertex {\n"
11826 " vec4 gl_Position;\n"
11827 "};\n"
11828 "void main(){\n"
11829 " gl_Position = vec4(consts.x);\n"
11830 "}\n";
11831
11832 char const *fsSource =
11833 "#version 450\n"
11834 "\n"
11835 "layout(location = 0) out vec4 uFragColor;\n"
11836 "void main(){\n"
11837 " uFragColor = vec4(0,1,0,1);\n"
11838 "}\n";
11839
11840 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11841 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11842
11843 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11844 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11845
11846 // Set up a push constant range
11847 VkPushConstantRange push_constant_ranges = {};
11848 // Set to the wrong stage to challenge core_validation
11849 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11850 push_constant_ranges.size = 4;
11851
11852 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
11853 pipeline_layout_create_info.pushConstantRangeCount = 1;
11854
11855 VkPipelineLayout pipeline_layout;
11856 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11857
11858 VkPipelineObj pipe(m_device);
11859 pipe.AddColorAttachment();
11860 pipe.AddShader(&vs);
11861 pipe.AddShader(&fs);
11862
11863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
11864 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11865 m_errorMonitor->VerifyFound();
11866
11867 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11868}
11869
11870TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
11871 TEST_DESCRIPTION(
11872 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
11873
11874 ASSERT_NO_FATAL_FAILURE(InitState());
11875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11876
11877 const char *feature_not_enabled_message =
11878 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
11879
11880 // Some awkward steps are required to test with custom device features.
11881 std::vector<const char *> device_extension_names;
11882 auto features = m_device->phy().features();
11883 // Disable support for 64 bit floats
11884 features.shaderFloat64 = false;
11885 // The sacrificial device object
11886 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11887
11888 char const *vsSource = "#version 450\n"
11889 "\n"
11890 "out gl_PerVertex {\n"
11891 " vec4 gl_Position;\n"
11892 "};\n"
11893 "void main(){\n"
11894 " gl_Position = vec4(1);\n"
11895 "}\n";
11896 char const *fsSource = "#version 450\n"
11897 "\n"
11898 "layout(location=0) out vec4 color;\n"
11899 "void main(){\n"
11900 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
11901 " color = vec4(green);\n"
11902 "}\n";
11903
11904 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11905 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11906
11907 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060011908
11909 VkPipelineObj pipe(&test_device);
11910 pipe.AddColorAttachment();
11911 pipe.AddShader(&vs);
11912 pipe.AddShader(&fs);
11913
11914 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11915 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11916 VkPipelineLayout pipeline_layout;
11917 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11918
11919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
11920 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
11921 m_errorMonitor->VerifyFound();
11922
11923 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
11924}
11925
11926TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
11927 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
11928
11929 ASSERT_NO_FATAL_FAILURE(InitState());
11930 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11931
11932 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
11933
11934 char const *vsSource = "#version 450\n"
11935 "\n"
11936 "out gl_PerVertex {\n"
11937 " vec4 gl_Position;\n"
11938 "};\n"
11939 "layout(xfb_buffer = 1) out;"
11940 "void main(){\n"
11941 " gl_Position = vec4(1);\n"
11942 "}\n";
11943 char const *fsSource = "#version 450\n"
11944 "\n"
11945 "layout(location=0) out vec4 color;\n"
11946 "void main(){\n"
11947 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
11948 " color = vec4(green);\n"
11949 "}\n";
11950
11951 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11952 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11953
11954 VkPipelineObj pipe(m_device);
11955 pipe.AddColorAttachment();
11956 pipe.AddShader(&vs);
11957 pipe.AddShader(&fs);
11958
11959 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11960 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11961 VkPipelineLayout pipeline_layout;
11962 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11963
11964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
11965 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11966 m_errorMonitor->VerifyFound();
11967
11968 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11969}
11970
Karl Schultz6addd812016-02-02 17:17:23 -070011971TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011972 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
11973 "which is not present in the outputs of the previous stage");
11974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011976
Chris Forbes59cb88d2015-05-25 11:13:13 +120011977 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120011979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011980 char const *vsSource = "#version 450\n"
11981 "\n"
11982 "out gl_PerVertex {\n"
11983 " vec4 gl_Position;\n"
11984 "};\n"
11985 "void main(){\n"
11986 " gl_Position = vec4(1);\n"
11987 "}\n";
11988 char const *fsSource = "#version 450\n"
11989 "\n"
11990 "layout(location=0) in float x;\n"
11991 "layout(location=0) out vec4 color;\n"
11992 "void main(){\n"
11993 " color = vec4(x);\n"
11994 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120011995
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011996 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11997 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120011998
11999 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012000 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012001 pipe.AddShader(&vs);
12002 pipe.AddShader(&fs);
12003
Chris Forbes59cb88d2015-05-25 11:13:13 +120012004 VkDescriptorSetObj descriptorSet(m_device);
12005 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012006 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012007
Tony Barbour5781e8f2015-08-04 16:23:11 -060012008 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012009
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012010 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012011}
12012
Karl Schultz6addd812016-02-02 17:17:23 -070012013TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012014 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12015 "within an interace block, which is not present in the outputs "
12016 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012018
12019 ASSERT_NO_FATAL_FAILURE(InitState());
12020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012022 char const *vsSource = "#version 450\n"
12023 "\n"
12024 "out gl_PerVertex {\n"
12025 " vec4 gl_Position;\n"
12026 "};\n"
12027 "void main(){\n"
12028 " gl_Position = vec4(1);\n"
12029 "}\n";
12030 char const *fsSource = "#version 450\n"
12031 "\n"
12032 "in block { layout(location=0) float x; } ins;\n"
12033 "layout(location=0) out vec4 color;\n"
12034 "void main(){\n"
12035 " color = vec4(ins.x);\n"
12036 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012037
12038 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12039 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12040
12041 VkPipelineObj pipe(m_device);
12042 pipe.AddColorAttachment();
12043 pipe.AddShader(&vs);
12044 pipe.AddShader(&fs);
12045
12046 VkDescriptorSetObj descriptorSet(m_device);
12047 descriptorSet.AppendDummy();
12048 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12049
12050 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12051
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012052 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012053}
12054
Karl Schultz6addd812016-02-02 17:17:23 -070012055TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012056 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012057 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12059 "output arr[2] of float32' vs 'ptr to "
12060 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012061
12062 ASSERT_NO_FATAL_FAILURE(InitState());
12063 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12064
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012065 char const *vsSource = "#version 450\n"
12066 "\n"
12067 "layout(location=0) out float x[2];\n"
12068 "out gl_PerVertex {\n"
12069 " vec4 gl_Position;\n"
12070 "};\n"
12071 "void main(){\n"
12072 " x[0] = 0; x[1] = 0;\n"
12073 " gl_Position = vec4(1);\n"
12074 "}\n";
12075 char const *fsSource = "#version 450\n"
12076 "\n"
12077 "layout(location=0) in float x[3];\n"
12078 "layout(location=0) out vec4 color;\n"
12079 "void main(){\n"
12080 " color = vec4(x[0] + x[1] + x[2]);\n"
12081 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012082
12083 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12084 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12085
12086 VkPipelineObj pipe(m_device);
12087 pipe.AddColorAttachment();
12088 pipe.AddShader(&vs);
12089 pipe.AddShader(&fs);
12090
12091 VkDescriptorSetObj descriptorSet(m_device);
12092 descriptorSet.AppendDummy();
12093 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12094
12095 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12096
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012097 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012098}
12099
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012100
Karl Schultz6addd812016-02-02 17:17:23 -070012101TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012102 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012103 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012105
Chris Forbesb56af562015-05-25 11:13:17 +120012106 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012109 char const *vsSource = "#version 450\n"
12110 "\n"
12111 "layout(location=0) out int x;\n"
12112 "out gl_PerVertex {\n"
12113 " vec4 gl_Position;\n"
12114 "};\n"
12115 "void main(){\n"
12116 " x = 0;\n"
12117 " gl_Position = vec4(1);\n"
12118 "}\n";
12119 char const *fsSource = "#version 450\n"
12120 "\n"
12121 "layout(location=0) in float x;\n" /* VS writes int */
12122 "layout(location=0) out vec4 color;\n"
12123 "void main(){\n"
12124 " color = vec4(x);\n"
12125 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012126
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012127 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12128 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012129
12130 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012131 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012132 pipe.AddShader(&vs);
12133 pipe.AddShader(&fs);
12134
Chris Forbesb56af562015-05-25 11:13:17 +120012135 VkDescriptorSetObj descriptorSet(m_device);
12136 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012137 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012138
Tony Barbour5781e8f2015-08-04 16:23:11 -060012139 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012140
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012141 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012142}
12143
Karl Schultz6addd812016-02-02 17:17:23 -070012144TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012145 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012146 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012147 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012149
12150 ASSERT_NO_FATAL_FAILURE(InitState());
12151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012153 char const *vsSource = "#version 450\n"
12154 "\n"
12155 "out block { layout(location=0) int x; } outs;\n"
12156 "out gl_PerVertex {\n"
12157 " vec4 gl_Position;\n"
12158 "};\n"
12159 "void main(){\n"
12160 " outs.x = 0;\n"
12161 " gl_Position = vec4(1);\n"
12162 "}\n";
12163 char const *fsSource = "#version 450\n"
12164 "\n"
12165 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12166 "layout(location=0) out vec4 color;\n"
12167 "void main(){\n"
12168 " color = vec4(ins.x);\n"
12169 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012170
12171 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12172 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12173
12174 VkPipelineObj pipe(m_device);
12175 pipe.AddColorAttachment();
12176 pipe.AddShader(&vs);
12177 pipe.AddShader(&fs);
12178
12179 VkDescriptorSetObj descriptorSet(m_device);
12180 descriptorSet.AppendDummy();
12181 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12182
12183 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12184
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012185 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012186}
12187
12188TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012189 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012190 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012191 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012192 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 +130012193
12194 ASSERT_NO_FATAL_FAILURE(InitState());
12195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012197 char const *vsSource = "#version 450\n"
12198 "\n"
12199 "out block { layout(location=1) float x; } outs;\n"
12200 "out gl_PerVertex {\n"
12201 " vec4 gl_Position;\n"
12202 "};\n"
12203 "void main(){\n"
12204 " outs.x = 0;\n"
12205 " gl_Position = vec4(1);\n"
12206 "}\n";
12207 char const *fsSource = "#version 450\n"
12208 "\n"
12209 "in block { layout(location=0) float x; } ins;\n"
12210 "layout(location=0) out vec4 color;\n"
12211 "void main(){\n"
12212 " color = vec4(ins.x);\n"
12213 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012214
12215 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12216 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12217
12218 VkPipelineObj pipe(m_device);
12219 pipe.AddColorAttachment();
12220 pipe.AddShader(&vs);
12221 pipe.AddShader(&fs);
12222
12223 VkDescriptorSetObj descriptorSet(m_device);
12224 descriptorSet.AppendDummy();
12225 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12226
12227 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12228
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012229 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012230}
12231
12232TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012233 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012234 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012235 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012236 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 +130012237
12238 ASSERT_NO_FATAL_FAILURE(InitState());
12239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012241 char const *vsSource = "#version 450\n"
12242 "\n"
12243 "out block { layout(location=0, component=0) float x; } outs;\n"
12244 "out gl_PerVertex {\n"
12245 " vec4 gl_Position;\n"
12246 "};\n"
12247 "void main(){\n"
12248 " outs.x = 0;\n"
12249 " gl_Position = vec4(1);\n"
12250 "}\n";
12251 char const *fsSource = "#version 450\n"
12252 "\n"
12253 "in block { layout(location=0, component=1) float x; } ins;\n"
12254 "layout(location=0) out vec4 color;\n"
12255 "void main(){\n"
12256 " color = vec4(ins.x);\n"
12257 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012258
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 VkPipelineObj pipe(m_device);
12263 pipe.AddColorAttachment();
12264 pipe.AddShader(&vs);
12265 pipe.AddShader(&fs);
12266
12267 VkDescriptorSetObj descriptorSet(m_device);
12268 descriptorSet.AppendDummy();
12269 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12270
12271 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12272
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012273 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012274}
12275
Karl Schultz6addd812016-02-02 17:17:23 -070012276TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012277 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12278 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012280
Chris Forbesde136e02015-05-25 11:13:28 +120012281 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012283
12284 VkVertexInputBindingDescription input_binding;
12285 memset(&input_binding, 0, sizeof(input_binding));
12286
12287 VkVertexInputAttributeDescription input_attrib;
12288 memset(&input_attrib, 0, sizeof(input_attrib));
12289 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12290
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012291 char const *vsSource = "#version 450\n"
12292 "\n"
12293 "out gl_PerVertex {\n"
12294 " vec4 gl_Position;\n"
12295 "};\n"
12296 "void main(){\n"
12297 " gl_Position = vec4(1);\n"
12298 "}\n";
12299 char const *fsSource = "#version 450\n"
12300 "\n"
12301 "layout(location=0) out vec4 color;\n"
12302 "void main(){\n"
12303 " color = vec4(1);\n"
12304 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012305
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012306 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12307 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012308
12309 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012310 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012311 pipe.AddShader(&vs);
12312 pipe.AddShader(&fs);
12313
12314 pipe.AddVertexInputBindings(&input_binding, 1);
12315 pipe.AddVertexInputAttribs(&input_attrib, 1);
12316
Chris Forbesde136e02015-05-25 11:13:28 +120012317 VkDescriptorSetObj descriptorSet(m_device);
12318 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012319 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012320
Tony Barbour5781e8f2015-08-04 16:23:11 -060012321 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012322
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012323 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012324}
12325
Karl Schultz6addd812016-02-02 17:17:23 -070012326TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012327 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12328 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012330
12331 ASSERT_NO_FATAL_FAILURE(InitState());
12332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12333
12334 VkVertexInputBindingDescription input_binding;
12335 memset(&input_binding, 0, sizeof(input_binding));
12336
12337 VkVertexInputAttributeDescription input_attrib;
12338 memset(&input_attrib, 0, sizeof(input_attrib));
12339 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012341 char const *vsSource = "#version 450\n"
12342 "\n"
12343 "layout(location=1) in float x;\n"
12344 "out gl_PerVertex {\n"
12345 " vec4 gl_Position;\n"
12346 "};\n"
12347 "void main(){\n"
12348 " gl_Position = vec4(x);\n"
12349 "}\n";
12350 char const *fsSource = "#version 450\n"
12351 "\n"
12352 "layout(location=0) out vec4 color;\n"
12353 "void main(){\n"
12354 " color = vec4(1);\n"
12355 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012356
12357 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12358 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12359
12360 VkPipelineObj pipe(m_device);
12361 pipe.AddColorAttachment();
12362 pipe.AddShader(&vs);
12363 pipe.AddShader(&fs);
12364
12365 pipe.AddVertexInputBindings(&input_binding, 1);
12366 pipe.AddVertexInputAttribs(&input_attrib, 1);
12367
12368 VkDescriptorSetObj descriptorSet(m_device);
12369 descriptorSet.AppendDummy();
12370 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12371
12372 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12373
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012374 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012375}
12376
Karl Schultz6addd812016-02-02 17:17:23 -070012377TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012378 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012379 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012380 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 -060012381
Chris Forbes62e8e502015-05-25 11:13:29 +120012382 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012383 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012384
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012385 char const *vsSource = "#version 450\n"
12386 "\n"
12387 "layout(location=0) in vec4 x;\n" /* not provided */
12388 "out gl_PerVertex {\n"
12389 " vec4 gl_Position;\n"
12390 "};\n"
12391 "void main(){\n"
12392 " gl_Position = x;\n"
12393 "}\n";
12394 char const *fsSource = "#version 450\n"
12395 "\n"
12396 "layout(location=0) out vec4 color;\n"
12397 "void main(){\n"
12398 " color = vec4(1);\n"
12399 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012400
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012401 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12402 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012403
12404 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012405 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012406 pipe.AddShader(&vs);
12407 pipe.AddShader(&fs);
12408
Chris Forbes62e8e502015-05-25 11:13:29 +120012409 VkDescriptorSetObj descriptorSet(m_device);
12410 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012411 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012412
Tony Barbour5781e8f2015-08-04 16:23:11 -060012413 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012414
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012415 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012416}
12417
Karl Schultz6addd812016-02-02 17:17:23 -070012418TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012419 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12420 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012421 "vertex shader input that consumes it");
12422 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 -060012423
Chris Forbesc97d98e2015-05-25 11:13:31 +120012424 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012425 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012426
12427 VkVertexInputBindingDescription input_binding;
12428 memset(&input_binding, 0, sizeof(input_binding));
12429
12430 VkVertexInputAttributeDescription input_attrib;
12431 memset(&input_attrib, 0, sizeof(input_attrib));
12432 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012434 char const *vsSource = "#version 450\n"
12435 "\n"
12436 "layout(location=0) in int x;\n" /* attrib provided float */
12437 "out gl_PerVertex {\n"
12438 " vec4 gl_Position;\n"
12439 "};\n"
12440 "void main(){\n"
12441 " gl_Position = vec4(x);\n"
12442 "}\n";
12443 char const *fsSource = "#version 450\n"
12444 "\n"
12445 "layout(location=0) out vec4 color;\n"
12446 "void main(){\n"
12447 " color = vec4(1);\n"
12448 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012449
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012450 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12451 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012452
12453 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012454 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012455 pipe.AddShader(&vs);
12456 pipe.AddShader(&fs);
12457
12458 pipe.AddVertexInputBindings(&input_binding, 1);
12459 pipe.AddVertexInputAttribs(&input_attrib, 1);
12460
Chris Forbesc97d98e2015-05-25 11:13:31 +120012461 VkDescriptorSetObj descriptorSet(m_device);
12462 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012463 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012464
Tony Barbour5781e8f2015-08-04 16:23:11 -060012465 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012466
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012467 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012468}
12469
Chris Forbesc68b43c2016-04-06 11:18:47 +120012470TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012471 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12472 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12474 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012475
12476 ASSERT_NO_FATAL_FAILURE(InitState());
12477 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12478
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012479 char const *vsSource = "#version 450\n"
12480 "\n"
12481 "out gl_PerVertex {\n"
12482 " vec4 gl_Position;\n"
12483 "};\n"
12484 "void main(){\n"
12485 " gl_Position = vec4(1);\n"
12486 "}\n";
12487 char const *fsSource = "#version 450\n"
12488 "\n"
12489 "layout(location=0) out vec4 color;\n"
12490 "void main(){\n"
12491 " color = vec4(1);\n"
12492 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012493
12494 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12495 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12496
12497 VkPipelineObj pipe(m_device);
12498 pipe.AddColorAttachment();
12499 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012500 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012501 pipe.AddShader(&fs);
12502
12503 VkDescriptorSetObj descriptorSet(m_device);
12504 descriptorSet.AppendDummy();
12505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12506
12507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12508
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012509 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012510}
12511
Chris Forbes82ff92a2016-09-09 10:50:24 +120012512TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12514 "No entrypoint found named `foo`");
12515
12516 ASSERT_NO_FATAL_FAILURE(InitState());
12517 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12518
12519 char const *vsSource = "#version 450\n"
12520 "out gl_PerVertex {\n"
12521 " vec4 gl_Position;\n"
12522 "};\n"
12523 "void main(){\n"
12524 " gl_Position = vec4(0);\n"
12525 "}\n";
12526 char const *fsSource = "#version 450\n"
12527 "\n"
12528 "layout(location=0) out vec4 color;\n"
12529 "void main(){\n"
12530 " color = vec4(1);\n"
12531 "}\n";
12532
12533 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12534 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12535
12536 VkPipelineObj pipe(m_device);
12537 pipe.AddColorAttachment();
12538 pipe.AddShader(&vs);
12539 pipe.AddShader(&fs);
12540
12541 VkDescriptorSetObj descriptorSet(m_device);
12542 descriptorSet.AppendDummy();
12543 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12544
12545 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12546
12547 m_errorMonitor->VerifyFound();
12548}
12549
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012550TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12551 m_errorMonitor->SetDesiredFailureMsg(
12552 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12553 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12554 "uses a depth/stencil attachment");
12555
12556 ASSERT_NO_FATAL_FAILURE(InitState());
12557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12558
12559 char const *vsSource = "#version 450\n"
12560 "void main(){ gl_Position = vec4(0); }\n";
12561 char const *fsSource = "#version 450\n"
12562 "\n"
12563 "layout(location=0) out vec4 color;\n"
12564 "void main(){\n"
12565 " color = vec4(1);\n"
12566 "}\n";
12567
12568 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12569 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12570
12571 VkPipelineObj pipe(m_device);
12572 pipe.AddColorAttachment();
12573 pipe.AddShader(&vs);
12574 pipe.AddShader(&fs);
12575
12576 VkDescriptorSetObj descriptorSet(m_device);
12577 descriptorSet.AppendDummy();
12578 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12579
12580 VkAttachmentDescription attachments[] = {
12581 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12582 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12583 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12584 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12585 },
12586 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12587 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12588 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12589 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12590 },
12591 };
12592 VkAttachmentReference refs[] = {
12593 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12594 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12595 };
12596 VkSubpassDescription subpass = {
12597 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12598 1, &refs[0], nullptr, &refs[1],
12599 0, nullptr
12600 };
12601 VkRenderPassCreateInfo rpci = {
12602 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12603 0, 2, attachments, 1, &subpass, 0, nullptr
12604 };
12605 VkRenderPass rp;
12606 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12607 ASSERT_VK_SUCCESS(err);
12608
12609 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12610
12611 m_errorMonitor->VerifyFound();
12612
12613 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12614}
12615
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012616TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012617 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12618 "the TCS without the patch decoration, but consumed in the TES "
12619 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12621 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012622
12623 ASSERT_NO_FATAL_FAILURE(InitState());
12624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12625
Chris Forbesc1e852d2016-04-04 19:26:42 +120012626 if (!m_device->phy().features().tessellationShader) {
12627 printf("Device does not support tessellation shaders; skipped.\n");
12628 return;
12629 }
12630
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012631 char const *vsSource = "#version 450\n"
12632 "void main(){}\n";
12633 char const *tcsSource = "#version 450\n"
12634 "layout(location=0) out int x[];\n"
12635 "layout(vertices=3) out;\n"
12636 "void main(){\n"
12637 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12638 " gl_TessLevelInner[0] = 1;\n"
12639 " x[gl_InvocationID] = gl_InvocationID;\n"
12640 "}\n";
12641 char const *tesSource = "#version 450\n"
12642 "layout(triangles, equal_spacing, cw) in;\n"
12643 "layout(location=0) patch in int x;\n"
12644 "out gl_PerVertex { vec4 gl_Position; };\n"
12645 "void main(){\n"
12646 " gl_Position.xyz = gl_TessCoord;\n"
12647 " gl_Position.w = x;\n"
12648 "}\n";
12649 char const *fsSource = "#version 450\n"
12650 "layout(location=0) out vec4 color;\n"
12651 "void main(){\n"
12652 " color = vec4(1);\n"
12653 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012654
12655 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12656 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12657 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12658 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12659
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012660 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12661 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012663 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012664
12665 VkPipelineObj pipe(m_device);
12666 pipe.SetInputAssembly(&iasci);
12667 pipe.SetTessellation(&tsci);
12668 pipe.AddColorAttachment();
12669 pipe.AddShader(&vs);
12670 pipe.AddShader(&tcs);
12671 pipe.AddShader(&tes);
12672 pipe.AddShader(&fs);
12673
12674 VkDescriptorSetObj descriptorSet(m_device);
12675 descriptorSet.AppendDummy();
12676 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12677
12678 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12679
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012680 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012681}
12682
Karl Schultz6addd812016-02-02 17:17:23 -070012683TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012684 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12685 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12687 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012688
Chris Forbes280ba2c2015-06-12 11:16:41 +120012689 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012691
12692 /* Two binding descriptions for binding 0 */
12693 VkVertexInputBindingDescription input_bindings[2];
12694 memset(input_bindings, 0, sizeof(input_bindings));
12695
12696 VkVertexInputAttributeDescription input_attrib;
12697 memset(&input_attrib, 0, sizeof(input_attrib));
12698 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012700 char const *vsSource = "#version 450\n"
12701 "\n"
12702 "layout(location=0) in float x;\n" /* attrib provided float */
12703 "out gl_PerVertex {\n"
12704 " vec4 gl_Position;\n"
12705 "};\n"
12706 "void main(){\n"
12707 " gl_Position = vec4(x);\n"
12708 "}\n";
12709 char const *fsSource = "#version 450\n"
12710 "\n"
12711 "layout(location=0) out vec4 color;\n"
12712 "void main(){\n"
12713 " color = vec4(1);\n"
12714 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012715
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012716 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12717 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012718
12719 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012720 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012721 pipe.AddShader(&vs);
12722 pipe.AddShader(&fs);
12723
12724 pipe.AddVertexInputBindings(input_bindings, 2);
12725 pipe.AddVertexInputAttribs(&input_attrib, 1);
12726
Chris Forbes280ba2c2015-06-12 11:16:41 +120012727 VkDescriptorSetObj descriptorSet(m_device);
12728 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012729 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012730
Tony Barbour5781e8f2015-08-04 16:23:11 -060012731 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012732
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012733 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012734}
Chris Forbes8f68b562015-05-25 11:13:32 +120012735
Karl Schultz6addd812016-02-02 17:17:23 -070012736TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012737 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012738 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012740
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012741 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012742
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012743 char const *vsSource = "#version 450\n"
12744 "\n"
12745 "out gl_PerVertex {\n"
12746 " vec4 gl_Position;\n"
12747 "};\n"
12748 "void main(){\n"
12749 " gl_Position = vec4(1);\n"
12750 "}\n";
12751 char const *fsSource = "#version 450\n"
12752 "\n"
12753 "void main(){\n"
12754 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012755
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012756 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12757 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012758
12759 VkPipelineObj pipe(m_device);
12760 pipe.AddShader(&vs);
12761 pipe.AddShader(&fs);
12762
Chia-I Wu08accc62015-07-07 11:50:03 +080012763 /* set up CB 0, not written */
12764 pipe.AddColorAttachment();
12765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012766
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012767 VkDescriptorSetObj descriptorSet(m_device);
12768 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012769 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012770
Tony Barbour5781e8f2015-08-04 16:23:11 -060012771 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012772
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012773 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012774}
12775
Karl Schultz6addd812016-02-02 17:17:23 -070012776TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012777 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120012778 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012780 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012781
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012782 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012783
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012784 char const *vsSource = "#version 450\n"
12785 "\n"
12786 "out gl_PerVertex {\n"
12787 " vec4 gl_Position;\n"
12788 "};\n"
12789 "void main(){\n"
12790 " gl_Position = vec4(1);\n"
12791 "}\n";
12792 char const *fsSource = "#version 450\n"
12793 "\n"
12794 "layout(location=0) out vec4 x;\n"
12795 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
12796 "void main(){\n"
12797 " x = vec4(1);\n"
12798 " y = vec4(1);\n"
12799 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012800
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012801 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12802 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012803
12804 VkPipelineObj pipe(m_device);
12805 pipe.AddShader(&vs);
12806 pipe.AddShader(&fs);
12807
Chia-I Wu08accc62015-07-07 11:50:03 +080012808 /* set up CB 0, not written */
12809 pipe.AddColorAttachment();
12810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012811 /* FS writes CB 1, but we don't configure it */
12812
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012813 VkDescriptorSetObj descriptorSet(m_device);
12814 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012815 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012816
Tony Barbour5781e8f2015-08-04 16:23:11 -060012817 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012818
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012819 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012820}
12821
Karl Schultz6addd812016-02-02 17:17:23 -070012822TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012823 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012824 "type of an fragment shader output variable, and the format of the corresponding attachment");
12825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012826
Chris Forbesa36d69e2015-05-25 11:13:44 +120012827 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012829 char const *vsSource = "#version 450\n"
12830 "\n"
12831 "out gl_PerVertex {\n"
12832 " vec4 gl_Position;\n"
12833 "};\n"
12834 "void main(){\n"
12835 " gl_Position = vec4(1);\n"
12836 "}\n";
12837 char const *fsSource = "#version 450\n"
12838 "\n"
12839 "layout(location=0) out ivec4 x;\n" /* not UNORM */
12840 "void main(){\n"
12841 " x = ivec4(1);\n"
12842 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120012843
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012844 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12845 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012846
12847 VkPipelineObj pipe(m_device);
12848 pipe.AddShader(&vs);
12849 pipe.AddShader(&fs);
12850
Chia-I Wu08accc62015-07-07 11:50:03 +080012851 /* set up CB 0; type is UNORM by default */
12852 pipe.AddColorAttachment();
12853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012854
Chris Forbesa36d69e2015-05-25 11:13:44 +120012855 VkDescriptorSetObj descriptorSet(m_device);
12856 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012857 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012858
Tony Barbour5781e8f2015-08-04 16:23:11 -060012859 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012860
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012861 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120012862}
Chris Forbes7b1b8932015-06-05 14:43:36 +120012863
Karl Schultz6addd812016-02-02 17:17:23 -070012864TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012865 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
12866 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012868
Chris Forbes556c76c2015-08-14 12:04:59 +120012869 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120012870
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012871 char const *vsSource = "#version 450\n"
12872 "\n"
12873 "out gl_PerVertex {\n"
12874 " vec4 gl_Position;\n"
12875 "};\n"
12876 "void main(){\n"
12877 " gl_Position = vec4(1);\n"
12878 "}\n";
12879 char const *fsSource = "#version 450\n"
12880 "\n"
12881 "layout(location=0) out vec4 x;\n"
12882 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
12883 "void main(){\n"
12884 " x = vec4(bar.y);\n"
12885 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120012886
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012887 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12888 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120012889
Chris Forbes556c76c2015-08-14 12:04:59 +120012890 VkPipelineObj pipe(m_device);
12891 pipe.AddShader(&vs);
12892 pipe.AddShader(&fs);
12893
12894 /* set up CB 0; type is UNORM by default */
12895 pipe.AddColorAttachment();
12896 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12897
12898 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012899 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120012900
12901 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12902
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012903 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120012904}
12905
Chris Forbes5c59e902016-02-26 16:56:09 +130012906TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012907 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
12908 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130012910
12911 ASSERT_NO_FATAL_FAILURE(InitState());
12912
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012913 char const *vsSource = "#version 450\n"
12914 "\n"
12915 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12916 "out gl_PerVertex {\n"
12917 " vec4 gl_Position;\n"
12918 "};\n"
12919 "void main(){\n"
12920 " gl_Position = vec4(consts.x);\n"
12921 "}\n";
12922 char const *fsSource = "#version 450\n"
12923 "\n"
12924 "layout(location=0) out vec4 x;\n"
12925 "void main(){\n"
12926 " x = vec4(1);\n"
12927 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130012928
12929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12931
12932 VkPipelineObj pipe(m_device);
12933 pipe.AddShader(&vs);
12934 pipe.AddShader(&fs);
12935
12936 /* set up CB 0; type is UNORM by default */
12937 pipe.AddColorAttachment();
12938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12939
12940 VkDescriptorSetObj descriptorSet(m_device);
12941 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12942
12943 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12944
12945 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012946 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130012947}
12948
Chris Forbes3fb17902016-08-22 14:57:55 +120012949TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
12950 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
12951 "which is not included in the subpass description");
12952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12953 "consumes input attachment index 0 but not provided in subpass");
12954
12955 ASSERT_NO_FATAL_FAILURE(InitState());
12956
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012957 char const *vsSource = "#version 450\n"
12958 "\n"
12959 "out gl_PerVertex {\n"
12960 " vec4 gl_Position;\n"
12961 "};\n"
12962 "void main(){\n"
12963 " gl_Position = vec4(1);\n"
12964 "}\n";
12965 char const *fsSource = "#version 450\n"
12966 "\n"
12967 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
12968 "layout(location=0) out vec4 color;\n"
12969 "void main() {\n"
12970 " color = subpassLoad(x);\n"
12971 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120012972
12973 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12974 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12975
12976 VkPipelineObj pipe(m_device);
12977 pipe.AddShader(&vs);
12978 pipe.AddShader(&fs);
12979 pipe.AddColorAttachment();
12980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12981
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012982 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
12983 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120012984 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012985 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120012986 ASSERT_VK_SUCCESS(err);
12987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012988 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120012989 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012990 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120012991 ASSERT_VK_SUCCESS(err);
12992
12993 // error here.
12994 pipe.CreateVKPipeline(pl, renderPass());
12995
12996 m_errorMonitor->VerifyFound();
12997
12998 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
12999 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13000}
13001
Chris Forbes5a9a0472016-08-22 16:02:09 +120013002TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13003 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13004 "with a format having a different fundamental type");
13005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13006 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13007
13008 ASSERT_NO_FATAL_FAILURE(InitState());
13009
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013010 char const *vsSource = "#version 450\n"
13011 "\n"
13012 "out gl_PerVertex {\n"
13013 " vec4 gl_Position;\n"
13014 "};\n"
13015 "void main(){\n"
13016 " gl_Position = vec4(1);\n"
13017 "}\n";
13018 char const *fsSource = "#version 450\n"
13019 "\n"
13020 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13021 "layout(location=0) out vec4 color;\n"
13022 "void main() {\n"
13023 " color = subpassLoad(x);\n"
13024 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013025
13026 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13027 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13028
13029 VkPipelineObj pipe(m_device);
13030 pipe.AddShader(&vs);
13031 pipe.AddShader(&fs);
13032 pipe.AddColorAttachment();
13033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013035 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13036 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013037 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013038 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013039 ASSERT_VK_SUCCESS(err);
13040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013041 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013042 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013043 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013044 ASSERT_VK_SUCCESS(err);
13045
13046 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013047 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13048 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13049 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13050 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13051 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 +120013052 };
13053 VkAttachmentReference color = {
13054 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13055 };
13056 VkAttachmentReference input = {
13057 1, VK_IMAGE_LAYOUT_GENERAL,
13058 };
13059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013060 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013061
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013062 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013063 VkRenderPass rp;
13064 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13065 ASSERT_VK_SUCCESS(err);
13066
13067 // error here.
13068 pipe.CreateVKPipeline(pl, rp);
13069
13070 m_errorMonitor->VerifyFound();
13071
13072 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13073 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13074 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13075}
13076
Chris Forbes541f7b02016-08-22 15:30:27 +120013077TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13078 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13079 "which is not included in the subpass description -- array case");
13080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13081 "consumes input attachment index 1 but not provided in subpass");
13082
13083 ASSERT_NO_FATAL_FAILURE(InitState());
13084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013085 char const *vsSource = "#version 450\n"
13086 "\n"
13087 "out gl_PerVertex {\n"
13088 " vec4 gl_Position;\n"
13089 "};\n"
13090 "void main(){\n"
13091 " gl_Position = vec4(1);\n"
13092 "}\n";
13093 char const *fsSource = "#version 450\n"
13094 "\n"
13095 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13096 "layout(location=0) out vec4 color;\n"
13097 "void main() {\n"
13098 " color = subpassLoad(xs[1]);\n"
13099 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013100
13101 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13102 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13103
13104 VkPipelineObj pipe(m_device);
13105 pipe.AddShader(&vs);
13106 pipe.AddShader(&fs);
13107 pipe.AddColorAttachment();
13108 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013110 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13111 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013112 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013113 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013114 ASSERT_VK_SUCCESS(err);
13115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013116 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013117 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013118 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013119 ASSERT_VK_SUCCESS(err);
13120
13121 // error here.
13122 pipe.CreateVKPipeline(pl, renderPass());
13123
13124 m_errorMonitor->VerifyFound();
13125
13126 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13127 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13128}
13129
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013130TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013131 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13132 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013134
13135 ASSERT_NO_FATAL_FAILURE(InitState());
13136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013137 char const *csSource = "#version 450\n"
13138 "\n"
13139 "layout(local_size_x=1) in;\n"
13140 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13141 "void main(){\n"
13142 " x = vec4(1);\n"
13143 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013144
13145 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13146
13147 VkDescriptorSetObj descriptorSet(m_device);
13148 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013150 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13151 nullptr,
13152 0,
13153 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13154 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13155 descriptorSet.GetPipelineLayout(),
13156 VK_NULL_HANDLE,
13157 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013158
13159 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013160 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013161
13162 m_errorMonitor->VerifyFound();
13163
13164 if (err == VK_SUCCESS) {
13165 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13166 }
13167}
13168
Chris Forbes22a9b092016-07-19 14:34:05 +120013169TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013170 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13171 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13173 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013174
13175 ASSERT_NO_FATAL_FAILURE(InitState());
13176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013177 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13178 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013179 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013180 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013181 ASSERT_VK_SUCCESS(err);
13182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013183 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013184 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013185 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013186 ASSERT_VK_SUCCESS(err);
13187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013188 char const *csSource = "#version 450\n"
13189 "\n"
13190 "layout(local_size_x=1) in;\n"
13191 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13192 "void main() {\n"
13193 " x.x = 1.0f;\n"
13194 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013195 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013197 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13198 nullptr,
13199 0,
13200 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13201 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13202 pl,
13203 VK_NULL_HANDLE,
13204 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013205
13206 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013207 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013208
13209 m_errorMonitor->VerifyFound();
13210
13211 if (err == VK_SUCCESS) {
13212 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13213 }
13214
13215 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13216 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13217}
13218
Chris Forbes50020592016-07-27 13:52:41 +120013219TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13220 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13221 "does not match the dimensionality declared in the shader");
13222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013223 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 +120013224
13225 ASSERT_NO_FATAL_FAILURE(InitState());
13226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13227
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013228 char const *vsSource = "#version 450\n"
13229 "\n"
13230 "out gl_PerVertex { vec4 gl_Position; };\n"
13231 "void main() { gl_Position = vec4(0); }\n";
13232 char const *fsSource = "#version 450\n"
13233 "\n"
13234 "layout(set=0, binding=0) uniform sampler3D s;\n"
13235 "layout(location=0) out vec4 color;\n"
13236 "void main() {\n"
13237 " color = texture(s, vec3(0));\n"
13238 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013239 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13240 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13241
13242 VkPipelineObj pipe(m_device);
13243 pipe.AddShader(&vs);
13244 pipe.AddShader(&fs);
13245 pipe.AddColorAttachment();
13246
13247 VkTextureObj texture(m_device, nullptr);
13248 VkSamplerObj sampler(m_device);
13249
13250 VkDescriptorSetObj descriptorSet(m_device);
13251 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13252 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13253
13254 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13255 ASSERT_VK_SUCCESS(err);
13256
13257 BeginCommandBuffer();
13258
13259 m_commandBuffer->BindPipeline(pipe);
13260 m_commandBuffer->BindDescriptorSet(descriptorSet);
13261
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013262 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013263 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013264 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013265 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13266
13267 // error produced here.
13268 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13269
13270 m_errorMonitor->VerifyFound();
13271
13272 EndCommandBuffer();
13273}
13274
Chris Forbes5533bfc2016-07-27 14:12:34 +120013275TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13276 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13277 "are consumed via singlesample images types in the shader, or vice versa.");
13278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013280
13281 ASSERT_NO_FATAL_FAILURE(InitState());
13282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13283
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013284 char const *vsSource = "#version 450\n"
13285 "\n"
13286 "out gl_PerVertex { vec4 gl_Position; };\n"
13287 "void main() { gl_Position = vec4(0); }\n";
13288 char const *fsSource = "#version 450\n"
13289 "\n"
13290 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13291 "layout(location=0) out vec4 color;\n"
13292 "void main() {\n"
13293 " color = texelFetch(s, ivec2(0), 0);\n"
13294 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013295 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13296 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13297
13298 VkPipelineObj pipe(m_device);
13299 pipe.AddShader(&vs);
13300 pipe.AddShader(&fs);
13301 pipe.AddColorAttachment();
13302
13303 VkTextureObj texture(m_device, nullptr);
13304 VkSamplerObj sampler(m_device);
13305
13306 VkDescriptorSetObj descriptorSet(m_device);
13307 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13308 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13309
13310 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13311 ASSERT_VK_SUCCESS(err);
13312
13313 BeginCommandBuffer();
13314
13315 m_commandBuffer->BindPipeline(pipe);
13316 m_commandBuffer->BindDescriptorSet(descriptorSet);
13317
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013318 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013319 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013320 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013321 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13322
13323 // error produced here.
13324 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13325
13326 m_errorMonitor->VerifyFound();
13327
13328 EndCommandBuffer();
13329}
13330
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013331#endif // SHADER_CHECKER_TESTS
13332
13333#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013334TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013336
13337 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013338
13339 // Create an image
13340 VkImage image;
13341
Karl Schultz6addd812016-02-02 17:17:23 -070013342 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13343 const int32_t tex_width = 32;
13344 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013345
13346 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013347 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13348 image_create_info.pNext = NULL;
13349 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13350 image_create_info.format = tex_format;
13351 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013352 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013353 image_create_info.extent.depth = 1;
13354 image_create_info.mipLevels = 1;
13355 image_create_info.arrayLayers = 1;
13356 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13357 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13358 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13359 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013360
13361 // Introduce error by sending down a bogus width extent
13362 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013363 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013364
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013365 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013366}
13367
Mark Youngc48c4c12016-04-11 14:26:49 -060013368TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13370 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013371
13372 ASSERT_NO_FATAL_FAILURE(InitState());
13373
13374 // Create an image
13375 VkImage image;
13376
13377 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13378 const int32_t tex_width = 32;
13379 const int32_t tex_height = 32;
13380
13381 VkImageCreateInfo image_create_info = {};
13382 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13383 image_create_info.pNext = NULL;
13384 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13385 image_create_info.format = tex_format;
13386 image_create_info.extent.width = tex_width;
13387 image_create_info.extent.height = tex_height;
13388 image_create_info.extent.depth = 1;
13389 image_create_info.mipLevels = 1;
13390 image_create_info.arrayLayers = 1;
13391 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13392 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13393 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13394 image_create_info.flags = 0;
13395
13396 // Introduce error by sending down a bogus width extent
13397 image_create_info.extent.width = 0;
13398 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13399
13400 m_errorMonitor->VerifyFound();
13401}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013402#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013403
Tobin Ehliscde08892015-09-22 10:11:37 -060013404#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013405TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13406 TEST_DESCRIPTION("Create a render pass with an attachment description "
13407 "format set to VK_FORMAT_UNDEFINED");
13408
13409 ASSERT_NO_FATAL_FAILURE(InitState());
13410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13411
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013413
13414 VkAttachmentReference color_attach = {};
13415 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13416 color_attach.attachment = 0;
13417 VkSubpassDescription subpass = {};
13418 subpass.colorAttachmentCount = 1;
13419 subpass.pColorAttachments = &color_attach;
13420
13421 VkRenderPassCreateInfo rpci = {};
13422 rpci.subpassCount = 1;
13423 rpci.pSubpasses = &subpass;
13424 rpci.attachmentCount = 1;
13425 VkAttachmentDescription attach_desc = {};
13426 attach_desc.format = VK_FORMAT_UNDEFINED;
13427 rpci.pAttachments = &attach_desc;
13428 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13429 VkRenderPass rp;
13430 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13431
13432 m_errorMonitor->VerifyFound();
13433
13434 if (result == VK_SUCCESS) {
13435 vkDestroyRenderPass(m_device->device(), rp, NULL);
13436 }
13437}
13438
Karl Schultz6addd812016-02-02 17:17:23 -070013439TEST_F(VkLayerTest, InvalidImageView) {
13440 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013441
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013443
Tobin Ehliscde08892015-09-22 10:11:37 -060013444 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013445
Mike Stroyana3082432015-09-25 13:39:21 -060013446 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013447 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013448
Karl Schultz6addd812016-02-02 17:17:23 -070013449 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13450 const int32_t tex_width = 32;
13451 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013452
13453 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013454 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13455 image_create_info.pNext = NULL;
13456 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13457 image_create_info.format = tex_format;
13458 image_create_info.extent.width = tex_width;
13459 image_create_info.extent.height = tex_height;
13460 image_create_info.extent.depth = 1;
13461 image_create_info.mipLevels = 1;
13462 image_create_info.arrayLayers = 1;
13463 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13464 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13465 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13466 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013467
Chia-I Wuf7458c52015-10-26 21:10:41 +080013468 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013469 ASSERT_VK_SUCCESS(err);
13470
13471 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013472 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13473 image_view_create_info.image = image;
13474 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13475 image_view_create_info.format = tex_format;
13476 image_view_create_info.subresourceRange.layerCount = 1;
13477 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13478 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013479 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013480
13481 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013482 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013483
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013484 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013485 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013486}
Mike Stroyana3082432015-09-25 13:39:21 -060013487
Mark Youngd339ba32016-05-30 13:28:35 -060013488TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13489 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013491 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013492
13493 ASSERT_NO_FATAL_FAILURE(InitState());
13494
13495 // Create an image and try to create a view with no memory backing the image
13496 VkImage image;
13497
13498 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13499 const int32_t tex_width = 32;
13500 const int32_t tex_height = 32;
13501
13502 VkImageCreateInfo image_create_info = {};
13503 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13504 image_create_info.pNext = NULL;
13505 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13506 image_create_info.format = tex_format;
13507 image_create_info.extent.width = tex_width;
13508 image_create_info.extent.height = tex_height;
13509 image_create_info.extent.depth = 1;
13510 image_create_info.mipLevels = 1;
13511 image_create_info.arrayLayers = 1;
13512 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13513 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13514 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13515 image_create_info.flags = 0;
13516
13517 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13518 ASSERT_VK_SUCCESS(err);
13519
13520 VkImageViewCreateInfo image_view_create_info = {};
13521 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13522 image_view_create_info.image = image;
13523 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13524 image_view_create_info.format = tex_format;
13525 image_view_create_info.subresourceRange.layerCount = 1;
13526 image_view_create_info.subresourceRange.baseMipLevel = 0;
13527 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013528 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013529
13530 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013531 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013532
13533 m_errorMonitor->VerifyFound();
13534 vkDestroyImage(m_device->device(), image, NULL);
13535 // If last error is success, it still created the view, so delete it.
13536 if (err == VK_SUCCESS) {
13537 vkDestroyImageView(m_device->device(), view, NULL);
13538 }
Mark Youngd339ba32016-05-30 13:28:35 -060013539}
13540
Karl Schultz6addd812016-02-02 17:17:23 -070013541TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013542 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013544 "formats must have ONLY the "
13545 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13547 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013548
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013549 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013550
Karl Schultz6addd812016-02-02 17:17:23 -070013551 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013552 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013553 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013554 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013555
13556 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013557 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013558 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013559 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13560 image_view_create_info.format = tex_format;
13561 image_view_create_info.subresourceRange.baseMipLevel = 0;
13562 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013563 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013564 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013565 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013566
13567 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013568 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013569
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013570 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013571}
13572
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013573TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013574 VkResult err;
13575 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013576
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13578 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013579
Mike Stroyana3082432015-09-25 13:39:21 -060013580 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013581
13582 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013583 VkImage srcImage;
13584 VkImage dstImage;
13585 VkDeviceMemory srcMem;
13586 VkDeviceMemory destMem;
13587 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013588
13589 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013590 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13591 image_create_info.pNext = NULL;
13592 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13593 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13594 image_create_info.extent.width = 32;
13595 image_create_info.extent.height = 32;
13596 image_create_info.extent.depth = 1;
13597 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013598 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013599 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13600 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13601 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13602 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013604 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013605 ASSERT_VK_SUCCESS(err);
13606
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013607 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013608 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013609 ASSERT_VK_SUCCESS(err);
13610
13611 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013612 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013613 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13614 memAlloc.pNext = NULL;
13615 memAlloc.allocationSize = 0;
13616 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013617
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013618 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013619 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013620 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013621 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013622 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013623 ASSERT_VK_SUCCESS(err);
13624
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013625 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013626 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013627 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013628 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013629 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013630 ASSERT_VK_SUCCESS(err);
13631
13632 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13633 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013634 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013635 ASSERT_VK_SUCCESS(err);
13636
13637 BeginCommandBuffer();
13638 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013639 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013640 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013641 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013642 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013643 copyRegion.srcOffset.x = 0;
13644 copyRegion.srcOffset.y = 0;
13645 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013646 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013647 copyRegion.dstSubresource.mipLevel = 0;
13648 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013649 // Introduce failure by forcing the dst layerCount to differ from src
13650 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013651 copyRegion.dstOffset.x = 0;
13652 copyRegion.dstOffset.y = 0;
13653 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013654 copyRegion.extent.width = 1;
13655 copyRegion.extent.height = 1;
13656 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013657 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013658 EndCommandBuffer();
13659
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013660 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013661
Chia-I Wuf7458c52015-10-26 21:10:41 +080013662 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013663 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013664 vkFreeMemory(m_device->device(), srcMem, NULL);
13665 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013666}
13667
Tony Barbourd6673642016-05-05 14:46:39 -060013668TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13669
13670 TEST_DESCRIPTION("Creating images with unsuported formats ");
13671
13672 ASSERT_NO_FATAL_FAILURE(InitState());
13673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13674 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013675 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 -060013676 VK_IMAGE_TILING_OPTIMAL, 0);
13677 ASSERT_TRUE(image.initialized());
13678
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013679 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13680 VkImageCreateInfo image_create_info;
13681 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13682 image_create_info.pNext = NULL;
13683 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13684 image_create_info.format = VK_FORMAT_UNDEFINED;
13685 image_create_info.extent.width = 32;
13686 image_create_info.extent.height = 32;
13687 image_create_info.extent.depth = 1;
13688 image_create_info.mipLevels = 1;
13689 image_create_info.arrayLayers = 1;
13690 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13691 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13692 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13693 image_create_info.flags = 0;
13694
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13696 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013697
13698 VkImage localImage;
13699 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13700 m_errorMonitor->VerifyFound();
13701
Tony Barbourd6673642016-05-05 14:46:39 -060013702 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013703 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013704 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13705 VkFormat format = static_cast<VkFormat>(f);
13706 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013707 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013708 unsupported = format;
13709 break;
13710 }
13711 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013712
Tony Barbourd6673642016-05-05 14:46:39 -060013713 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013714 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013716
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013717 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013718 m_errorMonitor->VerifyFound();
13719 }
13720}
13721
13722TEST_F(VkLayerTest, ImageLayerViewTests) {
13723 VkResult ret;
13724 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13725
13726 ASSERT_NO_FATAL_FAILURE(InitState());
13727
13728 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013729 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 -060013730 VK_IMAGE_TILING_OPTIMAL, 0);
13731 ASSERT_TRUE(image.initialized());
13732
13733 VkImageView imgView;
13734 VkImageViewCreateInfo imgViewInfo = {};
13735 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13736 imgViewInfo.image = image.handle();
13737 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13738 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13739 imgViewInfo.subresourceRange.layerCount = 1;
13740 imgViewInfo.subresourceRange.baseMipLevel = 0;
13741 imgViewInfo.subresourceRange.levelCount = 1;
13742 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13743
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013745 // View can't have baseMipLevel >= image's mipLevels - Expect
13746 // VIEW_CREATE_ERROR
13747 imgViewInfo.subresourceRange.baseMipLevel = 1;
13748 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13749 m_errorMonitor->VerifyFound();
13750 imgViewInfo.subresourceRange.baseMipLevel = 0;
13751
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060013753 // View can't have baseArrayLayer >= image's arraySize - Expect
13754 // VIEW_CREATE_ERROR
13755 imgViewInfo.subresourceRange.baseArrayLayer = 1;
13756 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13757 m_errorMonitor->VerifyFound();
13758 imgViewInfo.subresourceRange.baseArrayLayer = 0;
13759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13761 "pCreateInfo->subresourceRange."
13762 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060013763 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
13764 imgViewInfo.subresourceRange.levelCount = 0;
13765 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13766 m_errorMonitor->VerifyFound();
13767 imgViewInfo.subresourceRange.levelCount = 1;
13768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13770 "pCreateInfo->subresourceRange."
13771 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013772 m_errorMonitor->SetDesiredFailureMsg(
13773 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13774 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060013775 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
13776 imgViewInfo.subresourceRange.layerCount = 0;
13777 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13778 m_errorMonitor->VerifyFound();
13779 imgViewInfo.subresourceRange.layerCount = 1;
13780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13783 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13784 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013785 // Can't use depth format for view into color image - Expect INVALID_FORMAT
13786 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
13787 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13788 m_errorMonitor->VerifyFound();
13789 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13792 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13793 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013794 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
13795 // VIEW_CREATE_ERROR
13796 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
13797 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13798 m_errorMonitor->VerifyFound();
13799 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13800
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
13802 "differing formats but they must be "
13803 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013804 // TODO: Update framework to easily passing mutable flag into ImageObj init
13805 // For now just allowing image for this one test to not have memory bound
13806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13807 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060013808 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
13809 // VIEW_CREATE_ERROR
13810 VkImageCreateInfo mutImgInfo = image.create_info();
13811 VkImage mutImage;
13812 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013813 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060013814 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
13815 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
13816 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
13817 ASSERT_VK_SUCCESS(ret);
13818 imgViewInfo.image = mutImage;
13819 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13820 m_errorMonitor->VerifyFound();
13821 imgViewInfo.image = image.handle();
13822 vkDestroyImage(m_device->handle(), mutImage, NULL);
13823}
13824
13825TEST_F(VkLayerTest, MiscImageLayerTests) {
13826
13827 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
13828
13829 ASSERT_NO_FATAL_FAILURE(InitState());
13830
13831 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013832 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 -060013833 VK_IMAGE_TILING_OPTIMAL, 0);
13834 ASSERT_TRUE(image.initialized());
13835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060013837 vk_testing::Buffer buffer;
13838 VkMemoryPropertyFlags reqs = 0;
13839 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
13840 VkBufferImageCopy region = {};
13841 region.bufferRowLength = 128;
13842 region.bufferImageHeight = 128;
13843 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13844 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
13845 region.imageSubresource.layerCount = 0;
13846 region.imageExtent.height = 4;
13847 region.imageExtent.width = 4;
13848 region.imageExtent.depth = 1;
13849 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013850 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13851 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060013852 m_errorMonitor->VerifyFound();
13853 region.imageSubresource.layerCount = 1;
13854
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013855 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
13856 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
13857 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
13859 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13860 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013861 m_errorMonitor->VerifyFound();
13862
13863 // BufferOffset must be a multiple of 4
13864 // Introduce failure by setting bufferOffset to a value not divisible by 4
13865 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
13867 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13868 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013869 m_errorMonitor->VerifyFound();
13870
13871 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
13872 region.bufferOffset = 0;
13873 region.imageExtent.height = 128;
13874 region.imageExtent.width = 128;
13875 // Introduce failure by setting bufferRowLength > 0 but less than width
13876 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13878 "must be zero or greater-than-or-equal-to imageExtent.width");
13879 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13880 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013881 m_errorMonitor->VerifyFound();
13882
13883 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
13884 region.bufferRowLength = 128;
13885 // Introduce failure by setting bufferRowHeight > 0 but less than height
13886 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13888 "must be zero or greater-than-or-equal-to imageExtent.height");
13889 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13890 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013891 m_errorMonitor->VerifyFound();
13892
13893 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
13895 "specify only COLOR or DEPTH or "
13896 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060013897 // Expect MISMATCHED_IMAGE_ASPECT
13898 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013899 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13900 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060013901 m_errorMonitor->VerifyFound();
13902 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13903
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13905 "If the format of srcImage is a depth, stencil, depth stencil or "
13906 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060013907 // Expect INVALID_FILTER
13908 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013909 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 -060013910 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013911 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 -060013912 VkImageBlit blitRegion = {};
13913 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13914 blitRegion.srcSubresource.baseArrayLayer = 0;
13915 blitRegion.srcSubresource.layerCount = 1;
13916 blitRegion.srcSubresource.mipLevel = 0;
13917 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13918 blitRegion.dstSubresource.baseArrayLayer = 0;
13919 blitRegion.dstSubresource.layerCount = 1;
13920 blitRegion.dstSubresource.mipLevel = 0;
13921
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013922 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
13923 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060013924 m_errorMonitor->VerifyFound();
13925
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060013926 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
13928 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
13929 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060013930 m_errorMonitor->VerifyFound();
13931
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060013933 VkImageMemoryBarrier img_barrier;
13934 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
13935 img_barrier.pNext = NULL;
13936 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
13937 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
13938 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
13939 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
13940 img_barrier.image = image.handle();
13941 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
13942 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
13943 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13944 img_barrier.subresourceRange.baseArrayLayer = 0;
13945 img_barrier.subresourceRange.baseMipLevel = 0;
13946 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
13947 img_barrier.subresourceRange.layerCount = 0;
13948 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013949 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
13950 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060013951 m_errorMonitor->VerifyFound();
13952 img_barrier.subresourceRange.layerCount = 1;
13953}
13954
13955TEST_F(VkLayerTest, ImageFormatLimits) {
13956
13957 TEST_DESCRIPTION("Exceed the limits of image format ");
13958
Cody Northropc31a84f2016-08-22 10:41:47 -060013959 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060013961 VkImageCreateInfo image_create_info = {};
13962 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13963 image_create_info.pNext = NULL;
13964 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13965 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13966 image_create_info.extent.width = 32;
13967 image_create_info.extent.height = 32;
13968 image_create_info.extent.depth = 1;
13969 image_create_info.mipLevels = 1;
13970 image_create_info.arrayLayers = 1;
13971 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13972 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13973 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13974 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
13975 image_create_info.flags = 0;
13976
13977 VkImage nullImg;
13978 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013979 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
13980 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060013981 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
13982 // Expect INVALID_FORMAT_LIMITS_VIOLATION
13983 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
13984 m_errorMonitor->VerifyFound();
13985 image_create_info.extent.depth = 1;
13986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060013988 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
13989 // Expect INVALID_FORMAT_LIMITS_VIOLATION
13990 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
13991 m_errorMonitor->VerifyFound();
13992 image_create_info.mipLevels = 1;
13993
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060013995 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
13996 // Expect INVALID_FORMAT_LIMITS_VIOLATION
13997 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
13998 m_errorMonitor->VerifyFound();
13999 image_create_info.arrayLayers = 1;
14000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014002 int samples = imgFmtProps.sampleCounts >> 1;
14003 image_create_info.samples = (VkSampleCountFlagBits)samples;
14004 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14005 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14006 m_errorMonitor->VerifyFound();
14007 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14008
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14010 "VK_IMAGE_LAYOUT_UNDEFINED or "
14011 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014012 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14013 // Expect INVALID_LAYOUT
14014 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14015 m_errorMonitor->VerifyFound();
14016 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14017}
14018
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014019TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14020
14021 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014023
14024 ASSERT_NO_FATAL_FAILURE(InitState());
14025
14026 VkImageObj src_image(m_device);
14027 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14028 VkImageObj dst_image(m_device);
14029 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14030
14031 BeginCommandBuffer();
14032 VkImageCopy copy_region;
14033 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14034 copy_region.srcSubresource.mipLevel = 0;
14035 copy_region.srcSubresource.baseArrayLayer = 0;
14036 copy_region.srcSubresource.layerCount = 0;
14037 copy_region.srcOffset.x = 0;
14038 copy_region.srcOffset.y = 0;
14039 copy_region.srcOffset.z = 0;
14040 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14041 copy_region.dstSubresource.mipLevel = 0;
14042 copy_region.dstSubresource.baseArrayLayer = 0;
14043 copy_region.dstSubresource.layerCount = 0;
14044 copy_region.dstOffset.x = 0;
14045 copy_region.dstOffset.y = 0;
14046 copy_region.dstOffset.z = 0;
14047 copy_region.extent.width = 64;
14048 copy_region.extent.height = 64;
14049 copy_region.extent.depth = 1;
14050 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14051 &copy_region);
14052 EndCommandBuffer();
14053
14054 m_errorMonitor->VerifyFound();
14055}
14056
14057TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14058
14059 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014061
14062 ASSERT_NO_FATAL_FAILURE(InitState());
14063
14064 VkImageObj src_image(m_device);
14065 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14066 VkImageObj dst_image(m_device);
14067 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14068
14069 BeginCommandBuffer();
14070 VkImageCopy copy_region;
14071 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14072 copy_region.srcSubresource.mipLevel = 0;
14073 copy_region.srcSubresource.baseArrayLayer = 0;
14074 copy_region.srcSubresource.layerCount = 0;
14075 copy_region.srcOffset.x = 0;
14076 copy_region.srcOffset.y = 0;
14077 copy_region.srcOffset.z = 0;
14078 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14079 copy_region.dstSubresource.mipLevel = 0;
14080 copy_region.dstSubresource.baseArrayLayer = 0;
14081 copy_region.dstSubresource.layerCount = 0;
14082 copy_region.dstOffset.x = 0;
14083 copy_region.dstOffset.y = 0;
14084 copy_region.dstOffset.z = 0;
14085 copy_region.extent.width = 64;
14086 copy_region.extent.height = 64;
14087 copy_region.extent.depth = 1;
14088 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14089 &copy_region);
14090 EndCommandBuffer();
14091
14092 m_errorMonitor->VerifyFound();
14093}
14094
Karl Schultz6addd812016-02-02 17:17:23 -070014095TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014096 VkResult err;
14097 bool pass;
14098
14099 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14101 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014102
14103 ASSERT_NO_FATAL_FAILURE(InitState());
14104
14105 // Create two images of different types and try to copy between them
14106 VkImage srcImage;
14107 VkImage dstImage;
14108 VkDeviceMemory srcMem;
14109 VkDeviceMemory destMem;
14110 VkMemoryRequirements memReqs;
14111
14112 VkImageCreateInfo image_create_info = {};
14113 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14114 image_create_info.pNext = NULL;
14115 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14116 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14117 image_create_info.extent.width = 32;
14118 image_create_info.extent.height = 32;
14119 image_create_info.extent.depth = 1;
14120 image_create_info.mipLevels = 1;
14121 image_create_info.arrayLayers = 1;
14122 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14123 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14124 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14125 image_create_info.flags = 0;
14126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014127 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014128 ASSERT_VK_SUCCESS(err);
14129
14130 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14131 // Introduce failure by creating second image with a different-sized format.
14132 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014134 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014135 ASSERT_VK_SUCCESS(err);
14136
14137 // Allocate memory
14138 VkMemoryAllocateInfo memAlloc = {};
14139 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14140 memAlloc.pNext = NULL;
14141 memAlloc.allocationSize = 0;
14142 memAlloc.memoryTypeIndex = 0;
14143
14144 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14145 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014146 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014147 ASSERT_TRUE(pass);
14148 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14149 ASSERT_VK_SUCCESS(err);
14150
14151 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14152 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014153 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014154 ASSERT_TRUE(pass);
14155 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14156 ASSERT_VK_SUCCESS(err);
14157
14158 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14159 ASSERT_VK_SUCCESS(err);
14160 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14161 ASSERT_VK_SUCCESS(err);
14162
14163 BeginCommandBuffer();
14164 VkImageCopy copyRegion;
14165 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14166 copyRegion.srcSubresource.mipLevel = 0;
14167 copyRegion.srcSubresource.baseArrayLayer = 0;
14168 copyRegion.srcSubresource.layerCount = 0;
14169 copyRegion.srcOffset.x = 0;
14170 copyRegion.srcOffset.y = 0;
14171 copyRegion.srcOffset.z = 0;
14172 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14173 copyRegion.dstSubresource.mipLevel = 0;
14174 copyRegion.dstSubresource.baseArrayLayer = 0;
14175 copyRegion.dstSubresource.layerCount = 0;
14176 copyRegion.dstOffset.x = 0;
14177 copyRegion.dstOffset.y = 0;
14178 copyRegion.dstOffset.z = 0;
14179 copyRegion.extent.width = 1;
14180 copyRegion.extent.height = 1;
14181 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014182 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014183 EndCommandBuffer();
14184
14185 m_errorMonitor->VerifyFound();
14186
14187 vkDestroyImage(m_device->device(), srcImage, NULL);
14188 vkDestroyImage(m_device->device(), dstImage, NULL);
14189 vkFreeMemory(m_device->device(), srcMem, NULL);
14190 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014191}
14192
Karl Schultz6addd812016-02-02 17:17:23 -070014193TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14194 VkResult err;
14195 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014196
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014197 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14199 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014200
Mike Stroyana3082432015-09-25 13:39:21 -060014201 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014202
14203 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014204 VkImage srcImage;
14205 VkImage dstImage;
14206 VkDeviceMemory srcMem;
14207 VkDeviceMemory destMem;
14208 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014209
14210 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014211 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14212 image_create_info.pNext = NULL;
14213 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14214 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14215 image_create_info.extent.width = 32;
14216 image_create_info.extent.height = 32;
14217 image_create_info.extent.depth = 1;
14218 image_create_info.mipLevels = 1;
14219 image_create_info.arrayLayers = 1;
14220 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14221 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14222 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14223 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014225 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014226 ASSERT_VK_SUCCESS(err);
14227
Karl Schultzbdb75952016-04-19 11:36:49 -060014228 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14229
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014230 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014231 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014232 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014233 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014235 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014236 ASSERT_VK_SUCCESS(err);
14237
14238 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014239 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014240 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14241 memAlloc.pNext = NULL;
14242 memAlloc.allocationSize = 0;
14243 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014244
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014245 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014246 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014247 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014248 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014249 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014250 ASSERT_VK_SUCCESS(err);
14251
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014252 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014253 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014254 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014255 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014256 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014257 ASSERT_VK_SUCCESS(err);
14258
14259 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14260 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014261 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014262 ASSERT_VK_SUCCESS(err);
14263
14264 BeginCommandBuffer();
14265 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014266 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014267 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014268 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014269 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014270 copyRegion.srcOffset.x = 0;
14271 copyRegion.srcOffset.y = 0;
14272 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014273 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014274 copyRegion.dstSubresource.mipLevel = 0;
14275 copyRegion.dstSubresource.baseArrayLayer = 0;
14276 copyRegion.dstSubresource.layerCount = 0;
14277 copyRegion.dstOffset.x = 0;
14278 copyRegion.dstOffset.y = 0;
14279 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014280 copyRegion.extent.width = 1;
14281 copyRegion.extent.height = 1;
14282 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014283 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014284 EndCommandBuffer();
14285
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014286 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014287
Chia-I Wuf7458c52015-10-26 21:10:41 +080014288 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014289 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014290 vkFreeMemory(m_device->device(), srcMem, NULL);
14291 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014292}
14293
Karl Schultz6addd812016-02-02 17:17:23 -070014294TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14295 VkResult err;
14296 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14299 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014300
Mike Stroyana3082432015-09-25 13:39:21 -060014301 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014302
14303 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014304 VkImage srcImage;
14305 VkImage dstImage;
14306 VkDeviceMemory srcMem;
14307 VkDeviceMemory destMem;
14308 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014309
14310 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014311 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14312 image_create_info.pNext = NULL;
14313 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14314 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14315 image_create_info.extent.width = 32;
14316 image_create_info.extent.height = 1;
14317 image_create_info.extent.depth = 1;
14318 image_create_info.mipLevels = 1;
14319 image_create_info.arrayLayers = 1;
14320 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14321 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14322 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14323 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014325 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014326 ASSERT_VK_SUCCESS(err);
14327
Karl Schultz6addd812016-02-02 17:17:23 -070014328 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014330 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014331 ASSERT_VK_SUCCESS(err);
14332
14333 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014334 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014335 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14336 memAlloc.pNext = NULL;
14337 memAlloc.allocationSize = 0;
14338 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014339
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014340 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014341 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014342 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014343 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014344 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014345 ASSERT_VK_SUCCESS(err);
14346
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014347 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014348 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014349 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014350 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014351 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014352 ASSERT_VK_SUCCESS(err);
14353
14354 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14355 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014356 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014357 ASSERT_VK_SUCCESS(err);
14358
14359 BeginCommandBuffer();
14360 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014361 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14362 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014363 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014364 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014365 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014366 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014367 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014368 resolveRegion.srcOffset.x = 0;
14369 resolveRegion.srcOffset.y = 0;
14370 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014371 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014372 resolveRegion.dstSubresource.mipLevel = 0;
14373 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014374 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014375 resolveRegion.dstOffset.x = 0;
14376 resolveRegion.dstOffset.y = 0;
14377 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014378 resolveRegion.extent.width = 1;
14379 resolveRegion.extent.height = 1;
14380 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014381 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014382 EndCommandBuffer();
14383
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014384 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014385
Chia-I Wuf7458c52015-10-26 21:10:41 +080014386 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014387 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014388 vkFreeMemory(m_device->device(), srcMem, NULL);
14389 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014390}
14391
Karl Schultz6addd812016-02-02 17:17:23 -070014392TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14393 VkResult err;
14394 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014395
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14397 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014398
Mike Stroyana3082432015-09-25 13:39:21 -060014399 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014400
Chris Forbesa7530692016-05-08 12:35:39 +120014401 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014402 VkImage srcImage;
14403 VkImage dstImage;
14404 VkDeviceMemory srcMem;
14405 VkDeviceMemory destMem;
14406 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014407
14408 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014409 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14410 image_create_info.pNext = NULL;
14411 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14412 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14413 image_create_info.extent.width = 32;
14414 image_create_info.extent.height = 1;
14415 image_create_info.extent.depth = 1;
14416 image_create_info.mipLevels = 1;
14417 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014418 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014419 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14420 // Note: Some implementations expect color attachment usage for any
14421 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014422 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014423 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014424
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014425 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014426 ASSERT_VK_SUCCESS(err);
14427
Karl Schultz6addd812016-02-02 17:17:23 -070014428 // Note: Some implementations expect color attachment usage for any
14429 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014430 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014432 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014433 ASSERT_VK_SUCCESS(err);
14434
14435 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014436 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014437 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14438 memAlloc.pNext = NULL;
14439 memAlloc.allocationSize = 0;
14440 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014441
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014442 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014443 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014444 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014445 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014446 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014447 ASSERT_VK_SUCCESS(err);
14448
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014449 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014450 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014451 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014452 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014453 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014454 ASSERT_VK_SUCCESS(err);
14455
14456 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14457 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014458 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014459 ASSERT_VK_SUCCESS(err);
14460
14461 BeginCommandBuffer();
14462 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014463 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14464 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014465 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014466 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014467 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014468 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014469 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014470 resolveRegion.srcOffset.x = 0;
14471 resolveRegion.srcOffset.y = 0;
14472 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014473 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014474 resolveRegion.dstSubresource.mipLevel = 0;
14475 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014476 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014477 resolveRegion.dstOffset.x = 0;
14478 resolveRegion.dstOffset.y = 0;
14479 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014480 resolveRegion.extent.width = 1;
14481 resolveRegion.extent.height = 1;
14482 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014483 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014484 EndCommandBuffer();
14485
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014486 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014487
Chia-I Wuf7458c52015-10-26 21:10:41 +080014488 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014489 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014490 vkFreeMemory(m_device->device(), srcMem, NULL);
14491 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014492}
14493
Karl Schultz6addd812016-02-02 17:17:23 -070014494TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14495 VkResult err;
14496 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014497
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14499 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014500
Mike Stroyana3082432015-09-25 13:39:21 -060014501 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014502
14503 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014504 VkImage srcImage;
14505 VkImage dstImage;
14506 VkDeviceMemory srcMem;
14507 VkDeviceMemory destMem;
14508 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014509
14510 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014511 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14512 image_create_info.pNext = NULL;
14513 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14514 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14515 image_create_info.extent.width = 32;
14516 image_create_info.extent.height = 1;
14517 image_create_info.extent.depth = 1;
14518 image_create_info.mipLevels = 1;
14519 image_create_info.arrayLayers = 1;
14520 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14521 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14522 // Note: Some implementations expect color attachment usage for any
14523 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014524 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014525 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014527 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014528 ASSERT_VK_SUCCESS(err);
14529
Karl Schultz6addd812016-02-02 17:17:23 -070014530 // Set format to something other than source image
14531 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14532 // Note: Some implementations expect color attachment usage for any
14533 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014534 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014535 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014536
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014537 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014538 ASSERT_VK_SUCCESS(err);
14539
14540 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014541 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014542 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14543 memAlloc.pNext = NULL;
14544 memAlloc.allocationSize = 0;
14545 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014546
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014547 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014548 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014549 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014550 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014551 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014552 ASSERT_VK_SUCCESS(err);
14553
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014554 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014555 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014556 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014557 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014558 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014559 ASSERT_VK_SUCCESS(err);
14560
14561 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14562 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014563 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014564 ASSERT_VK_SUCCESS(err);
14565
14566 BeginCommandBuffer();
14567 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014568 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14569 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014570 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014571 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014572 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014573 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014574 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014575 resolveRegion.srcOffset.x = 0;
14576 resolveRegion.srcOffset.y = 0;
14577 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014578 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014579 resolveRegion.dstSubresource.mipLevel = 0;
14580 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014581 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014582 resolveRegion.dstOffset.x = 0;
14583 resolveRegion.dstOffset.y = 0;
14584 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014585 resolveRegion.extent.width = 1;
14586 resolveRegion.extent.height = 1;
14587 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014588 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014589 EndCommandBuffer();
14590
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014591 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014592
Chia-I Wuf7458c52015-10-26 21:10:41 +080014593 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014594 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014595 vkFreeMemory(m_device->device(), srcMem, NULL);
14596 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014597}
14598
Karl Schultz6addd812016-02-02 17:17:23 -070014599TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14600 VkResult err;
14601 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014602
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14604 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014605
Mike Stroyana3082432015-09-25 13:39:21 -060014606 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014607
14608 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014609 VkImage srcImage;
14610 VkImage dstImage;
14611 VkDeviceMemory srcMem;
14612 VkDeviceMemory destMem;
14613 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014614
14615 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014616 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14617 image_create_info.pNext = NULL;
14618 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14619 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14620 image_create_info.extent.width = 32;
14621 image_create_info.extent.height = 1;
14622 image_create_info.extent.depth = 1;
14623 image_create_info.mipLevels = 1;
14624 image_create_info.arrayLayers = 1;
14625 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14626 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14627 // Note: Some implementations expect color attachment usage for any
14628 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014629 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014630 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014631
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014632 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014633 ASSERT_VK_SUCCESS(err);
14634
Karl Schultz6addd812016-02-02 17:17:23 -070014635 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14636 // Note: Some implementations expect color attachment usage for any
14637 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014638 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014639 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014640
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014641 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014642 ASSERT_VK_SUCCESS(err);
14643
14644 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014645 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014646 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14647 memAlloc.pNext = NULL;
14648 memAlloc.allocationSize = 0;
14649 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014650
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014651 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014652 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014653 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014654 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014655 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014656 ASSERT_VK_SUCCESS(err);
14657
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014658 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014659 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014660 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014661 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014662 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014663 ASSERT_VK_SUCCESS(err);
14664
14665 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14666 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014667 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014668 ASSERT_VK_SUCCESS(err);
14669
14670 BeginCommandBuffer();
14671 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014672 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14673 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014674 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014675 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014676 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014677 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014678 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014679 resolveRegion.srcOffset.x = 0;
14680 resolveRegion.srcOffset.y = 0;
14681 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014682 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014683 resolveRegion.dstSubresource.mipLevel = 0;
14684 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014685 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014686 resolveRegion.dstOffset.x = 0;
14687 resolveRegion.dstOffset.y = 0;
14688 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014689 resolveRegion.extent.width = 1;
14690 resolveRegion.extent.height = 1;
14691 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014692 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014693 EndCommandBuffer();
14694
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014695 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014696
Chia-I Wuf7458c52015-10-26 21:10:41 +080014697 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014698 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014699 vkFreeMemory(m_device->device(), srcMem, NULL);
14700 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014701}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014702
Karl Schultz6addd812016-02-02 17:17:23 -070014703TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014704 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014705 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14706 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014707 // The image format check comes 2nd in validation so we trigger it first,
14708 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014709 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014710
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14712 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014713
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014714 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014715
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014716 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014717 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14718 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014719
14720 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014721 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14722 ds_pool_ci.pNext = NULL;
14723 ds_pool_ci.maxSets = 1;
14724 ds_pool_ci.poolSizeCount = 1;
14725 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014726
14727 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014728 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014729 ASSERT_VK_SUCCESS(err);
14730
14731 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014732 dsl_binding.binding = 0;
14733 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14734 dsl_binding.descriptorCount = 1;
14735 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14736 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014737
14738 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014739 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14740 ds_layout_ci.pNext = NULL;
14741 ds_layout_ci.bindingCount = 1;
14742 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014743 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014744 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014745 ASSERT_VK_SUCCESS(err);
14746
14747 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014748 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080014749 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070014750 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014751 alloc_info.descriptorPool = ds_pool;
14752 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014753 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014754 ASSERT_VK_SUCCESS(err);
14755
Karl Schultz6addd812016-02-02 17:17:23 -070014756 VkImage image_bad;
14757 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014758 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060014759 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014760 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070014761 const int32_t tex_width = 32;
14762 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014763
14764 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014765 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14766 image_create_info.pNext = NULL;
14767 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14768 image_create_info.format = tex_format_bad;
14769 image_create_info.extent.width = tex_width;
14770 image_create_info.extent.height = tex_height;
14771 image_create_info.extent.depth = 1;
14772 image_create_info.mipLevels = 1;
14773 image_create_info.arrayLayers = 1;
14774 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14775 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014776 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014777 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014778
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014779 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014780 ASSERT_VK_SUCCESS(err);
14781 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014782 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14783 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014784 ASSERT_VK_SUCCESS(err);
14785
14786 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014787 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14788 image_view_create_info.image = image_bad;
14789 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14790 image_view_create_info.format = tex_format_bad;
14791 image_view_create_info.subresourceRange.baseArrayLayer = 0;
14792 image_view_create_info.subresourceRange.baseMipLevel = 0;
14793 image_view_create_info.subresourceRange.layerCount = 1;
14794 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014795 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014796
14797 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014798 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014799
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014800 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014801
Chia-I Wuf7458c52015-10-26 21:10:41 +080014802 vkDestroyImage(m_device->device(), image_bad, NULL);
14803 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014804 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
14805 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014806}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014807
14808TEST_F(VkLayerTest, ClearImageErrors) {
14809 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
14810 "ClearDepthStencilImage with a color image.");
14811
14812 ASSERT_NO_FATAL_FAILURE(InitState());
14813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14814
14815 // Renderpass is started here so end it as Clear cmds can't be in renderpass
14816 BeginCommandBuffer();
14817 m_commandBuffer->EndRenderPass();
14818
14819 // Color image
14820 VkClearColorValue clear_color;
14821 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
14822 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
14823 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
14824 const int32_t img_width = 32;
14825 const int32_t img_height = 32;
14826 VkImageCreateInfo image_create_info = {};
14827 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14828 image_create_info.pNext = NULL;
14829 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14830 image_create_info.format = color_format;
14831 image_create_info.extent.width = img_width;
14832 image_create_info.extent.height = img_height;
14833 image_create_info.extent.depth = 1;
14834 image_create_info.mipLevels = 1;
14835 image_create_info.arrayLayers = 1;
14836 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14837 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14838 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14839
14840 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014841 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014842
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014843 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014844
14845 // Depth/Stencil image
14846 VkClearDepthStencilValue clear_value = {0};
14847 reqs = 0; // don't need HOST_VISIBLE DS image
14848 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
14849 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
14850 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
14851 ds_image_create_info.extent.width = 64;
14852 ds_image_create_info.extent.height = 64;
14853 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14854 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
14855
14856 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014857 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014858
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014859 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 -060014860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014862
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014863 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014864 &color_range);
14865
14866 m_errorMonitor->VerifyFound();
14867
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
14869 "image created without "
14870 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060014871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014872 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060014873 &color_range);
14874
14875 m_errorMonitor->VerifyFound();
14876
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014877 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14879 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014880
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014881 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
14882 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014883
14884 m_errorMonitor->VerifyFound();
14885}
Tobin Ehliscde08892015-09-22 10:11:37 -060014886#endif // IMAGE_TESTS
14887
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060014888
14889// WSI Enabled Tests
14890//
14891TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
14892
14893#if defined(VK_USE_PLATFORM_XCB_KHR)
14894 VkSurfaceKHR surface = VK_NULL_HANDLE;
14895
14896 VkResult err;
14897 bool pass;
14898 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
14899 VkSwapchainCreateInfoKHR swapchain_create_info = {};
14900 // uint32_t swapchain_image_count = 0;
14901 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
14902 // uint32_t image_index = 0;
14903 // VkPresentInfoKHR present_info = {};
14904
14905 ASSERT_NO_FATAL_FAILURE(InitState());
14906
14907 // Use the create function from one of the VK_KHR_*_surface extension in
14908 // order to create a surface, testing all known errors in the process,
14909 // before successfully creating a surface:
14910 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
14911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
14912 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
14913 pass = (err != VK_SUCCESS);
14914 ASSERT_TRUE(pass);
14915 m_errorMonitor->VerifyFound();
14916
14917 // Next, try to create a surface with the wrong
14918 // VkXcbSurfaceCreateInfoKHR::sType:
14919 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
14920 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
14921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
14922 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
14923 pass = (err != VK_SUCCESS);
14924 ASSERT_TRUE(pass);
14925 m_errorMonitor->VerifyFound();
14926
14927 // Create a native window, and then correctly create a surface:
14928 xcb_connection_t *connection;
14929 xcb_screen_t *screen;
14930 xcb_window_t xcb_window;
14931 xcb_intern_atom_reply_t *atom_wm_delete_window;
14932
14933 const xcb_setup_t *setup;
14934 xcb_screen_iterator_t iter;
14935 int scr;
14936 uint32_t value_mask, value_list[32];
14937 int width = 1;
14938 int height = 1;
14939
14940 connection = xcb_connect(NULL, &scr);
14941 ASSERT_TRUE(connection != NULL);
14942 setup = xcb_get_setup(connection);
14943 iter = xcb_setup_roots_iterator(setup);
14944 while (scr-- > 0)
14945 xcb_screen_next(&iter);
14946 screen = iter.data;
14947
14948 xcb_window = xcb_generate_id(connection);
14949
14950 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
14951 value_list[0] = screen->black_pixel;
14952 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
14953
14954 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
14955 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
14956
14957 /* Magic code that will send notification when window is destroyed */
14958 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
14959 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
14960
14961 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
14962 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
14963 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
14964 free(reply);
14965
14966 xcb_map_window(connection, xcb_window);
14967
14968 // Force the x/y coordinates to 100,100 results are identical in consecutive
14969 // runs
14970 const uint32_t coords[] = { 100, 100 };
14971 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
14972
14973 // Finally, try to correctly create a surface:
14974 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
14975 xcb_create_info.pNext = NULL;
14976 xcb_create_info.flags = 0;
14977 xcb_create_info.connection = connection;
14978 xcb_create_info.window = xcb_window;
14979 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
14980 pass = (err == VK_SUCCESS);
14981 ASSERT_TRUE(pass);
14982
14983 // Check if surface supports presentation:
14984
14985 // 1st, do so without having queried the queue families:
14986 VkBool32 supported = false;
14987 // TODO: Get the following error to come out:
14988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14989 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
14990 "function");
14991 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
14992 pass = (err != VK_SUCCESS);
14993 // ASSERT_TRUE(pass);
14994 // m_errorMonitor->VerifyFound();
14995
14996 // Next, query a queue family index that's too large:
14997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
14998 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
14999 pass = (err != VK_SUCCESS);
15000 ASSERT_TRUE(pass);
15001 m_errorMonitor->VerifyFound();
15002
15003 // Finally, do so correctly:
15004 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15005 // SUPPORTED
15006 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15007 pass = (err == VK_SUCCESS);
15008 ASSERT_TRUE(pass);
15009
15010 // Before proceeding, try to create a swapchain without having called
15011 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15012 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15013 swapchain_create_info.pNext = NULL;
15014 swapchain_create_info.flags = 0;
15015 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15016 swapchain_create_info.surface = surface;
15017 swapchain_create_info.imageArrayLayers = 1;
15018 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15019 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15021 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15022 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15023 pass = (err != VK_SUCCESS);
15024 ASSERT_TRUE(pass);
15025 m_errorMonitor->VerifyFound();
15026
15027 // Get the surface capabilities:
15028 VkSurfaceCapabilitiesKHR surface_capabilities;
15029
15030 // Do so correctly (only error logged by this entrypoint is if the
15031 // extension isn't enabled):
15032 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15033 pass = (err == VK_SUCCESS);
15034 ASSERT_TRUE(pass);
15035
15036 // Get the surface formats:
15037 uint32_t surface_format_count;
15038
15039 // First, try without a pointer to surface_format_count:
15040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15041 "specified as NULL");
15042 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15043 pass = (err == VK_SUCCESS);
15044 ASSERT_TRUE(pass);
15045 m_errorMonitor->VerifyFound();
15046
15047 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15048 // correctly done a 1st try (to get the count):
15049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15050 surface_format_count = 0;
15051 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15052 pass = (err == VK_SUCCESS);
15053 ASSERT_TRUE(pass);
15054 m_errorMonitor->VerifyFound();
15055
15056 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15057 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15058 pass = (err == VK_SUCCESS);
15059 ASSERT_TRUE(pass);
15060
15061 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15062 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15063
15064 // Next, do a 2nd try with surface_format_count being set too high:
15065 surface_format_count += 5;
15066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15067 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15068 pass = (err == VK_SUCCESS);
15069 ASSERT_TRUE(pass);
15070 m_errorMonitor->VerifyFound();
15071
15072 // Finally, do a correct 1st and 2nd try:
15073 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15074 pass = (err == VK_SUCCESS);
15075 ASSERT_TRUE(pass);
15076 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15077 pass = (err == VK_SUCCESS);
15078 ASSERT_TRUE(pass);
15079
15080 // Get the surface present modes:
15081 uint32_t surface_present_mode_count;
15082
15083 // First, try without a pointer to surface_format_count:
15084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15085 "specified as NULL");
15086
15087 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15088 pass = (err == VK_SUCCESS);
15089 ASSERT_TRUE(pass);
15090 m_errorMonitor->VerifyFound();
15091
15092 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15093 // correctly done a 1st try (to get the count):
15094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15095 surface_present_mode_count = 0;
15096 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15097 (VkPresentModeKHR *)&surface_present_mode_count);
15098 pass = (err == VK_SUCCESS);
15099 ASSERT_TRUE(pass);
15100 m_errorMonitor->VerifyFound();
15101
15102 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15103 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15104 pass = (err == VK_SUCCESS);
15105 ASSERT_TRUE(pass);
15106
15107 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15108 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15109
15110 // Next, do a 2nd try with surface_format_count being set too high:
15111 surface_present_mode_count += 5;
15112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15113 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15114 pass = (err == VK_SUCCESS);
15115 ASSERT_TRUE(pass);
15116 m_errorMonitor->VerifyFound();
15117
15118 // Finally, do a correct 1st and 2nd try:
15119 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15120 pass = (err == VK_SUCCESS);
15121 ASSERT_TRUE(pass);
15122 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15123 pass = (err == VK_SUCCESS);
15124 ASSERT_TRUE(pass);
15125
15126 // Create a swapchain:
15127
15128 // First, try without a pointer to swapchain_create_info:
15129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15130 "specified as NULL");
15131
15132 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15133 pass = (err != VK_SUCCESS);
15134 ASSERT_TRUE(pass);
15135 m_errorMonitor->VerifyFound();
15136
15137 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15138 // sType:
15139 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15141
15142 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15143 pass = (err != VK_SUCCESS);
15144 ASSERT_TRUE(pass);
15145 m_errorMonitor->VerifyFound();
15146
15147 // Next, call with a NULL swapchain pointer:
15148 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15149 swapchain_create_info.pNext = NULL;
15150 swapchain_create_info.flags = 0;
15151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15152 "specified as NULL");
15153
15154 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15155 pass = (err != VK_SUCCESS);
15156 ASSERT_TRUE(pass);
15157 m_errorMonitor->VerifyFound();
15158
15159 // TODO: Enhance swapchain layer so that
15160 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15161
15162 // Next, call with a queue family index that's too large:
15163 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15164 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15165 swapchain_create_info.queueFamilyIndexCount = 2;
15166 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15168 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15169 pass = (err != VK_SUCCESS);
15170 ASSERT_TRUE(pass);
15171 m_errorMonitor->VerifyFound();
15172
15173 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15174 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15175 swapchain_create_info.queueFamilyIndexCount = 1;
15176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15177 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15178 "pCreateInfo->pQueueFamilyIndices).");
15179 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15180 pass = (err != VK_SUCCESS);
15181 ASSERT_TRUE(pass);
15182 m_errorMonitor->VerifyFound();
15183
15184 // Next, call with an invalid imageSharingMode:
15185 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15186 swapchain_create_info.queueFamilyIndexCount = 1;
15187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15188 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15189 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15190 pass = (err != VK_SUCCESS);
15191 ASSERT_TRUE(pass);
15192 m_errorMonitor->VerifyFound();
15193 // Fix for the future:
15194 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15195 // SUPPORTED
15196 swapchain_create_info.queueFamilyIndexCount = 0;
15197 queueFamilyIndex[0] = 0;
15198 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15199
15200 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15201 // Get the images from a swapchain:
15202 // Acquire an image from a swapchain:
15203 // Present an image to a swapchain:
15204 // Destroy the swapchain:
15205
15206 // TODOs:
15207 //
15208 // - Try destroying the device without first destroying the swapchain
15209 //
15210 // - Try destroying the device without first destroying the surface
15211 //
15212 // - Try destroying the surface without first destroying the swapchain
15213
15214 // Destroy the surface:
15215 vkDestroySurfaceKHR(instance(), surface, NULL);
15216
15217 // Tear down the window:
15218 xcb_destroy_window(connection, xcb_window);
15219 xcb_disconnect(connection);
15220
15221#else // VK_USE_PLATFORM_XCB_KHR
15222 return;
15223#endif // VK_USE_PLATFORM_XCB_KHR
15224}
15225
15226//
15227// POSITIVE VALIDATION TESTS
15228//
15229// These tests do not expect to encounter ANY validation errors pass only if this is true
15230
15231// This is a positive test. No failures are expected.
15232TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15233 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15234 "is ignoring VkWriteDescriptorSet members that are not "
15235 "related to the descriptor type specified by "
15236 "VkWriteDescriptorSet::descriptorType. Correct "
15237 "validation behavior will result in the test running to "
15238 "completion without validation errors.");
15239
15240 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15241
15242 ASSERT_NO_FATAL_FAILURE(InitState());
15243
15244 // Image Case
15245 {
15246 m_errorMonitor->ExpectSuccess();
15247
15248 VkImage image;
15249 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15250 const int32_t tex_width = 32;
15251 const int32_t tex_height = 32;
15252 VkImageCreateInfo image_create_info = {};
15253 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15254 image_create_info.pNext = NULL;
15255 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15256 image_create_info.format = tex_format;
15257 image_create_info.extent.width = tex_width;
15258 image_create_info.extent.height = tex_height;
15259 image_create_info.extent.depth = 1;
15260 image_create_info.mipLevels = 1;
15261 image_create_info.arrayLayers = 1;
15262 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15263 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15264 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15265 image_create_info.flags = 0;
15266 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15267 ASSERT_VK_SUCCESS(err);
15268
15269 VkMemoryRequirements memory_reqs;
15270 VkDeviceMemory image_memory;
15271 bool pass;
15272 VkMemoryAllocateInfo memory_info = {};
15273 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15274 memory_info.pNext = NULL;
15275 memory_info.allocationSize = 0;
15276 memory_info.memoryTypeIndex = 0;
15277 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15278 memory_info.allocationSize = memory_reqs.size;
15279 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15280 ASSERT_TRUE(pass);
15281 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15282 ASSERT_VK_SUCCESS(err);
15283 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15284 ASSERT_VK_SUCCESS(err);
15285
15286 VkImageViewCreateInfo image_view_create_info = {};
15287 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15288 image_view_create_info.image = image;
15289 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15290 image_view_create_info.format = tex_format;
15291 image_view_create_info.subresourceRange.layerCount = 1;
15292 image_view_create_info.subresourceRange.baseMipLevel = 0;
15293 image_view_create_info.subresourceRange.levelCount = 1;
15294 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15295
15296 VkImageView view;
15297 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15298 ASSERT_VK_SUCCESS(err);
15299
15300 VkDescriptorPoolSize ds_type_count = {};
15301 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15302 ds_type_count.descriptorCount = 1;
15303
15304 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15305 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15306 ds_pool_ci.pNext = NULL;
15307 ds_pool_ci.maxSets = 1;
15308 ds_pool_ci.poolSizeCount = 1;
15309 ds_pool_ci.pPoolSizes = &ds_type_count;
15310
15311 VkDescriptorPool ds_pool;
15312 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15313 ASSERT_VK_SUCCESS(err);
15314
15315 VkDescriptorSetLayoutBinding dsl_binding = {};
15316 dsl_binding.binding = 0;
15317 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15318 dsl_binding.descriptorCount = 1;
15319 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15320 dsl_binding.pImmutableSamplers = NULL;
15321
15322 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15323 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15324 ds_layout_ci.pNext = NULL;
15325 ds_layout_ci.bindingCount = 1;
15326 ds_layout_ci.pBindings = &dsl_binding;
15327 VkDescriptorSetLayout ds_layout;
15328 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15329 ASSERT_VK_SUCCESS(err);
15330
15331 VkDescriptorSet descriptor_set;
15332 VkDescriptorSetAllocateInfo alloc_info = {};
15333 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15334 alloc_info.descriptorSetCount = 1;
15335 alloc_info.descriptorPool = ds_pool;
15336 alloc_info.pSetLayouts = &ds_layout;
15337 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15338 ASSERT_VK_SUCCESS(err);
15339
15340 VkDescriptorImageInfo image_info = {};
15341 image_info.imageView = view;
15342 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15343
15344 VkWriteDescriptorSet descriptor_write;
15345 memset(&descriptor_write, 0, sizeof(descriptor_write));
15346 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15347 descriptor_write.dstSet = descriptor_set;
15348 descriptor_write.dstBinding = 0;
15349 descriptor_write.descriptorCount = 1;
15350 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15351 descriptor_write.pImageInfo = &image_info;
15352
15353 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15354 // be
15355 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15356 // This will most likely produce a crash if the parameter_validation
15357 // layer
15358 // does not correctly ignore pBufferInfo.
15359 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15360 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15361
15362 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15363
15364 m_errorMonitor->VerifyNotFound();
15365
15366 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15367 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15368 vkDestroyImageView(m_device->device(), view, NULL);
15369 vkDestroyImage(m_device->device(), image, NULL);
15370 vkFreeMemory(m_device->device(), image_memory, NULL);
15371 }
15372
15373 // Buffer Case
15374 {
15375 m_errorMonitor->ExpectSuccess();
15376
15377 VkBuffer buffer;
15378 uint32_t queue_family_index = 0;
15379 VkBufferCreateInfo buffer_create_info = {};
15380 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15381 buffer_create_info.size = 1024;
15382 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15383 buffer_create_info.queueFamilyIndexCount = 1;
15384 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15385
15386 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15387 ASSERT_VK_SUCCESS(err);
15388
15389 VkMemoryRequirements memory_reqs;
15390 VkDeviceMemory buffer_memory;
15391 bool pass;
15392 VkMemoryAllocateInfo memory_info = {};
15393 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15394 memory_info.pNext = NULL;
15395 memory_info.allocationSize = 0;
15396 memory_info.memoryTypeIndex = 0;
15397
15398 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15399 memory_info.allocationSize = memory_reqs.size;
15400 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15401 ASSERT_TRUE(pass);
15402
15403 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15404 ASSERT_VK_SUCCESS(err);
15405 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15406 ASSERT_VK_SUCCESS(err);
15407
15408 VkDescriptorPoolSize ds_type_count = {};
15409 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15410 ds_type_count.descriptorCount = 1;
15411
15412 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15413 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15414 ds_pool_ci.pNext = NULL;
15415 ds_pool_ci.maxSets = 1;
15416 ds_pool_ci.poolSizeCount = 1;
15417 ds_pool_ci.pPoolSizes = &ds_type_count;
15418
15419 VkDescriptorPool ds_pool;
15420 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15421 ASSERT_VK_SUCCESS(err);
15422
15423 VkDescriptorSetLayoutBinding dsl_binding = {};
15424 dsl_binding.binding = 0;
15425 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15426 dsl_binding.descriptorCount = 1;
15427 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15428 dsl_binding.pImmutableSamplers = NULL;
15429
15430 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15431 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15432 ds_layout_ci.pNext = NULL;
15433 ds_layout_ci.bindingCount = 1;
15434 ds_layout_ci.pBindings = &dsl_binding;
15435 VkDescriptorSetLayout ds_layout;
15436 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15437 ASSERT_VK_SUCCESS(err);
15438
15439 VkDescriptorSet descriptor_set;
15440 VkDescriptorSetAllocateInfo alloc_info = {};
15441 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15442 alloc_info.descriptorSetCount = 1;
15443 alloc_info.descriptorPool = ds_pool;
15444 alloc_info.pSetLayouts = &ds_layout;
15445 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15446 ASSERT_VK_SUCCESS(err);
15447
15448 VkDescriptorBufferInfo buffer_info = {};
15449 buffer_info.buffer = buffer;
15450 buffer_info.offset = 0;
15451 buffer_info.range = 1024;
15452
15453 VkWriteDescriptorSet descriptor_write;
15454 memset(&descriptor_write, 0, sizeof(descriptor_write));
15455 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15456 descriptor_write.dstSet = descriptor_set;
15457 descriptor_write.dstBinding = 0;
15458 descriptor_write.descriptorCount = 1;
15459 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15460 descriptor_write.pBufferInfo = &buffer_info;
15461
15462 // Set pImageInfo and pTexelBufferView to invalid values, which should
15463 // be
15464 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15465 // This will most likely produce a crash if the parameter_validation
15466 // layer
15467 // does not correctly ignore pImageInfo.
15468 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15469 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15470
15471 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15472
15473 m_errorMonitor->VerifyNotFound();
15474
15475 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15476 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15477 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15478 vkDestroyBuffer(m_device->device(), buffer, NULL);
15479 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15480 }
15481
15482 // Texel Buffer Case
15483 {
15484 m_errorMonitor->ExpectSuccess();
15485
15486 VkBuffer buffer;
15487 uint32_t queue_family_index = 0;
15488 VkBufferCreateInfo buffer_create_info = {};
15489 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15490 buffer_create_info.size = 1024;
15491 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15492 buffer_create_info.queueFamilyIndexCount = 1;
15493 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15494
15495 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15496 ASSERT_VK_SUCCESS(err);
15497
15498 VkMemoryRequirements memory_reqs;
15499 VkDeviceMemory buffer_memory;
15500 bool pass;
15501 VkMemoryAllocateInfo memory_info = {};
15502 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15503 memory_info.pNext = NULL;
15504 memory_info.allocationSize = 0;
15505 memory_info.memoryTypeIndex = 0;
15506
15507 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15508 memory_info.allocationSize = memory_reqs.size;
15509 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15510 ASSERT_TRUE(pass);
15511
15512 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15513 ASSERT_VK_SUCCESS(err);
15514 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15515 ASSERT_VK_SUCCESS(err);
15516
15517 VkBufferViewCreateInfo buff_view_ci = {};
15518 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15519 buff_view_ci.buffer = buffer;
15520 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15521 buff_view_ci.range = VK_WHOLE_SIZE;
15522 VkBufferView buffer_view;
15523 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15524
15525 VkDescriptorPoolSize ds_type_count = {};
15526 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15527 ds_type_count.descriptorCount = 1;
15528
15529 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15530 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15531 ds_pool_ci.pNext = NULL;
15532 ds_pool_ci.maxSets = 1;
15533 ds_pool_ci.poolSizeCount = 1;
15534 ds_pool_ci.pPoolSizes = &ds_type_count;
15535
15536 VkDescriptorPool ds_pool;
15537 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15538 ASSERT_VK_SUCCESS(err);
15539
15540 VkDescriptorSetLayoutBinding dsl_binding = {};
15541 dsl_binding.binding = 0;
15542 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15543 dsl_binding.descriptorCount = 1;
15544 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15545 dsl_binding.pImmutableSamplers = NULL;
15546
15547 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15548 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15549 ds_layout_ci.pNext = NULL;
15550 ds_layout_ci.bindingCount = 1;
15551 ds_layout_ci.pBindings = &dsl_binding;
15552 VkDescriptorSetLayout ds_layout;
15553 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15554 ASSERT_VK_SUCCESS(err);
15555
15556 VkDescriptorSet descriptor_set;
15557 VkDescriptorSetAllocateInfo alloc_info = {};
15558 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15559 alloc_info.descriptorSetCount = 1;
15560 alloc_info.descriptorPool = ds_pool;
15561 alloc_info.pSetLayouts = &ds_layout;
15562 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15563 ASSERT_VK_SUCCESS(err);
15564
15565 VkWriteDescriptorSet descriptor_write;
15566 memset(&descriptor_write, 0, sizeof(descriptor_write));
15567 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15568 descriptor_write.dstSet = descriptor_set;
15569 descriptor_write.dstBinding = 0;
15570 descriptor_write.descriptorCount = 1;
15571 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15572 descriptor_write.pTexelBufferView = &buffer_view;
15573
15574 // Set pImageInfo and pBufferInfo to invalid values, which should be
15575 // ignored for descriptorType ==
15576 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15577 // This will most likely produce a crash if the parameter_validation
15578 // layer
15579 // does not correctly ignore pImageInfo and pBufferInfo.
15580 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15581 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15582
15583 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15584
15585 m_errorMonitor->VerifyNotFound();
15586
15587 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15588 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15589 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15590 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15591 vkDestroyBuffer(m_device->device(), buffer, NULL);
15592 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15593 }
15594}
15595
Tobin Ehlisf7428442016-10-25 07:58:24 -060015596TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
15597 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
15598
15599 ASSERT_NO_FATAL_FAILURE(InitState());
15600 // Create layout where two binding #s are "1"
15601 static const uint32_t NUM_BINDINGS = 3;
15602 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15603 dsl_binding[0].binding = 1;
15604 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15605 dsl_binding[0].descriptorCount = 1;
15606 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15607 dsl_binding[0].pImmutableSamplers = NULL;
15608 dsl_binding[1].binding = 0;
15609 dsl_binding[1].descriptorCount = 1;
15610 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15611 dsl_binding[1].descriptorCount = 1;
15612 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15613 dsl_binding[1].pImmutableSamplers = NULL;
15614 dsl_binding[2].binding = 1; // Duplicate binding should cause error
15615 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15616 dsl_binding[2].descriptorCount = 1;
15617 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15618 dsl_binding[2].pImmutableSamplers = NULL;
15619
15620 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15621 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15622 ds_layout_ci.pNext = NULL;
15623 ds_layout_ci.bindingCount = NUM_BINDINGS;
15624 ds_layout_ci.pBindings = dsl_binding;
15625 VkDescriptorSetLayout ds_layout;
15626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
15627 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15628 m_errorMonitor->VerifyFound();
15629}
15630
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015631// This is a positive test. No failures are expected.
15632TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
15633 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
15634 VkResult err;
15635
15636 ASSERT_NO_FATAL_FAILURE(InitState());
15637 m_errorMonitor->ExpectSuccess();
15638 VkDescriptorPoolSize ds_type_count = {};
15639 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15640 ds_type_count.descriptorCount = 2;
15641
15642 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15643 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15644 ds_pool_ci.pNext = NULL;
15645 ds_pool_ci.maxSets = 1;
15646 ds_pool_ci.poolSizeCount = 1;
15647 ds_pool_ci.pPoolSizes = &ds_type_count;
15648
15649 VkDescriptorPool ds_pool;
15650 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15651 ASSERT_VK_SUCCESS(err);
15652
15653 // Create layout with two uniform buffer descriptors w/ empty binding between them
15654 static const uint32_t NUM_BINDINGS = 3;
15655 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15656 dsl_binding[0].binding = 0;
15657 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15658 dsl_binding[0].descriptorCount = 1;
15659 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
15660 dsl_binding[0].pImmutableSamplers = NULL;
15661 dsl_binding[1].binding = 1;
15662 dsl_binding[1].descriptorCount = 0; // empty binding
15663 dsl_binding[2].binding = 2;
15664 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15665 dsl_binding[2].descriptorCount = 1;
15666 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
15667 dsl_binding[2].pImmutableSamplers = NULL;
15668
15669 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15670 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15671 ds_layout_ci.pNext = NULL;
15672 ds_layout_ci.bindingCount = NUM_BINDINGS;
15673 ds_layout_ci.pBindings = dsl_binding;
15674 VkDescriptorSetLayout ds_layout;
15675 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15676 ASSERT_VK_SUCCESS(err);
15677
15678 VkDescriptorSet descriptor_set = {};
15679 VkDescriptorSetAllocateInfo alloc_info = {};
15680 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15681 alloc_info.descriptorSetCount = 1;
15682 alloc_info.descriptorPool = ds_pool;
15683 alloc_info.pSetLayouts = &ds_layout;
15684 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15685 ASSERT_VK_SUCCESS(err);
15686
15687 // Create a buffer to be used for update
15688 VkBufferCreateInfo buff_ci = {};
15689 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15690 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15691 buff_ci.size = 256;
15692 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15693 VkBuffer buffer;
15694 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
15695 ASSERT_VK_SUCCESS(err);
15696 // Have to bind memory to buffer before descriptor update
15697 VkMemoryAllocateInfo mem_alloc = {};
15698 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15699 mem_alloc.pNext = NULL;
15700 mem_alloc.allocationSize = 512; // one allocation for both buffers
15701 mem_alloc.memoryTypeIndex = 0;
15702
15703 VkMemoryRequirements mem_reqs;
15704 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
15705 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
15706 if (!pass) {
15707 vkDestroyBuffer(m_device->device(), buffer, NULL);
15708 return;
15709 }
15710
15711 VkDeviceMemory mem;
15712 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
15713 ASSERT_VK_SUCCESS(err);
15714 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
15715 ASSERT_VK_SUCCESS(err);
15716
15717 // Only update the descriptor at binding 2
15718 VkDescriptorBufferInfo buff_info = {};
15719 buff_info.buffer = buffer;
15720 buff_info.offset = 0;
15721 buff_info.range = VK_WHOLE_SIZE;
15722 VkWriteDescriptorSet descriptor_write = {};
15723 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15724 descriptor_write.dstBinding = 2;
15725 descriptor_write.descriptorCount = 1;
15726 descriptor_write.pTexelBufferView = nullptr;
15727 descriptor_write.pBufferInfo = &buff_info;
15728 descriptor_write.pImageInfo = nullptr;
15729 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15730 descriptor_write.dstSet = descriptor_set;
15731
15732 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15733
15734 m_errorMonitor->VerifyNotFound();
15735 // Cleanup
15736 vkFreeMemory(m_device->device(), mem, NULL);
15737 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15738 vkDestroyBuffer(m_device->device(), buffer, NULL);
15739 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15740}
15741
15742// This is a positive test. No failures are expected.
15743TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
15744 VkResult err;
15745 bool pass;
15746
15747 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
15748 "the buffer, create an image, and bind the same memory to "
15749 "it");
15750
15751 m_errorMonitor->ExpectSuccess();
15752
15753 ASSERT_NO_FATAL_FAILURE(InitState());
15754
15755 VkBuffer buffer;
15756 VkImage image;
15757 VkDeviceMemory mem;
15758 VkMemoryRequirements mem_reqs;
15759
15760 VkBufferCreateInfo buf_info = {};
15761 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15762 buf_info.pNext = NULL;
15763 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15764 buf_info.size = 256;
15765 buf_info.queueFamilyIndexCount = 0;
15766 buf_info.pQueueFamilyIndices = NULL;
15767 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15768 buf_info.flags = 0;
15769 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
15770 ASSERT_VK_SUCCESS(err);
15771
15772 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
15773
15774 VkMemoryAllocateInfo alloc_info = {};
15775 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15776 alloc_info.pNext = NULL;
15777 alloc_info.memoryTypeIndex = 0;
15778
15779 // Ensure memory is big enough for both bindings
15780 alloc_info.allocationSize = 0x10000;
15781
15782 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
15783 if (!pass) {
15784 vkDestroyBuffer(m_device->device(), buffer, NULL);
15785 return;
15786 }
15787
15788 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
15789 ASSERT_VK_SUCCESS(err);
15790
15791 uint8_t *pData;
15792 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
15793 ASSERT_VK_SUCCESS(err);
15794
15795 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
15796
15797 vkUnmapMemory(m_device->device(), mem);
15798
15799 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
15800 ASSERT_VK_SUCCESS(err);
15801
15802 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
15803 // memory. In fact, it was never used by the GPU.
15804 // Just be be sure, wait for idle.
15805 vkDestroyBuffer(m_device->device(), buffer, NULL);
15806 vkDeviceWaitIdle(m_device->device());
15807
15808 VkImageCreateInfo image_create_info = {};
15809 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15810 image_create_info.pNext = NULL;
15811 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15812 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
15813 image_create_info.extent.width = 64;
15814 image_create_info.extent.height = 64;
15815 image_create_info.extent.depth = 1;
15816 image_create_info.mipLevels = 1;
15817 image_create_info.arrayLayers = 1;
15818 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15819 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15820 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
15821 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15822 image_create_info.queueFamilyIndexCount = 0;
15823 image_create_info.pQueueFamilyIndices = NULL;
15824 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15825 image_create_info.flags = 0;
15826
15827 VkMemoryAllocateInfo mem_alloc = {};
15828 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15829 mem_alloc.pNext = NULL;
15830 mem_alloc.allocationSize = 0;
15831 mem_alloc.memoryTypeIndex = 0;
15832
15833 /* Create a mappable image. It will be the texture if linear images are ok
15834 * to be textures or it will be the staging image if they are not.
15835 */
15836 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15837 ASSERT_VK_SUCCESS(err);
15838
15839 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
15840
15841 mem_alloc.allocationSize = mem_reqs.size;
15842
15843 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
15844 if (!pass) {
15845 vkDestroyImage(m_device->device(), image, NULL);
15846 return;
15847 }
15848
15849 // VALIDATION FAILURE:
15850 err = vkBindImageMemory(m_device->device(), image, mem, 0);
15851 ASSERT_VK_SUCCESS(err);
15852
15853 m_errorMonitor->VerifyNotFound();
15854
15855 vkFreeMemory(m_device->device(), mem, NULL);
15856 vkDestroyBuffer(m_device->device(), buffer, NULL);
15857 vkDestroyImage(m_device->device(), image, NULL);
15858}
15859
15860TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
15861
15862 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
15863 "mapping while using VK_WHOLE_SIZE does not cause access "
15864 "violations");
15865 VkResult err;
15866 uint8_t *pData;
15867 ASSERT_NO_FATAL_FAILURE(InitState());
15868
15869 VkDeviceMemory mem;
15870 VkMemoryRequirements mem_reqs;
15871 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
15872 VkMemoryAllocateInfo alloc_info = {};
15873 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15874 alloc_info.pNext = NULL;
15875 alloc_info.memoryTypeIndex = 0;
15876
15877 static const VkDeviceSize allocation_size = 0x1000;
15878 alloc_info.allocationSize = allocation_size;
15879
15880 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
15881 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
15882 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
15883 if (!pass) {
15884 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
15885 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
15886 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
15887 if (!pass) {
15888 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
15889 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
15890 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
15891 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
15892 if (!pass) {
15893 return;
15894 }
15895 }
15896 }
15897
15898 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
15899 ASSERT_VK_SUCCESS(err);
15900
15901 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
15902 // mapped range
15903 m_errorMonitor->ExpectSuccess();
15904 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
15905 ASSERT_VK_SUCCESS(err);
15906 VkMappedMemoryRange mmr = {};
15907 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
15908 mmr.memory = mem;
15909 mmr.offset = 0;
15910 mmr.size = VK_WHOLE_SIZE;
15911 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
15912 ASSERT_VK_SUCCESS(err);
15913 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
15914 ASSERT_VK_SUCCESS(err);
15915 m_errorMonitor->VerifyNotFound();
15916 vkUnmapMemory(m_device->device(), mem);
15917
15918 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
15919 // mapped range
15920 m_errorMonitor->ExpectSuccess();
15921 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
15922 ASSERT_VK_SUCCESS(err);
15923 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
15924 mmr.memory = mem;
15925 mmr.offset = 13;
15926 mmr.size = VK_WHOLE_SIZE;
15927 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
15928 ASSERT_VK_SUCCESS(err);
15929 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
15930 ASSERT_VK_SUCCESS(err);
15931 m_errorMonitor->VerifyNotFound();
15932 vkUnmapMemory(m_device->device(), mem);
15933
15934 // Map with prime offset and size
15935 // Flush/Invalidate subrange of mapped area with prime offset and size
15936 m_errorMonitor->ExpectSuccess();
15937 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
15938 ASSERT_VK_SUCCESS(err);
15939 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
15940 mmr.memory = mem;
15941 mmr.offset = allocation_size - 107;
15942 mmr.size = 61;
15943 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
15944 ASSERT_VK_SUCCESS(err);
15945 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
15946 ASSERT_VK_SUCCESS(err);
15947 m_errorMonitor->VerifyNotFound();
15948 vkUnmapMemory(m_device->device(), mem);
15949
15950 // Map without offset and flush WHOLE_SIZE with two separate offsets
15951 m_errorMonitor->ExpectSuccess();
15952 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
15953 ASSERT_VK_SUCCESS(err);
15954 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
15955 mmr.memory = mem;
15956 mmr.offset = allocation_size - 100;
15957 mmr.size = VK_WHOLE_SIZE;
15958 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
15959 ASSERT_VK_SUCCESS(err);
15960 mmr.offset = allocation_size - 200;
15961 mmr.size = VK_WHOLE_SIZE;
15962 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
15963 ASSERT_VK_SUCCESS(err);
15964 m_errorMonitor->VerifyNotFound();
15965 vkUnmapMemory(m_device->device(), mem);
15966
15967 vkFreeMemory(m_device->device(), mem, NULL);
15968}
15969
15970// This is a positive test. We used to expect error in this case but spec now allows it
15971TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
15972 m_errorMonitor->ExpectSuccess();
15973 vk_testing::Fence testFence;
15974 VkFenceCreateInfo fenceInfo = {};
15975 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
15976 fenceInfo.pNext = NULL;
15977
15978 ASSERT_NO_FATAL_FAILURE(InitState());
15979 testFence.init(*m_device, fenceInfo);
15980 VkFence fences[1] = { testFence.handle() };
15981 VkResult result = vkResetFences(m_device->device(), 1, fences);
15982 ASSERT_VK_SUCCESS(result);
15983
15984 m_errorMonitor->VerifyNotFound();
15985}
15986
15987TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
15988 m_errorMonitor->ExpectSuccess();
15989
15990 ASSERT_NO_FATAL_FAILURE(InitState());
15991 VkResult err;
15992
15993 // Record (empty!) command buffer that can be submitted multiple times
15994 // simultaneously.
15995 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
15996 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
15997 m_commandBuffer->BeginCommandBuffer(&cbbi);
15998 m_commandBuffer->EndCommandBuffer();
15999
16000 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16001 VkFence fence;
16002 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16003 ASSERT_VK_SUCCESS(err);
16004
16005 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16006 VkSemaphore s1, s2;
16007 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16008 ASSERT_VK_SUCCESS(err);
16009 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16010 ASSERT_VK_SUCCESS(err);
16011
16012 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16013 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16014 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16015 ASSERT_VK_SUCCESS(err);
16016
16017 // Submit CB again, signaling s2.
16018 si.pSignalSemaphores = &s2;
16019 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16020 ASSERT_VK_SUCCESS(err);
16021
16022 // Wait for fence.
16023 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16024 ASSERT_VK_SUCCESS(err);
16025
16026 // CB is still in flight from second submission, but semaphore s1 is no
16027 // longer in flight. delete it.
16028 vkDestroySemaphore(m_device->device(), s1, nullptr);
16029
16030 m_errorMonitor->VerifyNotFound();
16031
16032 // Force device idle and clean up remaining objects
16033 vkDeviceWaitIdle(m_device->device());
16034 vkDestroySemaphore(m_device->device(), s2, nullptr);
16035 vkDestroyFence(m_device->device(), fence, nullptr);
16036}
16037
16038TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16039 m_errorMonitor->ExpectSuccess();
16040
16041 ASSERT_NO_FATAL_FAILURE(InitState());
16042 VkResult err;
16043
16044 // A fence created signaled
16045 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16046 VkFence f1;
16047 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16048 ASSERT_VK_SUCCESS(err);
16049
16050 // A fence created not
16051 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16052 VkFence f2;
16053 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16054 ASSERT_VK_SUCCESS(err);
16055
16056 // Submit the unsignaled fence
16057 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16058 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16059
16060 // Wait on both fences, with signaled first.
16061 VkFence fences[] = { f1, f2 };
16062 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16063
16064 // Should have both retired!
16065 vkDestroyFence(m_device->device(), f1, nullptr);
16066 vkDestroyFence(m_device->device(), f2, nullptr);
16067
16068 m_errorMonitor->VerifyNotFound();
16069}
16070
16071TEST_F(VkPositiveLayerTest, ValidUsage) {
16072 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16073 "doesn't generate validation errors");
16074
16075 ASSERT_NO_FATAL_FAILURE(InitState());
16076
16077 m_errorMonitor->ExpectSuccess();
16078 // Verify that we can create a view with usage INPUT_ATTACHMENT
16079 VkImageObj image(m_device);
16080 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16081 ASSERT_TRUE(image.initialized());
16082 VkImageView imageView;
16083 VkImageViewCreateInfo ivci = {};
16084 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16085 ivci.image = image.handle();
16086 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16087 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16088 ivci.subresourceRange.layerCount = 1;
16089 ivci.subresourceRange.baseMipLevel = 0;
16090 ivci.subresourceRange.levelCount = 1;
16091 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16092
16093 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16094 m_errorMonitor->VerifyNotFound();
16095 vkDestroyImageView(m_device->device(), imageView, NULL);
16096}
16097
16098// This is a positive test. No failures are expected.
16099TEST_F(VkPositiveLayerTest, BindSparse) {
16100 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16101 "and then free the memory");
16102
16103 ASSERT_NO_FATAL_FAILURE(InitState());
16104
16105 auto index = m_device->graphics_queue_node_index_;
16106 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16107 return;
16108
16109 m_errorMonitor->ExpectSuccess();
16110
16111 VkImage image;
16112 VkImageCreateInfo image_create_info = {};
16113 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16114 image_create_info.pNext = NULL;
16115 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16116 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16117 image_create_info.extent.width = 64;
16118 image_create_info.extent.height = 64;
16119 image_create_info.extent.depth = 1;
16120 image_create_info.mipLevels = 1;
16121 image_create_info.arrayLayers = 1;
16122 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16123 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16124 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16125 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16126 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16127 ASSERT_VK_SUCCESS(err);
16128
16129 VkMemoryRequirements memory_reqs;
16130 VkDeviceMemory memory_one, memory_two;
16131 bool pass;
16132 VkMemoryAllocateInfo memory_info = {};
16133 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16134 memory_info.pNext = NULL;
16135 memory_info.allocationSize = 0;
16136 memory_info.memoryTypeIndex = 0;
16137 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16138 // Find an image big enough to allow sparse mapping of 2 memory regions
16139 // Increase the image size until it is at least twice the
16140 // size of the required alignment, to ensure we can bind both
16141 // allocated memory blocks to the image on aligned offsets.
16142 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16143 vkDestroyImage(m_device->device(), image, nullptr);
16144 image_create_info.extent.width *= 2;
16145 image_create_info.extent.height *= 2;
16146 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16147 ASSERT_VK_SUCCESS(err);
16148 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16149 }
16150 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16151 // at the end of the first
16152 memory_info.allocationSize = memory_reqs.alignment;
16153 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16154 ASSERT_TRUE(pass);
16155 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16156 ASSERT_VK_SUCCESS(err);
16157 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16158 ASSERT_VK_SUCCESS(err);
16159 VkSparseMemoryBind binds[2];
16160 binds[0].flags = 0;
16161 binds[0].memory = memory_one;
16162 binds[0].memoryOffset = 0;
16163 binds[0].resourceOffset = 0;
16164 binds[0].size = memory_info.allocationSize;
16165 binds[1].flags = 0;
16166 binds[1].memory = memory_two;
16167 binds[1].memoryOffset = 0;
16168 binds[1].resourceOffset = memory_info.allocationSize;
16169 binds[1].size = memory_info.allocationSize;
16170
16171 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16172 opaqueBindInfo.image = image;
16173 opaqueBindInfo.bindCount = 2;
16174 opaqueBindInfo.pBinds = binds;
16175
16176 VkFence fence = VK_NULL_HANDLE;
16177 VkBindSparseInfo bindSparseInfo = {};
16178 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16179 bindSparseInfo.imageOpaqueBindCount = 1;
16180 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16181
16182 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16183 vkQueueWaitIdle(m_device->m_queue);
16184 vkDestroyImage(m_device->device(), image, NULL);
16185 vkFreeMemory(m_device->device(), memory_one, NULL);
16186 vkFreeMemory(m_device->device(), memory_two, NULL);
16187 m_errorMonitor->VerifyNotFound();
16188}
16189
16190TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16191 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16192 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16193 "the command buffer has prior knowledge of that "
16194 "attachment's layout.");
16195
16196 m_errorMonitor->ExpectSuccess();
16197
16198 ASSERT_NO_FATAL_FAILURE(InitState());
16199
16200 // A renderpass with one color attachment.
16201 VkAttachmentDescription attachment = { 0,
16202 VK_FORMAT_R8G8B8A8_UNORM,
16203 VK_SAMPLE_COUNT_1_BIT,
16204 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16205 VK_ATTACHMENT_STORE_OP_STORE,
16206 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16207 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16208 VK_IMAGE_LAYOUT_UNDEFINED,
16209 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16210
16211 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16212
16213 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16214
16215 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16216
16217 VkRenderPass rp;
16218 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16219 ASSERT_VK_SUCCESS(err);
16220
16221 // A compatible framebuffer.
16222 VkImageObj image(m_device);
16223 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16224 ASSERT_TRUE(image.initialized());
16225
16226 VkImageViewCreateInfo ivci = {
16227 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16228 nullptr,
16229 0,
16230 image.handle(),
16231 VK_IMAGE_VIEW_TYPE_2D,
16232 VK_FORMAT_R8G8B8A8_UNORM,
16233 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16234 VK_COMPONENT_SWIZZLE_IDENTITY },
16235 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16236 };
16237 VkImageView view;
16238 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16239 ASSERT_VK_SUCCESS(err);
16240
16241 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16242 VkFramebuffer fb;
16243 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16244 ASSERT_VK_SUCCESS(err);
16245
16246 // Record a single command buffer which uses this renderpass twice. The
16247 // bug is triggered at the beginning of the second renderpass, when the
16248 // command buffer already has a layout recorded for the attachment.
16249 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16250 BeginCommandBuffer();
16251 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16252 vkCmdEndRenderPass(m_commandBuffer->handle());
16253 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16254
16255 m_errorMonitor->VerifyNotFound();
16256
16257 vkCmdEndRenderPass(m_commandBuffer->handle());
16258 EndCommandBuffer();
16259
16260 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16261 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16262 vkDestroyImageView(m_device->device(), view, nullptr);
16263}
16264
16265TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16266 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16267 "command buffer, bind them together, then destroy "
16268 "command pool and framebuffer and verify there are no "
16269 "errors.");
16270
16271 m_errorMonitor->ExpectSuccess();
16272
16273 ASSERT_NO_FATAL_FAILURE(InitState());
16274
16275 // A renderpass with one color attachment.
16276 VkAttachmentDescription attachment = { 0,
16277 VK_FORMAT_R8G8B8A8_UNORM,
16278 VK_SAMPLE_COUNT_1_BIT,
16279 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16280 VK_ATTACHMENT_STORE_OP_STORE,
16281 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16282 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16283 VK_IMAGE_LAYOUT_UNDEFINED,
16284 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16285
16286 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16287
16288 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16289
16290 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16291
16292 VkRenderPass rp;
16293 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16294 ASSERT_VK_SUCCESS(err);
16295
16296 // A compatible framebuffer.
16297 VkImageObj image(m_device);
16298 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16299 ASSERT_TRUE(image.initialized());
16300
16301 VkImageViewCreateInfo ivci = {
16302 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16303 nullptr,
16304 0,
16305 image.handle(),
16306 VK_IMAGE_VIEW_TYPE_2D,
16307 VK_FORMAT_R8G8B8A8_UNORM,
16308 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16309 VK_COMPONENT_SWIZZLE_IDENTITY },
16310 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16311 };
16312 VkImageView view;
16313 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16314 ASSERT_VK_SUCCESS(err);
16315
16316 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16317 VkFramebuffer fb;
16318 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16319 ASSERT_VK_SUCCESS(err);
16320
16321 // Explicitly create a command buffer to bind the FB to so that we can then
16322 // destroy the command pool in order to implicitly free command buffer
16323 VkCommandPool command_pool;
16324 VkCommandPoolCreateInfo pool_create_info{};
16325 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16326 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16327 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16328 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16329
16330 VkCommandBuffer command_buffer;
16331 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16332 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16333 command_buffer_allocate_info.commandPool = command_pool;
16334 command_buffer_allocate_info.commandBufferCount = 1;
16335 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16336 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16337
16338 // Begin our cmd buffer with renderpass using our framebuffer
16339 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16340 VkCommandBufferBeginInfo begin_info{};
16341 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16342 vkBeginCommandBuffer(command_buffer, &begin_info);
16343
16344 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16345 vkCmdEndRenderPass(command_buffer);
16346 vkEndCommandBuffer(command_buffer);
16347 vkDestroyImageView(m_device->device(), view, nullptr);
16348 // Destroy command pool to implicitly free command buffer
16349 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16350 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16351 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16352 m_errorMonitor->VerifyNotFound();
16353}
16354
16355TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16356 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16357 "transitions for the first subpass");
16358
16359 m_errorMonitor->ExpectSuccess();
16360
16361 ASSERT_NO_FATAL_FAILURE(InitState());
16362
16363 // A renderpass with one color attachment.
16364 VkAttachmentDescription attachment = { 0,
16365 VK_FORMAT_R8G8B8A8_UNORM,
16366 VK_SAMPLE_COUNT_1_BIT,
16367 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16368 VK_ATTACHMENT_STORE_OP_STORE,
16369 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16370 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16371 VK_IMAGE_LAYOUT_UNDEFINED,
16372 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16373
16374 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16375
16376 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16377
16378 VkSubpassDependency dep = { 0,
16379 0,
16380 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16381 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16382 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16383 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16384 VK_DEPENDENCY_BY_REGION_BIT };
16385
16386 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16387
16388 VkResult err;
16389 VkRenderPass rp;
16390 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16391 ASSERT_VK_SUCCESS(err);
16392
16393 // A compatible framebuffer.
16394 VkImageObj image(m_device);
16395 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16396 ASSERT_TRUE(image.initialized());
16397
16398 VkImageViewCreateInfo ivci = {
16399 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16400 nullptr,
16401 0,
16402 image.handle(),
16403 VK_IMAGE_VIEW_TYPE_2D,
16404 VK_FORMAT_R8G8B8A8_UNORM,
16405 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16406 VK_COMPONENT_SWIZZLE_IDENTITY },
16407 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16408 };
16409 VkImageView view;
16410 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16411 ASSERT_VK_SUCCESS(err);
16412
16413 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16414 VkFramebuffer fb;
16415 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16416 ASSERT_VK_SUCCESS(err);
16417
16418 // Record a single command buffer which issues a pipeline barrier w/
16419 // image memory barrier for the attachment. This detects the previously
16420 // missing tracking of the subpass layout by throwing a validation error
16421 // if it doesn't occur.
16422 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16423 BeginCommandBuffer();
16424 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16425
16426 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
16427 nullptr,
16428 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16429 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16430 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16431 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16432 VK_QUEUE_FAMILY_IGNORED,
16433 VK_QUEUE_FAMILY_IGNORED,
16434 image.handle(),
16435 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
16436 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16437 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16438 &imb);
16439
16440 vkCmdEndRenderPass(m_commandBuffer->handle());
16441 m_errorMonitor->VerifyNotFound();
16442 EndCommandBuffer();
16443
16444 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16445 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16446 vkDestroyImageView(m_device->device(), view, nullptr);
16447}
16448
16449TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
16450 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
16451 "is used as a depth/stencil framebuffer attachment, the "
16452 "aspectMask is ignored and both depth and stencil image "
16453 "subresources are used.");
16454
16455 VkFormatProperties format_properties;
16456 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
16457 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
16458 return;
16459 }
16460
16461 m_errorMonitor->ExpectSuccess();
16462
16463 ASSERT_NO_FATAL_FAILURE(InitState());
16464
16465 VkAttachmentDescription attachment = { 0,
16466 VK_FORMAT_D32_SFLOAT_S8_UINT,
16467 VK_SAMPLE_COUNT_1_BIT,
16468 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16469 VK_ATTACHMENT_STORE_OP_STORE,
16470 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16471 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16472 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
16473 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16474
16475 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16476
16477 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
16478
16479 VkSubpassDependency dep = { 0,
16480 0,
16481 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16482 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16483 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16484 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16485 VK_DEPENDENCY_BY_REGION_BIT};
16486
16487 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16488
16489 VkResult err;
16490 VkRenderPass rp;
16491 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16492 ASSERT_VK_SUCCESS(err);
16493
16494 VkImageObj image(m_device);
16495 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
16496 0x26, // usage
16497 VK_IMAGE_TILING_OPTIMAL, 0);
16498 ASSERT_TRUE(image.initialized());
16499 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
16500
16501 VkImageViewCreateInfo ivci = {
16502 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16503 nullptr,
16504 0,
16505 image.handle(),
16506 VK_IMAGE_VIEW_TYPE_2D,
16507 VK_FORMAT_D32_SFLOAT_S8_UINT,
16508 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
16509 { 0x2, 0, 1, 0, 1 },
16510 };
16511 VkImageView view;
16512 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16513 ASSERT_VK_SUCCESS(err);
16514
16515 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16516 VkFramebuffer fb;
16517 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16518 ASSERT_VK_SUCCESS(err);
16519
16520 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16521 BeginCommandBuffer();
16522 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16523
16524 VkImageMemoryBarrier imb = {};
16525 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16526 imb.pNext = nullptr;
16527 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16528 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16529 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16530 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16531 imb.srcQueueFamilyIndex = 0;
16532 imb.dstQueueFamilyIndex = 0;
16533 imb.image = image.handle();
16534 imb.subresourceRange.aspectMask = 0x6;
16535 imb.subresourceRange.baseMipLevel = 0;
16536 imb.subresourceRange.levelCount = 0x1;
16537 imb.subresourceRange.baseArrayLayer = 0;
16538 imb.subresourceRange.layerCount = 0x1;
16539
16540 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16541 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16542 &imb);
16543
16544 vkCmdEndRenderPass(m_commandBuffer->handle());
16545 EndCommandBuffer();
16546 QueueCommandBuffer(false);
16547 m_errorMonitor->VerifyNotFound();
16548
16549 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16550 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16551 vkDestroyImageView(m_device->device(), view, nullptr);
16552}
16553
16554TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
16555 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
16556 "errors, when an attachment reference is "
16557 "VK_ATTACHMENT_UNUSED");
16558
16559 m_errorMonitor->ExpectSuccess();
16560
16561 ASSERT_NO_FATAL_FAILURE(InitState());
16562
16563 // A renderpass with no attachments
16564 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16565
16566 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16567
16568 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
16569
16570 VkRenderPass rp;
16571 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16572 ASSERT_VK_SUCCESS(err);
16573
16574 // A compatible framebuffer.
16575 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
16576 VkFramebuffer fb;
16577 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16578 ASSERT_VK_SUCCESS(err);
16579
16580 // Record a command buffer which just begins and ends the renderpass. The
16581 // bug manifests in BeginRenderPass.
16582 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16583 BeginCommandBuffer();
16584 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16585 vkCmdEndRenderPass(m_commandBuffer->handle());
16586 m_errorMonitor->VerifyNotFound();
16587 EndCommandBuffer();
16588
16589 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16590 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16591}
16592
16593// This is a positive test. No errors are expected.
16594TEST_F(VkPositiveLayerTest, StencilLoadOp) {
16595 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
16596 "CLEAR. stencil[Load|Store]Op used to be ignored.");
16597 VkResult result = VK_SUCCESS;
16598 VkImageFormatProperties formatProps;
16599 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
16600 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
16601 &formatProps);
16602 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
16603 return;
16604 }
16605
16606 ASSERT_NO_FATAL_FAILURE(InitState());
16607 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
16608 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
16609 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
16610 VkAttachmentDescription att = {};
16611 VkAttachmentReference ref = {};
16612 att.format = depth_stencil_fmt;
16613 att.samples = VK_SAMPLE_COUNT_1_BIT;
16614 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
16615 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
16616 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
16617 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
16618 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16619 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16620
16621 VkClearValue clear;
16622 clear.depthStencil.depth = 1.0;
16623 clear.depthStencil.stencil = 0;
16624 ref.attachment = 0;
16625 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16626
16627 VkSubpassDescription subpass = {};
16628 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
16629 subpass.flags = 0;
16630 subpass.inputAttachmentCount = 0;
16631 subpass.pInputAttachments = NULL;
16632 subpass.colorAttachmentCount = 0;
16633 subpass.pColorAttachments = NULL;
16634 subpass.pResolveAttachments = NULL;
16635 subpass.pDepthStencilAttachment = &ref;
16636 subpass.preserveAttachmentCount = 0;
16637 subpass.pPreserveAttachments = NULL;
16638
16639 VkRenderPass rp;
16640 VkRenderPassCreateInfo rp_info = {};
16641 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16642 rp_info.attachmentCount = 1;
16643 rp_info.pAttachments = &att;
16644 rp_info.subpassCount = 1;
16645 rp_info.pSubpasses = &subpass;
16646 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
16647 ASSERT_VK_SUCCESS(result);
16648
16649 VkImageView *depthView = m_depthStencil->BindInfo();
16650 VkFramebufferCreateInfo fb_info = {};
16651 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
16652 fb_info.pNext = NULL;
16653 fb_info.renderPass = rp;
16654 fb_info.attachmentCount = 1;
16655 fb_info.pAttachments = depthView;
16656 fb_info.width = 100;
16657 fb_info.height = 100;
16658 fb_info.layers = 1;
16659 VkFramebuffer fb;
16660 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
16661 ASSERT_VK_SUCCESS(result);
16662
16663 VkRenderPassBeginInfo rpbinfo = {};
16664 rpbinfo.clearValueCount = 1;
16665 rpbinfo.pClearValues = &clear;
16666 rpbinfo.pNext = NULL;
16667 rpbinfo.renderPass = rp;
16668 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
16669 rpbinfo.renderArea.extent.width = 100;
16670 rpbinfo.renderArea.extent.height = 100;
16671 rpbinfo.renderArea.offset.x = 0;
16672 rpbinfo.renderArea.offset.y = 0;
16673 rpbinfo.framebuffer = fb;
16674
16675 VkFence fence = {};
16676 VkFenceCreateInfo fence_ci = {};
16677 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16678 fence_ci.pNext = nullptr;
16679 fence_ci.flags = 0;
16680 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
16681 ASSERT_VK_SUCCESS(result);
16682
16683 m_commandBuffer->BeginCommandBuffer();
16684 m_commandBuffer->BeginRenderPass(rpbinfo);
16685 m_commandBuffer->EndRenderPass();
16686 m_commandBuffer->EndCommandBuffer();
16687 m_commandBuffer->QueueCommandBuffer(fence);
16688
16689 VkImageObj destImage(m_device);
16690 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16691 VK_IMAGE_TILING_OPTIMAL, 0);
16692 VkImageMemoryBarrier barrier = {};
16693 VkImageSubresourceRange range;
16694 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16695 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16696 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
16697 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16698 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
16699 barrier.image = m_depthStencil->handle();
16700 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16701 range.baseMipLevel = 0;
16702 range.levelCount = 1;
16703 range.baseArrayLayer = 0;
16704 range.layerCount = 1;
16705 barrier.subresourceRange = range;
16706 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16707 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
16708 cmdbuf.BeginCommandBuffer();
16709 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
16710 &barrier);
16711 barrier.srcAccessMask = 0;
16712 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16713 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
16714 barrier.image = destImage.handle();
16715 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16716 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
16717 &barrier);
16718 VkImageCopy cregion;
16719 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16720 cregion.srcSubresource.mipLevel = 0;
16721 cregion.srcSubresource.baseArrayLayer = 0;
16722 cregion.srcSubresource.layerCount = 1;
16723 cregion.srcOffset.x = 0;
16724 cregion.srcOffset.y = 0;
16725 cregion.srcOffset.z = 0;
16726 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16727 cregion.dstSubresource.mipLevel = 0;
16728 cregion.dstSubresource.baseArrayLayer = 0;
16729 cregion.dstSubresource.layerCount = 1;
16730 cregion.dstOffset.x = 0;
16731 cregion.dstOffset.y = 0;
16732 cregion.dstOffset.z = 0;
16733 cregion.extent.width = 100;
16734 cregion.extent.height = 100;
16735 cregion.extent.depth = 1;
16736 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
16737 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
16738 cmdbuf.EndCommandBuffer();
16739
16740 VkSubmitInfo submit_info;
16741 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16742 submit_info.pNext = NULL;
16743 submit_info.waitSemaphoreCount = 0;
16744 submit_info.pWaitSemaphores = NULL;
16745 submit_info.pWaitDstStageMask = NULL;
16746 submit_info.commandBufferCount = 1;
16747 submit_info.pCommandBuffers = &cmdbuf.handle();
16748 submit_info.signalSemaphoreCount = 0;
16749 submit_info.pSignalSemaphores = NULL;
16750
16751 m_errorMonitor->ExpectSuccess();
16752 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16753 m_errorMonitor->VerifyNotFound();
16754
16755 vkQueueWaitIdle(m_device->m_queue);
16756 vkDestroyFence(m_device->device(), fence, nullptr);
16757 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16758 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16759}
16760
16761// This is a positive test. No errors should be generated.
16762TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
16763 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
16764
16765 m_errorMonitor->ExpectSuccess();
16766 ASSERT_NO_FATAL_FAILURE(InitState());
16767
16768 VkEvent event;
16769 VkEventCreateInfo event_create_info{};
16770 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
16771 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
16772
16773 VkCommandPool command_pool;
16774 VkCommandPoolCreateInfo pool_create_info{};
16775 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16776 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16777 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16778 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16779
16780 VkCommandBuffer command_buffer;
16781 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16782 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16783 command_buffer_allocate_info.commandPool = command_pool;
16784 command_buffer_allocate_info.commandBufferCount = 1;
16785 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16786 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16787
16788 VkQueue queue = VK_NULL_HANDLE;
16789 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
16790
16791 {
16792 VkCommandBufferBeginInfo begin_info{};
16793 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16794 vkBeginCommandBuffer(command_buffer, &begin_info);
16795
16796 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
16797 nullptr, 0, nullptr);
16798 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
16799 vkEndCommandBuffer(command_buffer);
16800 }
16801 {
16802 VkSubmitInfo submit_info{};
16803 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16804 submit_info.commandBufferCount = 1;
16805 submit_info.pCommandBuffers = &command_buffer;
16806 submit_info.signalSemaphoreCount = 0;
16807 submit_info.pSignalSemaphores = nullptr;
16808 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
16809 }
16810 { vkSetEvent(m_device->device(), event); }
16811
16812 vkQueueWaitIdle(queue);
16813
16814 vkDestroyEvent(m_device->device(), event, nullptr);
16815 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
16816 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16817
16818 m_errorMonitor->VerifyNotFound();
16819}
16820// This is a positive test. No errors should be generated.
16821TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
16822 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
16823
16824 ASSERT_NO_FATAL_FAILURE(InitState());
16825 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
16826 return;
16827
16828 m_errorMonitor->ExpectSuccess();
16829
16830 VkQueryPool query_pool;
16831 VkQueryPoolCreateInfo query_pool_create_info{};
16832 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
16833 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
16834 query_pool_create_info.queryCount = 1;
16835 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
16836
16837 VkCommandPool command_pool;
16838 VkCommandPoolCreateInfo pool_create_info{};
16839 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16840 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16841 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16842 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16843
16844 VkCommandBuffer command_buffer;
16845 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16846 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16847 command_buffer_allocate_info.commandPool = command_pool;
16848 command_buffer_allocate_info.commandBufferCount = 1;
16849 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16850 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16851
16852 VkCommandBuffer secondary_command_buffer;
16853 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16854 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
16855
16856 VkQueue queue = VK_NULL_HANDLE;
16857 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
16858
16859 uint32_t qfi = 0;
16860 VkBufferCreateInfo buff_create_info = {};
16861 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16862 buff_create_info.size = 1024;
16863 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
16864 buff_create_info.queueFamilyIndexCount = 1;
16865 buff_create_info.pQueueFamilyIndices = &qfi;
16866
16867 VkResult err;
16868 VkBuffer buffer;
16869 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
16870 ASSERT_VK_SUCCESS(err);
16871 VkMemoryAllocateInfo mem_alloc = {};
16872 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16873 mem_alloc.pNext = NULL;
16874 mem_alloc.allocationSize = 1024;
16875 mem_alloc.memoryTypeIndex = 0;
16876
16877 VkMemoryRequirements memReqs;
16878 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
16879 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
16880 if (!pass) {
16881 vkDestroyBuffer(m_device->device(), buffer, NULL);
16882 return;
16883 }
16884
16885 VkDeviceMemory mem;
16886 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16887 ASSERT_VK_SUCCESS(err);
16888 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16889 ASSERT_VK_SUCCESS(err);
16890
16891 VkCommandBufferInheritanceInfo hinfo = {};
16892 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16893 hinfo.renderPass = VK_NULL_HANDLE;
16894 hinfo.subpass = 0;
16895 hinfo.framebuffer = VK_NULL_HANDLE;
16896 hinfo.occlusionQueryEnable = VK_FALSE;
16897 hinfo.queryFlags = 0;
16898 hinfo.pipelineStatistics = 0;
16899
16900 {
16901 VkCommandBufferBeginInfo begin_info{};
16902 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16903 begin_info.pInheritanceInfo = &hinfo;
16904 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
16905
16906 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
16907 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
16908
16909 vkEndCommandBuffer(secondary_command_buffer);
16910
16911 begin_info.pInheritanceInfo = nullptr;
16912 vkBeginCommandBuffer(command_buffer, &begin_info);
16913
16914 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
16915 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
16916
16917 vkEndCommandBuffer(command_buffer);
16918 }
16919 {
16920 VkSubmitInfo submit_info{};
16921 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16922 submit_info.commandBufferCount = 1;
16923 submit_info.pCommandBuffers = &command_buffer;
16924 submit_info.signalSemaphoreCount = 0;
16925 submit_info.pSignalSemaphores = nullptr;
16926 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
16927 }
16928
16929 vkQueueWaitIdle(queue);
16930
16931 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
16932 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
16933 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
16934 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16935 vkDestroyBuffer(m_device->device(), buffer, NULL);
16936 vkFreeMemory(m_device->device(), mem, NULL);
16937
16938 m_errorMonitor->VerifyNotFound();
16939}
16940
16941// This is a positive test. No errors should be generated.
16942TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
16943 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
16944
16945 ASSERT_NO_FATAL_FAILURE(InitState());
16946 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
16947 return;
16948
16949 m_errorMonitor->ExpectSuccess();
16950
16951 VkQueryPool query_pool;
16952 VkQueryPoolCreateInfo query_pool_create_info{};
16953 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
16954 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
16955 query_pool_create_info.queryCount = 1;
16956 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
16957
16958 VkCommandPool command_pool;
16959 VkCommandPoolCreateInfo pool_create_info{};
16960 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16961 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16962 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16963 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16964
16965 VkCommandBuffer command_buffer[2];
16966 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16967 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16968 command_buffer_allocate_info.commandPool = command_pool;
16969 command_buffer_allocate_info.commandBufferCount = 2;
16970 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16971 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
16972
16973 VkQueue queue = VK_NULL_HANDLE;
16974 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
16975
16976 uint32_t qfi = 0;
16977 VkBufferCreateInfo buff_create_info = {};
16978 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16979 buff_create_info.size = 1024;
16980 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
16981 buff_create_info.queueFamilyIndexCount = 1;
16982 buff_create_info.pQueueFamilyIndices = &qfi;
16983
16984 VkResult err;
16985 VkBuffer buffer;
16986 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
16987 ASSERT_VK_SUCCESS(err);
16988 VkMemoryAllocateInfo mem_alloc = {};
16989 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16990 mem_alloc.pNext = NULL;
16991 mem_alloc.allocationSize = 1024;
16992 mem_alloc.memoryTypeIndex = 0;
16993
16994 VkMemoryRequirements memReqs;
16995 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
16996 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
16997 if (!pass) {
16998 vkDestroyBuffer(m_device->device(), buffer, NULL);
16999 return;
17000 }
17001
17002 VkDeviceMemory mem;
17003 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17004 ASSERT_VK_SUCCESS(err);
17005 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17006 ASSERT_VK_SUCCESS(err);
17007
17008 {
17009 VkCommandBufferBeginInfo begin_info{};
17010 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17011 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17012
17013 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17014 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17015
17016 vkEndCommandBuffer(command_buffer[0]);
17017
17018 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17019
17020 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17021
17022 vkEndCommandBuffer(command_buffer[1]);
17023 }
17024 {
17025 VkSubmitInfo submit_info{};
17026 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17027 submit_info.commandBufferCount = 2;
17028 submit_info.pCommandBuffers = command_buffer;
17029 submit_info.signalSemaphoreCount = 0;
17030 submit_info.pSignalSemaphores = nullptr;
17031 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17032 }
17033
17034 vkQueueWaitIdle(queue);
17035
17036 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17037 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17038 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17039 vkDestroyBuffer(m_device->device(), buffer, NULL);
17040 vkFreeMemory(m_device->device(), mem, NULL);
17041
17042 m_errorMonitor->VerifyNotFound();
17043}
17044
17045TEST_F(VkPositiveLayerTest, ResetEventThenSet) {
17046 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17047
17048 m_errorMonitor->ExpectSuccess();
17049
17050 ASSERT_NO_FATAL_FAILURE(InitState());
17051 VkEvent event;
17052 VkEventCreateInfo event_create_info{};
17053 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17054 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17055
17056 VkCommandPool command_pool;
17057 VkCommandPoolCreateInfo pool_create_info{};
17058 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17059 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17060 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17061 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17062
17063 VkCommandBuffer command_buffer;
17064 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17065 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17066 command_buffer_allocate_info.commandPool = command_pool;
17067 command_buffer_allocate_info.commandBufferCount = 1;
17068 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17069 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17070
17071 VkQueue queue = VK_NULL_HANDLE;
17072 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17073
17074 {
17075 VkCommandBufferBeginInfo begin_info{};
17076 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17077 vkBeginCommandBuffer(command_buffer, &begin_info);
17078
17079 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17080 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
17081 nullptr, 0, nullptr, 0, nullptr);
17082 vkEndCommandBuffer(command_buffer);
17083 }
17084 {
17085 VkSubmitInfo submit_info{};
17086 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17087 submit_info.commandBufferCount = 1;
17088 submit_info.pCommandBuffers = &command_buffer;
17089 submit_info.signalSemaphoreCount = 0;
17090 submit_info.pSignalSemaphores = nullptr;
17091 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17092 }
17093 {
17094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17095 "command buffer.");
17096 vkSetEvent(m_device->device(), event);
17097 m_errorMonitor->VerifyFound();
17098 }
17099
17100 vkQueueWaitIdle(queue);
17101
17102 vkDestroyEvent(m_device->device(), event, nullptr);
17103 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17104 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17105}
17106
17107// This is a positive test. No errors should be generated.
17108TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17109 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17110 "run through a Submit & WaitForFences cycle 3 times. This "
17111 "previously revealed a bug so running this positive test "
17112 "to prevent a regression.");
17113 m_errorMonitor->ExpectSuccess();
17114
17115 ASSERT_NO_FATAL_FAILURE(InitState());
17116 VkQueue queue = VK_NULL_HANDLE;
17117 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17118
17119 static const uint32_t NUM_OBJECTS = 2;
17120 static const uint32_t NUM_FRAMES = 3;
17121 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17122 VkFence fences[NUM_OBJECTS] = {};
17123
17124 VkCommandPool cmd_pool;
17125 VkCommandPoolCreateInfo cmd_pool_ci = {};
17126 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17127 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17128 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17129 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17130 ASSERT_VK_SUCCESS(err);
17131
17132 VkCommandBufferAllocateInfo cmd_buf_info = {};
17133 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17134 cmd_buf_info.commandPool = cmd_pool;
17135 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17136 cmd_buf_info.commandBufferCount = 1;
17137
17138 VkFenceCreateInfo fence_ci = {};
17139 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17140 fence_ci.pNext = nullptr;
17141 fence_ci.flags = 0;
17142
17143 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17144 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17145 ASSERT_VK_SUCCESS(err);
17146 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17147 ASSERT_VK_SUCCESS(err);
17148 }
17149
17150 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17151 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17152 // Create empty cmd buffer
17153 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17154 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17155
17156 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17157 ASSERT_VK_SUCCESS(err);
17158 err = vkEndCommandBuffer(cmd_buffers[obj]);
17159 ASSERT_VK_SUCCESS(err);
17160
17161 VkSubmitInfo submit_info = {};
17162 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17163 submit_info.commandBufferCount = 1;
17164 submit_info.pCommandBuffers = &cmd_buffers[obj];
17165 // Submit cmd buffer and wait for fence
17166 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17167 ASSERT_VK_SUCCESS(err);
17168 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17169 ASSERT_VK_SUCCESS(err);
17170 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17171 ASSERT_VK_SUCCESS(err);
17172 }
17173 }
17174 m_errorMonitor->VerifyNotFound();
17175 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17176 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17177 vkDestroyFence(m_device->device(), fences[i], nullptr);
17178 }
17179}
17180// This is a positive test. No errors should be generated.
17181TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17182
17183 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17184 "submitted on separate queues followed by a QueueWaitIdle.");
17185
17186 ASSERT_NO_FATAL_FAILURE(InitState());
17187 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17188 return;
17189
17190 m_errorMonitor->ExpectSuccess();
17191
17192 VkSemaphore semaphore;
17193 VkSemaphoreCreateInfo semaphore_create_info{};
17194 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17195 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17196
17197 VkCommandPool command_pool;
17198 VkCommandPoolCreateInfo pool_create_info{};
17199 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17200 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17201 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17202 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17203
17204 VkCommandBuffer command_buffer[2];
17205 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17206 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17207 command_buffer_allocate_info.commandPool = command_pool;
17208 command_buffer_allocate_info.commandBufferCount = 2;
17209 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17210 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17211
17212 VkQueue queue = VK_NULL_HANDLE;
17213 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17214
17215 {
17216 VkCommandBufferBeginInfo begin_info{};
17217 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17218 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17219
17220 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17221 nullptr, 0, nullptr, 0, nullptr);
17222
17223 VkViewport viewport{};
17224 viewport.maxDepth = 1.0f;
17225 viewport.minDepth = 0.0f;
17226 viewport.width = 512;
17227 viewport.height = 512;
17228 viewport.x = 0;
17229 viewport.y = 0;
17230 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17231 vkEndCommandBuffer(command_buffer[0]);
17232 }
17233 {
17234 VkCommandBufferBeginInfo begin_info{};
17235 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17236 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17237
17238 VkViewport viewport{};
17239 viewport.maxDepth = 1.0f;
17240 viewport.minDepth = 0.0f;
17241 viewport.width = 512;
17242 viewport.height = 512;
17243 viewport.x = 0;
17244 viewport.y = 0;
17245 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17246 vkEndCommandBuffer(command_buffer[1]);
17247 }
17248 {
17249 VkSubmitInfo submit_info{};
17250 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17251 submit_info.commandBufferCount = 1;
17252 submit_info.pCommandBuffers = &command_buffer[0];
17253 submit_info.signalSemaphoreCount = 1;
17254 submit_info.pSignalSemaphores = &semaphore;
17255 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17256 }
17257 {
17258 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17259 VkSubmitInfo submit_info{};
17260 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17261 submit_info.commandBufferCount = 1;
17262 submit_info.pCommandBuffers = &command_buffer[1];
17263 submit_info.waitSemaphoreCount = 1;
17264 submit_info.pWaitSemaphores = &semaphore;
17265 submit_info.pWaitDstStageMask = flags;
17266 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17267 }
17268
17269 vkQueueWaitIdle(m_device->m_queue);
17270
17271 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17272 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17273 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17274
17275 m_errorMonitor->VerifyNotFound();
17276}
17277
17278// This is a positive test. No errors should be generated.
17279TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17280
17281 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17282 "submitted on separate queues, the second having a fence"
17283 "followed by a QueueWaitIdle.");
17284
17285 ASSERT_NO_FATAL_FAILURE(InitState());
17286 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17287 return;
17288
17289 m_errorMonitor->ExpectSuccess();
17290
17291 VkFence fence;
17292 VkFenceCreateInfo fence_create_info{};
17293 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17294 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17295
17296 VkSemaphore semaphore;
17297 VkSemaphoreCreateInfo semaphore_create_info{};
17298 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17299 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17300
17301 VkCommandPool command_pool;
17302 VkCommandPoolCreateInfo pool_create_info{};
17303 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17304 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17305 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17306 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17307
17308 VkCommandBuffer command_buffer[2];
17309 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17310 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17311 command_buffer_allocate_info.commandPool = command_pool;
17312 command_buffer_allocate_info.commandBufferCount = 2;
17313 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17314 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17315
17316 VkQueue queue = VK_NULL_HANDLE;
17317 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17318
17319 {
17320 VkCommandBufferBeginInfo begin_info{};
17321 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17322 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17323
17324 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17325 nullptr, 0, nullptr, 0, nullptr);
17326
17327 VkViewport viewport{};
17328 viewport.maxDepth = 1.0f;
17329 viewport.minDepth = 0.0f;
17330 viewport.width = 512;
17331 viewport.height = 512;
17332 viewport.x = 0;
17333 viewport.y = 0;
17334 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17335 vkEndCommandBuffer(command_buffer[0]);
17336 }
17337 {
17338 VkCommandBufferBeginInfo begin_info{};
17339 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17340 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17341
17342 VkViewport viewport{};
17343 viewport.maxDepth = 1.0f;
17344 viewport.minDepth = 0.0f;
17345 viewport.width = 512;
17346 viewport.height = 512;
17347 viewport.x = 0;
17348 viewport.y = 0;
17349 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17350 vkEndCommandBuffer(command_buffer[1]);
17351 }
17352 {
17353 VkSubmitInfo submit_info{};
17354 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17355 submit_info.commandBufferCount = 1;
17356 submit_info.pCommandBuffers = &command_buffer[0];
17357 submit_info.signalSemaphoreCount = 1;
17358 submit_info.pSignalSemaphores = &semaphore;
17359 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17360 }
17361 {
17362 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17363 VkSubmitInfo submit_info{};
17364 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17365 submit_info.commandBufferCount = 1;
17366 submit_info.pCommandBuffers = &command_buffer[1];
17367 submit_info.waitSemaphoreCount = 1;
17368 submit_info.pWaitSemaphores = &semaphore;
17369 submit_info.pWaitDstStageMask = flags;
17370 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17371 }
17372
17373 vkQueueWaitIdle(m_device->m_queue);
17374
17375 vkDestroyFence(m_device->device(), fence, nullptr);
17376 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17377 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17378 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17379
17380 m_errorMonitor->VerifyNotFound();
17381}
17382
17383// This is a positive test. No errors should be generated.
17384TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17385
17386 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17387 "submitted on separate queues, the second having a fence"
17388 "followed by two consecutive WaitForFences calls on the same fence.");
17389
17390 ASSERT_NO_FATAL_FAILURE(InitState());
17391 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17392 return;
17393
17394 m_errorMonitor->ExpectSuccess();
17395
17396 VkFence fence;
17397 VkFenceCreateInfo fence_create_info{};
17398 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17399 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17400
17401 VkSemaphore semaphore;
17402 VkSemaphoreCreateInfo semaphore_create_info{};
17403 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17404 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17405
17406 VkCommandPool command_pool;
17407 VkCommandPoolCreateInfo pool_create_info{};
17408 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17409 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17410 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17411 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17412
17413 VkCommandBuffer command_buffer[2];
17414 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17415 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17416 command_buffer_allocate_info.commandPool = command_pool;
17417 command_buffer_allocate_info.commandBufferCount = 2;
17418 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17419 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17420
17421 VkQueue queue = VK_NULL_HANDLE;
17422 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17423
17424 {
17425 VkCommandBufferBeginInfo begin_info{};
17426 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17427 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17428
17429 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17430 nullptr, 0, nullptr, 0, nullptr);
17431
17432 VkViewport viewport{};
17433 viewport.maxDepth = 1.0f;
17434 viewport.minDepth = 0.0f;
17435 viewport.width = 512;
17436 viewport.height = 512;
17437 viewport.x = 0;
17438 viewport.y = 0;
17439 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17440 vkEndCommandBuffer(command_buffer[0]);
17441 }
17442 {
17443 VkCommandBufferBeginInfo begin_info{};
17444 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17445 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17446
17447 VkViewport viewport{};
17448 viewport.maxDepth = 1.0f;
17449 viewport.minDepth = 0.0f;
17450 viewport.width = 512;
17451 viewport.height = 512;
17452 viewport.x = 0;
17453 viewport.y = 0;
17454 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17455 vkEndCommandBuffer(command_buffer[1]);
17456 }
17457 {
17458 VkSubmitInfo submit_info{};
17459 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17460 submit_info.commandBufferCount = 1;
17461 submit_info.pCommandBuffers = &command_buffer[0];
17462 submit_info.signalSemaphoreCount = 1;
17463 submit_info.pSignalSemaphores = &semaphore;
17464 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17465 }
17466 {
17467 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17468 VkSubmitInfo submit_info{};
17469 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17470 submit_info.commandBufferCount = 1;
17471 submit_info.pCommandBuffers = &command_buffer[1];
17472 submit_info.waitSemaphoreCount = 1;
17473 submit_info.pWaitSemaphores = &semaphore;
17474 submit_info.pWaitDstStageMask = flags;
17475 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17476 }
17477
17478 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17479 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17480
17481 vkDestroyFence(m_device->device(), fence, nullptr);
17482 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17483 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17484 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17485
17486 m_errorMonitor->VerifyNotFound();
17487}
17488
17489TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
17490
17491 ASSERT_NO_FATAL_FAILURE(InitState());
17492 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
17493 printf("Test requires two queues, skipping\n");
17494 return;
17495 }
17496
17497 VkResult err;
17498
17499 m_errorMonitor->ExpectSuccess();
17500
17501 VkQueue q0 = m_device->m_queue;
17502 VkQueue q1 = nullptr;
17503 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
17504 ASSERT_NE(q1, nullptr);
17505
17506 // An (empty) command buffer. We must have work in the first submission --
17507 // the layer treats unfenced work differently from fenced work.
17508 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
17509 VkCommandPool pool;
17510 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
17511 ASSERT_VK_SUCCESS(err);
17512 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
17513 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
17514 VkCommandBuffer cb;
17515 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
17516 ASSERT_VK_SUCCESS(err);
17517 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
17518 err = vkBeginCommandBuffer(cb, &cbbi);
17519 ASSERT_VK_SUCCESS(err);
17520 err = vkEndCommandBuffer(cb);
17521 ASSERT_VK_SUCCESS(err);
17522
17523 // A semaphore
17524 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17525 VkSemaphore s;
17526 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
17527 ASSERT_VK_SUCCESS(err);
17528
17529 // First submission, to q0
17530 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
17531
17532 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
17533 ASSERT_VK_SUCCESS(err);
17534
17535 // Second submission, to q1, waiting on s
17536 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
17537 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
17538
17539 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
17540 ASSERT_VK_SUCCESS(err);
17541
17542 // Wait for q0 idle
17543 err = vkQueueWaitIdle(q0);
17544 ASSERT_VK_SUCCESS(err);
17545
17546 // Command buffer should have been completed (it was on q0); reset the pool.
17547 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
17548
17549 m_errorMonitor->VerifyNotFound();
17550
17551 // Force device completely idle and clean up resources
17552 vkDeviceWaitIdle(m_device->device());
17553 vkDestroyCommandPool(m_device->device(), pool, nullptr);
17554 vkDestroySemaphore(m_device->device(), s, nullptr);
17555}
17556
17557// This is a positive test. No errors should be generated.
17558TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
17559
17560 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17561 "submitted on separate queues, the second having a fence, "
17562 "followed by a WaitForFences call.");
17563
17564 ASSERT_NO_FATAL_FAILURE(InitState());
17565 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17566 return;
17567
17568 m_errorMonitor->ExpectSuccess();
17569
17570 ASSERT_NO_FATAL_FAILURE(InitState());
17571 VkFence fence;
17572 VkFenceCreateInfo fence_create_info{};
17573 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17574 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17575
17576 VkSemaphore semaphore;
17577 VkSemaphoreCreateInfo semaphore_create_info{};
17578 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17579 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17580
17581 VkCommandPool command_pool;
17582 VkCommandPoolCreateInfo pool_create_info{};
17583 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17584 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17585 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17586 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17587
17588 VkCommandBuffer command_buffer[2];
17589 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17590 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17591 command_buffer_allocate_info.commandPool = command_pool;
17592 command_buffer_allocate_info.commandBufferCount = 2;
17593 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17594 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17595
17596 VkQueue queue = VK_NULL_HANDLE;
17597 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17598
17599 {
17600 VkCommandBufferBeginInfo begin_info{};
17601 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17602 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17603
17604 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17605 nullptr, 0, nullptr, 0, nullptr);
17606
17607 VkViewport viewport{};
17608 viewport.maxDepth = 1.0f;
17609 viewport.minDepth = 0.0f;
17610 viewport.width = 512;
17611 viewport.height = 512;
17612 viewport.x = 0;
17613 viewport.y = 0;
17614 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17615 vkEndCommandBuffer(command_buffer[0]);
17616 }
17617 {
17618 VkCommandBufferBeginInfo begin_info{};
17619 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17620 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17621
17622 VkViewport viewport{};
17623 viewport.maxDepth = 1.0f;
17624 viewport.minDepth = 0.0f;
17625 viewport.width = 512;
17626 viewport.height = 512;
17627 viewport.x = 0;
17628 viewport.y = 0;
17629 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17630 vkEndCommandBuffer(command_buffer[1]);
17631 }
17632 {
17633 VkSubmitInfo submit_info{};
17634 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17635 submit_info.commandBufferCount = 1;
17636 submit_info.pCommandBuffers = &command_buffer[0];
17637 submit_info.signalSemaphoreCount = 1;
17638 submit_info.pSignalSemaphores = &semaphore;
17639 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17640 }
17641 {
17642 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17643 VkSubmitInfo submit_info{};
17644 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17645 submit_info.commandBufferCount = 1;
17646 submit_info.pCommandBuffers = &command_buffer[1];
17647 submit_info.waitSemaphoreCount = 1;
17648 submit_info.pWaitSemaphores = &semaphore;
17649 submit_info.pWaitDstStageMask = flags;
17650 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17651 }
17652
17653 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17654
17655 vkDestroyFence(m_device->device(), fence, nullptr);
17656 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17657 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17658 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17659
17660 m_errorMonitor->VerifyNotFound();
17661}
17662
17663// This is a positive test. No errors should be generated.
17664TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
17665
17666 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17667 "on the same queue, sharing a signal/wait semaphore, the "
17668 "second having a fence, "
17669 "followed by a WaitForFences call.");
17670
17671 m_errorMonitor->ExpectSuccess();
17672
17673 ASSERT_NO_FATAL_FAILURE(InitState());
17674 VkFence fence;
17675 VkFenceCreateInfo fence_create_info{};
17676 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17677 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17678
17679 VkSemaphore semaphore;
17680 VkSemaphoreCreateInfo semaphore_create_info{};
17681 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17682 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17683
17684 VkCommandPool command_pool;
17685 VkCommandPoolCreateInfo pool_create_info{};
17686 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17687 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17688 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17689 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17690
17691 VkCommandBuffer command_buffer[2];
17692 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17693 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17694 command_buffer_allocate_info.commandPool = command_pool;
17695 command_buffer_allocate_info.commandBufferCount = 2;
17696 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17697 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17698
17699 {
17700 VkCommandBufferBeginInfo begin_info{};
17701 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17702 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17703
17704 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17705 nullptr, 0, nullptr, 0, nullptr);
17706
17707 VkViewport viewport{};
17708 viewport.maxDepth = 1.0f;
17709 viewport.minDepth = 0.0f;
17710 viewport.width = 512;
17711 viewport.height = 512;
17712 viewport.x = 0;
17713 viewport.y = 0;
17714 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17715 vkEndCommandBuffer(command_buffer[0]);
17716 }
17717 {
17718 VkCommandBufferBeginInfo begin_info{};
17719 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17720 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17721
17722 VkViewport viewport{};
17723 viewport.maxDepth = 1.0f;
17724 viewport.minDepth = 0.0f;
17725 viewport.width = 512;
17726 viewport.height = 512;
17727 viewport.x = 0;
17728 viewport.y = 0;
17729 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17730 vkEndCommandBuffer(command_buffer[1]);
17731 }
17732 {
17733 VkSubmitInfo submit_info{};
17734 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17735 submit_info.commandBufferCount = 1;
17736 submit_info.pCommandBuffers = &command_buffer[0];
17737 submit_info.signalSemaphoreCount = 1;
17738 submit_info.pSignalSemaphores = &semaphore;
17739 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17740 }
17741 {
17742 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17743 VkSubmitInfo submit_info{};
17744 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17745 submit_info.commandBufferCount = 1;
17746 submit_info.pCommandBuffers = &command_buffer[1];
17747 submit_info.waitSemaphoreCount = 1;
17748 submit_info.pWaitSemaphores = &semaphore;
17749 submit_info.pWaitDstStageMask = flags;
17750 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17751 }
17752
17753 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17754
17755 vkDestroyFence(m_device->device(), fence, nullptr);
17756 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17757 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17758 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17759
17760 m_errorMonitor->VerifyNotFound();
17761}
17762
17763// This is a positive test. No errors should be generated.
17764TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
17765
17766 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17767 "on the same queue, no fences, followed by a third QueueSubmit with NO "
17768 "SubmitInfos but with a fence, followed by a WaitForFences call.");
17769
17770 m_errorMonitor->ExpectSuccess();
17771
17772 ASSERT_NO_FATAL_FAILURE(InitState());
17773 VkFence fence;
17774 VkFenceCreateInfo fence_create_info{};
17775 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17776 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17777
17778 VkCommandPool command_pool;
17779 VkCommandPoolCreateInfo pool_create_info{};
17780 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17781 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17782 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17783 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17784
17785 VkCommandBuffer command_buffer[2];
17786 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17787 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17788 command_buffer_allocate_info.commandPool = command_pool;
17789 command_buffer_allocate_info.commandBufferCount = 2;
17790 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17791 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17792
17793 {
17794 VkCommandBufferBeginInfo begin_info{};
17795 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17796 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17797
17798 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17799 nullptr, 0, nullptr, 0, nullptr);
17800
17801 VkViewport viewport{};
17802 viewport.maxDepth = 1.0f;
17803 viewport.minDepth = 0.0f;
17804 viewport.width = 512;
17805 viewport.height = 512;
17806 viewport.x = 0;
17807 viewport.y = 0;
17808 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17809 vkEndCommandBuffer(command_buffer[0]);
17810 }
17811 {
17812 VkCommandBufferBeginInfo begin_info{};
17813 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17814 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17815
17816 VkViewport viewport{};
17817 viewport.maxDepth = 1.0f;
17818 viewport.minDepth = 0.0f;
17819 viewport.width = 512;
17820 viewport.height = 512;
17821 viewport.x = 0;
17822 viewport.y = 0;
17823 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17824 vkEndCommandBuffer(command_buffer[1]);
17825 }
17826 {
17827 VkSubmitInfo submit_info{};
17828 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17829 submit_info.commandBufferCount = 1;
17830 submit_info.pCommandBuffers = &command_buffer[0];
17831 submit_info.signalSemaphoreCount = 0;
17832 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
17833 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17834 }
17835 {
17836 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17837 VkSubmitInfo submit_info{};
17838 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17839 submit_info.commandBufferCount = 1;
17840 submit_info.pCommandBuffers = &command_buffer[1];
17841 submit_info.waitSemaphoreCount = 0;
17842 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
17843 submit_info.pWaitDstStageMask = flags;
17844 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17845 }
17846
17847 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
17848
17849 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17850 ASSERT_VK_SUCCESS(err);
17851
17852 vkDestroyFence(m_device->device(), fence, nullptr);
17853 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17854 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17855
17856 m_errorMonitor->VerifyNotFound();
17857}
17858
17859// This is a positive test. No errors should be generated.
17860TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
17861
17862 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17863 "on the same queue, the second having a fence, followed "
17864 "by a WaitForFences call.");
17865
17866 m_errorMonitor->ExpectSuccess();
17867
17868 ASSERT_NO_FATAL_FAILURE(InitState());
17869 VkFence fence;
17870 VkFenceCreateInfo fence_create_info{};
17871 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17872 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17873
17874 VkCommandPool command_pool;
17875 VkCommandPoolCreateInfo pool_create_info{};
17876 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17877 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17878 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17879 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17880
17881 VkCommandBuffer command_buffer[2];
17882 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17883 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17884 command_buffer_allocate_info.commandPool = command_pool;
17885 command_buffer_allocate_info.commandBufferCount = 2;
17886 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17887 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17888
17889 {
17890 VkCommandBufferBeginInfo begin_info{};
17891 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17892 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17893
17894 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17895 nullptr, 0, nullptr, 0, nullptr);
17896
17897 VkViewport viewport{};
17898 viewport.maxDepth = 1.0f;
17899 viewport.minDepth = 0.0f;
17900 viewport.width = 512;
17901 viewport.height = 512;
17902 viewport.x = 0;
17903 viewport.y = 0;
17904 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17905 vkEndCommandBuffer(command_buffer[0]);
17906 }
17907 {
17908 VkCommandBufferBeginInfo begin_info{};
17909 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17910 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17911
17912 VkViewport viewport{};
17913 viewport.maxDepth = 1.0f;
17914 viewport.minDepth = 0.0f;
17915 viewport.width = 512;
17916 viewport.height = 512;
17917 viewport.x = 0;
17918 viewport.y = 0;
17919 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17920 vkEndCommandBuffer(command_buffer[1]);
17921 }
17922 {
17923 VkSubmitInfo submit_info{};
17924 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17925 submit_info.commandBufferCount = 1;
17926 submit_info.pCommandBuffers = &command_buffer[0];
17927 submit_info.signalSemaphoreCount = 0;
17928 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
17929 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17930 }
17931 {
17932 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17933 VkSubmitInfo submit_info{};
17934 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17935 submit_info.commandBufferCount = 1;
17936 submit_info.pCommandBuffers = &command_buffer[1];
17937 submit_info.waitSemaphoreCount = 0;
17938 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
17939 submit_info.pWaitDstStageMask = flags;
17940 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17941 }
17942
17943 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17944
17945 vkDestroyFence(m_device->device(), fence, nullptr);
17946 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17947 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17948
17949 m_errorMonitor->VerifyNotFound();
17950}
17951
17952// This is a positive test. No errors should be generated.
17953TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
17954
17955 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
17956 "QueueSubmit call followed by a WaitForFences call.");
17957 ASSERT_NO_FATAL_FAILURE(InitState());
17958
17959 m_errorMonitor->ExpectSuccess();
17960
17961 VkFence fence;
17962 VkFenceCreateInfo fence_create_info{};
17963 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17964 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17965
17966 VkSemaphore semaphore;
17967 VkSemaphoreCreateInfo semaphore_create_info{};
17968 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17969 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17970
17971 VkCommandPool command_pool;
17972 VkCommandPoolCreateInfo pool_create_info{};
17973 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17974 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17975 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17976 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17977
17978 VkCommandBuffer command_buffer[2];
17979 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17980 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17981 command_buffer_allocate_info.commandPool = command_pool;
17982 command_buffer_allocate_info.commandBufferCount = 2;
17983 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17984 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17985
17986 {
17987 VkCommandBufferBeginInfo begin_info{};
17988 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17989 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17990
17991 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17992 nullptr, 0, nullptr, 0, nullptr);
17993
17994 VkViewport viewport{};
17995 viewport.maxDepth = 1.0f;
17996 viewport.minDepth = 0.0f;
17997 viewport.width = 512;
17998 viewport.height = 512;
17999 viewport.x = 0;
18000 viewport.y = 0;
18001 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18002 vkEndCommandBuffer(command_buffer[0]);
18003 }
18004 {
18005 VkCommandBufferBeginInfo begin_info{};
18006 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18007 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18008
18009 VkViewport viewport{};
18010 viewport.maxDepth = 1.0f;
18011 viewport.minDepth = 0.0f;
18012 viewport.width = 512;
18013 viewport.height = 512;
18014 viewport.x = 0;
18015 viewport.y = 0;
18016 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18017 vkEndCommandBuffer(command_buffer[1]);
18018 }
18019 {
18020 VkSubmitInfo submit_info[2];
18021 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18022
18023 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18024 submit_info[0].pNext = NULL;
18025 submit_info[0].commandBufferCount = 1;
18026 submit_info[0].pCommandBuffers = &command_buffer[0];
18027 submit_info[0].signalSemaphoreCount = 1;
18028 submit_info[0].pSignalSemaphores = &semaphore;
18029 submit_info[0].waitSemaphoreCount = 0;
18030 submit_info[0].pWaitSemaphores = NULL;
18031 submit_info[0].pWaitDstStageMask = 0;
18032
18033 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18034 submit_info[1].pNext = NULL;
18035 submit_info[1].commandBufferCount = 1;
18036 submit_info[1].pCommandBuffers = &command_buffer[1];
18037 submit_info[1].waitSemaphoreCount = 1;
18038 submit_info[1].pWaitSemaphores = &semaphore;
18039 submit_info[1].pWaitDstStageMask = flags;
18040 submit_info[1].signalSemaphoreCount = 0;
18041 submit_info[1].pSignalSemaphores = NULL;
18042 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18043 }
18044
18045 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18046
18047 vkDestroyFence(m_device->device(), fence, nullptr);
18048 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18049 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18050 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18051
18052 m_errorMonitor->VerifyNotFound();
18053}
18054
18055TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18056 m_errorMonitor->ExpectSuccess();
18057
18058 ASSERT_NO_FATAL_FAILURE(InitState());
18059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18060
18061 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18062 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18063
18064 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18065 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18066 m_errorMonitor->VerifyNotFound();
18067 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18068 m_errorMonitor->VerifyNotFound();
18069 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18070 m_errorMonitor->VerifyNotFound();
18071
18072 m_commandBuffer->EndCommandBuffer();
18073 m_errorMonitor->VerifyNotFound();
18074}
18075
18076TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18077 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18078 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18079 "has a valid layout, and a second subpass then uses a "
18080 "valid *READ_ONLY* layout.");
18081 m_errorMonitor->ExpectSuccess();
18082 ASSERT_NO_FATAL_FAILURE(InitState());
18083
18084 VkAttachmentReference attach[2] = {};
18085 attach[0].attachment = 0;
18086 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18087 attach[1].attachment = 0;
18088 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18089 VkSubpassDescription subpasses[2] = {};
18090 // First subpass clears DS attach on load
18091 subpasses[0].pDepthStencilAttachment = &attach[0];
18092 // 2nd subpass reads in DS as input attachment
18093 subpasses[1].inputAttachmentCount = 1;
18094 subpasses[1].pInputAttachments = &attach[1];
18095 VkAttachmentDescription attach_desc = {};
18096 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18097 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18098 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18099 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18100 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18101 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18102 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18103 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18104 VkRenderPassCreateInfo rpci = {};
18105 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18106 rpci.attachmentCount = 1;
18107 rpci.pAttachments = &attach_desc;
18108 rpci.subpassCount = 2;
18109 rpci.pSubpasses = subpasses;
18110
18111 // Now create RenderPass and verify no errors
18112 VkRenderPass rp;
18113 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18114 m_errorMonitor->VerifyNotFound();
18115
18116 vkDestroyRenderPass(m_device->device(), rp, NULL);
18117}
18118
18119TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18120 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18121 "as vertex attributes");
18122 m_errorMonitor->ExpectSuccess();
18123
18124 ASSERT_NO_FATAL_FAILURE(InitState());
18125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18126
18127 VkVertexInputBindingDescription input_binding;
18128 memset(&input_binding, 0, sizeof(input_binding));
18129
18130 VkVertexInputAttributeDescription input_attribs[2];
18131 memset(input_attribs, 0, sizeof(input_attribs));
18132
18133 for (int i = 0; i < 2; i++) {
18134 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18135 input_attribs[i].location = i;
18136 }
18137
18138 char const *vsSource = "#version 450\n"
18139 "\n"
18140 "layout(location=0) in mat2x4 x;\n"
18141 "out gl_PerVertex {\n"
18142 " vec4 gl_Position;\n"
18143 "};\n"
18144 "void main(){\n"
18145 " gl_Position = x[0] + x[1];\n"
18146 "}\n";
18147 char const *fsSource = "#version 450\n"
18148 "\n"
18149 "layout(location=0) out vec4 color;\n"
18150 "void main(){\n"
18151 " color = vec4(1);\n"
18152 "}\n";
18153
18154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18156
18157 VkPipelineObj pipe(m_device);
18158 pipe.AddColorAttachment();
18159 pipe.AddShader(&vs);
18160 pipe.AddShader(&fs);
18161
18162 pipe.AddVertexInputBindings(&input_binding, 1);
18163 pipe.AddVertexInputAttribs(input_attribs, 2);
18164
18165 VkDescriptorSetObj descriptorSet(m_device);
18166 descriptorSet.AppendDummy();
18167 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18168
18169 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18170
18171 /* expect success */
18172 m_errorMonitor->VerifyNotFound();
18173}
18174
18175TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18176 m_errorMonitor->ExpectSuccess();
18177
18178 ASSERT_NO_FATAL_FAILURE(InitState());
18179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18180
18181 VkVertexInputBindingDescription input_binding;
18182 memset(&input_binding, 0, sizeof(input_binding));
18183
18184 VkVertexInputAttributeDescription input_attribs[2];
18185 memset(input_attribs, 0, sizeof(input_attribs));
18186
18187 for (int i = 0; i < 2; i++) {
18188 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18189 input_attribs[i].location = i;
18190 }
18191
18192 char const *vsSource = "#version 450\n"
18193 "\n"
18194 "layout(location=0) in vec4 x[2];\n"
18195 "out gl_PerVertex {\n"
18196 " vec4 gl_Position;\n"
18197 "};\n"
18198 "void main(){\n"
18199 " gl_Position = x[0] + x[1];\n"
18200 "}\n";
18201 char const *fsSource = "#version 450\n"
18202 "\n"
18203 "layout(location=0) out vec4 color;\n"
18204 "void main(){\n"
18205 " color = vec4(1);\n"
18206 "}\n";
18207
18208 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18209 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18210
18211 VkPipelineObj pipe(m_device);
18212 pipe.AddColorAttachment();
18213 pipe.AddShader(&vs);
18214 pipe.AddShader(&fs);
18215
18216 pipe.AddVertexInputBindings(&input_binding, 1);
18217 pipe.AddVertexInputAttribs(input_attribs, 2);
18218
18219 VkDescriptorSetObj descriptorSet(m_device);
18220 descriptorSet.AppendDummy();
18221 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18222
18223 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18224
18225 m_errorMonitor->VerifyNotFound();
18226}
18227
18228TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18229 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18230 "through multiple vertex shader inputs, each consuming a different "
18231 "subset of the components.");
18232 m_errorMonitor->ExpectSuccess();
18233
18234 ASSERT_NO_FATAL_FAILURE(InitState());
18235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18236
18237 VkVertexInputBindingDescription input_binding;
18238 memset(&input_binding, 0, sizeof(input_binding));
18239
18240 VkVertexInputAttributeDescription input_attribs[3];
18241 memset(input_attribs, 0, sizeof(input_attribs));
18242
18243 for (int i = 0; i < 3; i++) {
18244 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18245 input_attribs[i].location = i;
18246 }
18247
18248 char const *vsSource = "#version 450\n"
18249 "\n"
18250 "layout(location=0) in vec4 x;\n"
18251 "layout(location=1) in vec3 y1;\n"
18252 "layout(location=1, component=3) in float y2;\n"
18253 "layout(location=2) in vec4 z;\n"
18254 "out gl_PerVertex {\n"
18255 " vec4 gl_Position;\n"
18256 "};\n"
18257 "void main(){\n"
18258 " gl_Position = x + vec4(y1, y2) + z;\n"
18259 "}\n";
18260 char const *fsSource = "#version 450\n"
18261 "\n"
18262 "layout(location=0) out vec4 color;\n"
18263 "void main(){\n"
18264 " color = vec4(1);\n"
18265 "}\n";
18266
18267 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18268 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18269
18270 VkPipelineObj pipe(m_device);
18271 pipe.AddColorAttachment();
18272 pipe.AddShader(&vs);
18273 pipe.AddShader(&fs);
18274
18275 pipe.AddVertexInputBindings(&input_binding, 1);
18276 pipe.AddVertexInputAttribs(input_attribs, 3);
18277
18278 VkDescriptorSetObj descriptorSet(m_device);
18279 descriptorSet.AppendDummy();
18280 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18281
18282 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18283
18284 m_errorMonitor->VerifyNotFound();
18285}
18286
18287TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18288 m_errorMonitor->ExpectSuccess();
18289
18290 ASSERT_NO_FATAL_FAILURE(InitState());
18291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18292
18293 char const *vsSource = "#version 450\n"
18294 "out gl_PerVertex {\n"
18295 " vec4 gl_Position;\n"
18296 "};\n"
18297 "void main(){\n"
18298 " gl_Position = vec4(0);\n"
18299 "}\n";
18300 char const *fsSource = "#version 450\n"
18301 "\n"
18302 "layout(location=0) out vec4 color;\n"
18303 "void main(){\n"
18304 " color = vec4(1);\n"
18305 "}\n";
18306
18307 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18308 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18309
18310 VkPipelineObj pipe(m_device);
18311 pipe.AddColorAttachment();
18312 pipe.AddShader(&vs);
18313 pipe.AddShader(&fs);
18314
18315 VkDescriptorSetObj descriptorSet(m_device);
18316 descriptorSet.AppendDummy();
18317 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18318
18319 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18320
18321 m_errorMonitor->VerifyNotFound();
18322}
18323
18324TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18325 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18326 "set out in 14.1.3: fundamental type must match, and producer side must "
18327 "have at least as many components");
18328 m_errorMonitor->ExpectSuccess();
18329
18330 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18331
18332 ASSERT_NO_FATAL_FAILURE(InitState());
18333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18334
18335 char const *vsSource = "#version 450\n"
18336 "out gl_PerVertex {\n"
18337 " vec4 gl_Position;\n"
18338 "};\n"
18339 "layout(location=0) out vec3 x;\n"
18340 "layout(location=1) out ivec3 y;\n"
18341 "layout(location=2) out vec3 z;\n"
18342 "void main(){\n"
18343 " gl_Position = vec4(0);\n"
18344 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18345 "}\n";
18346 char const *fsSource = "#version 450\n"
18347 "\n"
18348 "layout(location=0) out vec4 color;\n"
18349 "layout(location=0) in float x;\n"
18350 "layout(location=1) flat in int y;\n"
18351 "layout(location=2) in vec2 z;\n"
18352 "void main(){\n"
18353 " color = vec4(1 + x + y + z.x);\n"
18354 "}\n";
18355
18356 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18357 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18358
18359 VkPipelineObj pipe(m_device);
18360 pipe.AddColorAttachment();
18361 pipe.AddShader(&vs);
18362 pipe.AddShader(&fs);
18363
18364 VkDescriptorSetObj descriptorSet(m_device);
18365 descriptorSet.AppendDummy();
18366 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18367
18368 VkResult err = VK_SUCCESS;
18369 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18370 ASSERT_VK_SUCCESS(err);
18371
18372 m_errorMonitor->VerifyNotFound();
18373}
18374
18375TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18376 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18377 "passed between the TCS and TES stages");
18378 m_errorMonitor->ExpectSuccess();
18379
18380 ASSERT_NO_FATAL_FAILURE(InitState());
18381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18382
18383 if (!m_device->phy().features().tessellationShader) {
18384 printf("Device does not support tessellation shaders; skipped.\n");
18385 return;
18386 }
18387
18388 char const *vsSource = "#version 450\n"
18389 "void main(){}\n";
18390 char const *tcsSource = "#version 450\n"
18391 "layout(location=0) out int x[];\n"
18392 "layout(vertices=3) out;\n"
18393 "void main(){\n"
18394 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
18395 " gl_TessLevelInner[0] = 1;\n"
18396 " x[gl_InvocationID] = gl_InvocationID;\n"
18397 "}\n";
18398 char const *tesSource = "#version 450\n"
18399 "layout(triangles, equal_spacing, cw) in;\n"
18400 "layout(location=0) in int x[];\n"
18401 "out gl_PerVertex { vec4 gl_Position; };\n"
18402 "void main(){\n"
18403 " gl_Position.xyz = gl_TessCoord;\n"
18404 " gl_Position.w = x[0] + x[1] + x[2];\n"
18405 "}\n";
18406 char const *fsSource = "#version 450\n"
18407 "layout(location=0) out vec4 color;\n"
18408 "void main(){\n"
18409 " color = vec4(1);\n"
18410 "}\n";
18411
18412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18413 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
18414 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
18415 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18416
18417 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
18418 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
18419
18420 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
18421
18422 VkPipelineObj pipe(m_device);
18423 pipe.SetInputAssembly(&iasci);
18424 pipe.SetTessellation(&tsci);
18425 pipe.AddColorAttachment();
18426 pipe.AddShader(&vs);
18427 pipe.AddShader(&tcs);
18428 pipe.AddShader(&tes);
18429 pipe.AddShader(&fs);
18430
18431 VkDescriptorSetObj descriptorSet(m_device);
18432 descriptorSet.AppendDummy();
18433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18434
18435 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18436
18437 m_errorMonitor->VerifyNotFound();
18438}
18439
18440TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
18441 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
18442 "interface block passed into the geometry shader. This "
18443 "is interesting because the 'extra' array level is not "
18444 "present on the member type, but on the block instance.");
18445 m_errorMonitor->ExpectSuccess();
18446
18447 ASSERT_NO_FATAL_FAILURE(InitState());
18448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18449
18450 if (!m_device->phy().features().geometryShader) {
18451 printf("Device does not support geometry shaders; skipped.\n");
18452 return;
18453 }
18454
18455 char const *vsSource = "#version 450\n"
18456 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
18457 "void main(){\n"
18458 " vs_out.x = vec4(1);\n"
18459 "}\n";
18460 char const *gsSource = "#version 450\n"
18461 "layout(triangles) in;\n"
18462 "layout(triangle_strip, max_vertices=3) out;\n"
18463 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
18464 "out gl_PerVertex { vec4 gl_Position; };\n"
18465 "void main() {\n"
18466 " gl_Position = gs_in[0].x;\n"
18467 " EmitVertex();\n"
18468 "}\n";
18469 char const *fsSource = "#version 450\n"
18470 "layout(location=0) out vec4 color;\n"
18471 "void main(){\n"
18472 " color = vec4(1);\n"
18473 "}\n";
18474
18475 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18476 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
18477 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18478
18479 VkPipelineObj pipe(m_device);
18480 pipe.AddColorAttachment();
18481 pipe.AddShader(&vs);
18482 pipe.AddShader(&gs);
18483 pipe.AddShader(&fs);
18484
18485 VkDescriptorSetObj descriptorSet(m_device);
18486 descriptorSet.AppendDummy();
18487 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18488
18489 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18490
18491 m_errorMonitor->VerifyNotFound();
18492}
18493
18494TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
18495 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
18496 "attributes. This is interesting because they consume multiple "
18497 "locations.");
18498 m_errorMonitor->ExpectSuccess();
18499
18500 ASSERT_NO_FATAL_FAILURE(InitState());
18501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18502
18503 if (!m_device->phy().features().shaderFloat64) {
18504 printf("Device does not support 64bit vertex attributes; skipped.\n");
18505 return;
18506 }
18507
18508 VkVertexInputBindingDescription input_bindings[1];
18509 memset(input_bindings, 0, sizeof(input_bindings));
18510
18511 VkVertexInputAttributeDescription input_attribs[4];
18512 memset(input_attribs, 0, sizeof(input_attribs));
18513 input_attribs[0].location = 0;
18514 input_attribs[0].offset = 0;
18515 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18516 input_attribs[1].location = 2;
18517 input_attribs[1].offset = 32;
18518 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18519 input_attribs[2].location = 4;
18520 input_attribs[2].offset = 64;
18521 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18522 input_attribs[3].location = 6;
18523 input_attribs[3].offset = 96;
18524 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18525
18526 char const *vsSource = "#version 450\n"
18527 "\n"
18528 "layout(location=0) in dmat4 x;\n"
18529 "out gl_PerVertex {\n"
18530 " vec4 gl_Position;\n"
18531 "};\n"
18532 "void main(){\n"
18533 " gl_Position = vec4(x[0][0]);\n"
18534 "}\n";
18535 char const *fsSource = "#version 450\n"
18536 "\n"
18537 "layout(location=0) out vec4 color;\n"
18538 "void main(){\n"
18539 " color = vec4(1);\n"
18540 "}\n";
18541
18542 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18543 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18544
18545 VkPipelineObj pipe(m_device);
18546 pipe.AddColorAttachment();
18547 pipe.AddShader(&vs);
18548 pipe.AddShader(&fs);
18549
18550 pipe.AddVertexInputBindings(input_bindings, 1);
18551 pipe.AddVertexInputAttribs(input_attribs, 4);
18552
18553 VkDescriptorSetObj descriptorSet(m_device);
18554 descriptorSet.AppendDummy();
18555 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18556
18557 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18558
18559 m_errorMonitor->VerifyNotFound();
18560}
18561
18562TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
18563 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
18564 m_errorMonitor->ExpectSuccess();
18565
18566 ASSERT_NO_FATAL_FAILURE(InitState());
18567
18568 char const *vsSource = "#version 450\n"
18569 "\n"
18570 "out gl_PerVertex {\n"
18571 " vec4 gl_Position;\n"
18572 "};\n"
18573 "void main(){\n"
18574 " gl_Position = vec4(1);\n"
18575 "}\n";
18576 char const *fsSource = "#version 450\n"
18577 "\n"
18578 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
18579 "layout(location=0) out vec4 color;\n"
18580 "void main() {\n"
18581 " color = subpassLoad(x);\n"
18582 "}\n";
18583
18584 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18585 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18586
18587 VkPipelineObj pipe(m_device);
18588 pipe.AddShader(&vs);
18589 pipe.AddShader(&fs);
18590 pipe.AddColorAttachment();
18591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18592
18593 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
18594 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
18595 VkDescriptorSetLayout dsl;
18596 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18597 ASSERT_VK_SUCCESS(err);
18598
18599 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18600 VkPipelineLayout pl;
18601 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18602 ASSERT_VK_SUCCESS(err);
18603
18604 VkAttachmentDescription descs[2] = {
18605 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18606 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18607 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
18608 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18609 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
18610 };
18611 VkAttachmentReference color = {
18612 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18613 };
18614 VkAttachmentReference input = {
18615 1, VK_IMAGE_LAYOUT_GENERAL,
18616 };
18617
18618 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
18619
18620 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
18621 VkRenderPass rp;
18622 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18623 ASSERT_VK_SUCCESS(err);
18624
18625 // should be OK. would go wrong here if it's going to...
18626 pipe.CreateVKPipeline(pl, rp);
18627
18628 m_errorMonitor->VerifyNotFound();
18629
18630 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18631 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18632 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18633}
18634
18635TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
18636 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
18637 "descriptor-backed resource which is not provided, but the shader does not "
18638 "statically use it. This is interesting because it requires compute pipelines "
18639 "to have a proper descriptor use walk, which they didn't for some time.");
18640 m_errorMonitor->ExpectSuccess();
18641
18642 ASSERT_NO_FATAL_FAILURE(InitState());
18643
18644 char const *csSource = "#version 450\n"
18645 "\n"
18646 "layout(local_size_x=1) in;\n"
18647 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
18648 "void main(){\n"
18649 " // x is not used.\n"
18650 "}\n";
18651
18652 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18653
18654 VkDescriptorSetObj descriptorSet(m_device);
18655 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18656
18657 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18658 nullptr,
18659 0,
18660 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18661 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18662 descriptorSet.GetPipelineLayout(),
18663 VK_NULL_HANDLE,
18664 -1 };
18665
18666 VkPipeline pipe;
18667 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18668
18669 m_errorMonitor->VerifyNotFound();
18670
18671 if (err == VK_SUCCESS) {
18672 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18673 }
18674}
18675
18676TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
18677 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
18678 "sampler portion of a combined image + sampler");
18679 m_errorMonitor->ExpectSuccess();
18680
18681 ASSERT_NO_FATAL_FAILURE(InitState());
18682
18683 VkDescriptorSetLayoutBinding bindings[] = {
18684 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18685 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18686 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18687 };
18688 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
18689 VkDescriptorSetLayout dsl;
18690 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18691 ASSERT_VK_SUCCESS(err);
18692
18693 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18694 VkPipelineLayout pl;
18695 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18696 ASSERT_VK_SUCCESS(err);
18697
18698 char const *csSource = "#version 450\n"
18699 "\n"
18700 "layout(local_size_x=1) in;\n"
18701 "layout(set=0, binding=0) uniform sampler s;\n"
18702 "layout(set=0, binding=1) uniform texture2D t;\n"
18703 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
18704 "void main() {\n"
18705 " x = texture(sampler2D(t, s), vec2(0));\n"
18706 "}\n";
18707 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18708
18709 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18710 nullptr,
18711 0,
18712 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18713 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18714 pl,
18715 VK_NULL_HANDLE,
18716 -1 };
18717
18718 VkPipeline pipe;
18719 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18720
18721 m_errorMonitor->VerifyNotFound();
18722
18723 if (err == VK_SUCCESS) {
18724 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18725 }
18726
18727 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18728 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18729}
18730
18731TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
18732 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
18733 "image portion of a combined image + sampler");
18734 m_errorMonitor->ExpectSuccess();
18735
18736 ASSERT_NO_FATAL_FAILURE(InitState());
18737
18738 VkDescriptorSetLayoutBinding bindings[] = {
18739 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18740 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18741 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18742 };
18743 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
18744 VkDescriptorSetLayout dsl;
18745 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18746 ASSERT_VK_SUCCESS(err);
18747
18748 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18749 VkPipelineLayout pl;
18750 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18751 ASSERT_VK_SUCCESS(err);
18752
18753 char const *csSource = "#version 450\n"
18754 "\n"
18755 "layout(local_size_x=1) in;\n"
18756 "layout(set=0, binding=0) uniform texture2D t;\n"
18757 "layout(set=0, binding=1) uniform sampler s;\n"
18758 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
18759 "void main() {\n"
18760 " x = texture(sampler2D(t, s), vec2(0));\n"
18761 "}\n";
18762 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18763
18764 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18765 nullptr,
18766 0,
18767 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18768 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18769 pl,
18770 VK_NULL_HANDLE,
18771 -1 };
18772
18773 VkPipeline pipe;
18774 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18775
18776 m_errorMonitor->VerifyNotFound();
18777
18778 if (err == VK_SUCCESS) {
18779 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18780 }
18781
18782 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18783 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18784}
18785
18786TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
18787 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
18788 "both the sampler and the image of a combined image+sampler "
18789 "but via separate variables");
18790 m_errorMonitor->ExpectSuccess();
18791
18792 ASSERT_NO_FATAL_FAILURE(InitState());
18793
18794 VkDescriptorSetLayoutBinding bindings[] = {
18795 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18796 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18797 };
18798 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
18799 VkDescriptorSetLayout dsl;
18800 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18801 ASSERT_VK_SUCCESS(err);
18802
18803 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18804 VkPipelineLayout pl;
18805 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18806 ASSERT_VK_SUCCESS(err);
18807
18808 char const *csSource = "#version 450\n"
18809 "\n"
18810 "layout(local_size_x=1) in;\n"
18811 "layout(set=0, binding=0) uniform texture2D t;\n"
18812 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
18813 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
18814 "void main() {\n"
18815 " x = texture(sampler2D(t, s), vec2(0));\n"
18816 "}\n";
18817 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18818
18819 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18820 nullptr,
18821 0,
18822 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18823 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18824 pl,
18825 VK_NULL_HANDLE,
18826 -1 };
18827
18828 VkPipeline pipe;
18829 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18830
18831 m_errorMonitor->VerifyNotFound();
18832
18833 if (err == VK_SUCCESS) {
18834 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18835 }
18836
18837 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18838 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18839}
18840
18841TEST_F(VkPositiveLayerTest, ValidStructPNext) {
18842 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
18843
18844 ASSERT_NO_FATAL_FAILURE(InitState());
18845
18846 // Positive test to check parameter_validation and unique_objects support
18847 // for NV_dedicated_allocation
18848 uint32_t extension_count = 0;
18849 bool supports_nv_dedicated_allocation = false;
18850 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
18851 ASSERT_VK_SUCCESS(err);
18852
18853 if (extension_count > 0) {
18854 std::vector<VkExtensionProperties> available_extensions(extension_count);
18855
18856 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
18857 ASSERT_VK_SUCCESS(err);
18858
18859 for (const auto &extension_props : available_extensions) {
18860 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
18861 supports_nv_dedicated_allocation = true;
18862 }
18863 }
18864 }
18865
18866 if (supports_nv_dedicated_allocation) {
18867 m_errorMonitor->ExpectSuccess();
18868
18869 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
18870 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
18871 dedicated_buffer_create_info.pNext = nullptr;
18872 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
18873
18874 uint32_t queue_family_index = 0;
18875 VkBufferCreateInfo buffer_create_info = {};
18876 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18877 buffer_create_info.pNext = &dedicated_buffer_create_info;
18878 buffer_create_info.size = 1024;
18879 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18880 buffer_create_info.queueFamilyIndexCount = 1;
18881 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18882
18883 VkBuffer buffer;
18884 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18885 ASSERT_VK_SUCCESS(err);
18886
18887 VkMemoryRequirements memory_reqs;
18888 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18889
18890 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
18891 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
18892 dedicated_memory_info.pNext = nullptr;
18893 dedicated_memory_info.buffer = buffer;
18894 dedicated_memory_info.image = VK_NULL_HANDLE;
18895
18896 VkMemoryAllocateInfo memory_info = {};
18897 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18898 memory_info.pNext = &dedicated_memory_info;
18899 memory_info.allocationSize = memory_reqs.size;
18900
18901 bool pass;
18902 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18903 ASSERT_TRUE(pass);
18904
18905 VkDeviceMemory buffer_memory;
18906 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18907 ASSERT_VK_SUCCESS(err);
18908
18909 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18910 ASSERT_VK_SUCCESS(err);
18911
18912 vkDestroyBuffer(m_device->device(), buffer, NULL);
18913 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18914
18915 m_errorMonitor->VerifyNotFound();
18916 }
18917}
18918
18919TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
18920 VkResult err;
18921
18922 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
18923
18924 ASSERT_NO_FATAL_FAILURE(InitState());
18925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18926
18927 std::vector<const char *> device_extension_names;
18928 auto features = m_device->phy().features();
18929 // Artificially disable support for non-solid fill modes
18930 features.fillModeNonSolid = false;
18931 // The sacrificial device object
18932 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
18933
18934 VkRenderpassObj render_pass(&test_device);
18935
18936 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18937 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18938 pipeline_layout_ci.setLayoutCount = 0;
18939 pipeline_layout_ci.pSetLayouts = NULL;
18940
18941 VkPipelineLayout pipeline_layout;
18942 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18943 ASSERT_VK_SUCCESS(err);
18944
18945 VkPipelineRasterizationStateCreateInfo rs_ci = {};
18946 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
18947 rs_ci.pNext = nullptr;
18948 rs_ci.lineWidth = 1.0f;
18949 rs_ci.rasterizerDiscardEnable = true;
18950
18951 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
18952 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18953
18954 // Set polygonMode=FILL. No error is expected
18955 m_errorMonitor->ExpectSuccess();
18956 {
18957 VkPipelineObj pipe(&test_device);
18958 pipe.AddShader(&vs);
18959 pipe.AddShader(&fs);
18960 pipe.AddColorAttachment();
18961 // Set polygonMode to a good value
18962 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
18963 pipe.SetRasterization(&rs_ci);
18964 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
18965 }
18966 m_errorMonitor->VerifyNotFound();
18967
18968 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
18969}
18970
18971TEST_F(VkPositiveLayerTest, ValidPushConstants) {
18972 VkResult err;
18973 ASSERT_NO_FATAL_FAILURE(InitState());
18974 ASSERT_NO_FATAL_FAILURE(InitViewport());
18975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18976
18977 VkPipelineLayout pipeline_layout;
18978 VkPushConstantRange pc_range = {};
18979 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18980 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18981 pipeline_layout_ci.pushConstantRangeCount = 1;
18982 pipeline_layout_ci.pPushConstantRanges = &pc_range;
18983
18984 //
18985 // Check for invalid push constant ranges in pipeline layouts.
18986 //
18987 struct PipelineLayoutTestCase {
18988 VkPushConstantRange const range;
18989 char const *msg;
18990 };
18991
18992 // Check for overlapping ranges
18993 const uint32_t ranges_per_test = 5;
18994 struct OverlappingRangeTestCase {
18995 VkPushConstantRange const ranges[ranges_per_test];
18996 char const *msg;
18997 };
18998
18999 // Run some positive tests to make sure overlap checking in the layer is OK
19000 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19001 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19002 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19003 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19004 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19005 "" },
19006 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19007 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19008 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19009 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19010 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19011 "" } } };
19012 for (const auto &iter : overlapping_range_tests_pos) {
19013 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19014 m_errorMonitor->ExpectSuccess();
19015 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19016 m_errorMonitor->VerifyNotFound();
19017 if (VK_SUCCESS == err) {
19018 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19019 }
19020 }
19021
19022 //
19023 // CmdPushConstants tests
19024 //
19025 const uint8_t dummy_values[100] = {};
19026
19027 BeginCommandBuffer();
19028
19029 // positive overlapping range tests with cmd
19030 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19031 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19032 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19033 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19034 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19035 } };
19036
19037 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19038 const VkPushConstantRange pc_range4[] = {
19039 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19040 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19041 };
19042
19043 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19044 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19045 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19046 ASSERT_VK_SUCCESS(err);
19047 for (const auto &iter : cmd_overlap_tests_pos) {
19048 m_errorMonitor->ExpectSuccess();
19049 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19050 iter.range.size, dummy_values);
19051 m_errorMonitor->VerifyNotFound();
19052 }
19053 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19054
19055 EndCommandBuffer();
19056}
19057
19058
19059
19060
19061
19062
19063
19064#if 0 // A few devices have issues with this test so disabling for now
19065TEST_F(VkPositiveLayerTest, LongFenceChain)
19066{
19067 m_errorMonitor->ExpectSuccess();
19068
19069 ASSERT_NO_FATAL_FAILURE(InitState());
19070 VkResult err;
19071
19072 std::vector<VkFence> fences;
19073
19074 const int chainLength = 32768;
19075
19076 for (int i = 0; i < chainLength; i++) {
19077 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19078 VkFence fence;
19079 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19080 ASSERT_VK_SUCCESS(err);
19081
19082 fences.push_back(fence);
19083
19084 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19085 0, nullptr, 0, nullptr };
19086 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19087 ASSERT_VK_SUCCESS(err);
19088
19089 }
19090
19091 // BOOM, stack overflow.
19092 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19093
19094 for (auto fence : fences)
19095 vkDestroyFence(m_device->device(), fence, nullptr);
19096
19097 m_errorMonitor->VerifyNotFound();
19098}
19099#endif
19100
19101
Cody Northrop1242dfd2016-07-13 17:24:59 -060019102#if defined(ANDROID) && defined(VALIDATION_APK)
19103static bool initialized = false;
19104static bool active = false;
19105
19106// Convert Intents to argv
19107// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019108std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019109 std::vector<std::string> args;
19110 JavaVM &vm = *app.activity->vm;
19111 JNIEnv *p_env;
19112 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19113 return args;
19114
19115 JNIEnv &env = *p_env;
19116 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019117 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019118 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019119 jmethodID get_string_extra_method =
19120 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019121 jvalue get_string_extra_args;
19122 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019123 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019124
19125 std::string args_str;
19126 if (extra_str) {
19127 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19128 args_str = extra_utf;
19129 env.ReleaseStringUTFChars(extra_str, extra_utf);
19130 env.DeleteLocalRef(extra_str);
19131 }
19132
19133 env.DeleteLocalRef(get_string_extra_args.l);
19134 env.DeleteLocalRef(intent);
19135 vm.DetachCurrentThread();
19136
19137 // split args_str
19138 std::stringstream ss(args_str);
19139 std::string arg;
19140 while (std::getline(ss, arg, ' ')) {
19141 if (!arg.empty())
19142 args.push_back(arg);
19143 }
19144
19145 return args;
19146}
19147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019148static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019150static void processCommand(struct android_app *app, int32_t cmd) {
19151 switch (cmd) {
19152 case APP_CMD_INIT_WINDOW: {
19153 if (app->window) {
19154 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019155 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019156 break;
19157 }
19158 case APP_CMD_GAINED_FOCUS: {
19159 active = true;
19160 break;
19161 }
19162 case APP_CMD_LOST_FOCUS: {
19163 active = false;
19164 break;
19165 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019166 }
19167}
19168
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019169void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019170 app_dummy();
19171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019172 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019173
19174 int vulkanSupport = InitVulkan();
19175 if (vulkanSupport == 0) {
19176 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19177 return;
19178 }
19179
19180 app->onAppCmd = processCommand;
19181 app->onInputEvent = processInput;
19182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019183 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019184 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019185 struct android_poll_source *source;
19186 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019187 if (source) {
19188 source->process(app, source);
19189 }
19190
19191 if (app->destroyRequested != 0) {
19192 VkTestFramework::Finish();
19193 return;
19194 }
19195 }
19196
19197 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019198 // Use the following key to send arguments to gtest, i.e.
19199 // --es args "--gtest_filter=-VkLayerTest.foo"
19200 const char key[] = "args";
19201 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019202
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019203 std::string filter = "";
19204 if (args.size() > 0) {
19205 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19206 filter += args[0];
19207 } else {
19208 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19209 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019210
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019211 int argc = 2;
19212 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19213 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019215 // Route output to files until we can override the gtest output
19216 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19217 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019219 ::testing::InitGoogleTest(&argc, argv);
19220 VkTestFramework::InitArgs(&argc, argv);
19221 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019223 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019225 if (result != 0) {
19226 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19227 } else {
19228 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19229 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019231 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019232
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019233 fclose(stdout);
19234 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019236 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019238 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019239 }
19240 }
19241}
19242#endif
19243
Tony Barbour300a6082015-04-07 13:44:53 -060019244int main(int argc, char **argv) {
19245 int result;
19246
Cody Northrop8e54a402016-03-08 22:25:52 -070019247#ifdef ANDROID
19248 int vulkanSupport = InitVulkan();
19249 if (vulkanSupport == 0)
19250 return 1;
19251#endif
19252
Tony Barbour300a6082015-04-07 13:44:53 -060019253 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019254 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019255
19256 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19257
19258 result = RUN_ALL_TESTS();
19259
Tony Barbour6918cd52015-04-09 12:58:51 -060019260 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019261 return result;
19262}