blob: 3afb767c7869f10a216b986dbcec5d225ea4e9c8 [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
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004357TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4358 TEST_DESCRIPTION("Delete in-use renderPass.");
4359
4360 ASSERT_NO_FATAL_FAILURE(InitState());
4361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4362
4363 // Create simple renderpass
4364 VkAttachmentReference attach = {};
4365 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4366 VkSubpassDescription subpass = {};
4367 subpass.pColorAttachments = &attach;
4368 VkRenderPassCreateInfo rpci = {};
4369 rpci.subpassCount = 1;
4370 rpci.pSubpasses = &subpass;
4371 rpci.attachmentCount = 1;
4372 VkAttachmentDescription attach_desc = {};
4373 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4374 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4375 rpci.pAttachments = &attach_desc;
4376 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4377 VkRenderPass rp;
4378 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4379 ASSERT_VK_SUCCESS(err);
4380
4381 // Create a pipeline that uses the given renderpass
4382 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4383 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4384
4385 VkPipelineLayout pipeline_layout;
4386 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4387 ASSERT_VK_SUCCESS(err);
4388
4389 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4390 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4391 vp_state_ci.viewportCount = 1;
4392 VkViewport vp = {}; // Just need dummy vp to point to
4393 vp_state_ci.pViewports = &vp;
4394 vp_state_ci.scissorCount = 1;
4395 VkRect2D scissors = {}; // Dummy scissors to point to
4396 vp_state_ci.pScissors = &scissors;
4397
4398 VkPipelineShaderStageCreateInfo shaderStages[2];
4399 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4400
4401 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4402 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4403 // but add it to be able to run on more devices
4404 shaderStages[0] = vs.GetStageCreateInfo();
4405 shaderStages[1] = fs.GetStageCreateInfo();
4406
4407 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4408 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4409
4410 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4411 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4412 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4413
4414 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4415 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4416 rs_ci.rasterizerDiscardEnable = true;
4417 rs_ci.lineWidth = 1.0f;
4418
4419 VkPipelineColorBlendAttachmentState att = {};
4420 att.blendEnable = VK_FALSE;
4421 att.colorWriteMask = 0xf;
4422
4423 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4424 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4425 cb_ci.attachmentCount = 1;
4426 cb_ci.pAttachments = &att;
4427
4428 VkGraphicsPipelineCreateInfo gp_ci = {};
4429 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4430 gp_ci.stageCount = 2;
4431 gp_ci.pStages = shaderStages;
4432 gp_ci.pVertexInputState = &vi_ci;
4433 gp_ci.pInputAssemblyState = &ia_ci;
4434 gp_ci.pViewportState = &vp_state_ci;
4435 gp_ci.pRasterizationState = &rs_ci;
4436 gp_ci.pColorBlendState = &cb_ci;
4437 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4438 gp_ci.layout = pipeline_layout;
4439 gp_ci.renderPass = rp;
4440
4441 VkPipelineCacheCreateInfo pc_ci = {};
4442 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4443
4444 VkPipeline pipeline;
4445 VkPipelineCache pipe_cache;
4446 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4447 ASSERT_VK_SUCCESS(err);
4448
4449 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4450 ASSERT_VK_SUCCESS(err);
4451 // Bind pipeline to cmd buffer, will also bind renderpass
4452 m_commandBuffer->BeginCommandBuffer();
4453 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4454 m_commandBuffer->EndCommandBuffer();
4455
4456 VkSubmitInfo submit_info = {};
4457 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4458 submit_info.commandBufferCount = 1;
4459 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4460 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4461
4462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4463 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4464 m_errorMonitor->VerifyFound();
4465
4466 // Wait for queue to complete so we can safely destroy everything
4467 vkQueueWaitIdle(m_device->m_queue);
4468 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4469 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4470 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4471 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4472}
4473
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004474TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004475 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004476 ASSERT_NO_FATAL_FAILURE(InitState());
4477
4478 VkImage image;
4479 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4480 VkImageCreateInfo image_create_info = {};
4481 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4482 image_create_info.pNext = NULL;
4483 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4484 image_create_info.format = tex_format;
4485 image_create_info.extent.width = 32;
4486 image_create_info.extent.height = 32;
4487 image_create_info.extent.depth = 1;
4488 image_create_info.mipLevels = 1;
4489 image_create_info.arrayLayers = 1;
4490 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4491 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004492 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004493 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004494 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004495 ASSERT_VK_SUCCESS(err);
4496 // Have to bind memory to image before recording cmd in cmd buffer using it
4497 VkMemoryRequirements mem_reqs;
4498 VkDeviceMemory image_mem;
4499 bool pass;
4500 VkMemoryAllocateInfo mem_alloc = {};
4501 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4502 mem_alloc.pNext = NULL;
4503 mem_alloc.memoryTypeIndex = 0;
4504 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4505 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004506 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004507 ASSERT_TRUE(pass);
4508 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4509 ASSERT_VK_SUCCESS(err);
4510
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004511 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004513 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004514
4515 m_commandBuffer->BeginCommandBuffer();
4516 VkClearColorValue ccv;
4517 ccv.float32[0] = 1.0f;
4518 ccv.float32[1] = 1.0f;
4519 ccv.float32[2] = 1.0f;
4520 ccv.float32[3] = 1.0f;
4521 VkImageSubresourceRange isr = {};
4522 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4523 isr.baseArrayLayer = 0;
4524 isr.baseMipLevel = 0;
4525 isr.layerCount = 1;
4526 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004527 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004528 m_commandBuffer->EndCommandBuffer();
4529
4530 m_errorMonitor->VerifyFound();
4531 vkDestroyImage(m_device->device(), image, NULL);
4532 vkFreeMemory(m_device->device(), image_mem, nullptr);
4533}
4534
4535TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004536 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004537 ASSERT_NO_FATAL_FAILURE(InitState());
4538
4539 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004540 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 -06004541 VK_IMAGE_TILING_OPTIMAL, 0);
4542 ASSERT_TRUE(image.initialized());
4543
4544 VkBuffer buffer;
4545 VkDeviceMemory mem;
4546 VkMemoryRequirements mem_reqs;
4547
4548 VkBufferCreateInfo buf_info = {};
4549 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004550 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004551 buf_info.size = 256;
4552 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4553 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4554 ASSERT_VK_SUCCESS(err);
4555
4556 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4557
4558 VkMemoryAllocateInfo alloc_info = {};
4559 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4560 alloc_info.allocationSize = 256;
4561 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004562 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 -06004563 if (!pass) {
4564 vkDestroyBuffer(m_device->device(), buffer, NULL);
4565 return;
4566 }
4567 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4568 ASSERT_VK_SUCCESS(err);
4569
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004570 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004572 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004573 VkBufferImageCopy region = {};
4574 region.bufferRowLength = 128;
4575 region.bufferImageHeight = 128;
4576 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4577
4578 region.imageSubresource.layerCount = 1;
4579 region.imageExtent.height = 4;
4580 region.imageExtent.width = 4;
4581 region.imageExtent.depth = 1;
4582 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004583 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4584 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004585 m_commandBuffer->EndCommandBuffer();
4586
4587 m_errorMonitor->VerifyFound();
4588
4589 vkDestroyBuffer(m_device->device(), buffer, NULL);
4590 vkFreeMemory(m_device->handle(), mem, NULL);
4591}
4592
Tobin Ehlis85940f52016-07-07 16:57:21 -06004593TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4594 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4595 "due to an event dependency being destroyed.");
4596 ASSERT_NO_FATAL_FAILURE(InitState());
4597
4598 VkEvent event;
4599 VkEventCreateInfo evci = {};
4600 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4601 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4602 ASSERT_VK_SUCCESS(result);
4603
4604 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004605 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004606 m_commandBuffer->EndCommandBuffer();
4607
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004609 // Destroy event dependency prior to submit to cause ERROR
4610 vkDestroyEvent(m_device->device(), event, NULL);
4611
4612 VkSubmitInfo submit_info = {};
4613 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4614 submit_info.commandBufferCount = 1;
4615 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4616 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4617
4618 m_errorMonitor->VerifyFound();
4619}
4620
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004621TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4622 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4623 "due to a query pool dependency being destroyed.");
4624 ASSERT_NO_FATAL_FAILURE(InitState());
4625
4626 VkQueryPool query_pool;
4627 VkQueryPoolCreateInfo qpci{};
4628 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4629 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4630 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004631 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004632 ASSERT_VK_SUCCESS(result);
4633
4634 m_commandBuffer->BeginCommandBuffer();
4635 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4636 m_commandBuffer->EndCommandBuffer();
4637
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004639 // Destroy query pool dependency prior to submit to cause ERROR
4640 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4641
4642 VkSubmitInfo submit_info = {};
4643 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4644 submit_info.commandBufferCount = 1;
4645 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4646 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4647
4648 m_errorMonitor->VerifyFound();
4649}
4650
Tobin Ehlis24130d92016-07-08 15:50:53 -06004651TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4652 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4653 "due to a pipeline dependency being destroyed.");
4654 ASSERT_NO_FATAL_FAILURE(InitState());
4655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4656
4657 VkResult err;
4658
4659 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4660 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4661
4662 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004663 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004664 ASSERT_VK_SUCCESS(err);
4665
4666 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4667 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4668 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004669 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004670 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004671 vp_state_ci.scissorCount = 1;
4672 VkRect2D scissors = {}; // Dummy scissors to point to
4673 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004674
4675 VkPipelineShaderStageCreateInfo shaderStages[2];
4676 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4677
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004678 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4679 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4680 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004681 shaderStages[0] = vs.GetStageCreateInfo();
4682 shaderStages[1] = fs.GetStageCreateInfo();
4683
4684 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4685 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4686
4687 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4688 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4689 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4690
4691 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4692 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004693 rs_ci.rasterizerDiscardEnable = true;
4694 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004695
4696 VkPipelineColorBlendAttachmentState att = {};
4697 att.blendEnable = VK_FALSE;
4698 att.colorWriteMask = 0xf;
4699
4700 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4701 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4702 cb_ci.attachmentCount = 1;
4703 cb_ci.pAttachments = &att;
4704
4705 VkGraphicsPipelineCreateInfo gp_ci = {};
4706 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4707 gp_ci.stageCount = 2;
4708 gp_ci.pStages = shaderStages;
4709 gp_ci.pVertexInputState = &vi_ci;
4710 gp_ci.pInputAssemblyState = &ia_ci;
4711 gp_ci.pViewportState = &vp_state_ci;
4712 gp_ci.pRasterizationState = &rs_ci;
4713 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004714 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4715 gp_ci.layout = pipeline_layout;
4716 gp_ci.renderPass = renderPass();
4717
4718 VkPipelineCacheCreateInfo pc_ci = {};
4719 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4720
4721 VkPipeline pipeline;
4722 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004723 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004724 ASSERT_VK_SUCCESS(err);
4725
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004726 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004727 ASSERT_VK_SUCCESS(err);
4728
4729 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004730 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004731 m_commandBuffer->EndCommandBuffer();
4732 // Now destroy pipeline in order to cause error when submitting
4733 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4734
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004736
4737 VkSubmitInfo submit_info = {};
4738 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4739 submit_info.commandBufferCount = 1;
4740 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4741 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4742
4743 m_errorMonitor->VerifyFound();
4744 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4745 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4746}
4747
Tobin Ehlis31289162016-08-17 14:57:58 -06004748TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4749 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4750 "due to a bound descriptor set with a buffer dependency "
4751 "being destroyed.");
4752 ASSERT_NO_FATAL_FAILURE(InitState());
4753 ASSERT_NO_FATAL_FAILURE(InitViewport());
4754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4755
4756 VkDescriptorPoolSize ds_type_count = {};
4757 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4758 ds_type_count.descriptorCount = 1;
4759
4760 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4761 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4762 ds_pool_ci.pNext = NULL;
4763 ds_pool_ci.maxSets = 1;
4764 ds_pool_ci.poolSizeCount = 1;
4765 ds_pool_ci.pPoolSizes = &ds_type_count;
4766
4767 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004768 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004769 ASSERT_VK_SUCCESS(err);
4770
4771 VkDescriptorSetLayoutBinding dsl_binding = {};
4772 dsl_binding.binding = 0;
4773 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4774 dsl_binding.descriptorCount = 1;
4775 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4776 dsl_binding.pImmutableSamplers = NULL;
4777
4778 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4779 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4780 ds_layout_ci.pNext = NULL;
4781 ds_layout_ci.bindingCount = 1;
4782 ds_layout_ci.pBindings = &dsl_binding;
4783 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004784 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004785 ASSERT_VK_SUCCESS(err);
4786
4787 VkDescriptorSet descriptorSet;
4788 VkDescriptorSetAllocateInfo alloc_info = {};
4789 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4790 alloc_info.descriptorSetCount = 1;
4791 alloc_info.descriptorPool = ds_pool;
4792 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004793 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004794 ASSERT_VK_SUCCESS(err);
4795
4796 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4797 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4798 pipeline_layout_ci.pNext = NULL;
4799 pipeline_layout_ci.setLayoutCount = 1;
4800 pipeline_layout_ci.pSetLayouts = &ds_layout;
4801
4802 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004803 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004804 ASSERT_VK_SUCCESS(err);
4805
4806 // Create a buffer to update the descriptor with
4807 uint32_t qfi = 0;
4808 VkBufferCreateInfo buffCI = {};
4809 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4810 buffCI.size = 1024;
4811 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4812 buffCI.queueFamilyIndexCount = 1;
4813 buffCI.pQueueFamilyIndices = &qfi;
4814
4815 VkBuffer buffer;
4816 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4817 ASSERT_VK_SUCCESS(err);
4818 // Allocate memory and bind to buffer so we can make it to the appropriate
4819 // error
4820 VkMemoryAllocateInfo mem_alloc = {};
4821 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4822 mem_alloc.pNext = NULL;
4823 mem_alloc.allocationSize = 1024;
4824 mem_alloc.memoryTypeIndex = 0;
4825
4826 VkMemoryRequirements memReqs;
4827 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004828 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004829 if (!pass) {
4830 vkDestroyBuffer(m_device->device(), buffer, NULL);
4831 return;
4832 }
4833
4834 VkDeviceMemory mem;
4835 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4836 ASSERT_VK_SUCCESS(err);
4837 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4838 ASSERT_VK_SUCCESS(err);
4839 // Correctly update descriptor to avoid "NOT_UPDATED" error
4840 VkDescriptorBufferInfo buffInfo = {};
4841 buffInfo.buffer = buffer;
4842 buffInfo.offset = 0;
4843 buffInfo.range = 1024;
4844
4845 VkWriteDescriptorSet descriptor_write;
4846 memset(&descriptor_write, 0, sizeof(descriptor_write));
4847 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4848 descriptor_write.dstSet = descriptorSet;
4849 descriptor_write.dstBinding = 0;
4850 descriptor_write.descriptorCount = 1;
4851 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4852 descriptor_write.pBufferInfo = &buffInfo;
4853
4854 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4855
4856 // Create PSO to be used for draw-time errors below
4857 char const *vsSource = "#version 450\n"
4858 "\n"
4859 "out gl_PerVertex { \n"
4860 " vec4 gl_Position;\n"
4861 "};\n"
4862 "void main(){\n"
4863 " gl_Position = vec4(1);\n"
4864 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004865 char const *fsSource = "#version 450\n"
4866 "\n"
4867 "layout(location=0) out vec4 x;\n"
4868 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4869 "void main(){\n"
4870 " x = vec4(bar.y);\n"
4871 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06004872 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4873 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4874 VkPipelineObj pipe(m_device);
4875 pipe.AddShader(&vs);
4876 pipe.AddShader(&fs);
4877 pipe.AddColorAttachment();
4878 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4879
4880 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004881 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4882 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4883 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06004884 Draw(1, 0, 0, 0);
4885 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06004887 // Destroy buffer should invalidate the cmd buffer, causing error on submit
4888 vkDestroyBuffer(m_device->device(), buffer, NULL);
4889 // Attempt to submit cmd buffer
4890 VkSubmitInfo submit_info = {};
4891 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4892 submit_info.commandBufferCount = 1;
4893 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4894 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4895 m_errorMonitor->VerifyFound();
4896 // Cleanup
4897 vkFreeMemory(m_device->device(), mem, NULL);
4898
4899 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4900 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4901 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4902}
4903
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004904TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
4905 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4906 "due to a bound descriptor sets with a combined image "
4907 "sampler having their image, sampler, and descriptor set "
4908 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06004909 "submit associated cmd buffers. Attempt to destroy a "
4910 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004911 ASSERT_NO_FATAL_FAILURE(InitState());
4912 ASSERT_NO_FATAL_FAILURE(InitViewport());
4913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4914
4915 VkDescriptorPoolSize ds_type_count = {};
4916 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4917 ds_type_count.descriptorCount = 1;
4918
4919 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4920 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4921 ds_pool_ci.pNext = NULL;
4922 ds_pool_ci.maxSets = 1;
4923 ds_pool_ci.poolSizeCount = 1;
4924 ds_pool_ci.pPoolSizes = &ds_type_count;
4925
4926 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004927 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004928 ASSERT_VK_SUCCESS(err);
4929
4930 VkDescriptorSetLayoutBinding dsl_binding = {};
4931 dsl_binding.binding = 0;
4932 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4933 dsl_binding.descriptorCount = 1;
4934 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4935 dsl_binding.pImmutableSamplers = NULL;
4936
4937 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4938 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4939 ds_layout_ci.pNext = NULL;
4940 ds_layout_ci.bindingCount = 1;
4941 ds_layout_ci.pBindings = &dsl_binding;
4942 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004943 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004944 ASSERT_VK_SUCCESS(err);
4945
4946 VkDescriptorSet descriptorSet;
4947 VkDescriptorSetAllocateInfo alloc_info = {};
4948 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4949 alloc_info.descriptorSetCount = 1;
4950 alloc_info.descriptorPool = ds_pool;
4951 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004952 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004953 ASSERT_VK_SUCCESS(err);
4954
4955 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4956 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4957 pipeline_layout_ci.pNext = NULL;
4958 pipeline_layout_ci.setLayoutCount = 1;
4959 pipeline_layout_ci.pSetLayouts = &ds_layout;
4960
4961 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004962 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004963 ASSERT_VK_SUCCESS(err);
4964
4965 // Create images to update the descriptor with
4966 VkImage image;
4967 VkImage image2;
4968 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4969 const int32_t tex_width = 32;
4970 const int32_t tex_height = 32;
4971 VkImageCreateInfo image_create_info = {};
4972 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4973 image_create_info.pNext = NULL;
4974 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4975 image_create_info.format = tex_format;
4976 image_create_info.extent.width = tex_width;
4977 image_create_info.extent.height = tex_height;
4978 image_create_info.extent.depth = 1;
4979 image_create_info.mipLevels = 1;
4980 image_create_info.arrayLayers = 1;
4981 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4982 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
4983 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4984 image_create_info.flags = 0;
4985 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
4986 ASSERT_VK_SUCCESS(err);
4987 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
4988 ASSERT_VK_SUCCESS(err);
4989
4990 VkMemoryRequirements memory_reqs;
4991 VkDeviceMemory image_memory;
4992 bool pass;
4993 VkMemoryAllocateInfo memory_info = {};
4994 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4995 memory_info.pNext = NULL;
4996 memory_info.allocationSize = 0;
4997 memory_info.memoryTypeIndex = 0;
4998 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4999 // Allocate enough memory for both images
5000 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005001 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005002 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005003 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005004 ASSERT_VK_SUCCESS(err);
5005 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5006 ASSERT_VK_SUCCESS(err);
5007 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005008 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005009 ASSERT_VK_SUCCESS(err);
5010
5011 VkImageViewCreateInfo image_view_create_info = {};
5012 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5013 image_view_create_info.image = image;
5014 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5015 image_view_create_info.format = tex_format;
5016 image_view_create_info.subresourceRange.layerCount = 1;
5017 image_view_create_info.subresourceRange.baseMipLevel = 0;
5018 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005019 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005020
5021 VkImageView view;
5022 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005023 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005024 ASSERT_VK_SUCCESS(err);
5025 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005026 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005027 ASSERT_VK_SUCCESS(err);
5028 // Create Samplers
5029 VkSamplerCreateInfo sampler_ci = {};
5030 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5031 sampler_ci.pNext = NULL;
5032 sampler_ci.magFilter = VK_FILTER_NEAREST;
5033 sampler_ci.minFilter = VK_FILTER_NEAREST;
5034 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5035 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5036 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5037 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5038 sampler_ci.mipLodBias = 1.0;
5039 sampler_ci.anisotropyEnable = VK_FALSE;
5040 sampler_ci.maxAnisotropy = 1;
5041 sampler_ci.compareEnable = VK_FALSE;
5042 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5043 sampler_ci.minLod = 1.0;
5044 sampler_ci.maxLod = 1.0;
5045 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5046 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5047 VkSampler sampler;
5048 VkSampler sampler2;
5049 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5050 ASSERT_VK_SUCCESS(err);
5051 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5052 ASSERT_VK_SUCCESS(err);
5053 // Update descriptor with image and sampler
5054 VkDescriptorImageInfo img_info = {};
5055 img_info.sampler = sampler;
5056 img_info.imageView = view;
5057 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5058
5059 VkWriteDescriptorSet descriptor_write;
5060 memset(&descriptor_write, 0, sizeof(descriptor_write));
5061 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5062 descriptor_write.dstSet = descriptorSet;
5063 descriptor_write.dstBinding = 0;
5064 descriptor_write.descriptorCount = 1;
5065 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5066 descriptor_write.pImageInfo = &img_info;
5067
5068 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5069
5070 // Create PSO to be used for draw-time errors below
5071 char const *vsSource = "#version 450\n"
5072 "\n"
5073 "out gl_PerVertex { \n"
5074 " vec4 gl_Position;\n"
5075 "};\n"
5076 "void main(){\n"
5077 " gl_Position = vec4(1);\n"
5078 "}\n";
5079 char const *fsSource = "#version 450\n"
5080 "\n"
5081 "layout(set=0, binding=0) uniform sampler2D s;\n"
5082 "layout(location=0) out vec4 x;\n"
5083 "void main(){\n"
5084 " x = texture(s, vec2(1));\n"
5085 "}\n";
5086 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5087 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5088 VkPipelineObj pipe(m_device);
5089 pipe.AddShader(&vs);
5090 pipe.AddShader(&fs);
5091 pipe.AddColorAttachment();
5092 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5093
5094 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005096 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005097 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5098 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5099 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005100 Draw(1, 0, 0, 0);
5101 EndCommandBuffer();
5102 // Destroy sampler invalidates the cmd buffer, causing error on submit
5103 vkDestroySampler(m_device->device(), sampler, NULL);
5104 // Attempt to submit cmd buffer
5105 VkSubmitInfo submit_info = {};
5106 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5107 submit_info.commandBufferCount = 1;
5108 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5109 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5110 m_errorMonitor->VerifyFound();
5111 // Now re-update descriptor with valid sampler and delete image
5112 img_info.sampler = sampler2;
5113 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005115 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005116 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5117 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5118 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005119 Draw(1, 0, 0, 0);
5120 EndCommandBuffer();
5121 // Destroy image invalidates the cmd buffer, causing error on submit
5122 vkDestroyImage(m_device->device(), image, NULL);
5123 // Attempt to submit cmd buffer
5124 submit_info = {};
5125 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5126 submit_info.commandBufferCount = 1;
5127 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5128 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5129 m_errorMonitor->VerifyFound();
5130 // Now update descriptor to be valid, but then free descriptor
5131 img_info.imageView = view2;
5132 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005134 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005135 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5136 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5137 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005138 Draw(1, 0, 0, 0);
5139 EndCommandBuffer();
5140 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005142 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005143 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005144 // Attempt to submit cmd buffer
5145 submit_info = {};
5146 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5147 submit_info.commandBufferCount = 1;
5148 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5149 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5150 m_errorMonitor->VerifyFound();
5151 // Cleanup
5152 vkFreeMemory(m_device->device(), image_memory, NULL);
5153 vkDestroySampler(m_device->device(), sampler2, NULL);
5154 vkDestroyImage(m_device->device(), image2, NULL);
5155 vkDestroyImageView(m_device->device(), view, NULL);
5156 vkDestroyImageView(m_device->device(), view2, NULL);
5157 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5158 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5159 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5160}
5161
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005162TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5163 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5164 ASSERT_NO_FATAL_FAILURE(InitState());
5165 ASSERT_NO_FATAL_FAILURE(InitViewport());
5166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5167
5168 VkDescriptorPoolSize ds_type_count = {};
5169 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5170 ds_type_count.descriptorCount = 1;
5171
5172 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5173 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5174 ds_pool_ci.pNext = NULL;
5175 ds_pool_ci.maxSets = 1;
5176 ds_pool_ci.poolSizeCount = 1;
5177 ds_pool_ci.pPoolSizes = &ds_type_count;
5178
5179 VkDescriptorPool ds_pool;
5180 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5181 ASSERT_VK_SUCCESS(err);
5182
5183 VkDescriptorSetLayoutBinding dsl_binding = {};
5184 dsl_binding.binding = 0;
5185 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5186 dsl_binding.descriptorCount = 1;
5187 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5188 dsl_binding.pImmutableSamplers = NULL;
5189
5190 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5191 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5192 ds_layout_ci.pNext = NULL;
5193 ds_layout_ci.bindingCount = 1;
5194 ds_layout_ci.pBindings = &dsl_binding;
5195 VkDescriptorSetLayout ds_layout;
5196 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5197 ASSERT_VK_SUCCESS(err);
5198
5199 VkDescriptorSet descriptor_set;
5200 VkDescriptorSetAllocateInfo alloc_info = {};
5201 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5202 alloc_info.descriptorSetCount = 1;
5203 alloc_info.descriptorPool = ds_pool;
5204 alloc_info.pSetLayouts = &ds_layout;
5205 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5206 ASSERT_VK_SUCCESS(err);
5207
5208 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5209 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5210 pipeline_layout_ci.pNext = NULL;
5211 pipeline_layout_ci.setLayoutCount = 1;
5212 pipeline_layout_ci.pSetLayouts = &ds_layout;
5213
5214 VkPipelineLayout pipeline_layout;
5215 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5216 ASSERT_VK_SUCCESS(err);
5217
5218 // Create image to update the descriptor with
5219 VkImageObj image(m_device);
5220 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5221 ASSERT_TRUE(image.initialized());
5222
5223 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5224 // Create Sampler
5225 VkSamplerCreateInfo sampler_ci = {};
5226 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5227 sampler_ci.pNext = NULL;
5228 sampler_ci.magFilter = VK_FILTER_NEAREST;
5229 sampler_ci.minFilter = VK_FILTER_NEAREST;
5230 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5231 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5232 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5233 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5234 sampler_ci.mipLodBias = 1.0;
5235 sampler_ci.anisotropyEnable = VK_FALSE;
5236 sampler_ci.maxAnisotropy = 1;
5237 sampler_ci.compareEnable = VK_FALSE;
5238 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5239 sampler_ci.minLod = 1.0;
5240 sampler_ci.maxLod = 1.0;
5241 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5242 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5243 VkSampler sampler;
5244 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5245 ASSERT_VK_SUCCESS(err);
5246 // Update descriptor with image and sampler
5247 VkDescriptorImageInfo img_info = {};
5248 img_info.sampler = sampler;
5249 img_info.imageView = view;
5250 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5251
5252 VkWriteDescriptorSet descriptor_write;
5253 memset(&descriptor_write, 0, sizeof(descriptor_write));
5254 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5255 descriptor_write.dstSet = descriptor_set;
5256 descriptor_write.dstBinding = 0;
5257 descriptor_write.descriptorCount = 1;
5258 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5259 descriptor_write.pImageInfo = &img_info;
5260
5261 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5262
5263 // Create PSO to be used for draw-time errors below
5264 char const *vsSource = "#version 450\n"
5265 "\n"
5266 "out gl_PerVertex { \n"
5267 " vec4 gl_Position;\n"
5268 "};\n"
5269 "void main(){\n"
5270 " gl_Position = vec4(1);\n"
5271 "}\n";
5272 char const *fsSource = "#version 450\n"
5273 "\n"
5274 "layout(set=0, binding=0) uniform sampler2D s;\n"
5275 "layout(location=0) out vec4 x;\n"
5276 "void main(){\n"
5277 " x = texture(s, vec2(1));\n"
5278 "}\n";
5279 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5280 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5281 VkPipelineObj pipe(m_device);
5282 pipe.AddShader(&vs);
5283 pipe.AddShader(&fs);
5284 pipe.AddColorAttachment();
5285 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5286
5287 BeginCommandBuffer();
5288 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5289 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5290 &descriptor_set, 0, NULL);
5291 Draw(1, 0, 0, 0);
5292 EndCommandBuffer();
5293 // Submit cmd buffer to put pool in-flight
5294 VkSubmitInfo submit_info = {};
5295 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5296 submit_info.commandBufferCount = 1;
5297 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5298 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5299 // Destroy pool while in-flight, causing error
5300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5301 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5302 m_errorMonitor->VerifyFound();
5303 vkQueueWaitIdle(m_device->m_queue);
5304 // Cleanup
5305 vkDestroySampler(m_device->device(), sampler, NULL);
5306 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5307 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5308 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5309}
5310
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005311TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5312 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5313 ASSERT_NO_FATAL_FAILURE(InitState());
5314 ASSERT_NO_FATAL_FAILURE(InitViewport());
5315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5316
5317 VkDescriptorPoolSize ds_type_count = {};
5318 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5319 ds_type_count.descriptorCount = 1;
5320
5321 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5322 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5323 ds_pool_ci.pNext = NULL;
5324 ds_pool_ci.maxSets = 1;
5325 ds_pool_ci.poolSizeCount = 1;
5326 ds_pool_ci.pPoolSizes = &ds_type_count;
5327
5328 VkDescriptorPool ds_pool;
5329 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5330 ASSERT_VK_SUCCESS(err);
5331
5332 VkDescriptorSetLayoutBinding dsl_binding = {};
5333 dsl_binding.binding = 0;
5334 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5335 dsl_binding.descriptorCount = 1;
5336 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5337 dsl_binding.pImmutableSamplers = NULL;
5338
5339 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5340 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5341 ds_layout_ci.pNext = NULL;
5342 ds_layout_ci.bindingCount = 1;
5343 ds_layout_ci.pBindings = &dsl_binding;
5344 VkDescriptorSetLayout ds_layout;
5345 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5346 ASSERT_VK_SUCCESS(err);
5347
5348 VkDescriptorSet descriptorSet;
5349 VkDescriptorSetAllocateInfo alloc_info = {};
5350 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5351 alloc_info.descriptorSetCount = 1;
5352 alloc_info.descriptorPool = ds_pool;
5353 alloc_info.pSetLayouts = &ds_layout;
5354 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5355 ASSERT_VK_SUCCESS(err);
5356
5357 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5358 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5359 pipeline_layout_ci.pNext = NULL;
5360 pipeline_layout_ci.setLayoutCount = 1;
5361 pipeline_layout_ci.pSetLayouts = &ds_layout;
5362
5363 VkPipelineLayout pipeline_layout;
5364 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5365 ASSERT_VK_SUCCESS(err);
5366
5367 // Create images to update the descriptor with
5368 VkImage image;
5369 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5370 const int32_t tex_width = 32;
5371 const int32_t tex_height = 32;
5372 VkImageCreateInfo image_create_info = {};
5373 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5374 image_create_info.pNext = NULL;
5375 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5376 image_create_info.format = tex_format;
5377 image_create_info.extent.width = tex_width;
5378 image_create_info.extent.height = tex_height;
5379 image_create_info.extent.depth = 1;
5380 image_create_info.mipLevels = 1;
5381 image_create_info.arrayLayers = 1;
5382 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5383 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5384 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5385 image_create_info.flags = 0;
5386 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5387 ASSERT_VK_SUCCESS(err);
5388 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5389 VkMemoryRequirements memory_reqs;
5390 VkDeviceMemory image_memory;
5391 bool pass;
5392 VkMemoryAllocateInfo memory_info = {};
5393 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5394 memory_info.pNext = NULL;
5395 memory_info.allocationSize = 0;
5396 memory_info.memoryTypeIndex = 0;
5397 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5398 // Allocate enough memory for image
5399 memory_info.allocationSize = memory_reqs.size;
5400 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5401 ASSERT_TRUE(pass);
5402 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5403 ASSERT_VK_SUCCESS(err);
5404 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5405 ASSERT_VK_SUCCESS(err);
5406
5407 VkImageViewCreateInfo image_view_create_info = {};
5408 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5409 image_view_create_info.image = image;
5410 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5411 image_view_create_info.format = tex_format;
5412 image_view_create_info.subresourceRange.layerCount = 1;
5413 image_view_create_info.subresourceRange.baseMipLevel = 0;
5414 image_view_create_info.subresourceRange.levelCount = 1;
5415 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5416
5417 VkImageView view;
5418 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5419 ASSERT_VK_SUCCESS(err);
5420 // Create Samplers
5421 VkSamplerCreateInfo sampler_ci = {};
5422 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5423 sampler_ci.pNext = NULL;
5424 sampler_ci.magFilter = VK_FILTER_NEAREST;
5425 sampler_ci.minFilter = VK_FILTER_NEAREST;
5426 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5427 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5428 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5429 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5430 sampler_ci.mipLodBias = 1.0;
5431 sampler_ci.anisotropyEnable = VK_FALSE;
5432 sampler_ci.maxAnisotropy = 1;
5433 sampler_ci.compareEnable = VK_FALSE;
5434 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5435 sampler_ci.minLod = 1.0;
5436 sampler_ci.maxLod = 1.0;
5437 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5438 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5439 VkSampler sampler;
5440 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5441 ASSERT_VK_SUCCESS(err);
5442 // Update descriptor with image and sampler
5443 VkDescriptorImageInfo img_info = {};
5444 img_info.sampler = sampler;
5445 img_info.imageView = view;
5446 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5447
5448 VkWriteDescriptorSet descriptor_write;
5449 memset(&descriptor_write, 0, sizeof(descriptor_write));
5450 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5451 descriptor_write.dstSet = descriptorSet;
5452 descriptor_write.dstBinding = 0;
5453 descriptor_write.descriptorCount = 1;
5454 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5455 descriptor_write.pImageInfo = &img_info;
5456 // Break memory binding and attempt update
5457 vkFreeMemory(m_device->device(), image_memory, nullptr);
5458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005459 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5461 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5462 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5463 m_errorMonitor->VerifyFound();
5464 // Cleanup
5465 vkDestroyImage(m_device->device(), image, NULL);
5466 vkDestroySampler(m_device->device(), sampler, NULL);
5467 vkDestroyImageView(m_device->device(), view, NULL);
5468 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5469 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5470 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5471}
5472
Karl Schultz6addd812016-02-02 17:17:23 -07005473TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005474 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5475 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005476 // Create a valid cmd buffer
5477 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005478 uint64_t fake_pipeline_handle = 0xbaad6001;
5479 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005480 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5482
5483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005484 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005485 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005486 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005487
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005488 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005489 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 -06005490 Draw(1, 0, 0, 0);
5491 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005492
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005493 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005494 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 +12005495 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005496 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5497 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005498}
5499
Karl Schultz6addd812016-02-02 17:17:23 -07005500TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005501 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005502 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005503
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005505
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005506 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005507 ASSERT_NO_FATAL_FAILURE(InitViewport());
5508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005509 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005510 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5511 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005512
5513 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005514 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5515 ds_pool_ci.pNext = NULL;
5516 ds_pool_ci.maxSets = 1;
5517 ds_pool_ci.poolSizeCount = 1;
5518 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005519
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005520 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005521 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005522 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005523
Tony Barboureb254902015-07-15 12:50:33 -06005524 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005525 dsl_binding.binding = 0;
5526 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5527 dsl_binding.descriptorCount = 1;
5528 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5529 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005530
Tony Barboureb254902015-07-15 12:50:33 -06005531 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005532 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5533 ds_layout_ci.pNext = NULL;
5534 ds_layout_ci.bindingCount = 1;
5535 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005536 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005537 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005538 ASSERT_VK_SUCCESS(err);
5539
5540 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005541 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005542 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005543 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005544 alloc_info.descriptorPool = ds_pool;
5545 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005546 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005547 ASSERT_VK_SUCCESS(err);
5548
Tony Barboureb254902015-07-15 12:50:33 -06005549 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005550 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5551 pipeline_layout_ci.pNext = NULL;
5552 pipeline_layout_ci.setLayoutCount = 1;
5553 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005554
5555 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005556 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005557 ASSERT_VK_SUCCESS(err);
5558
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005559 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005560 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005561 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005562 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005563
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005564 VkPipelineObj pipe(m_device);
5565 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005566 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005567 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005568 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005569
5570 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005571 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5572 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5573 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005574
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005575 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005576
Chia-I Wuf7458c52015-10-26 21:10:41 +08005577 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5578 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5579 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005580}
5581
Karl Schultz6addd812016-02-02 17:17:23 -07005582TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005583 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005584 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005585
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5587 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005588
5589 ASSERT_NO_FATAL_FAILURE(InitState());
5590 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005591 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5592 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005593
5594 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005595 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5596 ds_pool_ci.pNext = NULL;
5597 ds_pool_ci.maxSets = 1;
5598 ds_pool_ci.poolSizeCount = 1;
5599 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005600
5601 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005602 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005603 ASSERT_VK_SUCCESS(err);
5604
5605 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005606 dsl_binding.binding = 0;
5607 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5608 dsl_binding.descriptorCount = 1;
5609 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5610 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005611
5612 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005613 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5614 ds_layout_ci.pNext = NULL;
5615 ds_layout_ci.bindingCount = 1;
5616 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005617 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005618 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005619 ASSERT_VK_SUCCESS(err);
5620
5621 VkDescriptorSet descriptorSet;
5622 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005623 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005624 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005625 alloc_info.descriptorPool = ds_pool;
5626 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005627 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005628 ASSERT_VK_SUCCESS(err);
5629
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005630 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005631 VkWriteDescriptorSet descriptor_write;
5632 memset(&descriptor_write, 0, sizeof(descriptor_write));
5633 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5634 descriptor_write.dstSet = descriptorSet;
5635 descriptor_write.dstBinding = 0;
5636 descriptor_write.descriptorCount = 1;
5637 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5638 descriptor_write.pTexelBufferView = &view;
5639
5640 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5641
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005642 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005643
5644 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5645 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5646}
5647
Mark Youngd339ba32016-05-30 13:28:35 -06005648TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005649 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 -06005650
5651 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005653 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005654
5655 ASSERT_NO_FATAL_FAILURE(InitState());
5656
5657 // Create a buffer with no bound memory and then attempt to create
5658 // a buffer view.
5659 VkBufferCreateInfo buff_ci = {};
5660 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005661 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005662 buff_ci.size = 256;
5663 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5664 VkBuffer buffer;
5665 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5666 ASSERT_VK_SUCCESS(err);
5667
5668 VkBufferViewCreateInfo buff_view_ci = {};
5669 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5670 buff_view_ci.buffer = buffer;
5671 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5672 buff_view_ci.range = VK_WHOLE_SIZE;
5673 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005674 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005675
5676 m_errorMonitor->VerifyFound();
5677 vkDestroyBuffer(m_device->device(), buffer, NULL);
5678 // If last error is success, it still created the view, so delete it.
5679 if (err == VK_SUCCESS) {
5680 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5681 }
5682}
5683
Karl Schultz6addd812016-02-02 17:17:23 -07005684TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5685 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5686 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005687 // 1. No dynamicOffset supplied
5688 // 2. Too many dynamicOffsets supplied
5689 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005690 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5692 "0 dynamicOffsets are left in "
5693 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005694
5695 ASSERT_NO_FATAL_FAILURE(InitState());
5696 ASSERT_NO_FATAL_FAILURE(InitViewport());
5697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5698
5699 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005700 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5701 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005702
5703 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005704 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5705 ds_pool_ci.pNext = NULL;
5706 ds_pool_ci.maxSets = 1;
5707 ds_pool_ci.poolSizeCount = 1;
5708 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005709
5710 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005711 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005712 ASSERT_VK_SUCCESS(err);
5713
5714 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005715 dsl_binding.binding = 0;
5716 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5717 dsl_binding.descriptorCount = 1;
5718 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5719 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005720
5721 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005722 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5723 ds_layout_ci.pNext = NULL;
5724 ds_layout_ci.bindingCount = 1;
5725 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005726 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005727 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005728 ASSERT_VK_SUCCESS(err);
5729
5730 VkDescriptorSet descriptorSet;
5731 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005732 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005733 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005734 alloc_info.descriptorPool = ds_pool;
5735 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005736 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005737 ASSERT_VK_SUCCESS(err);
5738
5739 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005740 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5741 pipeline_layout_ci.pNext = NULL;
5742 pipeline_layout_ci.setLayoutCount = 1;
5743 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005744
5745 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005746 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005747 ASSERT_VK_SUCCESS(err);
5748
5749 // Create a buffer to update the descriptor with
5750 uint32_t qfi = 0;
5751 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005752 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5753 buffCI.size = 1024;
5754 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5755 buffCI.queueFamilyIndexCount = 1;
5756 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005757
5758 VkBuffer dyub;
5759 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5760 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005761 // Allocate memory and bind to buffer so we can make it to the appropriate
5762 // error
5763 VkMemoryAllocateInfo mem_alloc = {};
5764 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5765 mem_alloc.pNext = NULL;
5766 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005767 mem_alloc.memoryTypeIndex = 0;
5768
5769 VkMemoryRequirements memReqs;
5770 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005771 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005772 if (!pass) {
5773 vkDestroyBuffer(m_device->device(), dyub, NULL);
5774 return;
5775 }
5776
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005777 VkDeviceMemory mem;
5778 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5779 ASSERT_VK_SUCCESS(err);
5780 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5781 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005782 // Correctly update descriptor to avoid "NOT_UPDATED" error
5783 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005784 buffInfo.buffer = dyub;
5785 buffInfo.offset = 0;
5786 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005787
5788 VkWriteDescriptorSet descriptor_write;
5789 memset(&descriptor_write, 0, sizeof(descriptor_write));
5790 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5791 descriptor_write.dstSet = descriptorSet;
5792 descriptor_write.dstBinding = 0;
5793 descriptor_write.descriptorCount = 1;
5794 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5795 descriptor_write.pBufferInfo = &buffInfo;
5796
5797 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5798
5799 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005800 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5801 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005802 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005803 uint32_t pDynOff[2] = {512, 756};
5804 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5806 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5807 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5808 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005809 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005810 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5812 "offset 0 and range 1024 that "
5813 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005814 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005815 char const *vsSource = "#version 450\n"
5816 "\n"
5817 "out gl_PerVertex { \n"
5818 " vec4 gl_Position;\n"
5819 "};\n"
5820 "void main(){\n"
5821 " gl_Position = vec4(1);\n"
5822 "}\n";
5823 char const *fsSource = "#version 450\n"
5824 "\n"
5825 "layout(location=0) out vec4 x;\n"
5826 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5827 "void main(){\n"
5828 " x = vec4(bar.y);\n"
5829 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005830 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5831 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5832 VkPipelineObj pipe(m_device);
5833 pipe.AddShader(&vs);
5834 pipe.AddShader(&fs);
5835 pipe.AddColorAttachment();
5836 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5837
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005838 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005839 // This update should succeed, but offset size of 512 will overstep buffer
5840 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005841 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5842 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005843 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005844 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005845
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005846 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005847 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005848
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005849 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005850 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005851 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5852}
5853
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005854TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5855 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5856 "that doesn't have memory bound");
5857 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005859 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5861 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005862
5863 ASSERT_NO_FATAL_FAILURE(InitState());
5864 ASSERT_NO_FATAL_FAILURE(InitViewport());
5865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5866
5867 VkDescriptorPoolSize ds_type_count = {};
5868 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5869 ds_type_count.descriptorCount = 1;
5870
5871 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5872 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5873 ds_pool_ci.pNext = NULL;
5874 ds_pool_ci.maxSets = 1;
5875 ds_pool_ci.poolSizeCount = 1;
5876 ds_pool_ci.pPoolSizes = &ds_type_count;
5877
5878 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005879 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005880 ASSERT_VK_SUCCESS(err);
5881
5882 VkDescriptorSetLayoutBinding dsl_binding = {};
5883 dsl_binding.binding = 0;
5884 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5885 dsl_binding.descriptorCount = 1;
5886 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5887 dsl_binding.pImmutableSamplers = NULL;
5888
5889 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5890 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5891 ds_layout_ci.pNext = NULL;
5892 ds_layout_ci.bindingCount = 1;
5893 ds_layout_ci.pBindings = &dsl_binding;
5894 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005895 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005896 ASSERT_VK_SUCCESS(err);
5897
5898 VkDescriptorSet descriptorSet;
5899 VkDescriptorSetAllocateInfo alloc_info = {};
5900 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5901 alloc_info.descriptorSetCount = 1;
5902 alloc_info.descriptorPool = ds_pool;
5903 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005904 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005905 ASSERT_VK_SUCCESS(err);
5906
5907 // Create a buffer to update the descriptor with
5908 uint32_t qfi = 0;
5909 VkBufferCreateInfo buffCI = {};
5910 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5911 buffCI.size = 1024;
5912 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5913 buffCI.queueFamilyIndexCount = 1;
5914 buffCI.pQueueFamilyIndices = &qfi;
5915
5916 VkBuffer dyub;
5917 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5918 ASSERT_VK_SUCCESS(err);
5919
5920 // Attempt to update descriptor without binding memory to it
5921 VkDescriptorBufferInfo buffInfo = {};
5922 buffInfo.buffer = dyub;
5923 buffInfo.offset = 0;
5924 buffInfo.range = 1024;
5925
5926 VkWriteDescriptorSet descriptor_write;
5927 memset(&descriptor_write, 0, sizeof(descriptor_write));
5928 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5929 descriptor_write.dstSet = descriptorSet;
5930 descriptor_write.dstBinding = 0;
5931 descriptor_write.descriptorCount = 1;
5932 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5933 descriptor_write.pBufferInfo = &buffInfo;
5934
5935 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5936 m_errorMonitor->VerifyFound();
5937
5938 vkDestroyBuffer(m_device->device(), dyub, NULL);
5939 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5940 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5941}
5942
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005943TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005944 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005945 ASSERT_NO_FATAL_FAILURE(InitState());
5946 ASSERT_NO_FATAL_FAILURE(InitViewport());
5947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5948
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005949 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005950 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005951 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5952 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5953 pipeline_layout_ci.pushConstantRangeCount = 1;
5954 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5955
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005956 //
5957 // Check for invalid push constant ranges in pipeline layouts.
5958 //
5959 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005960 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005961 char const *msg;
5962 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005963
Karl Schultzc81037d2016-05-12 08:11:23 -06005964 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5965 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5966 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5967 "vkCreatePipelineLayout() call has push constants index 0 with "
5968 "size 0."},
5969 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5970 "vkCreatePipelineLayout() call has push constants index 0 with "
5971 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005972 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06005973 "vkCreatePipelineLayout() call has push constants index 0 with "
5974 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005975 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06005976 "vkCreatePipelineLayout() call has push constants index 0 with "
5977 "size 0."},
5978 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5979 "vkCreatePipelineLayout() call has push constants index 0 with "
5980 "offset 1. Offset must"},
5981 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5982 "vkCreatePipelineLayout() call has push constants index 0 "
5983 "with offset "},
5984 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5985 "vkCreatePipelineLayout() call has push constants "
5986 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005987 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06005988 "vkCreatePipelineLayout() call has push constants index 0 "
5989 "with offset "},
5990 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5991 "vkCreatePipelineLayout() call has push "
5992 "constants index 0 with offset "},
5993 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
5994 "vkCreatePipelineLayout() call has push "
5995 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005996 }};
5997
5998 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06005999 for (const auto &iter : range_tests) {
6000 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6002 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006003 m_errorMonitor->VerifyFound();
6004 if (VK_SUCCESS == err) {
6005 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6006 }
6007 }
6008
6009 // Check for invalid stage flag
6010 pc_range.offset = 0;
6011 pc_range.size = 16;
6012 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006013 m_errorMonitor->SetDesiredFailureMsg(
6014 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6015 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006016 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006017 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006018 if (VK_SUCCESS == err) {
6019 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6020 }
6021
6022 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006023 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006024 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006025 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006026 char const *msg;
6027 };
6028
Karl Schultzc81037d2016-05-12 08:11:23 -06006029 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006030 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6031 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6032 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6033 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6034 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006035 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006036 {
6037 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6038 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6039 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6040 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6041 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006042 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006043 },
6044 {
6045 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6046 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6047 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6048 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6049 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006050 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006051 },
6052 {
6053 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6054 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6055 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6056 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6057 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006058 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006059 },
6060 {
6061 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6062 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6063 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6064 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6065 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006066 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006067 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006068
Karl Schultzc81037d2016-05-12 08:11:23 -06006069 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006070 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006071 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6073 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006074 m_errorMonitor->VerifyFound();
6075 if (VK_SUCCESS == err) {
6076 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6077 }
6078 }
6079
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006080 //
6081 // CmdPushConstants tests
6082 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006083 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006084
6085 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006086 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6087 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006088 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6089 "vkCmdPushConstants() call has push constants with size 1. Size "
6090 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006091 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006092 "vkCmdPushConstants() call has push constants with size 1. Size "
6093 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006094 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006095 "vkCmdPushConstants() call has push constants with offset 1. "
6096 "Offset must be a multiple of 4."},
6097 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6098 "vkCmdPushConstants() call has push constants with offset 1. "
6099 "Offset must be a multiple of 4."},
6100 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6101 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6102 "0x1 not within flag-matching ranges in pipeline layout"},
6103 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6104 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6105 "0x1 not within flag-matching ranges in pipeline layout"},
6106 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6107 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6108 "0x1 not within flag-matching ranges in pipeline layout"},
6109 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6110 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6111 "0x1 not within flag-matching ranges in pipeline layout"},
6112 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6113 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6114 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006115 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006116 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6117 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006118 }};
6119
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006120 BeginCommandBuffer();
6121
6122 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006123 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006124 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006125 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006126 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006127 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006128 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006129 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006130 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6132 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006133 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006134 m_errorMonitor->VerifyFound();
6135 }
6136
6137 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006139 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006140 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006141 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006142
Karl Schultzc81037d2016-05-12 08:11:23 -06006143 // overlapping range tests with cmd
6144 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6145 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6146 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6147 "0x1 not within flag-matching ranges in pipeline layout"},
6148 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6149 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6150 "0x1 not within flag-matching ranges in pipeline layout"},
6151 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6152 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6153 "0x1 not within flag-matching ranges in pipeline layout"},
6154 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006155 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006156 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006157 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6158 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006159 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006160 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006161 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006162 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006163 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006164 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6166 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006167 iter.range.size, dummy_values);
6168 m_errorMonitor->VerifyFound();
6169 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006170 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6171
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006172 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006173}
6174
Karl Schultz6addd812016-02-02 17:17:23 -07006175TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006176 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006177 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006178
6179 ASSERT_NO_FATAL_FAILURE(InitState());
6180 ASSERT_NO_FATAL_FAILURE(InitViewport());
6181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6182
Mike Stroyanb8a61002016-06-20 16:00:28 -06006183 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6184 VkImageTiling tiling;
6185 VkFormatProperties format_properties;
6186 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006187 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006188 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006189 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006190 tiling = VK_IMAGE_TILING_OPTIMAL;
6191 } else {
6192 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6193 "skipped.\n");
6194 return;
6195 }
6196
Tobin Ehlis559c6382015-11-05 09:52:49 -07006197 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6198 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006199 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6200 ds_type_count[0].descriptorCount = 10;
6201 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6202 ds_type_count[1].descriptorCount = 2;
6203 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6204 ds_type_count[2].descriptorCount = 2;
6205 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6206 ds_type_count[3].descriptorCount = 5;
6207 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6208 // type
6209 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6210 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6211 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006212
6213 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006214 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6215 ds_pool_ci.pNext = NULL;
6216 ds_pool_ci.maxSets = 5;
6217 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6218 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006219
6220 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006221 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006222 ASSERT_VK_SUCCESS(err);
6223
6224 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6225 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006226 dsl_binding[0].binding = 0;
6227 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6228 dsl_binding[0].descriptorCount = 5;
6229 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6230 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006231
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006232 // Create layout identical to set0 layout but w/ different stageFlags
6233 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006234 dsl_fs_stage_only.binding = 0;
6235 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6236 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006237 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6238 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006239 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006240 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006241 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6242 ds_layout_ci.pNext = NULL;
6243 ds_layout_ci.bindingCount = 1;
6244 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006245 static const uint32_t NUM_LAYOUTS = 4;
6246 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006247 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006248 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6249 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006250 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006251 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006252 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006253 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006254 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006255 dsl_binding[0].binding = 0;
6256 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006257 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006258 dsl_binding[1].binding = 1;
6259 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6260 dsl_binding[1].descriptorCount = 2;
6261 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6262 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006263 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006264 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006265 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006266 ASSERT_VK_SUCCESS(err);
6267 dsl_binding[0].binding = 0;
6268 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006269 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006270 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006271 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006272 ASSERT_VK_SUCCESS(err);
6273 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006274 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006275 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006276 ASSERT_VK_SUCCESS(err);
6277
6278 static const uint32_t NUM_SETS = 4;
6279 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6280 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006281 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006282 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006283 alloc_info.descriptorPool = ds_pool;
6284 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006285 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006286 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006287 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006288 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006289 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006290 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006291 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006292
6293 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006294 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6295 pipeline_layout_ci.pNext = NULL;
6296 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6297 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006298
6299 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006300 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006301 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006302 // Create pipelineLayout with only one setLayout
6303 pipeline_layout_ci.setLayoutCount = 1;
6304 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006305 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006306 ASSERT_VK_SUCCESS(err);
6307 // Create pipelineLayout with 2 descriptor setLayout at index 0
6308 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6309 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006310 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006311 ASSERT_VK_SUCCESS(err);
6312 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6313 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6314 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006315 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006316 ASSERT_VK_SUCCESS(err);
6317 // Create pipelineLayout with UB type, but stageFlags for FS only
6318 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6319 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006320 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006321 ASSERT_VK_SUCCESS(err);
6322 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6323 VkDescriptorSetLayout pl_bad_s0[2] = {};
6324 pl_bad_s0[0] = ds_layout_fs_only;
6325 pl_bad_s0[1] = ds_layout[1];
6326 pipeline_layout_ci.setLayoutCount = 2;
6327 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6328 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006329 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006330 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006331
6332 // Create a buffer to update the descriptor with
6333 uint32_t qfi = 0;
6334 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006335 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6336 buffCI.size = 1024;
6337 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6338 buffCI.queueFamilyIndexCount = 1;
6339 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006340
6341 VkBuffer dyub;
6342 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6343 ASSERT_VK_SUCCESS(err);
6344 // Correctly update descriptor to avoid "NOT_UPDATED" error
6345 static const uint32_t NUM_BUFFS = 5;
6346 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006347 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006348 buffInfo[i].buffer = dyub;
6349 buffInfo[i].offset = 0;
6350 buffInfo[i].range = 1024;
6351 }
Karl Schultz6addd812016-02-02 17:17:23 -07006352 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006353 const int32_t tex_width = 32;
6354 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006355 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006356 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6357 image_create_info.pNext = NULL;
6358 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6359 image_create_info.format = tex_format;
6360 image_create_info.extent.width = tex_width;
6361 image_create_info.extent.height = tex_height;
6362 image_create_info.extent.depth = 1;
6363 image_create_info.mipLevels = 1;
6364 image_create_info.arrayLayers = 1;
6365 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006366 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006367 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006368 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006369 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6370 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006371
Karl Schultz6addd812016-02-02 17:17:23 -07006372 VkMemoryRequirements memReqs;
6373 VkDeviceMemory imageMem;
6374 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006375 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006376 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6377 memAlloc.pNext = NULL;
6378 memAlloc.allocationSize = 0;
6379 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006380 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6381 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006382 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006383 ASSERT_TRUE(pass);
6384 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6385 ASSERT_VK_SUCCESS(err);
6386 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6387 ASSERT_VK_SUCCESS(err);
6388
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006389 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006390 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6391 image_view_create_info.image = image;
6392 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6393 image_view_create_info.format = tex_format;
6394 image_view_create_info.subresourceRange.layerCount = 1;
6395 image_view_create_info.subresourceRange.baseMipLevel = 0;
6396 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006397 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006398
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006399 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006400 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006401 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006402 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006403 imageInfo[0].imageView = view;
6404 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6405 imageInfo[1].imageView = view;
6406 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006407 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006408 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006409 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006410 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006411
6412 static const uint32_t NUM_SET_UPDATES = 3;
6413 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6414 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6415 descriptor_write[0].dstSet = descriptorSet[0];
6416 descriptor_write[0].dstBinding = 0;
6417 descriptor_write[0].descriptorCount = 5;
6418 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6419 descriptor_write[0].pBufferInfo = buffInfo;
6420 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6421 descriptor_write[1].dstSet = descriptorSet[1];
6422 descriptor_write[1].dstBinding = 0;
6423 descriptor_write[1].descriptorCount = 2;
6424 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6425 descriptor_write[1].pImageInfo = imageInfo;
6426 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6427 descriptor_write[2].dstSet = descriptorSet[1];
6428 descriptor_write[2].dstBinding = 1;
6429 descriptor_write[2].descriptorCount = 2;
6430 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006431 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006432
6433 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006434
Tobin Ehlis88452832015-12-03 09:40:56 -07006435 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006436 char const *vsSource = "#version 450\n"
6437 "\n"
6438 "out gl_PerVertex {\n"
6439 " vec4 gl_Position;\n"
6440 "};\n"
6441 "void main(){\n"
6442 " gl_Position = vec4(1);\n"
6443 "}\n";
6444 char const *fsSource = "#version 450\n"
6445 "\n"
6446 "layout(location=0) out vec4 x;\n"
6447 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6448 "void main(){\n"
6449 " x = vec4(bar.y);\n"
6450 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006451 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6452 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006453 VkPipelineObj pipe(m_device);
6454 pipe.AddShader(&vs);
6455 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006456 pipe.AddColorAttachment();
6457 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006458
6459 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006460
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006461 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006462 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6463 // of PSO
6464 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6465 // cmd_pipeline.c
6466 // due to the fact that cmd_alloc_dset_data() has not been called in
6467 // cmd_bind_graphics_pipeline()
6468 // TODO : Want to cause various binding incompatibility issues here to test
6469 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006470 // First cause various verify_layout_compatibility() fails
6471 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006472 // verify_set_layout_compatibility fail cases:
6473 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6475 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6476 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006477 m_errorMonitor->VerifyFound();
6478
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006479 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6481 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6482 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006483 m_errorMonitor->VerifyFound();
6484
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006485 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006486 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6487 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6489 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6490 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006491 m_errorMonitor->VerifyFound();
6492
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006493 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6494 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6496 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6497 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006498 m_errorMonitor->VerifyFound();
6499
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006500 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6501 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6503 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6504 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6505 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006506 m_errorMonitor->VerifyFound();
6507
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006508 // Cause INFO messages due to disturbing previously bound Sets
6509 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006510 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6511 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006512 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6514 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6515 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006516 m_errorMonitor->VerifyFound();
6517
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006518 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6519 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006520 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6522 "any subsequent sets were disturbed ");
6523 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6524 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006525 m_errorMonitor->VerifyFound();
6526
Tobin Ehlis10fad692016-07-07 12:00:36 -06006527 // Now that we're done actively using the pipelineLayout that gfx pipeline
6528 // was created with, we should be able to delete it. Do that now to verify
6529 // that validation obeys pipelineLayout lifetime
6530 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6531
Tobin Ehlis88452832015-12-03 09:40:56 -07006532 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006533 // 1. Error due to not binding required set (we actually use same code as
6534 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006535 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6536 &descriptorSet[0], 0, NULL);
6537 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6538 &descriptorSet[1], 0, NULL);
6539 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 -07006540 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006541 m_errorMonitor->VerifyFound();
6542
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006543 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006544 // 2. Error due to bound set not being compatible with PSO's
6545 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006546 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6547 &descriptorSet[0], 0, NULL);
6548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006549 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006550 m_errorMonitor->VerifyFound();
6551
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006552 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006553 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006554 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6555 }
6556 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006557 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006558 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6559 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006560 vkFreeMemory(m_device->device(), imageMem, NULL);
6561 vkDestroyImage(m_device->device(), image, NULL);
6562 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006563}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006564
Karl Schultz6addd812016-02-02 17:17:23 -07006565TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006566
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6568 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006569
6570 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006571 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006572 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006573 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006574
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006575 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006576}
6577
Karl Schultz6addd812016-02-02 17:17:23 -07006578TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6579 VkResult err;
6580 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006581
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006583
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006584 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006585
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006586 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006587 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006588 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006589 cmd.commandPool = m_commandPool;
6590 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006591 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006592
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006593 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006594 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006595
6596 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006597 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006598 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006599 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006600 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006601 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 -07006602 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006603
6604 // The error should be caught by validation of the BeginCommandBuffer call
6605 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6606
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006607 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006608 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006609}
6610
Karl Schultz6addd812016-02-02 17:17:23 -07006611TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006612 // Cause error due to Begin while recording CB
6613 // Then cause 2 errors for attempting to reset CB w/o having
6614 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6615 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006617
6618 ASSERT_NO_FATAL_FAILURE(InitState());
6619
6620 // Calls AllocateCommandBuffers
6621 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6622
Karl Schultz6addd812016-02-02 17:17:23 -07006623 // Force the failure by setting the Renderpass and Framebuffer fields with
6624 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006625 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006626 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006627 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6628 cmd_buf_info.pNext = NULL;
6629 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006630 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006631
6632 // Begin CB to transition to recording state
6633 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6634 // Can't re-begin. This should trigger error
6635 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006636 m_errorMonitor->VerifyFound();
6637
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006639 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6640 // Reset attempt will trigger error due to incorrect CommandPool state
6641 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006642 m_errorMonitor->VerifyFound();
6643
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006645 // Transition CB to RECORDED state
6646 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6647 // Now attempting to Begin will implicitly reset, which triggers error
6648 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006649 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006650}
6651
Karl Schultz6addd812016-02-02 17:17:23 -07006652TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006653 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006654 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006655
Mike Weiblencce7ec72016-10-17 19:33:05 -06006656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006657
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006658 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006659 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006660
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006661 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006662 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6663 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006664
6665 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006666 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6667 ds_pool_ci.pNext = NULL;
6668 ds_pool_ci.maxSets = 1;
6669 ds_pool_ci.poolSizeCount = 1;
6670 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006671
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006672 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006673 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006674 ASSERT_VK_SUCCESS(err);
6675
Tony Barboureb254902015-07-15 12:50:33 -06006676 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006677 dsl_binding.binding = 0;
6678 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6679 dsl_binding.descriptorCount = 1;
6680 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6681 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006682
Tony Barboureb254902015-07-15 12:50:33 -06006683 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006684 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6685 ds_layout_ci.pNext = NULL;
6686 ds_layout_ci.bindingCount = 1;
6687 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006688
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006689 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006690 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006691 ASSERT_VK_SUCCESS(err);
6692
6693 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006694 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006695 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006696 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006697 alloc_info.descriptorPool = ds_pool;
6698 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006699 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006700 ASSERT_VK_SUCCESS(err);
6701
Tony Barboureb254902015-07-15 12:50:33 -06006702 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006703 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6704 pipeline_layout_ci.setLayoutCount = 1;
6705 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006706
6707 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006708 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006709 ASSERT_VK_SUCCESS(err);
6710
Tobin Ehlise68360f2015-10-01 11:15:13 -06006711 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006712 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006713
6714 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006715 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6716 vp_state_ci.scissorCount = 1;
6717 vp_state_ci.pScissors = &sc;
6718 vp_state_ci.viewportCount = 1;
6719 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006720
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006721 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6722 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6723 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6724 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6725 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6726 rs_state_ci.depthClampEnable = VK_FALSE;
6727 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6728 rs_state_ci.depthBiasEnable = VK_FALSE;
6729
Tony Barboureb254902015-07-15 12:50:33 -06006730 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006731 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6732 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006733 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006734 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6735 gp_ci.layout = pipeline_layout;
6736 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006737
6738 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006739 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6740 pc_ci.initialDataSize = 0;
6741 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006742
6743 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006744 VkPipelineCache pipelineCache;
6745
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006746 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006747 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006748 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006749
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006750 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006751
Chia-I Wuf7458c52015-10-26 21:10:41 +08006752 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6753 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6754 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6755 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006756}
Tobin Ehlis912df022015-09-17 08:46:18 -06006757/*// TODO : This test should be good, but needs Tess support in compiler to run
6758TEST_F(VkLayerTest, InvalidPatchControlPoints)
6759{
6760 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006761 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006762
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006764 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6765primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006766
Tobin Ehlis912df022015-09-17 08:46:18 -06006767 ASSERT_NO_FATAL_FAILURE(InitState());
6768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006769
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006770 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006771 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006772 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006773
6774 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6775 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6776 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006777 ds_pool_ci.poolSizeCount = 1;
6778 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006779
6780 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006781 err = vkCreateDescriptorPool(m_device->device(),
6782VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006783 ASSERT_VK_SUCCESS(err);
6784
6785 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006786 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006787 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006788 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006789 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6790 dsl_binding.pImmutableSamplers = NULL;
6791
6792 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006793 ds_layout_ci.sType =
6794VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006795 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006796 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006797 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006798
6799 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006800 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6801&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006802 ASSERT_VK_SUCCESS(err);
6803
6804 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006805 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6806VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006807 ASSERT_VK_SUCCESS(err);
6808
6809 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006810 pipeline_layout_ci.sType =
6811VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006812 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006813 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006814 pipeline_layout_ci.pSetLayouts = &ds_layout;
6815
6816 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006817 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6818&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006819 ASSERT_VK_SUCCESS(err);
6820
6821 VkPipelineShaderStageCreateInfo shaderStages[3];
6822 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6823
Karl Schultz6addd812016-02-02 17:17:23 -07006824 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6825this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006826 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006827 VkShaderObj
6828tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6829this);
6830 VkShaderObj
6831te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6832this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006833
Karl Schultz6addd812016-02-02 17:17:23 -07006834 shaderStages[0].sType =
6835VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006836 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006837 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006838 shaderStages[1].sType =
6839VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006840 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006841 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006842 shaderStages[2].sType =
6843VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006844 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006845 shaderStages[2].shader = te.handle();
6846
6847 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006848 iaCI.sType =
6849VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006850 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006851
6852 VkPipelineTessellationStateCreateInfo tsCI = {};
6853 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6854 tsCI.patchControlPoints = 0; // This will cause an error
6855
6856 VkGraphicsPipelineCreateInfo gp_ci = {};
6857 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6858 gp_ci.pNext = NULL;
6859 gp_ci.stageCount = 3;
6860 gp_ci.pStages = shaderStages;
6861 gp_ci.pVertexInputState = NULL;
6862 gp_ci.pInputAssemblyState = &iaCI;
6863 gp_ci.pTessellationState = &tsCI;
6864 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006865 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006866 gp_ci.pMultisampleState = NULL;
6867 gp_ci.pDepthStencilState = NULL;
6868 gp_ci.pColorBlendState = NULL;
6869 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6870 gp_ci.layout = pipeline_layout;
6871 gp_ci.renderPass = renderPass();
6872
6873 VkPipelineCacheCreateInfo pc_ci = {};
6874 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6875 pc_ci.pNext = NULL;
6876 pc_ci.initialSize = 0;
6877 pc_ci.initialData = 0;
6878 pc_ci.maxSize = 0;
6879
6880 VkPipeline pipeline;
6881 VkPipelineCache pipelineCache;
6882
Karl Schultz6addd812016-02-02 17:17:23 -07006883 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6884&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006885 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006886 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6887&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006888
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006889 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006890
Chia-I Wuf7458c52015-10-26 21:10:41 +08006891 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6892 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6893 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6894 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006895}
6896*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006897// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006898TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006899 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6902 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006903
Tobin Ehlise68360f2015-10-01 11:15:13 -06006904 ASSERT_NO_FATAL_FAILURE(InitState());
6905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006906
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006907 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006908 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6909 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006910
6911 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006912 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6913 ds_pool_ci.maxSets = 1;
6914 ds_pool_ci.poolSizeCount = 1;
6915 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006916
6917 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006918 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006919 ASSERT_VK_SUCCESS(err);
6920
6921 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006922 dsl_binding.binding = 0;
6923 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6924 dsl_binding.descriptorCount = 1;
6925 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006926
6927 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006928 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6929 ds_layout_ci.bindingCount = 1;
6930 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006931
6932 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006934 ASSERT_VK_SUCCESS(err);
6935
6936 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006937 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006938 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006939 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006940 alloc_info.descriptorPool = ds_pool;
6941 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006942 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006943 ASSERT_VK_SUCCESS(err);
6944
6945 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006946 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6947 pipeline_layout_ci.setLayoutCount = 1;
6948 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006949
6950 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006951 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006952 ASSERT_VK_SUCCESS(err);
6953
6954 VkViewport vp = {}; // Just need dummy vp to point to
6955
6956 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006957 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6958 vp_state_ci.scissorCount = 0;
6959 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6960 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006961
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006962 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6963 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6964 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6965 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6966 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6967 rs_state_ci.depthClampEnable = VK_FALSE;
6968 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6969 rs_state_ci.depthBiasEnable = VK_FALSE;
6970
Cody Northropeb3a6c12015-10-05 14:44:45 -06006971 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006972 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006973
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006974 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
6975 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
6976 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006977 shaderStages[0] = vs.GetStageCreateInfo();
6978 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006979
6980 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006981 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6982 gp_ci.stageCount = 2;
6983 gp_ci.pStages = shaderStages;
6984 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006985 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006986 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6987 gp_ci.layout = pipeline_layout;
6988 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006989
6990 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006991 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006992
6993 VkPipeline pipeline;
6994 VkPipelineCache pipelineCache;
6995
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006996 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006997 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006998 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006999
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007000 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007001
Chia-I Wuf7458c52015-10-26 21:10:41 +08007002 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7003 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7004 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7005 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007006}
Karl Schultz6addd812016-02-02 17:17:23 -07007007// Don't set viewport state in PSO. This is an error b/c we always need this
7008// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007009// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007010TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007011 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007012 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007013
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007015
Tobin Ehlise68360f2015-10-01 11:15:13 -06007016 ASSERT_NO_FATAL_FAILURE(InitState());
7017 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007018
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007019 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007020 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7021 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007022
7023 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007024 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7025 ds_pool_ci.maxSets = 1;
7026 ds_pool_ci.poolSizeCount = 1;
7027 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007028
7029 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007030 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007031 ASSERT_VK_SUCCESS(err);
7032
7033 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007034 dsl_binding.binding = 0;
7035 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7036 dsl_binding.descriptorCount = 1;
7037 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007038
7039 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007040 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7041 ds_layout_ci.bindingCount = 1;
7042 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007043
7044 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007045 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007046 ASSERT_VK_SUCCESS(err);
7047
7048 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007049 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007050 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007051 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007052 alloc_info.descriptorPool = ds_pool;
7053 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007054 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007055 ASSERT_VK_SUCCESS(err);
7056
7057 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007058 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7059 pipeline_layout_ci.setLayoutCount = 1;
7060 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007061
7062 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007063 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007064 ASSERT_VK_SUCCESS(err);
7065
7066 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7067 // Set scissor as dynamic to avoid second error
7068 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007069 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7070 dyn_state_ci.dynamicStateCount = 1;
7071 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007072
Cody Northropeb3a6c12015-10-05 14:44:45 -06007073 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007074 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007075
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007076 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7077 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7078 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007079 shaderStages[0] = vs.GetStageCreateInfo();
7080 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007081
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007082 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7083 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7084 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7085 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7086 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7087 rs_state_ci.depthClampEnable = VK_FALSE;
7088 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7089 rs_state_ci.depthBiasEnable = VK_FALSE;
7090
Tobin Ehlise68360f2015-10-01 11:15:13 -06007091 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007092 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7093 gp_ci.stageCount = 2;
7094 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007095 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007096 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7097 // should cause validation error
7098 gp_ci.pDynamicState = &dyn_state_ci;
7099 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7100 gp_ci.layout = pipeline_layout;
7101 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007102
7103 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007104 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007105
7106 VkPipeline pipeline;
7107 VkPipelineCache pipelineCache;
7108
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007109 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007110 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007111 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007112
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007113 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007114
Chia-I Wuf7458c52015-10-26 21:10:41 +08007115 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7116 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7117 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7118 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007119}
7120// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007121// Then run second test where dynamic scissor count doesn't match PSO scissor
7122// count
7123TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7124 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7127 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007128
Tobin Ehlise68360f2015-10-01 11:15:13 -06007129 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007130
7131 if (!m_device->phy().features().multiViewport) {
7132 printf("Device does not support multiple viewports/scissors; skipped.\n");
7133 return;
7134 }
7135
Tobin Ehlise68360f2015-10-01 11:15:13 -06007136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007137
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007138 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007139 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7140 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007141
7142 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007143 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7144 ds_pool_ci.maxSets = 1;
7145 ds_pool_ci.poolSizeCount = 1;
7146 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007147
7148 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007149 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007150 ASSERT_VK_SUCCESS(err);
7151
7152 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007153 dsl_binding.binding = 0;
7154 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7155 dsl_binding.descriptorCount = 1;
7156 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007157
7158 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007159 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7160 ds_layout_ci.bindingCount = 1;
7161 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007162
7163 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007164 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007165 ASSERT_VK_SUCCESS(err);
7166
7167 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007168 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007169 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007170 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007171 alloc_info.descriptorPool = ds_pool;
7172 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007173 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007174 ASSERT_VK_SUCCESS(err);
7175
7176 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007177 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7178 pipeline_layout_ci.setLayoutCount = 1;
7179 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007180
7181 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007182 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007183 ASSERT_VK_SUCCESS(err);
7184
7185 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007186 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7187 vp_state_ci.viewportCount = 1;
7188 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7189 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007190 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007191
7192 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7193 // Set scissor as dynamic to avoid that error
7194 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007195 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7196 dyn_state_ci.dynamicStateCount = 1;
7197 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007198
Cody Northropeb3a6c12015-10-05 14:44:45 -06007199 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007200 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007201
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007202 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7203 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7204 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007205 shaderStages[0] = vs.GetStageCreateInfo();
7206 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007207
Cody Northropf6622dc2015-10-06 10:33:21 -06007208 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7209 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7210 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007211 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007212 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007213 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007214 vi_ci.pVertexAttributeDescriptions = nullptr;
7215
7216 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7217 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7218 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7219
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007220 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007221 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007222 rs_ci.pNext = nullptr;
7223
Mark Youngc89c6312016-03-31 16:03:20 -06007224 VkPipelineColorBlendAttachmentState att = {};
7225 att.blendEnable = VK_FALSE;
7226 att.colorWriteMask = 0xf;
7227
Cody Northropf6622dc2015-10-06 10:33:21 -06007228 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7229 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7230 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007231 cb_ci.attachmentCount = 1;
7232 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007233
Tobin Ehlise68360f2015-10-01 11:15:13 -06007234 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007235 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7236 gp_ci.stageCount = 2;
7237 gp_ci.pStages = shaderStages;
7238 gp_ci.pVertexInputState = &vi_ci;
7239 gp_ci.pInputAssemblyState = &ia_ci;
7240 gp_ci.pViewportState = &vp_state_ci;
7241 gp_ci.pRasterizationState = &rs_ci;
7242 gp_ci.pColorBlendState = &cb_ci;
7243 gp_ci.pDynamicState = &dyn_state_ci;
7244 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7245 gp_ci.layout = pipeline_layout;
7246 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007247
7248 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007249 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007250
7251 VkPipeline pipeline;
7252 VkPipelineCache pipelineCache;
7253
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007254 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007255 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007256 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007257
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007258 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007259
Tobin Ehlisd332f282015-10-02 11:00:56 -06007260 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007261 // First need to successfully create the PSO from above by setting
7262 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007263 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 -07007264
7265 VkViewport vp = {}; // Just need dummy vp to point to
7266 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007267 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007268 ASSERT_VK_SUCCESS(err);
7269 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007270 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007271 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007272 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007273 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007274 Draw(1, 0, 0, 0);
7275
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007276 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007277
7278 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7279 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7280 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7281 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007282 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007283}
7284// Create PSO w/o non-zero scissorCount but no scissor data
7285// Then run second test where dynamic viewportCount doesn't match PSO
7286// viewportCount
7287TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7288 VkResult err;
7289
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007290 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 -07007291
7292 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007293
7294 if (!m_device->phy().features().multiViewport) {
7295 printf("Device does not support multiple viewports/scissors; skipped.\n");
7296 return;
7297 }
7298
Karl Schultz6addd812016-02-02 17:17:23 -07007299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7300
7301 VkDescriptorPoolSize ds_type_count = {};
7302 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7303 ds_type_count.descriptorCount = 1;
7304
7305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7307 ds_pool_ci.maxSets = 1;
7308 ds_pool_ci.poolSizeCount = 1;
7309 ds_pool_ci.pPoolSizes = &ds_type_count;
7310
7311 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007312 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007313 ASSERT_VK_SUCCESS(err);
7314
7315 VkDescriptorSetLayoutBinding dsl_binding = {};
7316 dsl_binding.binding = 0;
7317 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7318 dsl_binding.descriptorCount = 1;
7319 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7320
7321 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7322 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7323 ds_layout_ci.bindingCount = 1;
7324 ds_layout_ci.pBindings = &dsl_binding;
7325
7326 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007327 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007328 ASSERT_VK_SUCCESS(err);
7329
7330 VkDescriptorSet descriptorSet;
7331 VkDescriptorSetAllocateInfo alloc_info = {};
7332 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7333 alloc_info.descriptorSetCount = 1;
7334 alloc_info.descriptorPool = ds_pool;
7335 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007336 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007337 ASSERT_VK_SUCCESS(err);
7338
7339 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7340 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7341 pipeline_layout_ci.setLayoutCount = 1;
7342 pipeline_layout_ci.pSetLayouts = &ds_layout;
7343
7344 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007345 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007346 ASSERT_VK_SUCCESS(err);
7347
7348 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7349 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7350 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007351 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007352 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007353 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007354
7355 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7356 // Set scissor as dynamic to avoid that error
7357 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7358 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7359 dyn_state_ci.dynamicStateCount = 1;
7360 dyn_state_ci.pDynamicStates = &vp_state;
7361
7362 VkPipelineShaderStageCreateInfo shaderStages[2];
7363 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007365 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7366 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7367 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007368 shaderStages[0] = vs.GetStageCreateInfo();
7369 shaderStages[1] = fs.GetStageCreateInfo();
7370
7371 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7372 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7373 vi_ci.pNext = nullptr;
7374 vi_ci.vertexBindingDescriptionCount = 0;
7375 vi_ci.pVertexBindingDescriptions = nullptr;
7376 vi_ci.vertexAttributeDescriptionCount = 0;
7377 vi_ci.pVertexAttributeDescriptions = nullptr;
7378
7379 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7380 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7381 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7382
7383 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7384 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7385 rs_ci.pNext = nullptr;
7386
Mark Youngc89c6312016-03-31 16:03:20 -06007387 VkPipelineColorBlendAttachmentState att = {};
7388 att.blendEnable = VK_FALSE;
7389 att.colorWriteMask = 0xf;
7390
Karl Schultz6addd812016-02-02 17:17:23 -07007391 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7392 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7393 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007394 cb_ci.attachmentCount = 1;
7395 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007396
7397 VkGraphicsPipelineCreateInfo gp_ci = {};
7398 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7399 gp_ci.stageCount = 2;
7400 gp_ci.pStages = shaderStages;
7401 gp_ci.pVertexInputState = &vi_ci;
7402 gp_ci.pInputAssemblyState = &ia_ci;
7403 gp_ci.pViewportState = &vp_state_ci;
7404 gp_ci.pRasterizationState = &rs_ci;
7405 gp_ci.pColorBlendState = &cb_ci;
7406 gp_ci.pDynamicState = &dyn_state_ci;
7407 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7408 gp_ci.layout = pipeline_layout;
7409 gp_ci.renderPass = renderPass();
7410
7411 VkPipelineCacheCreateInfo pc_ci = {};
7412 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7413
7414 VkPipeline pipeline;
7415 VkPipelineCache pipelineCache;
7416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007417 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007418 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007419 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007420
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007421 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007422
7423 // Now hit second fail case where we set scissor w/ different count than PSO
7424 // First need to successfully create the PSO from above by setting
7425 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007426 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 -06007427
Tobin Ehlisd332f282015-10-02 11:00:56 -06007428 VkRect2D sc = {}; // Just need dummy vp to point to
7429 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007430 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007431 ASSERT_VK_SUCCESS(err);
7432 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007433 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007434 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007435 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007436 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007437 Draw(1, 0, 0, 0);
7438
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007439 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007440
Chia-I Wuf7458c52015-10-26 21:10:41 +08007441 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7442 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7443 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7444 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007445 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007446}
7447
Mark Young7394fdd2016-03-31 14:56:43 -06007448TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7449 VkResult err;
7450
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007452
7453 ASSERT_NO_FATAL_FAILURE(InitState());
7454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7455
7456 VkDescriptorPoolSize ds_type_count = {};
7457 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7458 ds_type_count.descriptorCount = 1;
7459
7460 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7461 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7462 ds_pool_ci.maxSets = 1;
7463 ds_pool_ci.poolSizeCount = 1;
7464 ds_pool_ci.pPoolSizes = &ds_type_count;
7465
7466 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007467 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007468 ASSERT_VK_SUCCESS(err);
7469
7470 VkDescriptorSetLayoutBinding dsl_binding = {};
7471 dsl_binding.binding = 0;
7472 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7473 dsl_binding.descriptorCount = 1;
7474 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7475
7476 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7477 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7478 ds_layout_ci.bindingCount = 1;
7479 ds_layout_ci.pBindings = &dsl_binding;
7480
7481 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007482 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007483 ASSERT_VK_SUCCESS(err);
7484
7485 VkDescriptorSet descriptorSet;
7486 VkDescriptorSetAllocateInfo alloc_info = {};
7487 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7488 alloc_info.descriptorSetCount = 1;
7489 alloc_info.descriptorPool = ds_pool;
7490 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007491 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007492 ASSERT_VK_SUCCESS(err);
7493
7494 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7495 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7496 pipeline_layout_ci.setLayoutCount = 1;
7497 pipeline_layout_ci.pSetLayouts = &ds_layout;
7498
7499 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007500 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007501 ASSERT_VK_SUCCESS(err);
7502
7503 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7504 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7505 vp_state_ci.scissorCount = 1;
7506 vp_state_ci.pScissors = NULL;
7507 vp_state_ci.viewportCount = 1;
7508 vp_state_ci.pViewports = NULL;
7509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007510 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007511 // Set scissor as dynamic to avoid that error
7512 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7513 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7514 dyn_state_ci.dynamicStateCount = 2;
7515 dyn_state_ci.pDynamicStates = dynamic_states;
7516
7517 VkPipelineShaderStageCreateInfo shaderStages[2];
7518 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7519
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007520 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7521 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007522 this); // TODO - We shouldn't need a fragment shader
7523 // but add it to be able to run on more devices
7524 shaderStages[0] = vs.GetStageCreateInfo();
7525 shaderStages[1] = fs.GetStageCreateInfo();
7526
7527 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7528 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7529 vi_ci.pNext = nullptr;
7530 vi_ci.vertexBindingDescriptionCount = 0;
7531 vi_ci.pVertexBindingDescriptions = nullptr;
7532 vi_ci.vertexAttributeDescriptionCount = 0;
7533 vi_ci.pVertexAttributeDescriptions = nullptr;
7534
7535 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7536 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7537 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7538
7539 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7540 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7541 rs_ci.pNext = nullptr;
7542
Mark Young47107952016-05-02 15:59:55 -06007543 // Check too low (line width of -1.0f).
7544 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007545
7546 VkPipelineColorBlendAttachmentState att = {};
7547 att.blendEnable = VK_FALSE;
7548 att.colorWriteMask = 0xf;
7549
7550 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7551 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7552 cb_ci.pNext = nullptr;
7553 cb_ci.attachmentCount = 1;
7554 cb_ci.pAttachments = &att;
7555
7556 VkGraphicsPipelineCreateInfo gp_ci = {};
7557 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7558 gp_ci.stageCount = 2;
7559 gp_ci.pStages = shaderStages;
7560 gp_ci.pVertexInputState = &vi_ci;
7561 gp_ci.pInputAssemblyState = &ia_ci;
7562 gp_ci.pViewportState = &vp_state_ci;
7563 gp_ci.pRasterizationState = &rs_ci;
7564 gp_ci.pColorBlendState = &cb_ci;
7565 gp_ci.pDynamicState = &dyn_state_ci;
7566 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7567 gp_ci.layout = pipeline_layout;
7568 gp_ci.renderPass = renderPass();
7569
7570 VkPipelineCacheCreateInfo pc_ci = {};
7571 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7572
7573 VkPipeline pipeline;
7574 VkPipelineCache pipelineCache;
7575
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007576 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007577 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007578 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007579
7580 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007581 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007582
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007584
7585 // Check too high (line width of 65536.0f).
7586 rs_ci.lineWidth = 65536.0f;
7587
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007588 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007589 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007590 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007591
7592 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007593 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007594
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007596
7597 dyn_state_ci.dynamicStateCount = 3;
7598
7599 rs_ci.lineWidth = 1.0f;
7600
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007601 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007602 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007603 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007604 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007605 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007606
7607 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007608 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007609 m_errorMonitor->VerifyFound();
7610
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007612
7613 // Check too high with dynamic setting.
7614 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7615 m_errorMonitor->VerifyFound();
7616 EndCommandBuffer();
7617
7618 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7619 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7620 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7621 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007622 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007623}
7624
Karl Schultz6addd812016-02-02 17:17:23 -07007625TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007626 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7628 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007629
7630 ASSERT_NO_FATAL_FAILURE(InitState());
7631 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007632
Tony Barbourfe3351b2015-07-28 10:17:20 -06007633 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007634 // Don't care about RenderPass handle b/c error should be flagged before
7635 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007636 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007637
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007638 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007639}
7640
Karl Schultz6addd812016-02-02 17:17:23 -07007641TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007642 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7644 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007645
7646 ASSERT_NO_FATAL_FAILURE(InitState());
7647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007648
Tony Barbourfe3351b2015-07-28 10:17:20 -06007649 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007650 // Just create a dummy Renderpass that's non-NULL so we can get to the
7651 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007652 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007653
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007654 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007655}
7656
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007657TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7658 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7659 "the number of renderPass attachments that use loadOp"
7660 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7661
7662 ASSERT_NO_FATAL_FAILURE(InitState());
7663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7664
7665 // Create a renderPass with a single attachment that uses loadOp CLEAR
7666 VkAttachmentReference attach = {};
7667 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7668 VkSubpassDescription subpass = {};
7669 subpass.inputAttachmentCount = 1;
7670 subpass.pInputAttachments = &attach;
7671 VkRenderPassCreateInfo rpci = {};
7672 rpci.subpassCount = 1;
7673 rpci.pSubpasses = &subpass;
7674 rpci.attachmentCount = 1;
7675 VkAttachmentDescription attach_desc = {};
7676 attach_desc.format = VK_FORMAT_UNDEFINED;
7677 // Set loadOp to CLEAR
7678 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7679 rpci.pAttachments = &attach_desc;
7680 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7681 VkRenderPass rp;
7682 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7683
7684 VkCommandBufferInheritanceInfo hinfo = {};
7685 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7686 hinfo.renderPass = VK_NULL_HANDLE;
7687 hinfo.subpass = 0;
7688 hinfo.framebuffer = VK_NULL_HANDLE;
7689 hinfo.occlusionQueryEnable = VK_FALSE;
7690 hinfo.queryFlags = 0;
7691 hinfo.pipelineStatistics = 0;
7692 VkCommandBufferBeginInfo info = {};
7693 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7694 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7695 info.pInheritanceInfo = &hinfo;
7696
7697 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7698 VkRenderPassBeginInfo rp_begin = {};
7699 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7700 rp_begin.pNext = NULL;
7701 rp_begin.renderPass = renderPass();
7702 rp_begin.framebuffer = framebuffer();
7703 rp_begin.clearValueCount = 0; // Should be 1
7704
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7706 "there must be at least 1 entries in "
7707 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007708
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007709 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007710
7711 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007712
7713 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007714}
7715
Cody Northrop3bb4d962016-05-09 16:15:57 -06007716TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7717
7718 TEST_DESCRIPTION("End a command buffer with an active render pass");
7719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7721 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007722
7723 ASSERT_NO_FATAL_FAILURE(InitState());
7724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7725
7726 // The framework's BeginCommandBuffer calls CreateRenderPass
7727 BeginCommandBuffer();
7728
7729 // Call directly into vkEndCommandBuffer instead of the
7730 // the framework's EndCommandBuffer, which inserts a
7731 // vkEndRenderPass
7732 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7733
7734 m_errorMonitor->VerifyFound();
7735
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7737 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007738}
7739
Karl Schultz6addd812016-02-02 17:17:23 -07007740TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007741 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7743 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007744
7745 ASSERT_NO_FATAL_FAILURE(InitState());
7746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007747
7748 // Renderpass is started here
7749 BeginCommandBuffer();
7750
7751 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007752 vk_testing::Buffer dstBuffer;
7753 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007754
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007755 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007756
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007757 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007758}
7759
Karl Schultz6addd812016-02-02 17:17:23 -07007760TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007761 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7763 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007764
7765 ASSERT_NO_FATAL_FAILURE(InitState());
7766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007767
7768 // Renderpass is started here
7769 BeginCommandBuffer();
7770
7771 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007772 vk_testing::Buffer dstBuffer;
7773 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007774
Karl Schultz6addd812016-02-02 17:17:23 -07007775 VkDeviceSize dstOffset = 0;
7776 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007777 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007778
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007779 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007780
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007781 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007782}
7783
Karl Schultz6addd812016-02-02 17:17:23 -07007784TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007785 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7787 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007788
7789 ASSERT_NO_FATAL_FAILURE(InitState());
7790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007791
7792 // Renderpass is started here
7793 BeginCommandBuffer();
7794
Michael Lentine0a369f62016-02-03 16:51:46 -06007795 VkClearColorValue clear_color;
7796 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007797 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7798 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7799 const int32_t tex_width = 32;
7800 const int32_t tex_height = 32;
7801 VkImageCreateInfo image_create_info = {};
7802 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7803 image_create_info.pNext = NULL;
7804 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7805 image_create_info.format = tex_format;
7806 image_create_info.extent.width = tex_width;
7807 image_create_info.extent.height = tex_height;
7808 image_create_info.extent.depth = 1;
7809 image_create_info.mipLevels = 1;
7810 image_create_info.arrayLayers = 1;
7811 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7812 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7813 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007814
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007815 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007816 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007817
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007818 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007819
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007820 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007821
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007822 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007823}
7824
Karl Schultz6addd812016-02-02 17:17:23 -07007825TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007826 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7828 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007829
7830 ASSERT_NO_FATAL_FAILURE(InitState());
7831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007832
7833 // Renderpass is started here
7834 BeginCommandBuffer();
7835
7836 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007837 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007838 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7839 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7840 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7841 image_create_info.extent.width = 64;
7842 image_create_info.extent.height = 64;
7843 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7844 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007845
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007846 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007847 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007849 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007850
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007851 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7852 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007853
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007854 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007855}
7856
Karl Schultz6addd812016-02-02 17:17:23 -07007857TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007858 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007859 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007860
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7862 "must be issued inside an active "
7863 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007864
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007865 ASSERT_NO_FATAL_FAILURE(InitState());
7866 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007867
7868 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007869 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007870 ASSERT_VK_SUCCESS(err);
7871
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007872 VkClearAttachment color_attachment;
7873 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7874 color_attachment.clearValue.color.float32[0] = 0;
7875 color_attachment.clearValue.color.float32[1] = 0;
7876 color_attachment.clearValue.color.float32[2] = 0;
7877 color_attachment.clearValue.color.float32[3] = 0;
7878 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007879 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007880 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007881
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007882 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007883}
7884
Chris Forbes3b97e932016-09-07 11:29:24 +12007885TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
7886 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
7887 "called too many times in a renderpass instance");
7888
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
7890 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12007891
7892 ASSERT_NO_FATAL_FAILURE(InitState());
7893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7894
7895 BeginCommandBuffer();
7896
7897 // error here.
7898 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
7899 m_errorMonitor->VerifyFound();
7900
7901 EndCommandBuffer();
7902}
7903
Chris Forbes6d624702016-09-07 13:57:05 +12007904TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
7905 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
7906 "called before the final subpass has been reached");
7907
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
7909 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12007910
7911 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007912 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
7913 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12007914
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007915 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12007916
7917 VkRenderPass rp;
7918 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
7919 ASSERT_VK_SUCCESS(err);
7920
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12007922
7923 VkFramebuffer fb;
7924 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
7925 ASSERT_VK_SUCCESS(err);
7926
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007927 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12007928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007929 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 +12007930
7931 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
7932
7933 // Error here.
7934 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7935 m_errorMonitor->VerifyFound();
7936
7937 // Clean up.
7938 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
7939 vkDestroyRenderPass(m_device->device(), rp, nullptr);
7940}
7941
Karl Schultz9e66a292016-04-21 15:57:51 -06007942TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7943 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7945 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06007946
7947 ASSERT_NO_FATAL_FAILURE(InitState());
7948 BeginCommandBuffer();
7949
7950 VkBufferMemoryBarrier buf_barrier = {};
7951 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7952 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7953 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7954 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7955 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7956 buf_barrier.buffer = VK_NULL_HANDLE;
7957 buf_barrier.offset = 0;
7958 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007959 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7960 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06007961
7962 m_errorMonitor->VerifyFound();
7963}
7964
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007965TEST_F(VkLayerTest, InvalidBarriers) {
7966 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7967
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007969
7970 ASSERT_NO_FATAL_FAILURE(InitState());
7971 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7972
7973 VkMemoryBarrier mem_barrier = {};
7974 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7975 mem_barrier.pNext = NULL;
7976 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7977 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7978 BeginCommandBuffer();
7979 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007980 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007981 &mem_barrier, 0, nullptr, 0, nullptr);
7982 m_errorMonitor->VerifyFound();
7983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007985 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007986 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 -06007987 ASSERT_TRUE(image.initialized());
7988 VkImageMemoryBarrier img_barrier = {};
7989 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7990 img_barrier.pNext = NULL;
7991 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7992 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7993 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7994 // New layout can't be UNDEFINED
7995 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7996 img_barrier.image = image.handle();
7997 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7998 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7999 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8000 img_barrier.subresourceRange.baseArrayLayer = 0;
8001 img_barrier.subresourceRange.baseMipLevel = 0;
8002 img_barrier.subresourceRange.layerCount = 1;
8003 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008004 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8005 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008006 m_errorMonitor->VerifyFound();
8007 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8008
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8010 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008011 // baseArrayLayer + layerCount must be <= image's arrayLayers
8012 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008013 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8014 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008015 m_errorMonitor->VerifyFound();
8016 img_barrier.subresourceRange.baseArrayLayer = 0;
8017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008019 // baseMipLevel + levelCount must be <= image's mipLevels
8020 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008021 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8022 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008023 m_errorMonitor->VerifyFound();
8024 img_barrier.subresourceRange.baseMipLevel = 0;
8025
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008026 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 -06008027 vk_testing::Buffer buffer;
8028 buffer.init(*m_device, 256);
8029 VkBufferMemoryBarrier buf_barrier = {};
8030 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8031 buf_barrier.pNext = NULL;
8032 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8033 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8034 buf_barrier.buffer = buffer.handle();
8035 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8036 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8037 buf_barrier.offset = 0;
8038 buf_barrier.size = VK_WHOLE_SIZE;
8039 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008040 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8041 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008042 m_errorMonitor->VerifyFound();
8043 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8044
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008046 buf_barrier.offset = 257;
8047 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008048 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8049 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008050 m_errorMonitor->VerifyFound();
8051 buf_barrier.offset = 0;
8052
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008054 buf_barrier.size = 257;
8055 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008056 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8057 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008058 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008059
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008060 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008061 m_errorMonitor->SetDesiredFailureMsg(
8062 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8063 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8064 m_errorMonitor->SetDesiredFailureMsg(
8065 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8066 "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 -06008067 VkDepthStencilObj ds_image(m_device);
8068 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8069 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008070 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8071 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008072 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008073 // Use of COLOR aspect on DS image is error
8074 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008075 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8076 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008077 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008078 // Now test depth-only
8079 VkFormatProperties format_props;
8080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008081 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8082 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8084 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8086 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008087 VkDepthStencilObj d_image(m_device);
8088 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8089 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008090 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008091 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008092 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008093 // Use of COLOR aspect on depth image is error
8094 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008095 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8096 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008097 m_errorMonitor->VerifyFound();
8098 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008099 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8100 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008101 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8103 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008104 VkDepthStencilObj s_image(m_device);
8105 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8106 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008107 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008108 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008109 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008110 // Use of COLOR aspect on depth image is error
8111 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008112 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8113 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008114 m_errorMonitor->VerifyFound();
8115 }
8116 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8118 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8120 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008121 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008122 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 -06008123 ASSERT_TRUE(c_image.initialized());
8124 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8125 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8126 img_barrier.image = c_image.handle();
8127 // Set aspect to depth (non-color)
8128 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008129 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8130 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008131 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008132}
8133
Tony Barbour18ba25c2016-09-29 13:42:40 -06008134TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8135 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8136
8137 m_errorMonitor->SetDesiredFailureMsg(
8138 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8139 "must have required access bit");
8140 ASSERT_NO_FATAL_FAILURE(InitState());
8141 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008142 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 -06008143 ASSERT_TRUE(image.initialized());
8144
8145 VkImageMemoryBarrier barrier = {};
8146 VkImageSubresourceRange range;
8147 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8148 barrier.srcAccessMask = 0;
8149 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8150 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8151 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8152 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8153 barrier.image = image.handle();
8154 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8155 range.baseMipLevel = 0;
8156 range.levelCount = 1;
8157 range.baseArrayLayer = 0;
8158 range.layerCount = 1;
8159 barrier.subresourceRange = range;
8160 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8161 cmdbuf.BeginCommandBuffer();
8162 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8163 &barrier);
8164 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8165 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8166 barrier.srcAccessMask = 0;
8167 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8168 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8169 &barrier);
8170
8171 m_errorMonitor->VerifyFound();
8172}
8173
Karl Schultz6addd812016-02-02 17:17:23 -07008174TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008175 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008176 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008177
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008179
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008180 ASSERT_NO_FATAL_FAILURE(InitState());
8181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008182 uint32_t qfi = 0;
8183 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008184 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8185 buffCI.size = 1024;
8186 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8187 buffCI.queueFamilyIndexCount = 1;
8188 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008189
8190 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008191 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008192 ASSERT_VK_SUCCESS(err);
8193
8194 BeginCommandBuffer();
8195 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008196 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8197 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008198 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008199 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008200
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008201 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008202
Chia-I Wuf7458c52015-10-26 21:10:41 +08008203 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008204}
8205
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008206TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8207 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8209 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8210 "of the indices specified when the device was created, via the "
8211 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008212
8213 ASSERT_NO_FATAL_FAILURE(InitState());
8214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8215 VkBufferCreateInfo buffCI = {};
8216 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8217 buffCI.size = 1024;
8218 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8219 buffCI.queueFamilyIndexCount = 1;
8220 // Introduce failure by specifying invalid queue_family_index
8221 uint32_t qfi = 777;
8222 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008223 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008224
8225 VkBuffer ib;
8226 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8227
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008228 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008229 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008230}
8231
Karl Schultz6addd812016-02-02 17:17:23 -07008232TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008233TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008234 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008235
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008236 ASSERT_NO_FATAL_FAILURE(InitState());
8237 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008238
Chris Forbesf29a84f2016-10-06 18:39:28 +13008239 // An empty primary command buffer
8240 VkCommandBufferObj cb(m_device, m_commandPool);
8241 cb.BeginCommandBuffer();
8242 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008243
Chris Forbesf29a84f2016-10-06 18:39:28 +13008244 m_commandBuffer->BeginCommandBuffer();
8245 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8246 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008247
Chris Forbesf29a84f2016-10-06 18:39:28 +13008248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8249 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008250 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008251}
8252
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008253TEST_F(VkLayerTest, DSUsageBitsErrors) {
8254 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8255 "that do not have correct usage bits sets.");
8256 VkResult err;
8257
8258 ASSERT_NO_FATAL_FAILURE(InitState());
8259 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8260 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8261 ds_type_count[i].type = VkDescriptorType(i);
8262 ds_type_count[i].descriptorCount = 1;
8263 }
8264 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8265 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8266 ds_pool_ci.pNext = NULL;
8267 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8268 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8269 ds_pool_ci.pPoolSizes = ds_type_count;
8270
8271 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008272 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008273 ASSERT_VK_SUCCESS(err);
8274
8275 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008276 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008277 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8278 dsl_binding[i].binding = 0;
8279 dsl_binding[i].descriptorType = VkDescriptorType(i);
8280 dsl_binding[i].descriptorCount = 1;
8281 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8282 dsl_binding[i].pImmutableSamplers = NULL;
8283 }
8284
8285 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8286 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8287 ds_layout_ci.pNext = NULL;
8288 ds_layout_ci.bindingCount = 1;
8289 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8290 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8291 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008292 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008293 ASSERT_VK_SUCCESS(err);
8294 }
8295 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8296 VkDescriptorSetAllocateInfo alloc_info = {};
8297 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8298 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8299 alloc_info.descriptorPool = ds_pool;
8300 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008301 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008302 ASSERT_VK_SUCCESS(err);
8303
8304 // Create a buffer & bufferView to be used for invalid updates
8305 VkBufferCreateInfo buff_ci = {};
8306 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8307 // This usage is not valid for any descriptor type
8308 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8309 buff_ci.size = 256;
8310 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8311 VkBuffer buffer;
8312 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8313 ASSERT_VK_SUCCESS(err);
8314
8315 VkBufferViewCreateInfo buff_view_ci = {};
8316 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8317 buff_view_ci.buffer = buffer;
8318 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8319 buff_view_ci.range = VK_WHOLE_SIZE;
8320 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008321 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008322 ASSERT_VK_SUCCESS(err);
8323
8324 // Create an image to be used for invalid updates
8325 VkImageCreateInfo image_ci = {};
8326 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8327 image_ci.imageType = VK_IMAGE_TYPE_2D;
8328 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8329 image_ci.extent.width = 64;
8330 image_ci.extent.height = 64;
8331 image_ci.extent.depth = 1;
8332 image_ci.mipLevels = 1;
8333 image_ci.arrayLayers = 1;
8334 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8335 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8336 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8337 // This usage is not valid for any descriptor type
8338 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8339 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8340 VkImage image;
8341 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8342 ASSERT_VK_SUCCESS(err);
8343 // Bind memory to image
8344 VkMemoryRequirements mem_reqs;
8345 VkDeviceMemory image_mem;
8346 bool pass;
8347 VkMemoryAllocateInfo mem_alloc = {};
8348 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8349 mem_alloc.pNext = NULL;
8350 mem_alloc.allocationSize = 0;
8351 mem_alloc.memoryTypeIndex = 0;
8352 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8353 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008354 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008355 ASSERT_TRUE(pass);
8356 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8357 ASSERT_VK_SUCCESS(err);
8358 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8359 ASSERT_VK_SUCCESS(err);
8360 // Now create view for image
8361 VkImageViewCreateInfo image_view_ci = {};
8362 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8363 image_view_ci.image = image;
8364 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8365 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8366 image_view_ci.subresourceRange.layerCount = 1;
8367 image_view_ci.subresourceRange.baseArrayLayer = 0;
8368 image_view_ci.subresourceRange.levelCount = 1;
8369 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8370 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008371 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008372 ASSERT_VK_SUCCESS(err);
8373
8374 VkDescriptorBufferInfo buff_info = {};
8375 buff_info.buffer = buffer;
8376 VkDescriptorImageInfo img_info = {};
8377 img_info.imageView = image_view;
8378 VkWriteDescriptorSet descriptor_write = {};
8379 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8380 descriptor_write.dstBinding = 0;
8381 descriptor_write.descriptorCount = 1;
8382 descriptor_write.pTexelBufferView = &buff_view;
8383 descriptor_write.pBufferInfo = &buff_info;
8384 descriptor_write.pImageInfo = &img_info;
8385
8386 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008387 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8388 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8389 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8390 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8391 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8392 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8393 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8394 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8395 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8396 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8397 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008398 // Start loop at 1 as SAMPLER desc type has no usage bit error
8399 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8400 descriptor_write.descriptorType = VkDescriptorType(i);
8401 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008403
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008404 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008405
8406 m_errorMonitor->VerifyFound();
8407 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8408 }
8409 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8410 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008411 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008412 vkDestroyImageView(m_device->device(), image_view, NULL);
8413 vkDestroyBuffer(m_device->device(), buffer, NULL);
8414 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008415 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008416 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8417}
8418
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008419TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008420 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8421 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8422 "1. offset value greater than buffer size\n"
8423 "2. range value of 0\n"
8424 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008425 VkResult err;
8426
8427 ASSERT_NO_FATAL_FAILURE(InitState());
8428 VkDescriptorPoolSize ds_type_count = {};
8429 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8430 ds_type_count.descriptorCount = 1;
8431
8432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8434 ds_pool_ci.pNext = NULL;
8435 ds_pool_ci.maxSets = 1;
8436 ds_pool_ci.poolSizeCount = 1;
8437 ds_pool_ci.pPoolSizes = &ds_type_count;
8438
8439 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008440 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008441 ASSERT_VK_SUCCESS(err);
8442
8443 // Create layout with single uniform buffer descriptor
8444 VkDescriptorSetLayoutBinding dsl_binding = {};
8445 dsl_binding.binding = 0;
8446 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8447 dsl_binding.descriptorCount = 1;
8448 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8449 dsl_binding.pImmutableSamplers = NULL;
8450
8451 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8452 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8453 ds_layout_ci.pNext = NULL;
8454 ds_layout_ci.bindingCount = 1;
8455 ds_layout_ci.pBindings = &dsl_binding;
8456 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008457 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008458 ASSERT_VK_SUCCESS(err);
8459
8460 VkDescriptorSet descriptor_set = {};
8461 VkDescriptorSetAllocateInfo alloc_info = {};
8462 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8463 alloc_info.descriptorSetCount = 1;
8464 alloc_info.descriptorPool = ds_pool;
8465 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008466 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008467 ASSERT_VK_SUCCESS(err);
8468
8469 // Create a buffer to be used for invalid updates
8470 VkBufferCreateInfo buff_ci = {};
8471 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8472 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8473 buff_ci.size = 256;
8474 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8475 VkBuffer buffer;
8476 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8477 ASSERT_VK_SUCCESS(err);
8478 // Have to bind memory to buffer before descriptor update
8479 VkMemoryAllocateInfo mem_alloc = {};
8480 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8481 mem_alloc.pNext = NULL;
8482 mem_alloc.allocationSize = 256;
8483 mem_alloc.memoryTypeIndex = 0;
8484
8485 VkMemoryRequirements mem_reqs;
8486 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008488 if (!pass) {
8489 vkDestroyBuffer(m_device->device(), buffer, NULL);
8490 return;
8491 }
8492
8493 VkDeviceMemory mem;
8494 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8495 ASSERT_VK_SUCCESS(err);
8496 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8497 ASSERT_VK_SUCCESS(err);
8498
8499 VkDescriptorBufferInfo buff_info = {};
8500 buff_info.buffer = buffer;
8501 // First make offset 1 larger than buffer size
8502 buff_info.offset = 257;
8503 buff_info.range = VK_WHOLE_SIZE;
8504 VkWriteDescriptorSet descriptor_write = {};
8505 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8506 descriptor_write.dstBinding = 0;
8507 descriptor_write.descriptorCount = 1;
8508 descriptor_write.pTexelBufferView = nullptr;
8509 descriptor_write.pBufferInfo = &buff_info;
8510 descriptor_write.pImageInfo = nullptr;
8511
8512 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8513 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008515
8516 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8517
8518 m_errorMonitor->VerifyFound();
8519 // Now cause error due to range of 0
8520 buff_info.offset = 0;
8521 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8523 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008524
8525 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8526
8527 m_errorMonitor->VerifyFound();
8528 // Now cause error due to range exceeding buffer size - offset
8529 buff_info.offset = 128;
8530 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008531 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 -06008532
8533 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8534
8535 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008536 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008537 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8538 vkDestroyBuffer(m_device->device(), buffer, NULL);
8539 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8540 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8541}
8542
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008543TEST_F(VkLayerTest, DSAspectBitsErrors) {
8544 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8545 // are set, but could expand this test to hit more cases.
8546 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8547 "that do not have correct aspect bits sets.");
8548 VkResult err;
8549
8550 ASSERT_NO_FATAL_FAILURE(InitState());
8551 VkDescriptorPoolSize ds_type_count = {};
8552 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8553 ds_type_count.descriptorCount = 1;
8554
8555 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8556 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8557 ds_pool_ci.pNext = NULL;
8558 ds_pool_ci.maxSets = 5;
8559 ds_pool_ci.poolSizeCount = 1;
8560 ds_pool_ci.pPoolSizes = &ds_type_count;
8561
8562 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008563 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008564 ASSERT_VK_SUCCESS(err);
8565
8566 VkDescriptorSetLayoutBinding dsl_binding = {};
8567 dsl_binding.binding = 0;
8568 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8569 dsl_binding.descriptorCount = 1;
8570 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8571 dsl_binding.pImmutableSamplers = NULL;
8572
8573 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8574 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8575 ds_layout_ci.pNext = NULL;
8576 ds_layout_ci.bindingCount = 1;
8577 ds_layout_ci.pBindings = &dsl_binding;
8578 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008579 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008580 ASSERT_VK_SUCCESS(err);
8581
8582 VkDescriptorSet descriptor_set = {};
8583 VkDescriptorSetAllocateInfo alloc_info = {};
8584 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8585 alloc_info.descriptorSetCount = 1;
8586 alloc_info.descriptorPool = ds_pool;
8587 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008588 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008589 ASSERT_VK_SUCCESS(err);
8590
8591 // Create an image to be used for invalid updates
8592 VkImageCreateInfo image_ci = {};
8593 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8594 image_ci.imageType = VK_IMAGE_TYPE_2D;
8595 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8596 image_ci.extent.width = 64;
8597 image_ci.extent.height = 64;
8598 image_ci.extent.depth = 1;
8599 image_ci.mipLevels = 1;
8600 image_ci.arrayLayers = 1;
8601 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8602 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8603 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8604 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8605 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8606 VkImage image;
8607 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8608 ASSERT_VK_SUCCESS(err);
8609 // Bind memory to image
8610 VkMemoryRequirements mem_reqs;
8611 VkDeviceMemory image_mem;
8612 bool pass;
8613 VkMemoryAllocateInfo mem_alloc = {};
8614 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8615 mem_alloc.pNext = NULL;
8616 mem_alloc.allocationSize = 0;
8617 mem_alloc.memoryTypeIndex = 0;
8618 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8619 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008620 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008621 ASSERT_TRUE(pass);
8622 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8623 ASSERT_VK_SUCCESS(err);
8624 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8625 ASSERT_VK_SUCCESS(err);
8626 // Now create view for image
8627 VkImageViewCreateInfo image_view_ci = {};
8628 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8629 image_view_ci.image = image;
8630 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8631 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8632 image_view_ci.subresourceRange.layerCount = 1;
8633 image_view_ci.subresourceRange.baseArrayLayer = 0;
8634 image_view_ci.subresourceRange.levelCount = 1;
8635 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008636 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008637
8638 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008639 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008640 ASSERT_VK_SUCCESS(err);
8641
8642 VkDescriptorImageInfo img_info = {};
8643 img_info.imageView = image_view;
8644 VkWriteDescriptorSet descriptor_write = {};
8645 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8646 descriptor_write.dstBinding = 0;
8647 descriptor_write.descriptorCount = 1;
8648 descriptor_write.pTexelBufferView = NULL;
8649 descriptor_write.pBufferInfo = NULL;
8650 descriptor_write.pImageInfo = &img_info;
8651 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8652 descriptor_write.dstSet = descriptor_set;
8653 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8654 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008656
8657 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8658
8659 m_errorMonitor->VerifyFound();
8660 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8661 vkDestroyImage(m_device->device(), image, NULL);
8662 vkFreeMemory(m_device->device(), image_mem, NULL);
8663 vkDestroyImageView(m_device->device(), image_view, NULL);
8664 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8665 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8666}
8667
Karl Schultz6addd812016-02-02 17:17:23 -07008668TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008669 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008670 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008671
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8673 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8674 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008675
Tobin Ehlis3b780662015-05-28 12:11:26 -06008676 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008677 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008678 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008679 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8680 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008681
8682 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008683 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8684 ds_pool_ci.pNext = NULL;
8685 ds_pool_ci.maxSets = 1;
8686 ds_pool_ci.poolSizeCount = 1;
8687 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008688
Tobin Ehlis3b780662015-05-28 12:11:26 -06008689 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008690 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008691 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008692 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008693 dsl_binding.binding = 0;
8694 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8695 dsl_binding.descriptorCount = 1;
8696 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8697 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008698
Tony Barboureb254902015-07-15 12:50:33 -06008699 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008700 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8701 ds_layout_ci.pNext = NULL;
8702 ds_layout_ci.bindingCount = 1;
8703 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008704
Tobin Ehlis3b780662015-05-28 12:11:26 -06008705 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008706 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008707 ASSERT_VK_SUCCESS(err);
8708
8709 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008710 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008711 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008712 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008713 alloc_info.descriptorPool = ds_pool;
8714 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008715 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008716 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008717
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008718 VkSamplerCreateInfo sampler_ci = {};
8719 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8720 sampler_ci.pNext = NULL;
8721 sampler_ci.magFilter = VK_FILTER_NEAREST;
8722 sampler_ci.minFilter = VK_FILTER_NEAREST;
8723 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8724 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8725 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8726 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8727 sampler_ci.mipLodBias = 1.0;
8728 sampler_ci.anisotropyEnable = VK_FALSE;
8729 sampler_ci.maxAnisotropy = 1;
8730 sampler_ci.compareEnable = VK_FALSE;
8731 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8732 sampler_ci.minLod = 1.0;
8733 sampler_ci.maxLod = 1.0;
8734 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8735 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8736 VkSampler sampler;
8737 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8738 ASSERT_VK_SUCCESS(err);
8739
8740 VkDescriptorImageInfo info = {};
8741 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008742
8743 VkWriteDescriptorSet descriptor_write;
8744 memset(&descriptor_write, 0, sizeof(descriptor_write));
8745 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008746 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008747 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008748 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008749 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008750 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008751
8752 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8753
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008754 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008755
Chia-I Wuf7458c52015-10-26 21:10:41 +08008756 vkDestroySampler(m_device->device(), sampler, NULL);
8757 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8758 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008759}
8760
Karl Schultz6addd812016-02-02 17:17:23 -07008761TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008762 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008763 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008764
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8766 " binding #0 with 1 total descriptors but update of 1 descriptors "
8767 "starting at binding offset of 0 combined with update array element "
8768 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008769
Tobin Ehlis3b780662015-05-28 12:11:26 -06008770 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008771 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008772 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008773 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8774 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008775
8776 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008777 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8778 ds_pool_ci.pNext = NULL;
8779 ds_pool_ci.maxSets = 1;
8780 ds_pool_ci.poolSizeCount = 1;
8781 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008782
Tobin Ehlis3b780662015-05-28 12:11:26 -06008783 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008784 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008785 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008786
Tony Barboureb254902015-07-15 12:50:33 -06008787 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008788 dsl_binding.binding = 0;
8789 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8790 dsl_binding.descriptorCount = 1;
8791 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8792 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008793
8794 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008795 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8796 ds_layout_ci.pNext = NULL;
8797 ds_layout_ci.bindingCount = 1;
8798 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008799
Tobin Ehlis3b780662015-05-28 12:11:26 -06008800 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008801 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008802 ASSERT_VK_SUCCESS(err);
8803
8804 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008805 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008806 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008807 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008808 alloc_info.descriptorPool = ds_pool;
8809 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008810 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008811 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008812
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008813 // Correctly update descriptor to avoid "NOT_UPDATED" error
8814 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008815 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008816 buff_info.offset = 0;
8817 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008818
8819 VkWriteDescriptorSet descriptor_write;
8820 memset(&descriptor_write, 0, sizeof(descriptor_write));
8821 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008822 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008823 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008824 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008825 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8826 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008827
8828 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8829
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008830 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008831
Chia-I Wuf7458c52015-10-26 21:10:41 +08008832 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8833 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008834}
8835
Karl Schultz6addd812016-02-02 17:17:23 -07008836TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8837 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8838 // index 2
8839 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008840
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008842
Tobin Ehlis3b780662015-05-28 12:11:26 -06008843 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008844 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008845 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008846 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8847 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008848
8849 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008850 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8851 ds_pool_ci.pNext = NULL;
8852 ds_pool_ci.maxSets = 1;
8853 ds_pool_ci.poolSizeCount = 1;
8854 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008855
Tobin Ehlis3b780662015-05-28 12:11:26 -06008856 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008857 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008858 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008859
Tony Barboureb254902015-07-15 12:50:33 -06008860 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008861 dsl_binding.binding = 0;
8862 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8863 dsl_binding.descriptorCount = 1;
8864 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8865 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008866
8867 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008868 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8869 ds_layout_ci.pNext = NULL;
8870 ds_layout_ci.bindingCount = 1;
8871 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008872 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008873 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008874 ASSERT_VK_SUCCESS(err);
8875
8876 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008877 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008878 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008879 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008880 alloc_info.descriptorPool = ds_pool;
8881 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008882 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008883 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008884
Tony Barboureb254902015-07-15 12:50:33 -06008885 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008886 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8887 sampler_ci.pNext = NULL;
8888 sampler_ci.magFilter = VK_FILTER_NEAREST;
8889 sampler_ci.minFilter = VK_FILTER_NEAREST;
8890 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8891 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8892 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8893 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8894 sampler_ci.mipLodBias = 1.0;
8895 sampler_ci.anisotropyEnable = VK_FALSE;
8896 sampler_ci.maxAnisotropy = 1;
8897 sampler_ci.compareEnable = VK_FALSE;
8898 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8899 sampler_ci.minLod = 1.0;
8900 sampler_ci.maxLod = 1.0;
8901 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8902 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008903
Tobin Ehlis3b780662015-05-28 12:11:26 -06008904 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008905 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008906 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008907
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008908 VkDescriptorImageInfo info = {};
8909 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008910
8911 VkWriteDescriptorSet descriptor_write;
8912 memset(&descriptor_write, 0, sizeof(descriptor_write));
8913 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008914 descriptor_write.dstSet = descriptorSet;
8915 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008916 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008917 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008918 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008919 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008920
8921 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8922
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008923 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008924
Chia-I Wuf7458c52015-10-26 21:10:41 +08008925 vkDestroySampler(m_device->device(), sampler, NULL);
8926 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8927 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008928}
8929
Karl Schultz6addd812016-02-02 17:17:23 -07008930TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8931 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8932 // types
8933 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008934
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008935 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 -06008936
Tobin Ehlis3b780662015-05-28 12:11:26 -06008937 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008938
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008939 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008940 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8941 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008942
8943 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008944 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8945 ds_pool_ci.pNext = NULL;
8946 ds_pool_ci.maxSets = 1;
8947 ds_pool_ci.poolSizeCount = 1;
8948 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008949
Tobin Ehlis3b780662015-05-28 12:11:26 -06008950 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008951 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008952 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008953 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008954 dsl_binding.binding = 0;
8955 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8956 dsl_binding.descriptorCount = 1;
8957 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8958 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008959
Tony Barboureb254902015-07-15 12:50:33 -06008960 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008961 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8962 ds_layout_ci.pNext = NULL;
8963 ds_layout_ci.bindingCount = 1;
8964 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008965
Tobin Ehlis3b780662015-05-28 12:11:26 -06008966 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008967 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008968 ASSERT_VK_SUCCESS(err);
8969
8970 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008971 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008972 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008973 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008974 alloc_info.descriptorPool = ds_pool;
8975 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008976 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008977 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008978
Tony Barboureb254902015-07-15 12:50:33 -06008979 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008980 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8981 sampler_ci.pNext = NULL;
8982 sampler_ci.magFilter = VK_FILTER_NEAREST;
8983 sampler_ci.minFilter = VK_FILTER_NEAREST;
8984 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8985 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8986 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8987 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8988 sampler_ci.mipLodBias = 1.0;
8989 sampler_ci.anisotropyEnable = VK_FALSE;
8990 sampler_ci.maxAnisotropy = 1;
8991 sampler_ci.compareEnable = VK_FALSE;
8992 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8993 sampler_ci.minLod = 1.0;
8994 sampler_ci.maxLod = 1.0;
8995 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8996 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008997 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008998 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008999 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009000
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009001 VkDescriptorImageInfo info = {};
9002 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009003
9004 VkWriteDescriptorSet descriptor_write;
9005 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009006 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009007 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009008 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009009 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009010 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009011 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009012
9013 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9014
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009015 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009016
Chia-I Wuf7458c52015-10-26 21:10:41 +08009017 vkDestroySampler(m_device->device(), sampler, NULL);
9018 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9019 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009020}
9021
Karl Schultz6addd812016-02-02 17:17:23 -07009022TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009023 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009024 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009025
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9027 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009028
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009029 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009030 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9031 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009032 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009033 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9034 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009035
9036 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009037 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9038 ds_pool_ci.pNext = NULL;
9039 ds_pool_ci.maxSets = 1;
9040 ds_pool_ci.poolSizeCount = 1;
9041 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009042
9043 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009044 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009045 ASSERT_VK_SUCCESS(err);
9046
9047 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009048 dsl_binding.binding = 0;
9049 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9050 dsl_binding.descriptorCount = 1;
9051 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9052 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009053
9054 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009055 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9056 ds_layout_ci.pNext = NULL;
9057 ds_layout_ci.bindingCount = 1;
9058 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009059 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009060 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009061 ASSERT_VK_SUCCESS(err);
9062
9063 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009064 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009065 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009066 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009067 alloc_info.descriptorPool = ds_pool;
9068 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009069 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009070 ASSERT_VK_SUCCESS(err);
9071
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009072 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009073
9074 VkDescriptorImageInfo descriptor_info;
9075 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9076 descriptor_info.sampler = sampler;
9077
9078 VkWriteDescriptorSet descriptor_write;
9079 memset(&descriptor_write, 0, sizeof(descriptor_write));
9080 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009081 descriptor_write.dstSet = descriptorSet;
9082 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009083 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009084 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9085 descriptor_write.pImageInfo = &descriptor_info;
9086
9087 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9088
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009089 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009090
Chia-I Wuf7458c52015-10-26 21:10:41 +08009091 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9092 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009093}
9094
Karl Schultz6addd812016-02-02 17:17:23 -07009095TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9096 // Create a single combined Image/Sampler descriptor and send it an invalid
9097 // imageView
9098 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009099
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9101 "image sampler descriptor failed due "
9102 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009103
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009104 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009105 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009106 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9107 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009108
9109 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009110 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9111 ds_pool_ci.pNext = NULL;
9112 ds_pool_ci.maxSets = 1;
9113 ds_pool_ci.poolSizeCount = 1;
9114 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009115
9116 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009117 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009118 ASSERT_VK_SUCCESS(err);
9119
9120 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009121 dsl_binding.binding = 0;
9122 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9123 dsl_binding.descriptorCount = 1;
9124 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9125 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009126
9127 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009128 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9129 ds_layout_ci.pNext = NULL;
9130 ds_layout_ci.bindingCount = 1;
9131 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009132 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009133 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009134 ASSERT_VK_SUCCESS(err);
9135
9136 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009137 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009138 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009139 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009140 alloc_info.descriptorPool = ds_pool;
9141 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009142 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009143 ASSERT_VK_SUCCESS(err);
9144
9145 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009146 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9147 sampler_ci.pNext = NULL;
9148 sampler_ci.magFilter = VK_FILTER_NEAREST;
9149 sampler_ci.minFilter = VK_FILTER_NEAREST;
9150 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9151 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9152 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9153 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9154 sampler_ci.mipLodBias = 1.0;
9155 sampler_ci.anisotropyEnable = VK_FALSE;
9156 sampler_ci.maxAnisotropy = 1;
9157 sampler_ci.compareEnable = VK_FALSE;
9158 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9159 sampler_ci.minLod = 1.0;
9160 sampler_ci.maxLod = 1.0;
9161 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9162 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009163
9164 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009165 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009166 ASSERT_VK_SUCCESS(err);
9167
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009168 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009169
9170 VkDescriptorImageInfo descriptor_info;
9171 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9172 descriptor_info.sampler = sampler;
9173 descriptor_info.imageView = view;
9174
9175 VkWriteDescriptorSet descriptor_write;
9176 memset(&descriptor_write, 0, sizeof(descriptor_write));
9177 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009178 descriptor_write.dstSet = descriptorSet;
9179 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009180 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009181 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9182 descriptor_write.pImageInfo = &descriptor_info;
9183
9184 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9185
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009186 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009187
Chia-I Wuf7458c52015-10-26 21:10:41 +08009188 vkDestroySampler(m_device->device(), sampler, NULL);
9189 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9190 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009191}
9192
Karl Schultz6addd812016-02-02 17:17:23 -07009193TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9194 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9195 // into the other
9196 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009197
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9199 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9200 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009201
Tobin Ehlis04356f92015-10-27 16:35:27 -06009202 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009203 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009204 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009205 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9206 ds_type_count[0].descriptorCount = 1;
9207 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9208 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009209
9210 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009211 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9212 ds_pool_ci.pNext = NULL;
9213 ds_pool_ci.maxSets = 1;
9214 ds_pool_ci.poolSizeCount = 2;
9215 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009216
9217 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009218 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009219 ASSERT_VK_SUCCESS(err);
9220 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009221 dsl_binding[0].binding = 0;
9222 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9223 dsl_binding[0].descriptorCount = 1;
9224 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9225 dsl_binding[0].pImmutableSamplers = NULL;
9226 dsl_binding[1].binding = 1;
9227 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9228 dsl_binding[1].descriptorCount = 1;
9229 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9230 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009231
9232 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009233 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9234 ds_layout_ci.pNext = NULL;
9235 ds_layout_ci.bindingCount = 2;
9236 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009237
9238 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009239 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009240 ASSERT_VK_SUCCESS(err);
9241
9242 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009243 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009244 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009245 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009246 alloc_info.descriptorPool = ds_pool;
9247 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009248 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009249 ASSERT_VK_SUCCESS(err);
9250
9251 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009252 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9253 sampler_ci.pNext = NULL;
9254 sampler_ci.magFilter = VK_FILTER_NEAREST;
9255 sampler_ci.minFilter = VK_FILTER_NEAREST;
9256 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9257 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9258 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9259 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9260 sampler_ci.mipLodBias = 1.0;
9261 sampler_ci.anisotropyEnable = VK_FALSE;
9262 sampler_ci.maxAnisotropy = 1;
9263 sampler_ci.compareEnable = VK_FALSE;
9264 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9265 sampler_ci.minLod = 1.0;
9266 sampler_ci.maxLod = 1.0;
9267 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9268 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009269
9270 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009271 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009272 ASSERT_VK_SUCCESS(err);
9273
9274 VkDescriptorImageInfo info = {};
9275 info.sampler = sampler;
9276
9277 VkWriteDescriptorSet descriptor_write;
9278 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9279 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009280 descriptor_write.dstSet = descriptorSet;
9281 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009282 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009283 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9284 descriptor_write.pImageInfo = &info;
9285 // This write update should succeed
9286 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9287 // Now perform a copy update that fails due to type mismatch
9288 VkCopyDescriptorSet copy_ds_update;
9289 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9290 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9291 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009292 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009293 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009294 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009295 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009296 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9297
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009298 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009299 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009300 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 -06009301 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9302 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9303 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009304 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009305 copy_ds_update.dstSet = descriptorSet;
9306 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009307 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009308 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9309
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009310 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009311
Tobin Ehlis04356f92015-10-27 16:35:27 -06009312 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9314 "update array offset of 0 and update of "
9315 "5 descriptors oversteps total number "
9316 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009317
Tobin Ehlis04356f92015-10-27 16:35:27 -06009318 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9319 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9320 copy_ds_update.srcSet = descriptorSet;
9321 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009322 copy_ds_update.dstSet = descriptorSet;
9323 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009324 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009325 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9326
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009327 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009328
Chia-I Wuf7458c52015-10-26 21:10:41 +08009329 vkDestroySampler(m_device->device(), sampler, NULL);
9330 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9331 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009332}
9333
Karl Schultz6addd812016-02-02 17:17:23 -07009334TEST_F(VkLayerTest, NumSamplesMismatch) {
9335 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9336 // sampleCount
9337 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009338
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009340
Tobin Ehlis3b780662015-05-28 12:11:26 -06009341 ASSERT_NO_FATAL_FAILURE(InitState());
9342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009343 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009344 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009345 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009346
9347 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009348 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9349 ds_pool_ci.pNext = NULL;
9350 ds_pool_ci.maxSets = 1;
9351 ds_pool_ci.poolSizeCount = 1;
9352 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009353
Tobin Ehlis3b780662015-05-28 12:11:26 -06009354 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009355 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009356 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009357
Tony Barboureb254902015-07-15 12:50:33 -06009358 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009359 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009360 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009361 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009362 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9363 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009364
Tony Barboureb254902015-07-15 12:50:33 -06009365 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9366 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9367 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009368 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009369 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009370
Tobin Ehlis3b780662015-05-28 12:11:26 -06009371 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009372 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009373 ASSERT_VK_SUCCESS(err);
9374
9375 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009376 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009377 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009378 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009379 alloc_info.descriptorPool = ds_pool;
9380 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009381 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009382 ASSERT_VK_SUCCESS(err);
9383
Tony Barboureb254902015-07-15 12:50:33 -06009384 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009385 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009386 pipe_ms_state_ci.pNext = NULL;
9387 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9388 pipe_ms_state_ci.sampleShadingEnable = 0;
9389 pipe_ms_state_ci.minSampleShading = 1.0;
9390 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009391
Tony Barboureb254902015-07-15 12:50:33 -06009392 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009393 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9394 pipeline_layout_ci.pNext = NULL;
9395 pipeline_layout_ci.setLayoutCount = 1;
9396 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009397
9398 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009399 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009400 ASSERT_VK_SUCCESS(err);
9401
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009402 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9403 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9404 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009405 VkPipelineObj pipe(m_device);
9406 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009407 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009408 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009409 pipe.SetMSAA(&pipe_ms_state_ci);
9410 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009411
Tony Barbourfe3351b2015-07-28 10:17:20 -06009412 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009413 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009414
Mark Young29927482016-05-04 14:38:51 -06009415 // Render triangle (the error should trigger on the attempt to draw).
9416 Draw(3, 1, 0, 0);
9417
9418 // Finalize recording of the command buffer
9419 EndCommandBuffer();
9420
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009421 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009422
Chia-I Wuf7458c52015-10-26 21:10:41 +08009423 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9424 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009426}
Mark Young29927482016-05-04 14:38:51 -06009427
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009428TEST_F(VkLayerTest, RenderPassIncompatible) {
9429 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9430 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009431 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009432 VkResult err;
9433
9434 ASSERT_NO_FATAL_FAILURE(InitState());
9435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9436
9437 VkDescriptorSetLayoutBinding dsl_binding = {};
9438 dsl_binding.binding = 0;
9439 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9440 dsl_binding.descriptorCount = 1;
9441 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9442 dsl_binding.pImmutableSamplers = NULL;
9443
9444 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9445 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9446 ds_layout_ci.pNext = NULL;
9447 ds_layout_ci.bindingCount = 1;
9448 ds_layout_ci.pBindings = &dsl_binding;
9449
9450 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009451 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009452 ASSERT_VK_SUCCESS(err);
9453
9454 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9455 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9456 pipeline_layout_ci.pNext = NULL;
9457 pipeline_layout_ci.setLayoutCount = 1;
9458 pipeline_layout_ci.pSetLayouts = &ds_layout;
9459
9460 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009461 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009462 ASSERT_VK_SUCCESS(err);
9463
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009464 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9465 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9466 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009467 // Create a renderpass that will be incompatible with default renderpass
9468 VkAttachmentReference attach = {};
9469 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9470 VkAttachmentReference color_att = {};
9471 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9472 VkSubpassDescription subpass = {};
9473 subpass.inputAttachmentCount = 1;
9474 subpass.pInputAttachments = &attach;
9475 subpass.colorAttachmentCount = 1;
9476 subpass.pColorAttachments = &color_att;
9477 VkRenderPassCreateInfo rpci = {};
9478 rpci.subpassCount = 1;
9479 rpci.pSubpasses = &subpass;
9480 rpci.attachmentCount = 1;
9481 VkAttachmentDescription attach_desc = {};
9482 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009483 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9484 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009485 rpci.pAttachments = &attach_desc;
9486 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9487 VkRenderPass rp;
9488 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9489 VkPipelineObj pipe(m_device);
9490 pipe.AddShader(&vs);
9491 pipe.AddShader(&fs);
9492 pipe.AddColorAttachment();
9493 VkViewport view_port = {};
9494 m_viewports.push_back(view_port);
9495 pipe.SetViewport(m_viewports);
9496 VkRect2D rect = {};
9497 m_scissors.push_back(rect);
9498 pipe.SetScissor(m_scissors);
9499 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9500
9501 VkCommandBufferInheritanceInfo cbii = {};
9502 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9503 cbii.renderPass = rp;
9504 cbii.subpass = 0;
9505 VkCommandBufferBeginInfo cbbi = {};
9506 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9507 cbbi.pInheritanceInfo = &cbii;
9508 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9509 VkRenderPassBeginInfo rpbi = {};
9510 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9511 rpbi.framebuffer = m_framebuffer;
9512 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009513 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9514 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009515
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009517 // Render triangle (the error should trigger on the attempt to draw).
9518 Draw(3, 1, 0, 0);
9519
9520 // Finalize recording of the command buffer
9521 EndCommandBuffer();
9522
9523 m_errorMonitor->VerifyFound();
9524
9525 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9526 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9527 vkDestroyRenderPass(m_device->device(), rp, NULL);
9528}
9529
Mark Youngc89c6312016-03-31 16:03:20 -06009530TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9531 // Create Pipeline where the number of blend attachments doesn't match the
9532 // number of color attachments. In this case, we don't add any color
9533 // blend attachments even though we have a color attachment.
9534 VkResult err;
9535
9536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009537 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009538
9539 ASSERT_NO_FATAL_FAILURE(InitState());
9540 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9541 VkDescriptorPoolSize ds_type_count = {};
9542 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9543 ds_type_count.descriptorCount = 1;
9544
9545 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9546 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9547 ds_pool_ci.pNext = NULL;
9548 ds_pool_ci.maxSets = 1;
9549 ds_pool_ci.poolSizeCount = 1;
9550 ds_pool_ci.pPoolSizes = &ds_type_count;
9551
9552 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009553 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009554 ASSERT_VK_SUCCESS(err);
9555
9556 VkDescriptorSetLayoutBinding dsl_binding = {};
9557 dsl_binding.binding = 0;
9558 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9559 dsl_binding.descriptorCount = 1;
9560 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9561 dsl_binding.pImmutableSamplers = NULL;
9562
9563 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9564 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9565 ds_layout_ci.pNext = NULL;
9566 ds_layout_ci.bindingCount = 1;
9567 ds_layout_ci.pBindings = &dsl_binding;
9568
9569 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009570 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009571 ASSERT_VK_SUCCESS(err);
9572
9573 VkDescriptorSet descriptorSet;
9574 VkDescriptorSetAllocateInfo alloc_info = {};
9575 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9576 alloc_info.descriptorSetCount = 1;
9577 alloc_info.descriptorPool = ds_pool;
9578 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009579 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009580 ASSERT_VK_SUCCESS(err);
9581
9582 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009583 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009584 pipe_ms_state_ci.pNext = NULL;
9585 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9586 pipe_ms_state_ci.sampleShadingEnable = 0;
9587 pipe_ms_state_ci.minSampleShading = 1.0;
9588 pipe_ms_state_ci.pSampleMask = NULL;
9589
9590 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9591 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9592 pipeline_layout_ci.pNext = NULL;
9593 pipeline_layout_ci.setLayoutCount = 1;
9594 pipeline_layout_ci.pSetLayouts = &ds_layout;
9595
9596 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009597 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009598 ASSERT_VK_SUCCESS(err);
9599
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009600 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9601 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9602 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009603 VkPipelineObj pipe(m_device);
9604 pipe.AddShader(&vs);
9605 pipe.AddShader(&fs);
9606 pipe.SetMSAA(&pipe_ms_state_ci);
9607 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9608
9609 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009610 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009611
Mark Young29927482016-05-04 14:38:51 -06009612 // Render triangle (the error should trigger on the attempt to draw).
9613 Draw(3, 1, 0, 0);
9614
9615 // Finalize recording of the command buffer
9616 EndCommandBuffer();
9617
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009618 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009619
9620 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9621 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9622 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9623}
Mark Young29927482016-05-04 14:38:51 -06009624
Mark Muellerd4914412016-06-13 17:52:06 -06009625TEST_F(VkLayerTest, MissingClearAttachment) {
9626 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9627 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009628 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +12009630 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -06009631
9632 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9633 m_errorMonitor->VerifyFound();
9634}
9635
Karl Schultz6addd812016-02-02 17:17:23 -07009636TEST_F(VkLayerTest, ClearCmdNoDraw) {
9637 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9638 // to issuing a Draw
9639 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009640
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009642 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009643
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009644 ASSERT_NO_FATAL_FAILURE(InitState());
9645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009646
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009647 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009648 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9649 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009650
9651 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009652 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9653 ds_pool_ci.pNext = NULL;
9654 ds_pool_ci.maxSets = 1;
9655 ds_pool_ci.poolSizeCount = 1;
9656 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009657
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009658 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009659 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009660 ASSERT_VK_SUCCESS(err);
9661
Tony Barboureb254902015-07-15 12:50:33 -06009662 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009663 dsl_binding.binding = 0;
9664 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9665 dsl_binding.descriptorCount = 1;
9666 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9667 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009668
Tony Barboureb254902015-07-15 12:50:33 -06009669 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009670 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9671 ds_layout_ci.pNext = NULL;
9672 ds_layout_ci.bindingCount = 1;
9673 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009674
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009675 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009676 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009677 ASSERT_VK_SUCCESS(err);
9678
9679 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009680 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009681 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009682 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009683 alloc_info.descriptorPool = ds_pool;
9684 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009685 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009686 ASSERT_VK_SUCCESS(err);
9687
Tony Barboureb254902015-07-15 12:50:33 -06009688 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009689 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009690 pipe_ms_state_ci.pNext = NULL;
9691 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9692 pipe_ms_state_ci.sampleShadingEnable = 0;
9693 pipe_ms_state_ci.minSampleShading = 1.0;
9694 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009695
Tony Barboureb254902015-07-15 12:50:33 -06009696 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009697 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9698 pipeline_layout_ci.pNext = NULL;
9699 pipeline_layout_ci.setLayoutCount = 1;
9700 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009701
9702 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009703 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009704 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009705
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009706 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009707 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009708 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009709 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009710
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009711 VkPipelineObj pipe(m_device);
9712 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009713 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009714 pipe.SetMSAA(&pipe_ms_state_ci);
9715 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009716
9717 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009718
Karl Schultz6addd812016-02-02 17:17:23 -07009719 // Main thing we care about for this test is that the VkImage obj we're
9720 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009721 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009722 VkClearAttachment color_attachment;
9723 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9724 color_attachment.clearValue.color.float32[0] = 1.0;
9725 color_attachment.clearValue.color.float32[1] = 1.0;
9726 color_attachment.clearValue.color.float32[2] = 1.0;
9727 color_attachment.clearValue.color.float32[3] = 1.0;
9728 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009729 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009731 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009732
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009733 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009734
Chia-I Wuf7458c52015-10-26 21:10:41 +08009735 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9736 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9737 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009738}
9739
Karl Schultz6addd812016-02-02 17:17:23 -07009740TEST_F(VkLayerTest, VtxBufferBadIndex) {
9741 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009742
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9744 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009745
Tobin Ehlis502480b2015-06-24 15:53:07 -06009746 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009747 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009749
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009750 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009751 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9752 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009753
9754 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009755 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9756 ds_pool_ci.pNext = NULL;
9757 ds_pool_ci.maxSets = 1;
9758 ds_pool_ci.poolSizeCount = 1;
9759 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009760
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009761 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009762 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009763 ASSERT_VK_SUCCESS(err);
9764
Tony Barboureb254902015-07-15 12:50:33 -06009765 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009766 dsl_binding.binding = 0;
9767 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9768 dsl_binding.descriptorCount = 1;
9769 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9770 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009771
Tony Barboureb254902015-07-15 12:50:33 -06009772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9774 ds_layout_ci.pNext = NULL;
9775 ds_layout_ci.bindingCount = 1;
9776 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009777
Tobin Ehlis502480b2015-06-24 15:53:07 -06009778 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009779 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009780 ASSERT_VK_SUCCESS(err);
9781
9782 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009783 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009784 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009785 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009786 alloc_info.descriptorPool = ds_pool;
9787 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009788 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009789 ASSERT_VK_SUCCESS(err);
9790
Tony Barboureb254902015-07-15 12:50:33 -06009791 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009792 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009793 pipe_ms_state_ci.pNext = NULL;
9794 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9795 pipe_ms_state_ci.sampleShadingEnable = 0;
9796 pipe_ms_state_ci.minSampleShading = 1.0;
9797 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009798
Tony Barboureb254902015-07-15 12:50:33 -06009799 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009800 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9801 pipeline_layout_ci.pNext = NULL;
9802 pipeline_layout_ci.setLayoutCount = 1;
9803 pipeline_layout_ci.pSetLayouts = &ds_layout;
9804 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009805
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009806 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009807 ASSERT_VK_SUCCESS(err);
9808
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009809 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9810 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9811 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009812 VkPipelineObj pipe(m_device);
9813 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009814 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009815 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009816 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009817 pipe.SetViewport(m_viewports);
9818 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009819 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009820
9821 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009822 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009823 // Don't care about actual data, just need to get to draw to flag error
9824 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009825 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009826 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009827 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009828
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009829 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009830
Chia-I Wuf7458c52015-10-26 21:10:41 +08009831 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9832 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9833 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009834}
Mark Muellerdfe37552016-07-07 14:47:42 -06009835
Mark Mueller2ee294f2016-08-04 12:59:48 -06009836TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9837 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9838 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009839 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009840
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009841 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9842 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009843
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009844 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9845 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009846
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009847 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009850 // The following test fails with recent NVidia drivers.
9851 // By the time core_validation is reached, the NVidia
9852 // driver has sanitized the invalid condition and core_validation
9853 // is not introduced to the failure condition. This is not the case
9854 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009855 // uint32_t count = static_cast<uint32_t>(~0);
9856 // VkPhysicalDevice physical_device;
9857 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9858 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009859
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009861 float queue_priority = 0.0;
9862
9863 VkDeviceQueueCreateInfo queue_create_info = {};
9864 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9865 queue_create_info.queueCount = 1;
9866 queue_create_info.pQueuePriorities = &queue_priority;
9867 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
9868
9869 VkPhysicalDeviceFeatures features = m_device->phy().features();
9870 VkDevice testDevice;
9871 VkDeviceCreateInfo device_create_info = {};
9872 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
9873 device_create_info.queueCreateInfoCount = 1;
9874 device_create_info.pQueueCreateInfos = &queue_create_info;
9875 device_create_info.pEnabledFeatures = &features;
9876 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9877 m_errorMonitor->VerifyFound();
9878
9879 queue_create_info.queueFamilyIndex = 1;
9880
9881 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
9882 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
9883 for (unsigned i = 0; i < feature_count; i++) {
9884 if (VK_FALSE == feature_array[i]) {
9885 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009887 device_create_info.pEnabledFeatures = &features;
9888 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9889 m_errorMonitor->VerifyFound();
9890 break;
9891 }
9892 }
9893}
9894
9895TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
9896 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
9897 "End a command buffer with a query still in progress.");
9898
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009899 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
9900 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
9901 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009902
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009903 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009904
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009906
9907 ASSERT_NO_FATAL_FAILURE(InitState());
9908
9909 VkEvent event;
9910 VkEventCreateInfo event_create_info{};
9911 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9912 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9913
Mark Mueller2ee294f2016-08-04 12:59:48 -06009914 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009915 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009916
9917 BeginCommandBuffer();
9918
9919 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009920 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 -06009921 ASSERT_TRUE(image.initialized());
9922 VkImageMemoryBarrier img_barrier = {};
9923 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9924 img_barrier.pNext = NULL;
9925 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9926 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9927 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9928 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9929 img_barrier.image = image.handle();
9930 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -06009931
9932 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
9933 // that layer validation catches the case when it is not.
9934 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -06009935 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9936 img_barrier.subresourceRange.baseArrayLayer = 0;
9937 img_barrier.subresourceRange.baseMipLevel = 0;
9938 img_barrier.subresourceRange.layerCount = 1;
9939 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009940 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
9941 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009942 m_errorMonitor->VerifyFound();
9943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009945
9946 VkQueryPool query_pool;
9947 VkQueryPoolCreateInfo query_pool_create_info = {};
9948 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
9949 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
9950 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009951 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009952
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009953 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009954 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
9955
9956 vkEndCommandBuffer(m_commandBuffer->handle());
9957 m_errorMonitor->VerifyFound();
9958
9959 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
9960 vkDestroyEvent(m_device->device(), event, nullptr);
9961}
9962
Mark Muellerdfe37552016-07-07 14:47:42 -06009963TEST_F(VkLayerTest, VertexBufferInvalid) {
9964 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
9965 "delete a buffer twice, use an invalid offset for each "
9966 "buffer type, and attempt to bind a null buffer");
9967
9968 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
9969 "using deleted buffer ";
9970 const char *double_destroy_message = "Cannot free buffer 0x";
9971 const char *invalid_offset_message = "vkBindBufferMemory(): "
9972 "memoryOffset is 0x";
9973 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
9974 "storage memoryOffset "
9975 "is 0x";
9976 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
9977 "texel memoryOffset "
9978 "is 0x";
9979 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
9980 "uniform memoryOffset "
9981 "is 0x";
9982 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
9983 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -06009984 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -06009985
9986 ASSERT_NO_FATAL_FAILURE(InitState());
9987 ASSERT_NO_FATAL_FAILURE(InitViewport());
9988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9989
9990 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009991 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -06009992 pipe_ms_state_ci.pNext = NULL;
9993 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9994 pipe_ms_state_ci.sampleShadingEnable = 0;
9995 pipe_ms_state_ci.minSampleShading = 1.0;
9996 pipe_ms_state_ci.pSampleMask = nullptr;
9997
9998 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9999 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10000 VkPipelineLayout pipeline_layout;
10001
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010002 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010003 ASSERT_VK_SUCCESS(err);
10004
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010005 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10006 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010007 VkPipelineObj pipe(m_device);
10008 pipe.AddShader(&vs);
10009 pipe.AddShader(&fs);
10010 pipe.AddColorAttachment();
10011 pipe.SetMSAA(&pipe_ms_state_ci);
10012 pipe.SetViewport(m_viewports);
10013 pipe.SetScissor(m_scissors);
10014 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10015
10016 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010017 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010018
10019 {
10020 // Create and bind a vertex buffer in a reduced scope, which will cause
10021 // it to be deleted upon leaving this scope
10022 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010023 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010024 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10025 draw_verticies.AddVertexInputToPipe(pipe);
10026 }
10027
10028 Draw(1, 0, 0, 0);
10029
10030 EndCommandBuffer();
10031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010033 QueueCommandBuffer(false);
10034 m_errorMonitor->VerifyFound();
10035
10036 {
10037 // Create and bind a vertex buffer in a reduced scope, and delete it
10038 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010039 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010041 buffer_test.TestDoubleDestroy();
10042 }
10043 m_errorMonitor->VerifyFound();
10044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010045 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010046 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10048 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10049 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010050 m_errorMonitor->VerifyFound();
10051 }
10052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010053 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10054 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010055 // Create and bind a memory buffer with an invalid offset again,
10056 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10058 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10059 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010060 m_errorMonitor->VerifyFound();
10061 }
10062
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010063 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010064 // Create and bind a memory buffer with an invalid offset again, but
10065 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10067 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10068 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010069 m_errorMonitor->VerifyFound();
10070 }
10071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010072 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010073 // Create and bind a memory buffer with an invalid offset again, but
10074 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10076 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10077 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010078 m_errorMonitor->VerifyFound();
10079 }
10080
10081 {
10082 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10084 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10085 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010086 m_errorMonitor->VerifyFound();
10087 }
10088
10089 {
10090 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10092 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10093 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010094 }
10095 m_errorMonitor->VerifyFound();
10096
10097 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10098}
10099
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010100// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10101TEST_F(VkLayerTest, InvalidImageLayout) {
10102 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010103 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10104 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010105 // 3 in ValidateCmdBufImageLayouts
10106 // * -1 Attempt to submit cmd buf w/ deleted image
10107 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10108 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10110 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010111
10112 ASSERT_NO_FATAL_FAILURE(InitState());
10113 // Create src & dst images to use for copy operations
10114 VkImage src_image;
10115 VkImage dst_image;
10116
10117 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10118 const int32_t tex_width = 32;
10119 const int32_t tex_height = 32;
10120
10121 VkImageCreateInfo image_create_info = {};
10122 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10123 image_create_info.pNext = NULL;
10124 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10125 image_create_info.format = tex_format;
10126 image_create_info.extent.width = tex_width;
10127 image_create_info.extent.height = tex_height;
10128 image_create_info.extent.depth = 1;
10129 image_create_info.mipLevels = 1;
10130 image_create_info.arrayLayers = 4;
10131 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10132 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10133 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10134 image_create_info.flags = 0;
10135
10136 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10137 ASSERT_VK_SUCCESS(err);
10138 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10139 ASSERT_VK_SUCCESS(err);
10140
10141 BeginCommandBuffer();
10142 VkImageCopy copyRegion;
10143 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10144 copyRegion.srcSubresource.mipLevel = 0;
10145 copyRegion.srcSubresource.baseArrayLayer = 0;
10146 copyRegion.srcSubresource.layerCount = 1;
10147 copyRegion.srcOffset.x = 0;
10148 copyRegion.srcOffset.y = 0;
10149 copyRegion.srcOffset.z = 0;
10150 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10151 copyRegion.dstSubresource.mipLevel = 0;
10152 copyRegion.dstSubresource.baseArrayLayer = 0;
10153 copyRegion.dstSubresource.layerCount = 1;
10154 copyRegion.dstOffset.x = 0;
10155 copyRegion.dstOffset.y = 0;
10156 copyRegion.dstOffset.z = 0;
10157 copyRegion.extent.width = 1;
10158 copyRegion.extent.height = 1;
10159 copyRegion.extent.depth = 1;
10160 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10161 m_errorMonitor->VerifyFound();
10162 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10164 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10165 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010166 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10167 m_errorMonitor->VerifyFound();
10168 // Final src error is due to bad layout type
10169 m_errorMonitor->SetDesiredFailureMsg(
10170 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10171 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10172 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10173 m_errorMonitor->VerifyFound();
10174 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10176 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010177 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10178 m_errorMonitor->VerifyFound();
10179 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10181 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10182 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010183 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10184 m_errorMonitor->VerifyFound();
10185 m_errorMonitor->SetDesiredFailureMsg(
10186 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10187 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10188 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10189 m_errorMonitor->VerifyFound();
10190 // Now cause error due to bad image layout transition in PipelineBarrier
10191 VkImageMemoryBarrier image_barrier[1] = {};
10192 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10193 image_barrier[0].image = src_image;
10194 image_barrier[0].subresourceRange.layerCount = 2;
10195 image_barrier[0].subresourceRange.levelCount = 2;
10196 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10198 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10199 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10200 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10201 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010202 m_errorMonitor->VerifyFound();
10203
10204 // Finally some layout errors at RenderPass create time
10205 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10206 VkAttachmentReference attach = {};
10207 // perf warning for GENERAL layout w/ non-DS input attachment
10208 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10209 VkSubpassDescription subpass = {};
10210 subpass.inputAttachmentCount = 1;
10211 subpass.pInputAttachments = &attach;
10212 VkRenderPassCreateInfo rpci = {};
10213 rpci.subpassCount = 1;
10214 rpci.pSubpasses = &subpass;
10215 rpci.attachmentCount = 1;
10216 VkAttachmentDescription attach_desc = {};
10217 attach_desc.format = VK_FORMAT_UNDEFINED;
10218 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010219 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010220 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10222 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010223 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10224 m_errorMonitor->VerifyFound();
10225 // error w/ non-general layout
10226 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10227
10228 m_errorMonitor->SetDesiredFailureMsg(
10229 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10230 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10231 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10232 m_errorMonitor->VerifyFound();
10233 subpass.inputAttachmentCount = 0;
10234 subpass.colorAttachmentCount = 1;
10235 subpass.pColorAttachments = &attach;
10236 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10237 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10239 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010240 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10241 m_errorMonitor->VerifyFound();
10242 // error w/ non-color opt or GENERAL layout for color attachment
10243 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10244 m_errorMonitor->SetDesiredFailureMsg(
10245 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10246 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10247 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10248 m_errorMonitor->VerifyFound();
10249 subpass.colorAttachmentCount = 0;
10250 subpass.pDepthStencilAttachment = &attach;
10251 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10252 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10254 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010255 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10256 m_errorMonitor->VerifyFound();
10257 // error w/ non-ds opt or GENERAL layout for color attachment
10258 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10260 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10261 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010262 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10263 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010264 // For this error we need a valid renderpass so create default one
10265 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10266 attach.attachment = 0;
10267 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10268 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10269 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10270 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10271 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10272 // Can't do a CLEAR load on READ_ONLY initialLayout
10273 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10274 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10275 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10277 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10278 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010279 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10280 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010281
10282 vkDestroyImage(m_device->device(), src_image, NULL);
10283 vkDestroyImage(m_device->device(), dst_image, NULL);
10284}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010285
Tobin Ehlise0936662016-10-11 08:10:51 -060010286TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10287 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10288 VkResult err;
10289
10290 ASSERT_NO_FATAL_FAILURE(InitState());
10291
10292 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10293 VkImageTiling tiling;
10294 VkFormatProperties format_properties;
10295 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10296 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10297 tiling = VK_IMAGE_TILING_LINEAR;
10298 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10299 tiling = VK_IMAGE_TILING_OPTIMAL;
10300 } else {
10301 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10302 "skipped.\n");
10303 return;
10304 }
10305
10306 VkDescriptorPoolSize ds_type = {};
10307 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10308 ds_type.descriptorCount = 1;
10309
10310 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10311 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10312 ds_pool_ci.maxSets = 1;
10313 ds_pool_ci.poolSizeCount = 1;
10314 ds_pool_ci.pPoolSizes = &ds_type;
10315 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10316
10317 VkDescriptorPool ds_pool;
10318 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10319 ASSERT_VK_SUCCESS(err);
10320
10321 VkDescriptorSetLayoutBinding dsl_binding = {};
10322 dsl_binding.binding = 0;
10323 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10324 dsl_binding.descriptorCount = 1;
10325 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10326 dsl_binding.pImmutableSamplers = NULL;
10327
10328 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10329 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10330 ds_layout_ci.pNext = NULL;
10331 ds_layout_ci.bindingCount = 1;
10332 ds_layout_ci.pBindings = &dsl_binding;
10333
10334 VkDescriptorSetLayout ds_layout;
10335 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10336 ASSERT_VK_SUCCESS(err);
10337
10338 VkDescriptorSetAllocateInfo alloc_info = {};
10339 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10340 alloc_info.descriptorSetCount = 1;
10341 alloc_info.descriptorPool = ds_pool;
10342 alloc_info.pSetLayouts = &ds_layout;
10343 VkDescriptorSet descriptor_set;
10344 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10345 ASSERT_VK_SUCCESS(err);
10346
10347 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10348 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10349 pipeline_layout_ci.pNext = NULL;
10350 pipeline_layout_ci.setLayoutCount = 1;
10351 pipeline_layout_ci.pSetLayouts = &ds_layout;
10352 VkPipelineLayout pipeline_layout;
10353 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10354 ASSERT_VK_SUCCESS(err);
10355
10356 VkImageObj image(m_device);
10357 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10358 ASSERT_TRUE(image.initialized());
10359 VkImageView view = image.targetView(tex_format);
10360
10361 VkDescriptorImageInfo image_info = {};
10362 image_info.imageView = view;
10363 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10364
10365 VkWriteDescriptorSet descriptor_write = {};
10366 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10367 descriptor_write.dstSet = descriptor_set;
10368 descriptor_write.dstBinding = 0;
10369 descriptor_write.descriptorCount = 1;
10370 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10371 descriptor_write.pImageInfo = &image_info;
10372
10373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10374 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10375 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10376 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10377 m_errorMonitor->VerifyFound();
10378
10379 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10380 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10381 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10382 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10383}
10384
Mark Mueller93b938f2016-08-18 10:27:40 -060010385TEST_F(VkLayerTest, SimultaneousUse) {
10386 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10387 "in primary and secondary command buffers.");
10388
10389 ASSERT_NO_FATAL_FAILURE(InitState());
10390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10391
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010392 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010393 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10394 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010395
10396 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010397 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010398 command_buffer_allocate_info.commandPool = m_commandPool;
10399 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10400 command_buffer_allocate_info.commandBufferCount = 1;
10401
10402 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010403 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010404 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10405 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010406 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010407 command_buffer_inheritance_info.renderPass = m_renderPass;
10408 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10409 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010410 command_buffer_begin_info.flags =
10411 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010412 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10413
10414 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010415 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10416 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010417 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010418 vkEndCommandBuffer(secondary_command_buffer);
10419
Mark Mueller93b938f2016-08-18 10:27:40 -060010420 VkSubmitInfo submit_info = {};
10421 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10422 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010423 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010424 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010425
Mark Mueller4042b652016-09-05 22:52:21 -060010426 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010427 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10429 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010430 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010431 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10432 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010433
10434 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010435 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10436
Mark Mueller4042b652016-09-05 22:52:21 -060010437 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010438 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010439 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10442 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010443 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010444 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10445 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010446}
10447
Mark Mueller917f6bc2016-08-30 10:57:19 -060010448TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10449 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10450 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010451 "Delete objects that are inuse. Call VkQueueSubmit "
10452 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010453
10454 ASSERT_NO_FATAL_FAILURE(InitState());
10455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10456
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010457 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10458 const char *cannot_delete_event_message = "Cannot delete event 0x";
10459 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10460 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010461
10462 BeginCommandBuffer();
10463
10464 VkEvent event;
10465 VkEventCreateInfo event_create_info = {};
10466 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10467 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010468 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010469
Mark Muellerc8d441e2016-08-23 17:36:00 -060010470 EndCommandBuffer();
10471 vkDestroyEvent(m_device->device(), event, nullptr);
10472
10473 VkSubmitInfo submit_info = {};
10474 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10475 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010476 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010478 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10479 m_errorMonitor->VerifyFound();
10480
10481 m_errorMonitor->SetDesiredFailureMsg(0, "");
10482 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10483
10484 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10485
Mark Mueller917f6bc2016-08-30 10:57:19 -060010486 VkSemaphoreCreateInfo semaphore_create_info = {};
10487 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10488 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010489 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010490 VkFenceCreateInfo fence_create_info = {};
10491 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10492 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010493 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010494
10495 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010496 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010497 descriptor_pool_type_count.descriptorCount = 1;
10498
10499 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10500 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10501 descriptor_pool_create_info.maxSets = 1;
10502 descriptor_pool_create_info.poolSizeCount = 1;
10503 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010504 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010505
10506 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010507 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010508
10509 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010510 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010511 descriptorset_layout_binding.descriptorCount = 1;
10512 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10513
10514 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010515 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010516 descriptorset_layout_create_info.bindingCount = 1;
10517 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10518
10519 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010520 ASSERT_VK_SUCCESS(
10521 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010522
10523 VkDescriptorSet descriptorset;
10524 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010525 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010526 descriptorset_allocate_info.descriptorSetCount = 1;
10527 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10528 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010529 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010530
Mark Mueller4042b652016-09-05 22:52:21 -060010531 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10532
10533 VkDescriptorBufferInfo buffer_info = {};
10534 buffer_info.buffer = buffer_test.GetBuffer();
10535 buffer_info.offset = 0;
10536 buffer_info.range = 1024;
10537
10538 VkWriteDescriptorSet write_descriptor_set = {};
10539 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10540 write_descriptor_set.dstSet = descriptorset;
10541 write_descriptor_set.descriptorCount = 1;
10542 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10543 write_descriptor_set.pBufferInfo = &buffer_info;
10544
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010545 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010547 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10548 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010549
10550 VkPipelineObj pipe(m_device);
10551 pipe.AddColorAttachment();
10552 pipe.AddShader(&vs);
10553 pipe.AddShader(&fs);
10554
10555 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010556 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010557 pipeline_layout_create_info.setLayoutCount = 1;
10558 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10559
10560 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010561 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010562
10563 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10564
Mark Muellerc8d441e2016-08-23 17:36:00 -060010565 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010566 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010568 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10569 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10570 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010571
Mark Muellerc8d441e2016-08-23 17:36:00 -060010572 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010573
Mark Mueller917f6bc2016-08-30 10:57:19 -060010574 submit_info.signalSemaphoreCount = 1;
10575 submit_info.pSignalSemaphores = &semaphore;
10576 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010577
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010579 vkDestroyEvent(m_device->device(), event, nullptr);
10580 m_errorMonitor->VerifyFound();
10581
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010583 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10584 m_errorMonitor->VerifyFound();
10585
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010587 vkDestroyFence(m_device->device(), fence, nullptr);
10588 m_errorMonitor->VerifyFound();
10589
Tobin Ehlis122207b2016-09-01 08:50:06 -070010590 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010591 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10592 vkDestroyFence(m_device->device(), fence, nullptr);
10593 vkDestroyEvent(m_device->device(), event, nullptr);
10594 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010595 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010596 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10597}
10598
Tobin Ehlis2adda372016-09-01 08:51:06 -070010599TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10600 TEST_DESCRIPTION("Delete in-use query pool.");
10601
10602 ASSERT_NO_FATAL_FAILURE(InitState());
10603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10604
10605 VkQueryPool query_pool;
10606 VkQueryPoolCreateInfo query_pool_ci{};
10607 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10608 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10609 query_pool_ci.queryCount = 1;
10610 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10611 BeginCommandBuffer();
10612 // Reset query pool to create binding with cmd buffer
10613 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10614
10615 EndCommandBuffer();
10616
10617 VkSubmitInfo submit_info = {};
10618 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10619 submit_info.commandBufferCount = 1;
10620 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10621 // Submit cmd buffer and then destroy query pool while in-flight
10622 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010625 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10626 m_errorMonitor->VerifyFound();
10627
10628 vkQueueWaitIdle(m_device->m_queue);
10629 // Now that cmd buffer done we can safely destroy query_pool
10630 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10631}
10632
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010633TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10634 TEST_DESCRIPTION("Delete in-use pipeline.");
10635
10636 ASSERT_NO_FATAL_FAILURE(InitState());
10637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10638
10639 // Empty pipeline layout used for binding PSO
10640 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10641 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10642 pipeline_layout_ci.setLayoutCount = 0;
10643 pipeline_layout_ci.pSetLayouts = NULL;
10644
10645 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010646 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010647 ASSERT_VK_SUCCESS(err);
10648
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010650 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010651 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10652 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010653 // Store pipeline handle so we can actually delete it before test finishes
10654 VkPipeline delete_this_pipeline;
10655 { // Scope pipeline so it will be auto-deleted
10656 VkPipelineObj pipe(m_device);
10657 pipe.AddShader(&vs);
10658 pipe.AddShader(&fs);
10659 pipe.AddColorAttachment();
10660 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10661 delete_this_pipeline = pipe.handle();
10662
10663 BeginCommandBuffer();
10664 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010665 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010666
10667 EndCommandBuffer();
10668
10669 VkSubmitInfo submit_info = {};
10670 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10671 submit_info.commandBufferCount = 1;
10672 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10673 // Submit cmd buffer and then pipeline destroyed while in-flight
10674 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10675 } // Pipeline deletion triggered here
10676 m_errorMonitor->VerifyFound();
10677 // Make sure queue finished and then actually delete pipeline
10678 vkQueueWaitIdle(m_device->m_queue);
10679 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10680 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10681}
10682
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010683TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10684 TEST_DESCRIPTION("Delete in-use imageView.");
10685
10686 ASSERT_NO_FATAL_FAILURE(InitState());
10687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10688
10689 VkDescriptorPoolSize ds_type_count;
10690 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10691 ds_type_count.descriptorCount = 1;
10692
10693 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10694 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10695 ds_pool_ci.maxSets = 1;
10696 ds_pool_ci.poolSizeCount = 1;
10697 ds_pool_ci.pPoolSizes = &ds_type_count;
10698
10699 VkDescriptorPool ds_pool;
10700 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10701 ASSERT_VK_SUCCESS(err);
10702
10703 VkSamplerCreateInfo sampler_ci = {};
10704 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10705 sampler_ci.pNext = NULL;
10706 sampler_ci.magFilter = VK_FILTER_NEAREST;
10707 sampler_ci.minFilter = VK_FILTER_NEAREST;
10708 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10709 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10710 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10711 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10712 sampler_ci.mipLodBias = 1.0;
10713 sampler_ci.anisotropyEnable = VK_FALSE;
10714 sampler_ci.maxAnisotropy = 1;
10715 sampler_ci.compareEnable = VK_FALSE;
10716 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10717 sampler_ci.minLod = 1.0;
10718 sampler_ci.maxLod = 1.0;
10719 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10720 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10721 VkSampler sampler;
10722
10723 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10724 ASSERT_VK_SUCCESS(err);
10725
10726 VkDescriptorSetLayoutBinding layout_binding;
10727 layout_binding.binding = 0;
10728 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10729 layout_binding.descriptorCount = 1;
10730 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10731 layout_binding.pImmutableSamplers = NULL;
10732
10733 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10734 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10735 ds_layout_ci.bindingCount = 1;
10736 ds_layout_ci.pBindings = &layout_binding;
10737 VkDescriptorSetLayout ds_layout;
10738 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10739 ASSERT_VK_SUCCESS(err);
10740
10741 VkDescriptorSetAllocateInfo alloc_info = {};
10742 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10743 alloc_info.descriptorSetCount = 1;
10744 alloc_info.descriptorPool = ds_pool;
10745 alloc_info.pSetLayouts = &ds_layout;
10746 VkDescriptorSet descriptor_set;
10747 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10748 ASSERT_VK_SUCCESS(err);
10749
10750 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10751 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10752 pipeline_layout_ci.pNext = NULL;
10753 pipeline_layout_ci.setLayoutCount = 1;
10754 pipeline_layout_ci.pSetLayouts = &ds_layout;
10755
10756 VkPipelineLayout pipeline_layout;
10757 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10758 ASSERT_VK_SUCCESS(err);
10759
10760 VkImageObj image(m_device);
10761 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10762 ASSERT_TRUE(image.initialized());
10763
10764 VkImageView view;
10765 VkImageViewCreateInfo ivci = {};
10766 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10767 ivci.image = image.handle();
10768 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10769 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10770 ivci.subresourceRange.layerCount = 1;
10771 ivci.subresourceRange.baseMipLevel = 0;
10772 ivci.subresourceRange.levelCount = 1;
10773 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10774
10775 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10776 ASSERT_VK_SUCCESS(err);
10777
10778 VkDescriptorImageInfo image_info{};
10779 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10780 image_info.imageView = view;
10781 image_info.sampler = sampler;
10782
10783 VkWriteDescriptorSet descriptor_write = {};
10784 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10785 descriptor_write.dstSet = descriptor_set;
10786 descriptor_write.dstBinding = 0;
10787 descriptor_write.descriptorCount = 1;
10788 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10789 descriptor_write.pImageInfo = &image_info;
10790
10791 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10792
10793 // Create PSO to use the sampler
10794 char const *vsSource = "#version 450\n"
10795 "\n"
10796 "out gl_PerVertex { \n"
10797 " vec4 gl_Position;\n"
10798 "};\n"
10799 "void main(){\n"
10800 " gl_Position = vec4(1);\n"
10801 "}\n";
10802 char const *fsSource = "#version 450\n"
10803 "\n"
10804 "layout(set=0, binding=0) uniform sampler2D s;\n"
10805 "layout(location=0) out vec4 x;\n"
10806 "void main(){\n"
10807 " x = texture(s, vec2(1));\n"
10808 "}\n";
10809 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10810 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10811 VkPipelineObj pipe(m_device);
10812 pipe.AddShader(&vs);
10813 pipe.AddShader(&fs);
10814 pipe.AddColorAttachment();
10815 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10816
10817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10818
10819 BeginCommandBuffer();
10820 // Bind pipeline to cmd buffer
10821 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10822 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10823 &descriptor_set, 0, nullptr);
10824 Draw(1, 0, 0, 0);
10825 EndCommandBuffer();
10826 // Submit cmd buffer then destroy sampler
10827 VkSubmitInfo submit_info = {};
10828 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10829 submit_info.commandBufferCount = 1;
10830 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10831 // Submit cmd buffer and then destroy imageView while in-flight
10832 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10833
10834 vkDestroyImageView(m_device->device(), view, nullptr);
10835 m_errorMonitor->VerifyFound();
10836 vkQueueWaitIdle(m_device->m_queue);
10837 // Now we can actually destroy imageView
10838 vkDestroyImageView(m_device->device(), view, NULL);
10839 vkDestroySampler(m_device->device(), sampler, nullptr);
10840 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10841 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10842 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10843}
10844
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010845TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10846 TEST_DESCRIPTION("Delete in-use bufferView.");
10847
10848 ASSERT_NO_FATAL_FAILURE(InitState());
10849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10850
10851 VkDescriptorPoolSize ds_type_count;
10852 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10853 ds_type_count.descriptorCount = 1;
10854
10855 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10856 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10857 ds_pool_ci.maxSets = 1;
10858 ds_pool_ci.poolSizeCount = 1;
10859 ds_pool_ci.pPoolSizes = &ds_type_count;
10860
10861 VkDescriptorPool ds_pool;
10862 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10863 ASSERT_VK_SUCCESS(err);
10864
10865 VkDescriptorSetLayoutBinding layout_binding;
10866 layout_binding.binding = 0;
10867 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10868 layout_binding.descriptorCount = 1;
10869 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10870 layout_binding.pImmutableSamplers = NULL;
10871
10872 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10873 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10874 ds_layout_ci.bindingCount = 1;
10875 ds_layout_ci.pBindings = &layout_binding;
10876 VkDescriptorSetLayout ds_layout;
10877 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10878 ASSERT_VK_SUCCESS(err);
10879
10880 VkDescriptorSetAllocateInfo alloc_info = {};
10881 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10882 alloc_info.descriptorSetCount = 1;
10883 alloc_info.descriptorPool = ds_pool;
10884 alloc_info.pSetLayouts = &ds_layout;
10885 VkDescriptorSet descriptor_set;
10886 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10887 ASSERT_VK_SUCCESS(err);
10888
10889 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10890 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10891 pipeline_layout_ci.pNext = NULL;
10892 pipeline_layout_ci.setLayoutCount = 1;
10893 pipeline_layout_ci.pSetLayouts = &ds_layout;
10894
10895 VkPipelineLayout pipeline_layout;
10896 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10897 ASSERT_VK_SUCCESS(err);
10898
10899 VkBuffer buffer;
10900 uint32_t queue_family_index = 0;
10901 VkBufferCreateInfo buffer_create_info = {};
10902 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10903 buffer_create_info.size = 1024;
10904 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10905 buffer_create_info.queueFamilyIndexCount = 1;
10906 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
10907
10908 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
10909 ASSERT_VK_SUCCESS(err);
10910
10911 VkMemoryRequirements memory_reqs;
10912 VkDeviceMemory buffer_memory;
10913
10914 VkMemoryAllocateInfo memory_info = {};
10915 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10916 memory_info.allocationSize = 0;
10917 memory_info.memoryTypeIndex = 0;
10918
10919 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
10920 memory_info.allocationSize = memory_reqs.size;
10921 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
10922 ASSERT_TRUE(pass);
10923
10924 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
10925 ASSERT_VK_SUCCESS(err);
10926 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
10927 ASSERT_VK_SUCCESS(err);
10928
10929 VkBufferView view;
10930 VkBufferViewCreateInfo bvci = {};
10931 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10932 bvci.buffer = buffer;
10933 bvci.format = VK_FORMAT_R8_UNORM;
10934 bvci.range = VK_WHOLE_SIZE;
10935
10936 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
10937 ASSERT_VK_SUCCESS(err);
10938
10939 VkWriteDescriptorSet descriptor_write = {};
10940 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10941 descriptor_write.dstSet = descriptor_set;
10942 descriptor_write.dstBinding = 0;
10943 descriptor_write.descriptorCount = 1;
10944 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10945 descriptor_write.pTexelBufferView = &view;
10946
10947 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10948
10949 char const *vsSource = "#version 450\n"
10950 "\n"
10951 "out gl_PerVertex { \n"
10952 " vec4 gl_Position;\n"
10953 "};\n"
10954 "void main(){\n"
10955 " gl_Position = vec4(1);\n"
10956 "}\n";
10957 char const *fsSource = "#version 450\n"
10958 "\n"
10959 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
10960 "layout(location=0) out vec4 x;\n"
10961 "void main(){\n"
10962 " x = imageLoad(s, 0);\n"
10963 "}\n";
10964 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10965 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10966 VkPipelineObj pipe(m_device);
10967 pipe.AddShader(&vs);
10968 pipe.AddShader(&fs);
10969 pipe.AddColorAttachment();
10970 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10971
10972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
10973
10974 BeginCommandBuffer();
10975 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10976 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10977 VkRect2D scissor = {{0, 0}, {16, 16}};
10978 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10979 // Bind pipeline to cmd buffer
10980 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10981 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10982 &descriptor_set, 0, nullptr);
10983 Draw(1, 0, 0, 0);
10984 EndCommandBuffer();
10985
10986 VkSubmitInfo submit_info = {};
10987 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10988 submit_info.commandBufferCount = 1;
10989 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10990 // Submit cmd buffer and then destroy bufferView while in-flight
10991 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10992
10993 vkDestroyBufferView(m_device->device(), view, nullptr);
10994 m_errorMonitor->VerifyFound();
10995 vkQueueWaitIdle(m_device->m_queue);
10996 // Now we can actually destroy bufferView
10997 vkDestroyBufferView(m_device->device(), view, NULL);
10998 vkDestroyBuffer(m_device->device(), buffer, NULL);
10999 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11000 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11001 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11002 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11003}
11004
Tobin Ehlis209532e2016-09-07 13:52:18 -060011005TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11006 TEST_DESCRIPTION("Delete in-use sampler.");
11007
11008 ASSERT_NO_FATAL_FAILURE(InitState());
11009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11010
11011 VkDescriptorPoolSize ds_type_count;
11012 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11013 ds_type_count.descriptorCount = 1;
11014
11015 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11016 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11017 ds_pool_ci.maxSets = 1;
11018 ds_pool_ci.poolSizeCount = 1;
11019 ds_pool_ci.pPoolSizes = &ds_type_count;
11020
11021 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011022 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011023 ASSERT_VK_SUCCESS(err);
11024
11025 VkSamplerCreateInfo sampler_ci = {};
11026 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11027 sampler_ci.pNext = NULL;
11028 sampler_ci.magFilter = VK_FILTER_NEAREST;
11029 sampler_ci.minFilter = VK_FILTER_NEAREST;
11030 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11031 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11032 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11033 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11034 sampler_ci.mipLodBias = 1.0;
11035 sampler_ci.anisotropyEnable = VK_FALSE;
11036 sampler_ci.maxAnisotropy = 1;
11037 sampler_ci.compareEnable = VK_FALSE;
11038 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11039 sampler_ci.minLod = 1.0;
11040 sampler_ci.maxLod = 1.0;
11041 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11042 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11043 VkSampler sampler;
11044
11045 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11046 ASSERT_VK_SUCCESS(err);
11047
11048 VkDescriptorSetLayoutBinding layout_binding;
11049 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011050 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011051 layout_binding.descriptorCount = 1;
11052 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11053 layout_binding.pImmutableSamplers = NULL;
11054
11055 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11056 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11057 ds_layout_ci.bindingCount = 1;
11058 ds_layout_ci.pBindings = &layout_binding;
11059 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011060 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011061 ASSERT_VK_SUCCESS(err);
11062
11063 VkDescriptorSetAllocateInfo alloc_info = {};
11064 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11065 alloc_info.descriptorSetCount = 1;
11066 alloc_info.descriptorPool = ds_pool;
11067 alloc_info.pSetLayouts = &ds_layout;
11068 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011069 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011070 ASSERT_VK_SUCCESS(err);
11071
11072 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11073 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11074 pipeline_layout_ci.pNext = NULL;
11075 pipeline_layout_ci.setLayoutCount = 1;
11076 pipeline_layout_ci.pSetLayouts = &ds_layout;
11077
11078 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011079 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011080 ASSERT_VK_SUCCESS(err);
11081
11082 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011083 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 -060011084 ASSERT_TRUE(image.initialized());
11085
11086 VkImageView view;
11087 VkImageViewCreateInfo ivci = {};
11088 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11089 ivci.image = image.handle();
11090 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11091 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11092 ivci.subresourceRange.layerCount = 1;
11093 ivci.subresourceRange.baseMipLevel = 0;
11094 ivci.subresourceRange.levelCount = 1;
11095 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11096
11097 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11098 ASSERT_VK_SUCCESS(err);
11099
11100 VkDescriptorImageInfo image_info{};
11101 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11102 image_info.imageView = view;
11103 image_info.sampler = sampler;
11104
11105 VkWriteDescriptorSet descriptor_write = {};
11106 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11107 descriptor_write.dstSet = descriptor_set;
11108 descriptor_write.dstBinding = 0;
11109 descriptor_write.descriptorCount = 1;
11110 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11111 descriptor_write.pImageInfo = &image_info;
11112
11113 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11114
11115 // Create PSO to use the sampler
11116 char const *vsSource = "#version 450\n"
11117 "\n"
11118 "out gl_PerVertex { \n"
11119 " vec4 gl_Position;\n"
11120 "};\n"
11121 "void main(){\n"
11122 " gl_Position = vec4(1);\n"
11123 "}\n";
11124 char const *fsSource = "#version 450\n"
11125 "\n"
11126 "layout(set=0, binding=0) uniform sampler2D s;\n"
11127 "layout(location=0) out vec4 x;\n"
11128 "void main(){\n"
11129 " x = texture(s, vec2(1));\n"
11130 "}\n";
11131 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11132 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11133 VkPipelineObj pipe(m_device);
11134 pipe.AddShader(&vs);
11135 pipe.AddShader(&fs);
11136 pipe.AddColorAttachment();
11137 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11138
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011140
11141 BeginCommandBuffer();
11142 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011143 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11144 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11145 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011146 Draw(1, 0, 0, 0);
11147 EndCommandBuffer();
11148 // Submit cmd buffer then destroy sampler
11149 VkSubmitInfo submit_info = {};
11150 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11151 submit_info.commandBufferCount = 1;
11152 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11153 // Submit cmd buffer and then destroy sampler while in-flight
11154 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11155
11156 vkDestroySampler(m_device->device(), sampler, nullptr);
11157 m_errorMonitor->VerifyFound();
11158 vkQueueWaitIdle(m_device->m_queue);
11159 // Now we can actually destroy sampler
11160 vkDestroySampler(m_device->device(), sampler, nullptr);
11161 vkDestroyImageView(m_device->device(), view, NULL);
11162 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11163 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11164 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11165}
11166
Mark Mueller1cd9f412016-08-25 13:23:52 -060011167TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011168 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011169 "signaled but not waited on by the queue. Wait on a "
11170 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011171
11172 ASSERT_NO_FATAL_FAILURE(InitState());
11173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011175 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11176 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11177 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011178
11179 BeginCommandBuffer();
11180 EndCommandBuffer();
11181
11182 VkSemaphoreCreateInfo semaphore_create_info = {};
11183 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11184 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011185 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011186 VkSubmitInfo submit_info = {};
11187 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11188 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011189 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011190 submit_info.signalSemaphoreCount = 1;
11191 submit_info.pSignalSemaphores = &semaphore;
11192 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11193 m_errorMonitor->SetDesiredFailureMsg(0, "");
11194 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11195 BeginCommandBuffer();
11196 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011198 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11199 m_errorMonitor->VerifyFound();
11200
Mark Mueller1cd9f412016-08-25 13:23:52 -060011201 VkFenceCreateInfo fence_create_info = {};
11202 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11203 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011204 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011207 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11208 m_errorMonitor->VerifyFound();
11209
Mark Mueller4042b652016-09-05 22:52:21 -060011210 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011211 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011212 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11213}
11214
Tobin Ehlis4af23302016-07-19 10:50:30 -060011215TEST_F(VkLayerTest, FramebufferIncompatible) {
11216 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11217 "that does not match the framebuffer for the active "
11218 "renderpass.");
11219 ASSERT_NO_FATAL_FAILURE(InitState());
11220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11221
11222 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011223 VkAttachmentDescription attachment = {0,
11224 VK_FORMAT_B8G8R8A8_UNORM,
11225 VK_SAMPLE_COUNT_1_BIT,
11226 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11227 VK_ATTACHMENT_STORE_OP_STORE,
11228 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11229 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11230 VK_IMAGE_LAYOUT_UNDEFINED,
11231 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011232
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011233 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011235 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011237 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011238
11239 VkRenderPass rp;
11240 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11241 ASSERT_VK_SUCCESS(err);
11242
11243 // A compatible framebuffer.
11244 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011245 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 -060011246 ASSERT_TRUE(image.initialized());
11247
11248 VkImageViewCreateInfo ivci = {
11249 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11250 nullptr,
11251 0,
11252 image.handle(),
11253 VK_IMAGE_VIEW_TYPE_2D,
11254 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011255 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11256 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011257 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11258 };
11259 VkImageView view;
11260 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11261 ASSERT_VK_SUCCESS(err);
11262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011263 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011264 VkFramebuffer fb;
11265 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11266 ASSERT_VK_SUCCESS(err);
11267
11268 VkCommandBufferAllocateInfo cbai = {};
11269 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11270 cbai.commandPool = m_commandPool;
11271 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11272 cbai.commandBufferCount = 1;
11273
11274 VkCommandBuffer sec_cb;
11275 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11276 ASSERT_VK_SUCCESS(err);
11277 VkCommandBufferBeginInfo cbbi = {};
11278 VkCommandBufferInheritanceInfo cbii = {};
11279 cbii.renderPass = renderPass();
11280 cbii.framebuffer = fb;
11281 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11282 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011283 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 -060011284 cbbi.pInheritanceInfo = &cbii;
11285 vkBeginCommandBuffer(sec_cb, &cbbi);
11286 vkEndCommandBuffer(sec_cb);
11287
Chris Forbes3400bc52016-09-13 18:10:34 +120011288 VkCommandBufferBeginInfo cbbi2 = {
11289 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11290 0, nullptr
11291 };
11292 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11293 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011294
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011296 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011297 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11298 m_errorMonitor->VerifyFound();
11299 // Cleanup
11300 vkDestroyImageView(m_device->device(), view, NULL);
11301 vkDestroyRenderPass(m_device->device(), rp, NULL);
11302 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11303}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011304
11305TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11306 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11307 "invalid value. If logicOp is not available, attempt to "
11308 "use it and verify that we see the correct error.");
11309 ASSERT_NO_FATAL_FAILURE(InitState());
11310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11311
11312 auto features = m_device->phy().features();
11313 // Set the expected error depending on whether or not logicOp available
11314 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11316 "enabled, logicOpEnable must be "
11317 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011318 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011320 }
11321 // Create a pipeline using logicOp
11322 VkResult err;
11323
11324 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11325 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11326
11327 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011328 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011329 ASSERT_VK_SUCCESS(err);
11330
11331 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11332 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11333 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011334 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011335 vp_state_ci.pViewports = &vp;
11336 vp_state_ci.scissorCount = 1;
11337 VkRect2D scissors = {}; // Dummy scissors to point to
11338 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011339
11340 VkPipelineShaderStageCreateInfo shaderStages[2];
11341 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011343 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11344 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011345 shaderStages[0] = vs.GetStageCreateInfo();
11346 shaderStages[1] = fs.GetStageCreateInfo();
11347
11348 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11349 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11350
11351 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11352 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11353 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11354
11355 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11356 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011357 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011358
11359 VkPipelineColorBlendAttachmentState att = {};
11360 att.blendEnable = VK_FALSE;
11361 att.colorWriteMask = 0xf;
11362
11363 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11364 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11365 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11366 cb_ci.logicOpEnable = VK_TRUE;
11367 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11368 cb_ci.attachmentCount = 1;
11369 cb_ci.pAttachments = &att;
11370
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011371 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11372 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11373 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11374
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011375 VkGraphicsPipelineCreateInfo gp_ci = {};
11376 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11377 gp_ci.stageCount = 2;
11378 gp_ci.pStages = shaderStages;
11379 gp_ci.pVertexInputState = &vi_ci;
11380 gp_ci.pInputAssemblyState = &ia_ci;
11381 gp_ci.pViewportState = &vp_state_ci;
11382 gp_ci.pRasterizationState = &rs_ci;
11383 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011384 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011385 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11386 gp_ci.layout = pipeline_layout;
11387 gp_ci.renderPass = renderPass();
11388
11389 VkPipelineCacheCreateInfo pc_ci = {};
11390 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11391
11392 VkPipeline pipeline;
11393 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011394 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011395 ASSERT_VK_SUCCESS(err);
11396
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011397 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011398 m_errorMonitor->VerifyFound();
11399 if (VK_SUCCESS == err) {
11400 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11401 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011402 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11403 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11404}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011405#endif // DRAW_STATE_TESTS
11406
Tobin Ehlis0788f522015-05-26 16:11:58 -060011407#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011408#if GTEST_IS_THREADSAFE
11409struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011410 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011411 VkEvent event;
11412 bool bailout;
11413};
11414
Karl Schultz6addd812016-02-02 17:17:23 -070011415extern "C" void *AddToCommandBuffer(void *arg) {
11416 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011417
Mike Stroyana6d14942016-07-13 15:10:05 -060011418 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011419 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011420 if (data->bailout) {
11421 break;
11422 }
11423 }
11424 return NULL;
11425}
11426
Karl Schultz6addd812016-02-02 17:17:23 -070011427TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011428 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011431
Mike Stroyanaccf7692015-05-12 16:00:45 -060011432 ASSERT_NO_FATAL_FAILURE(InitState());
11433 ASSERT_NO_FATAL_FAILURE(InitViewport());
11434 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11435
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011436 // Calls AllocateCommandBuffers
11437 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011438
11439 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011440 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011441
11442 VkEventCreateInfo event_info;
11443 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011444 VkResult err;
11445
11446 memset(&event_info, 0, sizeof(event_info));
11447 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11448
Chia-I Wuf7458c52015-10-26 21:10:41 +080011449 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011450 ASSERT_VK_SUCCESS(err);
11451
Mike Stroyanaccf7692015-05-12 16:00:45 -060011452 err = vkResetEvent(device(), event);
11453 ASSERT_VK_SUCCESS(err);
11454
11455 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011456 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011457 data.event = event;
11458 data.bailout = false;
11459 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011460
11461 // First do some correct operations using multiple threads.
11462 // Add many entries to command buffer from another thread.
11463 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11464 // Make non-conflicting calls from this thread at the same time.
11465 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011466 uint32_t count;
11467 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011468 }
11469 test_platform_thread_join(thread, NULL);
11470
11471 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011472 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011473 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011474 // Add many entries to command buffer from this thread at the same time.
11475 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011476
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011477 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011478 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011479
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011480 m_errorMonitor->SetBailout(NULL);
11481
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011482 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011483
Chia-I Wuf7458c52015-10-26 21:10:41 +080011484 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011485}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011486#endif // GTEST_IS_THREADSAFE
11487#endif // THREADING_TESTS
11488
Chris Forbes9f7ff632015-05-25 11:13:08 +120011489#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011490TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011491 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11492 "with an impossible code size");
11493
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011495
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011496 ASSERT_NO_FATAL_FAILURE(InitState());
11497 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11498
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011499 VkShaderModule module;
11500 VkShaderModuleCreateInfo moduleCreateInfo;
11501 struct icd_spv_header spv;
11502
11503 spv.magic = ICD_SPV_MAGIC;
11504 spv.version = ICD_SPV_VERSION;
11505 spv.gen_magic = 0;
11506
11507 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11508 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011509 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011510 moduleCreateInfo.codeSize = 4;
11511 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011512 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011513
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011514 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011515}
11516
Karl Schultz6addd812016-02-02 17:17:23 -070011517TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011518 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11519 "with a bad magic number");
11520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011522
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011523 ASSERT_NO_FATAL_FAILURE(InitState());
11524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11525
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011526 VkShaderModule module;
11527 VkShaderModuleCreateInfo moduleCreateInfo;
11528 struct icd_spv_header spv;
11529
11530 spv.magic = ~ICD_SPV_MAGIC;
11531 spv.version = ICD_SPV_VERSION;
11532 spv.gen_magic = 0;
11533
11534 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11535 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011536 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011537 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11538 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011539 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011540
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011541 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011542}
11543
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011544#if 0
11545// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011546TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011548 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011549
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011550 ASSERT_NO_FATAL_FAILURE(InitState());
11551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11552
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011553 VkShaderModule module;
11554 VkShaderModuleCreateInfo moduleCreateInfo;
11555 struct icd_spv_header spv;
11556
11557 spv.magic = ICD_SPV_MAGIC;
11558 spv.version = ~ICD_SPV_VERSION;
11559 spv.gen_magic = 0;
11560
11561 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11562 moduleCreateInfo.pNext = NULL;
11563
Karl Schultz6addd812016-02-02 17:17:23 -070011564 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011565 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11566 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011567 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011568
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011569 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011570}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011571#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011572
Karl Schultz6addd812016-02-02 17:17:23 -070011573TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011574 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11575 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011577
Chris Forbes9f7ff632015-05-25 11:13:08 +120011578 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011579 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011581 char const *vsSource = "#version 450\n"
11582 "\n"
11583 "layout(location=0) out float x;\n"
11584 "out gl_PerVertex {\n"
11585 " vec4 gl_Position;\n"
11586 "};\n"
11587 "void main(){\n"
11588 " gl_Position = vec4(1);\n"
11589 " x = 0;\n"
11590 "}\n";
11591 char const *fsSource = "#version 450\n"
11592 "\n"
11593 "layout(location=0) out vec4 color;\n"
11594 "void main(){\n"
11595 " color = vec4(1);\n"
11596 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011597
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011598 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11599 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011600
11601 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011602 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011603 pipe.AddShader(&vs);
11604 pipe.AddShader(&fs);
11605
Chris Forbes9f7ff632015-05-25 11:13:08 +120011606 VkDescriptorSetObj descriptorSet(m_device);
11607 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011608 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011609
Tony Barbour5781e8f2015-08-04 16:23:11 -060011610 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011611
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011612 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011613}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011614
Mark Mueller098c9cb2016-09-08 09:01:57 -060011615TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11616 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11617
11618 ASSERT_NO_FATAL_FAILURE(InitState());
11619 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11620
11621 const char *bad_specialization_message =
11622 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11623
11624 char const *vsSource =
11625 "#version 450\n"
11626 "\n"
11627 "out gl_PerVertex {\n"
11628 " vec4 gl_Position;\n"
11629 "};\n"
11630 "void main(){\n"
11631 " gl_Position = vec4(1);\n"
11632 "}\n";
11633
11634 char const *fsSource =
11635 "#version 450\n"
11636 "\n"
11637 "layout (constant_id = 0) const float r = 0.0f;\n"
11638 "layout(location = 0) out vec4 uFragColor;\n"
11639 "void main(){\n"
11640 " uFragColor = vec4(r,1,0,1);\n"
11641 "}\n";
11642
11643 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11644 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11645
11646 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11647 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11648
11649 VkPipelineLayout pipeline_layout;
11650 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11651
11652 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11653 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11654 vp_state_create_info.viewportCount = 1;
11655 VkViewport viewport = {};
11656 vp_state_create_info.pViewports = &viewport;
11657 vp_state_create_info.scissorCount = 1;
11658 VkRect2D scissors = {};
11659 vp_state_create_info.pScissors = &scissors;
11660
11661 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11662
11663 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11664 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11665 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11666 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11667
11668 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11669 vs.GetStageCreateInfo(),
11670 fs.GetStageCreateInfo()
11671 };
11672
11673 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11674 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11675
11676 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11677 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11678 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11679
11680 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11681 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11682 rasterization_state_create_info.pNext = nullptr;
11683 rasterization_state_create_info.lineWidth = 1.0f;
11684 rasterization_state_create_info.rasterizerDiscardEnable = true;
11685
11686 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11687 color_blend_attachment_state.blendEnable = VK_FALSE;
11688 color_blend_attachment_state.colorWriteMask = 0xf;
11689
11690 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11691 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11692 color_blend_state_create_info.attachmentCount = 1;
11693 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11694
11695 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11696 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11697 graphicspipe_create_info.stageCount = 2;
11698 graphicspipe_create_info.pStages = shader_stage_create_info;
11699 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11700 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11701 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11702 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11703 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11704 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11705 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11706 graphicspipe_create_info.layout = pipeline_layout;
11707 graphicspipe_create_info.renderPass = renderPass();
11708
11709 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11710 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11711
11712 VkPipelineCache pipelineCache;
11713 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11714
11715 // This structure maps constant ids to data locations.
11716 const VkSpecializationMapEntry entry =
11717 // id, offset, size
11718 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11719
11720 uint32_t data = 1;
11721
11722 // Set up the info describing spec map and data
11723 const VkSpecializationInfo specialization_info = {
11724 1,
11725 &entry,
11726 1 * sizeof(float),
11727 &data,
11728 };
11729 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11730
11731 VkPipeline pipeline;
11732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11733 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11734 m_errorMonitor->VerifyFound();
11735
11736 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11737 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11738}
11739
11740TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11741 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11742
11743 ASSERT_NO_FATAL_FAILURE(InitState());
11744 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11745
11746 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11747
11748 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11749 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11750 descriptor_pool_type_count[0].descriptorCount = 1;
11751 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11752 descriptor_pool_type_count[1].descriptorCount = 1;
11753
11754 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11755 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11756 descriptor_pool_create_info.maxSets = 1;
11757 descriptor_pool_create_info.poolSizeCount = 2;
11758 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11759 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11760
11761 VkDescriptorPool descriptorset_pool;
11762 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11763
11764 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11765 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11766 descriptorset_layout_binding.descriptorCount = 1;
11767 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11768
11769 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11770 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11771 descriptorset_layout_create_info.bindingCount = 1;
11772 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11773
11774 VkDescriptorSetLayout descriptorset_layout;
11775 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11776
11777 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11778 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11779 descriptorset_allocate_info.descriptorSetCount = 1;
11780 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11781 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11782 VkDescriptorSet descriptorset;
11783 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11784
11785 // Challenge core_validation with a non uniform buffer type.
11786 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11787
Mark Mueller098c9cb2016-09-08 09:01:57 -060011788 char const *vsSource =
11789 "#version 450\n"
11790 "\n"
11791 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11792 " mat4 mvp;\n"
11793 "} ubuf;\n"
11794 "out gl_PerVertex {\n"
11795 " vec4 gl_Position;\n"
11796 "};\n"
11797 "void main(){\n"
11798 " gl_Position = ubuf.mvp * vec4(1);\n"
11799 "}\n";
11800
11801 char const *fsSource =
11802 "#version 450\n"
11803 "\n"
11804 "layout(location = 0) out vec4 uFragColor;\n"
11805 "void main(){\n"
11806 " uFragColor = vec4(0,1,0,1);\n"
11807 "}\n";
11808
11809 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11810 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11811
11812 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11813 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11814 pipeline_layout_create_info.setLayoutCount = 1;
11815 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11816
11817 VkPipelineLayout pipeline_layout;
11818 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11819
11820 VkPipelineObj pipe(m_device);
11821 pipe.AddColorAttachment();
11822 pipe.AddShader(&vs);
11823 pipe.AddShader(&fs);
11824
11825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11826 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11827 m_errorMonitor->VerifyFound();
11828
11829 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11830 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11831 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11832}
11833
11834TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11835 TEST_DESCRIPTION(
11836 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11837
11838 ASSERT_NO_FATAL_FAILURE(InitState());
11839 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11840
11841 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11842
11843 VkDescriptorPoolSize descriptor_pool_type_count = {};
11844 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11845 descriptor_pool_type_count.descriptorCount = 1;
11846
11847 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11848 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11849 descriptor_pool_create_info.maxSets = 1;
11850 descriptor_pool_create_info.poolSizeCount = 1;
11851 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11852 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11853
11854 VkDescriptorPool descriptorset_pool;
11855 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11856
11857 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11858 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11859 descriptorset_layout_binding.descriptorCount = 1;
11860 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11861 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11862
11863 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11864 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11865 descriptorset_layout_create_info.bindingCount = 1;
11866 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11867
11868 VkDescriptorSetLayout descriptorset_layout;
11869 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
11870 nullptr, &descriptorset_layout));
11871
11872 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11873 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11874 descriptorset_allocate_info.descriptorSetCount = 1;
11875 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11876 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11877 VkDescriptorSet descriptorset;
11878 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11879
11880 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11881
Mark Mueller098c9cb2016-09-08 09:01:57 -060011882 char const *vsSource =
11883 "#version 450\n"
11884 "\n"
11885 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11886 " mat4 mvp;\n"
11887 "} ubuf;\n"
11888 "out gl_PerVertex {\n"
11889 " vec4 gl_Position;\n"
11890 "};\n"
11891 "void main(){\n"
11892 " gl_Position = ubuf.mvp * vec4(1);\n"
11893 "}\n";
11894
11895 char const *fsSource =
11896 "#version 450\n"
11897 "\n"
11898 "layout(location = 0) out vec4 uFragColor;\n"
11899 "void main(){\n"
11900 " uFragColor = vec4(0,1,0,1);\n"
11901 "}\n";
11902
11903 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11904 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11905
11906 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11907 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11908 pipeline_layout_create_info.setLayoutCount = 1;
11909 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11910
11911 VkPipelineLayout pipeline_layout;
11912 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11913
11914 VkPipelineObj pipe(m_device);
11915 pipe.AddColorAttachment();
11916 pipe.AddShader(&vs);
11917 pipe.AddShader(&fs);
11918
11919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
11920 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11921 m_errorMonitor->VerifyFound();
11922
11923 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11924 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11925 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11926}
11927
11928TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
11929 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
11930 "accessible from the current shader stage.");
11931
11932 ASSERT_NO_FATAL_FAILURE(InitState());
11933 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11934
11935 const char *push_constant_not_accessible_message =
11936 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
11937
11938 char const *vsSource =
11939 "#version 450\n"
11940 "\n"
11941 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
11942 "out gl_PerVertex {\n"
11943 " vec4 gl_Position;\n"
11944 "};\n"
11945 "void main(){\n"
11946 " gl_Position = vec4(consts.x);\n"
11947 "}\n";
11948
11949 char const *fsSource =
11950 "#version 450\n"
11951 "\n"
11952 "layout(location = 0) out vec4 uFragColor;\n"
11953 "void main(){\n"
11954 " uFragColor = vec4(0,1,0,1);\n"
11955 "}\n";
11956
11957 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11958 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11959
11960 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11961 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11962
11963 // Set up a push constant range
11964 VkPushConstantRange push_constant_ranges = {};
11965 // Set to the wrong stage to challenge core_validation
11966 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11967 push_constant_ranges.size = 4;
11968
11969 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
11970 pipeline_layout_create_info.pushConstantRangeCount = 1;
11971
11972 VkPipelineLayout pipeline_layout;
11973 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11974
11975 VkPipelineObj pipe(m_device);
11976 pipe.AddColorAttachment();
11977 pipe.AddShader(&vs);
11978 pipe.AddShader(&fs);
11979
11980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
11981 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11982 m_errorMonitor->VerifyFound();
11983
11984 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11985}
11986
11987TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
11988 TEST_DESCRIPTION(
11989 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
11990
11991 ASSERT_NO_FATAL_FAILURE(InitState());
11992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11993
11994 const char *feature_not_enabled_message =
11995 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
11996
11997 // Some awkward steps are required to test with custom device features.
11998 std::vector<const char *> device_extension_names;
11999 auto features = m_device->phy().features();
12000 // Disable support for 64 bit floats
12001 features.shaderFloat64 = false;
12002 // The sacrificial device object
12003 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12004
12005 char const *vsSource = "#version 450\n"
12006 "\n"
12007 "out gl_PerVertex {\n"
12008 " vec4 gl_Position;\n"
12009 "};\n"
12010 "void main(){\n"
12011 " gl_Position = vec4(1);\n"
12012 "}\n";
12013 char const *fsSource = "#version 450\n"
12014 "\n"
12015 "layout(location=0) out vec4 color;\n"
12016 "void main(){\n"
12017 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12018 " color = vec4(green);\n"
12019 "}\n";
12020
12021 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12022 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12023
12024 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012025
12026 VkPipelineObj pipe(&test_device);
12027 pipe.AddColorAttachment();
12028 pipe.AddShader(&vs);
12029 pipe.AddShader(&fs);
12030
12031 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12032 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12033 VkPipelineLayout pipeline_layout;
12034 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12035
12036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12037 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12038 m_errorMonitor->VerifyFound();
12039
12040 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12041}
12042
12043TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12044 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12045
12046 ASSERT_NO_FATAL_FAILURE(InitState());
12047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12048
12049 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12050
12051 char const *vsSource = "#version 450\n"
12052 "\n"
12053 "out gl_PerVertex {\n"
12054 " vec4 gl_Position;\n"
12055 "};\n"
12056 "layout(xfb_buffer = 1) out;"
12057 "void main(){\n"
12058 " gl_Position = vec4(1);\n"
12059 "}\n";
12060 char const *fsSource = "#version 450\n"
12061 "\n"
12062 "layout(location=0) out vec4 color;\n"
12063 "void main(){\n"
12064 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12065 " color = vec4(green);\n"
12066 "}\n";
12067
12068 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12069 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12070
12071 VkPipelineObj pipe(m_device);
12072 pipe.AddColorAttachment();
12073 pipe.AddShader(&vs);
12074 pipe.AddShader(&fs);
12075
12076 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12077 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12078 VkPipelineLayout pipeline_layout;
12079 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12080
12081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12082 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12083 m_errorMonitor->VerifyFound();
12084
12085 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12086}
12087
Karl Schultz6addd812016-02-02 17:17:23 -070012088TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012089 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12090 "which is not present in the outputs of the previous stage");
12091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012093
Chris Forbes59cb88d2015-05-25 11:13:13 +120012094 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012097 char const *vsSource = "#version 450\n"
12098 "\n"
12099 "out gl_PerVertex {\n"
12100 " vec4 gl_Position;\n"
12101 "};\n"
12102 "void main(){\n"
12103 " gl_Position = vec4(1);\n"
12104 "}\n";
12105 char const *fsSource = "#version 450\n"
12106 "\n"
12107 "layout(location=0) in float x;\n"
12108 "layout(location=0) out vec4 color;\n"
12109 "void main(){\n"
12110 " color = vec4(x);\n"
12111 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012112
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012113 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12114 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012115
12116 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012117 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012118 pipe.AddShader(&vs);
12119 pipe.AddShader(&fs);
12120
Chris Forbes59cb88d2015-05-25 11:13:13 +120012121 VkDescriptorSetObj descriptorSet(m_device);
12122 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012123 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012124
Tony Barbour5781e8f2015-08-04 16:23:11 -060012125 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012126
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012127 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012128}
12129
Karl Schultz6addd812016-02-02 17:17:23 -070012130TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012131 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12132 "within an interace block, which is not present in the outputs "
12133 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012135
12136 ASSERT_NO_FATAL_FAILURE(InitState());
12137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12138
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012139 char const *vsSource = "#version 450\n"
12140 "\n"
12141 "out gl_PerVertex {\n"
12142 " vec4 gl_Position;\n"
12143 "};\n"
12144 "void main(){\n"
12145 " gl_Position = vec4(1);\n"
12146 "}\n";
12147 char const *fsSource = "#version 450\n"
12148 "\n"
12149 "in block { layout(location=0) float x; } ins;\n"
12150 "layout(location=0) out vec4 color;\n"
12151 "void main(){\n"
12152 " color = vec4(ins.x);\n"
12153 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012154
12155 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12156 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12157
12158 VkPipelineObj pipe(m_device);
12159 pipe.AddColorAttachment();
12160 pipe.AddShader(&vs);
12161 pipe.AddShader(&fs);
12162
12163 VkDescriptorSetObj descriptorSet(m_device);
12164 descriptorSet.AppendDummy();
12165 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12166
12167 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12168
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012169 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012170}
12171
Karl Schultz6addd812016-02-02 17:17:23 -070012172TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012173 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012174 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12176 "output arr[2] of float32' vs 'ptr to "
12177 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012178
12179 ASSERT_NO_FATAL_FAILURE(InitState());
12180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012182 char const *vsSource = "#version 450\n"
12183 "\n"
12184 "layout(location=0) out float x[2];\n"
12185 "out gl_PerVertex {\n"
12186 " vec4 gl_Position;\n"
12187 "};\n"
12188 "void main(){\n"
12189 " x[0] = 0; x[1] = 0;\n"
12190 " gl_Position = vec4(1);\n"
12191 "}\n";
12192 char const *fsSource = "#version 450\n"
12193 "\n"
12194 "layout(location=0) in float x[3];\n"
12195 "layout(location=0) out vec4 color;\n"
12196 "void main(){\n"
12197 " color = vec4(x[0] + x[1] + x[2]);\n"
12198 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012199
12200 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12201 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12202
12203 VkPipelineObj pipe(m_device);
12204 pipe.AddColorAttachment();
12205 pipe.AddShader(&vs);
12206 pipe.AddShader(&fs);
12207
12208 VkDescriptorSetObj descriptorSet(m_device);
12209 descriptorSet.AppendDummy();
12210 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12211
12212 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12213
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012214 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012215}
12216
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012217
Karl Schultz6addd812016-02-02 17:17:23 -070012218TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012219 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012220 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012222
Chris Forbesb56af562015-05-25 11:13:17 +120012223 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012224 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012225
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012226 char const *vsSource = "#version 450\n"
12227 "\n"
12228 "layout(location=0) out int x;\n"
12229 "out gl_PerVertex {\n"
12230 " vec4 gl_Position;\n"
12231 "};\n"
12232 "void main(){\n"
12233 " x = 0;\n"
12234 " gl_Position = vec4(1);\n"
12235 "}\n";
12236 char const *fsSource = "#version 450\n"
12237 "\n"
12238 "layout(location=0) in float x;\n" /* VS writes int */
12239 "layout(location=0) out vec4 color;\n"
12240 "void main(){\n"
12241 " color = vec4(x);\n"
12242 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012243
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012244 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12245 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012246
12247 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012248 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012249 pipe.AddShader(&vs);
12250 pipe.AddShader(&fs);
12251
Chris Forbesb56af562015-05-25 11:13:17 +120012252 VkDescriptorSetObj descriptorSet(m_device);
12253 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012254 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012255
Tony Barbour5781e8f2015-08-04 16:23:11 -060012256 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012257
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012258 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012259}
12260
Karl Schultz6addd812016-02-02 17:17:23 -070012261TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012262 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012263 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012264 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012266
12267 ASSERT_NO_FATAL_FAILURE(InitState());
12268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012270 char const *vsSource = "#version 450\n"
12271 "\n"
12272 "out block { layout(location=0) int x; } outs;\n"
12273 "out gl_PerVertex {\n"
12274 " vec4 gl_Position;\n"
12275 "};\n"
12276 "void main(){\n"
12277 " outs.x = 0;\n"
12278 " gl_Position = vec4(1);\n"
12279 "}\n";
12280 char const *fsSource = "#version 450\n"
12281 "\n"
12282 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12283 "layout(location=0) out vec4 color;\n"
12284 "void main(){\n"
12285 " color = vec4(ins.x);\n"
12286 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012287
12288 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12289 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12290
12291 VkPipelineObj pipe(m_device);
12292 pipe.AddColorAttachment();
12293 pipe.AddShader(&vs);
12294 pipe.AddShader(&fs);
12295
12296 VkDescriptorSetObj descriptorSet(m_device);
12297 descriptorSet.AppendDummy();
12298 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12299
12300 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12301
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012302 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012303}
12304
12305TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012306 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012307 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012308 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012309 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 +130012310
12311 ASSERT_NO_FATAL_FAILURE(InitState());
12312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12313
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012314 char const *vsSource = "#version 450\n"
12315 "\n"
12316 "out block { layout(location=1) float x; } outs;\n"
12317 "out gl_PerVertex {\n"
12318 " vec4 gl_Position;\n"
12319 "};\n"
12320 "void main(){\n"
12321 " outs.x = 0;\n"
12322 " gl_Position = vec4(1);\n"
12323 "}\n";
12324 char const *fsSource = "#version 450\n"
12325 "\n"
12326 "in block { layout(location=0) float x; } ins;\n"
12327 "layout(location=0) out vec4 color;\n"
12328 "void main(){\n"
12329 " color = vec4(ins.x);\n"
12330 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012331
12332 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12333 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12334
12335 VkPipelineObj pipe(m_device);
12336 pipe.AddColorAttachment();
12337 pipe.AddShader(&vs);
12338 pipe.AddShader(&fs);
12339
12340 VkDescriptorSetObj descriptorSet(m_device);
12341 descriptorSet.AppendDummy();
12342 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12343
12344 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12345
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012346 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012347}
12348
12349TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012350 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012351 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012352 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012353 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 +130012354
12355 ASSERT_NO_FATAL_FAILURE(InitState());
12356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012358 char const *vsSource = "#version 450\n"
12359 "\n"
12360 "out block { layout(location=0, component=0) float x; } outs;\n"
12361 "out gl_PerVertex {\n"
12362 " vec4 gl_Position;\n"
12363 "};\n"
12364 "void main(){\n"
12365 " outs.x = 0;\n"
12366 " gl_Position = vec4(1);\n"
12367 "}\n";
12368 char const *fsSource = "#version 450\n"
12369 "\n"
12370 "in block { layout(location=0, component=1) float x; } ins;\n"
12371 "layout(location=0) out vec4 color;\n"
12372 "void main(){\n"
12373 " color = vec4(ins.x);\n"
12374 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012375
12376 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12377 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12378
12379 VkPipelineObj pipe(m_device);
12380 pipe.AddColorAttachment();
12381 pipe.AddShader(&vs);
12382 pipe.AddShader(&fs);
12383
12384 VkDescriptorSetObj descriptorSet(m_device);
12385 descriptorSet.AppendDummy();
12386 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12387
12388 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12389
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012390 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012391}
12392
Karl Schultz6addd812016-02-02 17:17:23 -070012393TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012394 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12395 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012397
Chris Forbesde136e02015-05-25 11:13:28 +120012398 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012400
12401 VkVertexInputBindingDescription input_binding;
12402 memset(&input_binding, 0, sizeof(input_binding));
12403
12404 VkVertexInputAttributeDescription input_attrib;
12405 memset(&input_attrib, 0, sizeof(input_attrib));
12406 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012408 char const *vsSource = "#version 450\n"
12409 "\n"
12410 "out gl_PerVertex {\n"
12411 " vec4 gl_Position;\n"
12412 "};\n"
12413 "void main(){\n"
12414 " gl_Position = vec4(1);\n"
12415 "}\n";
12416 char const *fsSource = "#version 450\n"
12417 "\n"
12418 "layout(location=0) out vec4 color;\n"
12419 "void main(){\n"
12420 " color = vec4(1);\n"
12421 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012422
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012423 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12424 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012425
12426 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012427 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012428 pipe.AddShader(&vs);
12429 pipe.AddShader(&fs);
12430
12431 pipe.AddVertexInputBindings(&input_binding, 1);
12432 pipe.AddVertexInputAttribs(&input_attrib, 1);
12433
Chris Forbesde136e02015-05-25 11:13:28 +120012434 VkDescriptorSetObj descriptorSet(m_device);
12435 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012436 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012437
Tony Barbour5781e8f2015-08-04 16:23:11 -060012438 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012439
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012440 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012441}
12442
Karl Schultz6addd812016-02-02 17:17:23 -070012443TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012444 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12445 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012447
12448 ASSERT_NO_FATAL_FAILURE(InitState());
12449 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12450
12451 VkVertexInputBindingDescription input_binding;
12452 memset(&input_binding, 0, sizeof(input_binding));
12453
12454 VkVertexInputAttributeDescription input_attrib;
12455 memset(&input_attrib, 0, sizeof(input_attrib));
12456 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12457
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012458 char const *vsSource = "#version 450\n"
12459 "\n"
12460 "layout(location=1) in float x;\n"
12461 "out gl_PerVertex {\n"
12462 " vec4 gl_Position;\n"
12463 "};\n"
12464 "void main(){\n"
12465 " gl_Position = vec4(x);\n"
12466 "}\n";
12467 char const *fsSource = "#version 450\n"
12468 "\n"
12469 "layout(location=0) out vec4 color;\n"
12470 "void main(){\n"
12471 " color = vec4(1);\n"
12472 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012473
12474 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12475 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12476
12477 VkPipelineObj pipe(m_device);
12478 pipe.AddColorAttachment();
12479 pipe.AddShader(&vs);
12480 pipe.AddShader(&fs);
12481
12482 pipe.AddVertexInputBindings(&input_binding, 1);
12483 pipe.AddVertexInputAttribs(&input_attrib, 1);
12484
12485 VkDescriptorSetObj descriptorSet(m_device);
12486 descriptorSet.AppendDummy();
12487 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12488
12489 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12490
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012491 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012492}
12493
Karl Schultz6addd812016-02-02 17:17:23 -070012494TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012495 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012496 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012497 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 -060012498
Chris Forbes62e8e502015-05-25 11:13:29 +120012499 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012502 char const *vsSource = "#version 450\n"
12503 "\n"
12504 "layout(location=0) in vec4 x;\n" /* not provided */
12505 "out gl_PerVertex {\n"
12506 " vec4 gl_Position;\n"
12507 "};\n"
12508 "void main(){\n"
12509 " gl_Position = x;\n"
12510 "}\n";
12511 char const *fsSource = "#version 450\n"
12512 "\n"
12513 "layout(location=0) out vec4 color;\n"
12514 "void main(){\n"
12515 " color = vec4(1);\n"
12516 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012517
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012518 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12519 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012520
12521 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012522 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012523 pipe.AddShader(&vs);
12524 pipe.AddShader(&fs);
12525
Chris Forbes62e8e502015-05-25 11:13:29 +120012526 VkDescriptorSetObj descriptorSet(m_device);
12527 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012528 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012529
Tony Barbour5781e8f2015-08-04 16:23:11 -060012530 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012531
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012532 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012533}
12534
Karl Schultz6addd812016-02-02 17:17:23 -070012535TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012536 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12537 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012538 "vertex shader input that consumes it");
12539 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 -060012540
Chris Forbesc97d98e2015-05-25 11:13:31 +120012541 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012543
12544 VkVertexInputBindingDescription input_binding;
12545 memset(&input_binding, 0, sizeof(input_binding));
12546
12547 VkVertexInputAttributeDescription input_attrib;
12548 memset(&input_attrib, 0, sizeof(input_attrib));
12549 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12550
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012551 char const *vsSource = "#version 450\n"
12552 "\n"
12553 "layout(location=0) in int x;\n" /* attrib provided float */
12554 "out gl_PerVertex {\n"
12555 " vec4 gl_Position;\n"
12556 "};\n"
12557 "void main(){\n"
12558 " gl_Position = vec4(x);\n"
12559 "}\n";
12560 char const *fsSource = "#version 450\n"
12561 "\n"
12562 "layout(location=0) out vec4 color;\n"
12563 "void main(){\n"
12564 " color = vec4(1);\n"
12565 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012566
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012567 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12568 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012569
12570 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012571 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012572 pipe.AddShader(&vs);
12573 pipe.AddShader(&fs);
12574
12575 pipe.AddVertexInputBindings(&input_binding, 1);
12576 pipe.AddVertexInputAttribs(&input_attrib, 1);
12577
Chris Forbesc97d98e2015-05-25 11:13:31 +120012578 VkDescriptorSetObj descriptorSet(m_device);
12579 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012580 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012581
Tony Barbour5781e8f2015-08-04 16:23:11 -060012582 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012583
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012584 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012585}
12586
Chris Forbesc68b43c2016-04-06 11:18:47 +120012587TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012588 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12589 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12591 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012592
12593 ASSERT_NO_FATAL_FAILURE(InitState());
12594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012596 char const *vsSource = "#version 450\n"
12597 "\n"
12598 "out gl_PerVertex {\n"
12599 " vec4 gl_Position;\n"
12600 "};\n"
12601 "void main(){\n"
12602 " gl_Position = vec4(1);\n"
12603 "}\n";
12604 char const *fsSource = "#version 450\n"
12605 "\n"
12606 "layout(location=0) out vec4 color;\n"
12607 "void main(){\n"
12608 " color = vec4(1);\n"
12609 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012610
12611 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12612 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12613
12614 VkPipelineObj pipe(m_device);
12615 pipe.AddColorAttachment();
12616 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012617 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012618 pipe.AddShader(&fs);
12619
12620 VkDescriptorSetObj descriptorSet(m_device);
12621 descriptorSet.AppendDummy();
12622 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12623
12624 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12625
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012626 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012627}
12628
Chris Forbes82ff92a2016-09-09 10:50:24 +120012629TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12631 "No entrypoint found named `foo`");
12632
12633 ASSERT_NO_FATAL_FAILURE(InitState());
12634 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12635
12636 char const *vsSource = "#version 450\n"
12637 "out gl_PerVertex {\n"
12638 " vec4 gl_Position;\n"
12639 "};\n"
12640 "void main(){\n"
12641 " gl_Position = vec4(0);\n"
12642 "}\n";
12643 char const *fsSource = "#version 450\n"
12644 "\n"
12645 "layout(location=0) out vec4 color;\n"
12646 "void main(){\n"
12647 " color = vec4(1);\n"
12648 "}\n";
12649
12650 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12651 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12652
12653 VkPipelineObj pipe(m_device);
12654 pipe.AddColorAttachment();
12655 pipe.AddShader(&vs);
12656 pipe.AddShader(&fs);
12657
12658 VkDescriptorSetObj descriptorSet(m_device);
12659 descriptorSet.AppendDummy();
12660 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12661
12662 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12663
12664 m_errorMonitor->VerifyFound();
12665}
12666
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012667TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12668 m_errorMonitor->SetDesiredFailureMsg(
12669 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12670 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12671 "uses a depth/stencil attachment");
12672
12673 ASSERT_NO_FATAL_FAILURE(InitState());
12674 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12675
12676 char const *vsSource = "#version 450\n"
12677 "void main(){ gl_Position = vec4(0); }\n";
12678 char const *fsSource = "#version 450\n"
12679 "\n"
12680 "layout(location=0) out vec4 color;\n"
12681 "void main(){\n"
12682 " color = vec4(1);\n"
12683 "}\n";
12684
12685 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12686 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12687
12688 VkPipelineObj pipe(m_device);
12689 pipe.AddColorAttachment();
12690 pipe.AddShader(&vs);
12691 pipe.AddShader(&fs);
12692
12693 VkDescriptorSetObj descriptorSet(m_device);
12694 descriptorSet.AppendDummy();
12695 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12696
12697 VkAttachmentDescription attachments[] = {
12698 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12699 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12700 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12701 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12702 },
12703 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12704 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12705 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12706 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12707 },
12708 };
12709 VkAttachmentReference refs[] = {
12710 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12711 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12712 };
12713 VkSubpassDescription subpass = {
12714 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12715 1, &refs[0], nullptr, &refs[1],
12716 0, nullptr
12717 };
12718 VkRenderPassCreateInfo rpci = {
12719 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12720 0, 2, attachments, 1, &subpass, 0, nullptr
12721 };
12722 VkRenderPass rp;
12723 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12724 ASSERT_VK_SUCCESS(err);
12725
12726 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12727
12728 m_errorMonitor->VerifyFound();
12729
12730 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12731}
12732
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012733TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012734 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12735 "the TCS without the patch decoration, but consumed in the TES "
12736 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12738 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012739
12740 ASSERT_NO_FATAL_FAILURE(InitState());
12741 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12742
Chris Forbesc1e852d2016-04-04 19:26:42 +120012743 if (!m_device->phy().features().tessellationShader) {
12744 printf("Device does not support tessellation shaders; skipped.\n");
12745 return;
12746 }
12747
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012748 char const *vsSource = "#version 450\n"
12749 "void main(){}\n";
12750 char const *tcsSource = "#version 450\n"
12751 "layout(location=0) out int x[];\n"
12752 "layout(vertices=3) out;\n"
12753 "void main(){\n"
12754 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12755 " gl_TessLevelInner[0] = 1;\n"
12756 " x[gl_InvocationID] = gl_InvocationID;\n"
12757 "}\n";
12758 char const *tesSource = "#version 450\n"
12759 "layout(triangles, equal_spacing, cw) in;\n"
12760 "layout(location=0) patch in int x;\n"
12761 "out gl_PerVertex { vec4 gl_Position; };\n"
12762 "void main(){\n"
12763 " gl_Position.xyz = gl_TessCoord;\n"
12764 " gl_Position.w = x;\n"
12765 "}\n";
12766 char const *fsSource = "#version 450\n"
12767 "layout(location=0) out vec4 color;\n"
12768 "void main(){\n"
12769 " color = vec4(1);\n"
12770 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012771
12772 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12773 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12774 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12775 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12776
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012777 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12778 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012779
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012780 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012781
12782 VkPipelineObj pipe(m_device);
12783 pipe.SetInputAssembly(&iasci);
12784 pipe.SetTessellation(&tsci);
12785 pipe.AddColorAttachment();
12786 pipe.AddShader(&vs);
12787 pipe.AddShader(&tcs);
12788 pipe.AddShader(&tes);
12789 pipe.AddShader(&fs);
12790
12791 VkDescriptorSetObj descriptorSet(m_device);
12792 descriptorSet.AppendDummy();
12793 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12794
12795 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12796
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012797 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012798}
12799
Karl Schultz6addd812016-02-02 17:17:23 -070012800TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012801 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12802 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12804 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012805
Chris Forbes280ba2c2015-06-12 11:16:41 +120012806 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012808
12809 /* Two binding descriptions for binding 0 */
12810 VkVertexInputBindingDescription input_bindings[2];
12811 memset(input_bindings, 0, sizeof(input_bindings));
12812
12813 VkVertexInputAttributeDescription input_attrib;
12814 memset(&input_attrib, 0, sizeof(input_attrib));
12815 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12816
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012817 char const *vsSource = "#version 450\n"
12818 "\n"
12819 "layout(location=0) in float x;\n" /* attrib provided float */
12820 "out gl_PerVertex {\n"
12821 " vec4 gl_Position;\n"
12822 "};\n"
12823 "void main(){\n"
12824 " gl_Position = vec4(x);\n"
12825 "}\n";
12826 char const *fsSource = "#version 450\n"
12827 "\n"
12828 "layout(location=0) out vec4 color;\n"
12829 "void main(){\n"
12830 " color = vec4(1);\n"
12831 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012832
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012833 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12834 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012835
12836 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012837 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012838 pipe.AddShader(&vs);
12839 pipe.AddShader(&fs);
12840
12841 pipe.AddVertexInputBindings(input_bindings, 2);
12842 pipe.AddVertexInputAttribs(&input_attrib, 1);
12843
Chris Forbes280ba2c2015-06-12 11:16:41 +120012844 VkDescriptorSetObj descriptorSet(m_device);
12845 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012846 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012847
Tony Barbour5781e8f2015-08-04 16:23:11 -060012848 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012849
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012850 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012851}
Chris Forbes8f68b562015-05-25 11:13:32 +120012852
Karl Schultz6addd812016-02-02 17:17:23 -070012853TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012854 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012855 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012857
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012858 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012859
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012860 char const *vsSource = "#version 450\n"
12861 "\n"
12862 "out gl_PerVertex {\n"
12863 " vec4 gl_Position;\n"
12864 "};\n"
12865 "void main(){\n"
12866 " gl_Position = vec4(1);\n"
12867 "}\n";
12868 char const *fsSource = "#version 450\n"
12869 "\n"
12870 "void main(){\n"
12871 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012872
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012873 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12874 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012875
12876 VkPipelineObj pipe(m_device);
12877 pipe.AddShader(&vs);
12878 pipe.AddShader(&fs);
12879
Chia-I Wu08accc62015-07-07 11:50:03 +080012880 /* set up CB 0, not written */
12881 pipe.AddColorAttachment();
12882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012883
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012884 VkDescriptorSetObj descriptorSet(m_device);
12885 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012886 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012887
Tony Barbour5781e8f2015-08-04 16:23:11 -060012888 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012889
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012890 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012891}
12892
Karl Schultz6addd812016-02-02 17:17:23 -070012893TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012894 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120012895 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012897 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012898
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012899 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012900
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012901 char const *vsSource = "#version 450\n"
12902 "\n"
12903 "out gl_PerVertex {\n"
12904 " vec4 gl_Position;\n"
12905 "};\n"
12906 "void main(){\n"
12907 " gl_Position = vec4(1);\n"
12908 "}\n";
12909 char const *fsSource = "#version 450\n"
12910 "\n"
12911 "layout(location=0) out vec4 x;\n"
12912 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
12913 "void main(){\n"
12914 " x = vec4(1);\n"
12915 " y = vec4(1);\n"
12916 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012917
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012918 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12919 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012920
12921 VkPipelineObj pipe(m_device);
12922 pipe.AddShader(&vs);
12923 pipe.AddShader(&fs);
12924
Chia-I Wu08accc62015-07-07 11:50:03 +080012925 /* set up CB 0, not written */
12926 pipe.AddColorAttachment();
12927 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012928 /* FS writes CB 1, but we don't configure it */
12929
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012930 VkDescriptorSetObj descriptorSet(m_device);
12931 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012932 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012933
Tony Barbour5781e8f2015-08-04 16:23:11 -060012934 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012935
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012936 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012937}
12938
Karl Schultz6addd812016-02-02 17:17:23 -070012939TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012940 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012941 "type of an fragment shader output variable, and the format of the corresponding attachment");
12942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012943
Chris Forbesa36d69e2015-05-25 11:13:44 +120012944 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012945
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012946 char const *vsSource = "#version 450\n"
12947 "\n"
12948 "out gl_PerVertex {\n"
12949 " vec4 gl_Position;\n"
12950 "};\n"
12951 "void main(){\n"
12952 " gl_Position = vec4(1);\n"
12953 "}\n";
12954 char const *fsSource = "#version 450\n"
12955 "\n"
12956 "layout(location=0) out ivec4 x;\n" /* not UNORM */
12957 "void main(){\n"
12958 " x = ivec4(1);\n"
12959 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120012960
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012961 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12962 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012963
12964 VkPipelineObj pipe(m_device);
12965 pipe.AddShader(&vs);
12966 pipe.AddShader(&fs);
12967
Chia-I Wu08accc62015-07-07 11:50:03 +080012968 /* set up CB 0; type is UNORM by default */
12969 pipe.AddColorAttachment();
12970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012971
Chris Forbesa36d69e2015-05-25 11:13:44 +120012972 VkDescriptorSetObj descriptorSet(m_device);
12973 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012974 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012975
Tony Barbour5781e8f2015-08-04 16:23:11 -060012976 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012977
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012978 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120012979}
Chris Forbes7b1b8932015-06-05 14:43:36 +120012980
Karl Schultz6addd812016-02-02 17:17:23 -070012981TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012982 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
12983 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012985
Chris Forbes556c76c2015-08-14 12:04:59 +120012986 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120012987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012988 char const *vsSource = "#version 450\n"
12989 "\n"
12990 "out gl_PerVertex {\n"
12991 " vec4 gl_Position;\n"
12992 "};\n"
12993 "void main(){\n"
12994 " gl_Position = vec4(1);\n"
12995 "}\n";
12996 char const *fsSource = "#version 450\n"
12997 "\n"
12998 "layout(location=0) out vec4 x;\n"
12999 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13000 "void main(){\n"
13001 " x = vec4(bar.y);\n"
13002 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013003
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013004 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13005 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013006
Chris Forbes556c76c2015-08-14 12:04:59 +120013007 VkPipelineObj pipe(m_device);
13008 pipe.AddShader(&vs);
13009 pipe.AddShader(&fs);
13010
13011 /* set up CB 0; type is UNORM by default */
13012 pipe.AddColorAttachment();
13013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13014
13015 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013016 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013017
13018 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13019
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013020 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013021}
13022
Chris Forbes5c59e902016-02-26 16:56:09 +130013023TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013024 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13025 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013027
13028 ASSERT_NO_FATAL_FAILURE(InitState());
13029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013030 char const *vsSource = "#version 450\n"
13031 "\n"
13032 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13033 "out gl_PerVertex {\n"
13034 " vec4 gl_Position;\n"
13035 "};\n"
13036 "void main(){\n"
13037 " gl_Position = vec4(consts.x);\n"
13038 "}\n";
13039 char const *fsSource = "#version 450\n"
13040 "\n"
13041 "layout(location=0) out vec4 x;\n"
13042 "void main(){\n"
13043 " x = vec4(1);\n"
13044 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013045
13046 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13047 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13048
13049 VkPipelineObj pipe(m_device);
13050 pipe.AddShader(&vs);
13051 pipe.AddShader(&fs);
13052
13053 /* set up CB 0; type is UNORM by default */
13054 pipe.AddColorAttachment();
13055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13056
13057 VkDescriptorSetObj descriptorSet(m_device);
13058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13059
13060 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13061
13062 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013063 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013064}
13065
Chris Forbes3fb17902016-08-22 14:57:55 +120013066TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13067 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13068 "which is not included in the subpass description");
13069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13070 "consumes input attachment index 0 but not provided in subpass");
13071
13072 ASSERT_NO_FATAL_FAILURE(InitState());
13073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013074 char const *vsSource = "#version 450\n"
13075 "\n"
13076 "out gl_PerVertex {\n"
13077 " vec4 gl_Position;\n"
13078 "};\n"
13079 "void main(){\n"
13080 " gl_Position = vec4(1);\n"
13081 "}\n";
13082 char const *fsSource = "#version 450\n"
13083 "\n"
13084 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13085 "layout(location=0) out vec4 color;\n"
13086 "void main() {\n"
13087 " color = subpassLoad(x);\n"
13088 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013089
13090 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13091 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13092
13093 VkPipelineObj pipe(m_device);
13094 pipe.AddShader(&vs);
13095 pipe.AddShader(&fs);
13096 pipe.AddColorAttachment();
13097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013099 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13100 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013101 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013102 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013103 ASSERT_VK_SUCCESS(err);
13104
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013105 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013106 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013107 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013108 ASSERT_VK_SUCCESS(err);
13109
13110 // error here.
13111 pipe.CreateVKPipeline(pl, renderPass());
13112
13113 m_errorMonitor->VerifyFound();
13114
13115 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13116 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13117}
13118
Chris Forbes5a9a0472016-08-22 16:02:09 +120013119TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13120 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13121 "with a format having a different fundamental type");
13122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13123 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13124
13125 ASSERT_NO_FATAL_FAILURE(InitState());
13126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013127 char const *vsSource = "#version 450\n"
13128 "\n"
13129 "out gl_PerVertex {\n"
13130 " vec4 gl_Position;\n"
13131 "};\n"
13132 "void main(){\n"
13133 " gl_Position = vec4(1);\n"
13134 "}\n";
13135 char const *fsSource = "#version 450\n"
13136 "\n"
13137 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13138 "layout(location=0) out vec4 color;\n"
13139 "void main() {\n"
13140 " color = subpassLoad(x);\n"
13141 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013142
13143 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13144 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13145
13146 VkPipelineObj pipe(m_device);
13147 pipe.AddShader(&vs);
13148 pipe.AddShader(&fs);
13149 pipe.AddColorAttachment();
13150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013152 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13153 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013154 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013155 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013156 ASSERT_VK_SUCCESS(err);
13157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013158 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013159 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013160 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013161 ASSERT_VK_SUCCESS(err);
13162
13163 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013164 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13165 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13166 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13167 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13168 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 +120013169 };
13170 VkAttachmentReference color = {
13171 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13172 };
13173 VkAttachmentReference input = {
13174 1, VK_IMAGE_LAYOUT_GENERAL,
13175 };
13176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013177 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013179 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013180 VkRenderPass rp;
13181 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13182 ASSERT_VK_SUCCESS(err);
13183
13184 // error here.
13185 pipe.CreateVKPipeline(pl, rp);
13186
13187 m_errorMonitor->VerifyFound();
13188
13189 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13190 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13191 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13192}
13193
Chris Forbes541f7b02016-08-22 15:30:27 +120013194TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13195 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13196 "which is not included in the subpass description -- array case");
13197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13198 "consumes input attachment index 1 but not provided in subpass");
13199
13200 ASSERT_NO_FATAL_FAILURE(InitState());
13201
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013202 char const *vsSource = "#version 450\n"
13203 "\n"
13204 "out gl_PerVertex {\n"
13205 " vec4 gl_Position;\n"
13206 "};\n"
13207 "void main(){\n"
13208 " gl_Position = vec4(1);\n"
13209 "}\n";
13210 char const *fsSource = "#version 450\n"
13211 "\n"
13212 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13213 "layout(location=0) out vec4 color;\n"
13214 "void main() {\n"
13215 " color = subpassLoad(xs[1]);\n"
13216 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013217
13218 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13219 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13220
13221 VkPipelineObj pipe(m_device);
13222 pipe.AddShader(&vs);
13223 pipe.AddShader(&fs);
13224 pipe.AddColorAttachment();
13225 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13226
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013227 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13228 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013229 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013230 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013231 ASSERT_VK_SUCCESS(err);
13232
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013233 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013234 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013235 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013236 ASSERT_VK_SUCCESS(err);
13237
13238 // error here.
13239 pipe.CreateVKPipeline(pl, renderPass());
13240
13241 m_errorMonitor->VerifyFound();
13242
13243 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13244 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13245}
13246
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013247TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013248 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13249 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013251
13252 ASSERT_NO_FATAL_FAILURE(InitState());
13253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013254 char const *csSource = "#version 450\n"
13255 "\n"
13256 "layout(local_size_x=1) in;\n"
13257 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13258 "void main(){\n"
13259 " x = vec4(1);\n"
13260 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013261
13262 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13263
13264 VkDescriptorSetObj descriptorSet(m_device);
13265 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013267 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13268 nullptr,
13269 0,
13270 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13271 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13272 descriptorSet.GetPipelineLayout(),
13273 VK_NULL_HANDLE,
13274 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013275
13276 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013277 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013278
13279 m_errorMonitor->VerifyFound();
13280
13281 if (err == VK_SUCCESS) {
13282 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13283 }
13284}
13285
Chris Forbes22a9b092016-07-19 14:34:05 +120013286TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013287 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13288 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13290 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013291
13292 ASSERT_NO_FATAL_FAILURE(InitState());
13293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013294 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13295 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013296 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013297 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013298 ASSERT_VK_SUCCESS(err);
13299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013300 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013301 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013302 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013303 ASSERT_VK_SUCCESS(err);
13304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013305 char const *csSource = "#version 450\n"
13306 "\n"
13307 "layout(local_size_x=1) in;\n"
13308 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13309 "void main() {\n"
13310 " x.x = 1.0f;\n"
13311 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013312 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13313
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013314 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13315 nullptr,
13316 0,
13317 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13318 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13319 pl,
13320 VK_NULL_HANDLE,
13321 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013322
13323 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013324 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013325
13326 m_errorMonitor->VerifyFound();
13327
13328 if (err == VK_SUCCESS) {
13329 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13330 }
13331
13332 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13333 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13334}
13335
Chris Forbes50020592016-07-27 13:52:41 +120013336TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13337 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13338 "does not match the dimensionality declared in the shader");
13339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013340 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 +120013341
13342 ASSERT_NO_FATAL_FAILURE(InitState());
13343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13344
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013345 char const *vsSource = "#version 450\n"
13346 "\n"
13347 "out gl_PerVertex { vec4 gl_Position; };\n"
13348 "void main() { gl_Position = vec4(0); }\n";
13349 char const *fsSource = "#version 450\n"
13350 "\n"
13351 "layout(set=0, binding=0) uniform sampler3D s;\n"
13352 "layout(location=0) out vec4 color;\n"
13353 "void main() {\n"
13354 " color = texture(s, vec3(0));\n"
13355 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013356 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13357 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13358
13359 VkPipelineObj pipe(m_device);
13360 pipe.AddShader(&vs);
13361 pipe.AddShader(&fs);
13362 pipe.AddColorAttachment();
13363
13364 VkTextureObj texture(m_device, nullptr);
13365 VkSamplerObj sampler(m_device);
13366
13367 VkDescriptorSetObj descriptorSet(m_device);
13368 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13369 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13370
13371 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13372 ASSERT_VK_SUCCESS(err);
13373
13374 BeginCommandBuffer();
13375
13376 m_commandBuffer->BindPipeline(pipe);
13377 m_commandBuffer->BindDescriptorSet(descriptorSet);
13378
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013379 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013380 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013381 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013382 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13383
13384 // error produced here.
13385 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13386
13387 m_errorMonitor->VerifyFound();
13388
13389 EndCommandBuffer();
13390}
13391
Chris Forbes5533bfc2016-07-27 14:12:34 +120013392TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13393 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13394 "are consumed via singlesample images types in the shader, or vice versa.");
13395
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013397
13398 ASSERT_NO_FATAL_FAILURE(InitState());
13399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13400
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013401 char const *vsSource = "#version 450\n"
13402 "\n"
13403 "out gl_PerVertex { vec4 gl_Position; };\n"
13404 "void main() { gl_Position = vec4(0); }\n";
13405 char const *fsSource = "#version 450\n"
13406 "\n"
13407 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13408 "layout(location=0) out vec4 color;\n"
13409 "void main() {\n"
13410 " color = texelFetch(s, ivec2(0), 0);\n"
13411 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13413 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13414
13415 VkPipelineObj pipe(m_device);
13416 pipe.AddShader(&vs);
13417 pipe.AddShader(&fs);
13418 pipe.AddColorAttachment();
13419
13420 VkTextureObj texture(m_device, nullptr);
13421 VkSamplerObj sampler(m_device);
13422
13423 VkDescriptorSetObj descriptorSet(m_device);
13424 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13425 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13426
13427 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13428 ASSERT_VK_SUCCESS(err);
13429
13430 BeginCommandBuffer();
13431
13432 m_commandBuffer->BindPipeline(pipe);
13433 m_commandBuffer->BindDescriptorSet(descriptorSet);
13434
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013435 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013436 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013437 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013438 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13439
13440 // error produced here.
13441 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13442
13443 m_errorMonitor->VerifyFound();
13444
13445 EndCommandBuffer();
13446}
13447
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013448#endif // SHADER_CHECKER_TESTS
13449
13450#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013451TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013453
13454 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013455
13456 // Create an image
13457 VkImage image;
13458
Karl Schultz6addd812016-02-02 17:17:23 -070013459 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13460 const int32_t tex_width = 32;
13461 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013462
13463 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013464 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13465 image_create_info.pNext = NULL;
13466 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13467 image_create_info.format = tex_format;
13468 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013469 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013470 image_create_info.extent.depth = 1;
13471 image_create_info.mipLevels = 1;
13472 image_create_info.arrayLayers = 1;
13473 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13474 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13475 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13476 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013477
13478 // Introduce error by sending down a bogus width extent
13479 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013480 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013481
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013482 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013483}
13484
Mark Youngc48c4c12016-04-11 14:26:49 -060013485TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13487 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013488
13489 ASSERT_NO_FATAL_FAILURE(InitState());
13490
13491 // Create an image
13492 VkImage image;
13493
13494 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13495 const int32_t tex_width = 32;
13496 const int32_t tex_height = 32;
13497
13498 VkImageCreateInfo image_create_info = {};
13499 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13500 image_create_info.pNext = NULL;
13501 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13502 image_create_info.format = tex_format;
13503 image_create_info.extent.width = tex_width;
13504 image_create_info.extent.height = tex_height;
13505 image_create_info.extent.depth = 1;
13506 image_create_info.mipLevels = 1;
13507 image_create_info.arrayLayers = 1;
13508 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13509 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13510 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13511 image_create_info.flags = 0;
13512
13513 // Introduce error by sending down a bogus width extent
13514 image_create_info.extent.width = 0;
13515 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13516
13517 m_errorMonitor->VerifyFound();
13518}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013519#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013520
Tobin Ehliscde08892015-09-22 10:11:37 -060013521#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013522TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13523 TEST_DESCRIPTION("Create a render pass with an attachment description "
13524 "format set to VK_FORMAT_UNDEFINED");
13525
13526 ASSERT_NO_FATAL_FAILURE(InitState());
13527 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013530
13531 VkAttachmentReference color_attach = {};
13532 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13533 color_attach.attachment = 0;
13534 VkSubpassDescription subpass = {};
13535 subpass.colorAttachmentCount = 1;
13536 subpass.pColorAttachments = &color_attach;
13537
13538 VkRenderPassCreateInfo rpci = {};
13539 rpci.subpassCount = 1;
13540 rpci.pSubpasses = &subpass;
13541 rpci.attachmentCount = 1;
13542 VkAttachmentDescription attach_desc = {};
13543 attach_desc.format = VK_FORMAT_UNDEFINED;
13544 rpci.pAttachments = &attach_desc;
13545 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13546 VkRenderPass rp;
13547 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13548
13549 m_errorMonitor->VerifyFound();
13550
13551 if (result == VK_SUCCESS) {
13552 vkDestroyRenderPass(m_device->device(), rp, NULL);
13553 }
13554}
13555
Karl Schultz6addd812016-02-02 17:17:23 -070013556TEST_F(VkLayerTest, InvalidImageView) {
13557 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013558
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013560
Tobin Ehliscde08892015-09-22 10:11:37 -060013561 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013562
Mike Stroyana3082432015-09-25 13:39:21 -060013563 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013564 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013565
Karl Schultz6addd812016-02-02 17:17:23 -070013566 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13567 const int32_t tex_width = 32;
13568 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013569
13570 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013571 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13572 image_create_info.pNext = NULL;
13573 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13574 image_create_info.format = tex_format;
13575 image_create_info.extent.width = tex_width;
13576 image_create_info.extent.height = tex_height;
13577 image_create_info.extent.depth = 1;
13578 image_create_info.mipLevels = 1;
13579 image_create_info.arrayLayers = 1;
13580 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13581 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13582 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13583 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013584
Chia-I Wuf7458c52015-10-26 21:10:41 +080013585 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013586 ASSERT_VK_SUCCESS(err);
13587
13588 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013589 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13590 image_view_create_info.image = image;
13591 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13592 image_view_create_info.format = tex_format;
13593 image_view_create_info.subresourceRange.layerCount = 1;
13594 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13595 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013596 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013597
13598 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013599 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013600
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013601 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013602 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013603}
Mike Stroyana3082432015-09-25 13:39:21 -060013604
Mark Youngd339ba32016-05-30 13:28:35 -060013605TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13606 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013608 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013609
13610 ASSERT_NO_FATAL_FAILURE(InitState());
13611
13612 // Create an image and try to create a view with no memory backing the image
13613 VkImage image;
13614
13615 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13616 const int32_t tex_width = 32;
13617 const int32_t tex_height = 32;
13618
13619 VkImageCreateInfo image_create_info = {};
13620 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13621 image_create_info.pNext = NULL;
13622 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13623 image_create_info.format = tex_format;
13624 image_create_info.extent.width = tex_width;
13625 image_create_info.extent.height = tex_height;
13626 image_create_info.extent.depth = 1;
13627 image_create_info.mipLevels = 1;
13628 image_create_info.arrayLayers = 1;
13629 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13630 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13631 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13632 image_create_info.flags = 0;
13633
13634 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13635 ASSERT_VK_SUCCESS(err);
13636
13637 VkImageViewCreateInfo image_view_create_info = {};
13638 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13639 image_view_create_info.image = image;
13640 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13641 image_view_create_info.format = tex_format;
13642 image_view_create_info.subresourceRange.layerCount = 1;
13643 image_view_create_info.subresourceRange.baseMipLevel = 0;
13644 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013645 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013646
13647 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013648 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013649
13650 m_errorMonitor->VerifyFound();
13651 vkDestroyImage(m_device->device(), image, NULL);
13652 // If last error is success, it still created the view, so delete it.
13653 if (err == VK_SUCCESS) {
13654 vkDestroyImageView(m_device->device(), view, NULL);
13655 }
Mark Youngd339ba32016-05-30 13:28:35 -060013656}
13657
Karl Schultz6addd812016-02-02 17:17:23 -070013658TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013659 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013661 "formats must have ONLY the "
13662 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13664 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013665
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013666 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013667
Karl Schultz6addd812016-02-02 17:17:23 -070013668 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013669 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013670 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013671 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013672
13673 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013674 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013675 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013676 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13677 image_view_create_info.format = tex_format;
13678 image_view_create_info.subresourceRange.baseMipLevel = 0;
13679 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013680 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013681 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013682 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013683
13684 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013685 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013686
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013687 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013688}
13689
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013690TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013691 VkResult err;
13692 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013693
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13695 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013696
Mike Stroyana3082432015-09-25 13:39:21 -060013697 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013698
13699 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013700 VkImage srcImage;
13701 VkImage dstImage;
13702 VkDeviceMemory srcMem;
13703 VkDeviceMemory destMem;
13704 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013705
13706 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013707 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13708 image_create_info.pNext = NULL;
13709 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13710 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13711 image_create_info.extent.width = 32;
13712 image_create_info.extent.height = 32;
13713 image_create_info.extent.depth = 1;
13714 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013715 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013716 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13717 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13718 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13719 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013721 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013722 ASSERT_VK_SUCCESS(err);
13723
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013724 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013725 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013726 ASSERT_VK_SUCCESS(err);
13727
13728 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013729 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013730 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13731 memAlloc.pNext = NULL;
13732 memAlloc.allocationSize = 0;
13733 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013734
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013735 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013736 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013737 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013738 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013739 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013740 ASSERT_VK_SUCCESS(err);
13741
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013742 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013743 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013744 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013745 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013746 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013747 ASSERT_VK_SUCCESS(err);
13748
13749 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13750 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013751 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013752 ASSERT_VK_SUCCESS(err);
13753
13754 BeginCommandBuffer();
13755 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013756 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013757 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013758 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013759 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013760 copyRegion.srcOffset.x = 0;
13761 copyRegion.srcOffset.y = 0;
13762 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013763 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013764 copyRegion.dstSubresource.mipLevel = 0;
13765 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013766 // Introduce failure by forcing the dst layerCount to differ from src
13767 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013768 copyRegion.dstOffset.x = 0;
13769 copyRegion.dstOffset.y = 0;
13770 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013771 copyRegion.extent.width = 1;
13772 copyRegion.extent.height = 1;
13773 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013774 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013775 EndCommandBuffer();
13776
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013777 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013778
Chia-I Wuf7458c52015-10-26 21:10:41 +080013779 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013780 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013781 vkFreeMemory(m_device->device(), srcMem, NULL);
13782 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013783}
13784
Tony Barbourd6673642016-05-05 14:46:39 -060013785TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13786
13787 TEST_DESCRIPTION("Creating images with unsuported formats ");
13788
13789 ASSERT_NO_FATAL_FAILURE(InitState());
13790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13791 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013792 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 -060013793 VK_IMAGE_TILING_OPTIMAL, 0);
13794 ASSERT_TRUE(image.initialized());
13795
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013796 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13797 VkImageCreateInfo image_create_info;
13798 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13799 image_create_info.pNext = NULL;
13800 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13801 image_create_info.format = VK_FORMAT_UNDEFINED;
13802 image_create_info.extent.width = 32;
13803 image_create_info.extent.height = 32;
13804 image_create_info.extent.depth = 1;
13805 image_create_info.mipLevels = 1;
13806 image_create_info.arrayLayers = 1;
13807 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13808 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13809 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13810 image_create_info.flags = 0;
13811
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13813 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013814
13815 VkImage localImage;
13816 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13817 m_errorMonitor->VerifyFound();
13818
Tony Barbourd6673642016-05-05 14:46:39 -060013819 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013820 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013821 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13822 VkFormat format = static_cast<VkFormat>(f);
13823 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013824 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013825 unsupported = format;
13826 break;
13827 }
13828 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013829
Tony Barbourd6673642016-05-05 14:46:39 -060013830 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013831 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013833
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013834 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013835 m_errorMonitor->VerifyFound();
13836 }
13837}
13838
13839TEST_F(VkLayerTest, ImageLayerViewTests) {
13840 VkResult ret;
13841 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13842
13843 ASSERT_NO_FATAL_FAILURE(InitState());
13844
13845 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013846 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 -060013847 VK_IMAGE_TILING_OPTIMAL, 0);
13848 ASSERT_TRUE(image.initialized());
13849
13850 VkImageView imgView;
13851 VkImageViewCreateInfo imgViewInfo = {};
13852 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13853 imgViewInfo.image = image.handle();
13854 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13855 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13856 imgViewInfo.subresourceRange.layerCount = 1;
13857 imgViewInfo.subresourceRange.baseMipLevel = 0;
13858 imgViewInfo.subresourceRange.levelCount = 1;
13859 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013862 // View can't have baseMipLevel >= image's mipLevels - Expect
13863 // VIEW_CREATE_ERROR
13864 imgViewInfo.subresourceRange.baseMipLevel = 1;
13865 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13866 m_errorMonitor->VerifyFound();
13867 imgViewInfo.subresourceRange.baseMipLevel = 0;
13868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060013870 // View can't have baseArrayLayer >= image's arraySize - Expect
13871 // VIEW_CREATE_ERROR
13872 imgViewInfo.subresourceRange.baseArrayLayer = 1;
13873 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13874 m_errorMonitor->VerifyFound();
13875 imgViewInfo.subresourceRange.baseArrayLayer = 0;
13876
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13878 "pCreateInfo->subresourceRange."
13879 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060013880 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
13881 imgViewInfo.subresourceRange.levelCount = 0;
13882 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13883 m_errorMonitor->VerifyFound();
13884 imgViewInfo.subresourceRange.levelCount = 1;
13885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13887 "pCreateInfo->subresourceRange."
13888 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013889 m_errorMonitor->SetDesiredFailureMsg(
13890 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13891 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060013892 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
13893 imgViewInfo.subresourceRange.layerCount = 0;
13894 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13895 m_errorMonitor->VerifyFound();
13896 imgViewInfo.subresourceRange.layerCount = 1;
13897
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13900 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13901 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013902 // Can't use depth format for view into color image - Expect INVALID_FORMAT
13903 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
13904 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13905 m_errorMonitor->VerifyFound();
13906 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13909 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13910 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013911 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
13912 // VIEW_CREATE_ERROR
13913 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
13914 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13915 m_errorMonitor->VerifyFound();
13916 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13917
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
13919 "differing formats but they must be "
13920 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013921 // TODO: Update framework to easily passing mutable flag into ImageObj init
13922 // For now just allowing image for this one test to not have memory bound
13923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13924 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060013925 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
13926 // VIEW_CREATE_ERROR
13927 VkImageCreateInfo mutImgInfo = image.create_info();
13928 VkImage mutImage;
13929 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013930 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060013931 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
13932 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
13933 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
13934 ASSERT_VK_SUCCESS(ret);
13935 imgViewInfo.image = mutImage;
13936 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13937 m_errorMonitor->VerifyFound();
13938 imgViewInfo.image = image.handle();
13939 vkDestroyImage(m_device->handle(), mutImage, NULL);
13940}
13941
13942TEST_F(VkLayerTest, MiscImageLayerTests) {
13943
13944 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
13945
13946 ASSERT_NO_FATAL_FAILURE(InitState());
13947
13948 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013949 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 -060013950 VK_IMAGE_TILING_OPTIMAL, 0);
13951 ASSERT_TRUE(image.initialized());
13952
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060013954 vk_testing::Buffer buffer;
13955 VkMemoryPropertyFlags reqs = 0;
13956 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
13957 VkBufferImageCopy region = {};
13958 region.bufferRowLength = 128;
13959 region.bufferImageHeight = 128;
13960 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13961 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
13962 region.imageSubresource.layerCount = 0;
13963 region.imageExtent.height = 4;
13964 region.imageExtent.width = 4;
13965 region.imageExtent.depth = 1;
13966 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013967 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13968 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060013969 m_errorMonitor->VerifyFound();
13970 region.imageSubresource.layerCount = 1;
13971
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013972 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
13973 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
13974 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
13976 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13977 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013978 m_errorMonitor->VerifyFound();
13979
13980 // BufferOffset must be a multiple of 4
13981 // Introduce failure by setting bufferOffset to a value not divisible by 4
13982 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
13984 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13985 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013986 m_errorMonitor->VerifyFound();
13987
13988 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
13989 region.bufferOffset = 0;
13990 region.imageExtent.height = 128;
13991 region.imageExtent.width = 128;
13992 // Introduce failure by setting bufferRowLength > 0 but less than width
13993 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13995 "must be zero or greater-than-or-equal-to imageExtent.width");
13996 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13997 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013998 m_errorMonitor->VerifyFound();
13999
14000 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14001 region.bufferRowLength = 128;
14002 // Introduce failure by setting bufferRowHeight > 0 but less than height
14003 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14005 "must be zero or greater-than-or-equal-to imageExtent.height");
14006 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14007 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014008 m_errorMonitor->VerifyFound();
14009
14010 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
14012 "specify only COLOR or DEPTH or "
14013 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060014014 // Expect MISMATCHED_IMAGE_ASPECT
14015 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014016 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14017 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014018 m_errorMonitor->VerifyFound();
14019 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14022 "If the format of srcImage is a depth, stencil, depth stencil or "
14023 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014024 // Expect INVALID_FILTER
14025 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014026 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 -060014027 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014028 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 -060014029 VkImageBlit blitRegion = {};
14030 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14031 blitRegion.srcSubresource.baseArrayLayer = 0;
14032 blitRegion.srcSubresource.layerCount = 1;
14033 blitRegion.srcSubresource.mipLevel = 0;
14034 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14035 blitRegion.dstSubresource.baseArrayLayer = 0;
14036 blitRegion.dstSubresource.layerCount = 1;
14037 blitRegion.dstSubresource.mipLevel = 0;
14038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014039 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14040 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014041 m_errorMonitor->VerifyFound();
14042
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014043 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14045 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14046 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014047 m_errorMonitor->VerifyFound();
14048
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014050 VkImageMemoryBarrier img_barrier;
14051 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14052 img_barrier.pNext = NULL;
14053 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14054 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14055 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14056 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14057 img_barrier.image = image.handle();
14058 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14059 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14060 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14061 img_barrier.subresourceRange.baseArrayLayer = 0;
14062 img_barrier.subresourceRange.baseMipLevel = 0;
14063 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14064 img_barrier.subresourceRange.layerCount = 0;
14065 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014066 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14067 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014068 m_errorMonitor->VerifyFound();
14069 img_barrier.subresourceRange.layerCount = 1;
14070}
14071
14072TEST_F(VkLayerTest, ImageFormatLimits) {
14073
14074 TEST_DESCRIPTION("Exceed the limits of image format ");
14075
Cody Northropc31a84f2016-08-22 10:41:47 -060014076 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014078 VkImageCreateInfo image_create_info = {};
14079 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14080 image_create_info.pNext = NULL;
14081 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14082 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14083 image_create_info.extent.width = 32;
14084 image_create_info.extent.height = 32;
14085 image_create_info.extent.depth = 1;
14086 image_create_info.mipLevels = 1;
14087 image_create_info.arrayLayers = 1;
14088 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14089 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14090 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14091 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14092 image_create_info.flags = 0;
14093
14094 VkImage nullImg;
14095 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014096 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14097 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014098 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14099 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14100 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14101 m_errorMonitor->VerifyFound();
14102 image_create_info.extent.depth = 1;
14103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014105 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14106 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14107 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14108 m_errorMonitor->VerifyFound();
14109 image_create_info.mipLevels = 1;
14110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014112 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14113 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14114 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14115 m_errorMonitor->VerifyFound();
14116 image_create_info.arrayLayers = 1;
14117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014119 int samples = imgFmtProps.sampleCounts >> 1;
14120 image_create_info.samples = (VkSampleCountFlagBits)samples;
14121 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14122 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14123 m_errorMonitor->VerifyFound();
14124 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14127 "VK_IMAGE_LAYOUT_UNDEFINED or "
14128 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014129 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14130 // Expect INVALID_LAYOUT
14131 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14132 m_errorMonitor->VerifyFound();
14133 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14134}
14135
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014136TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14137
14138 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014140
14141 ASSERT_NO_FATAL_FAILURE(InitState());
14142
14143 VkImageObj src_image(m_device);
14144 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14145 VkImageObj dst_image(m_device);
14146 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14147
14148 BeginCommandBuffer();
14149 VkImageCopy copy_region;
14150 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14151 copy_region.srcSubresource.mipLevel = 0;
14152 copy_region.srcSubresource.baseArrayLayer = 0;
14153 copy_region.srcSubresource.layerCount = 0;
14154 copy_region.srcOffset.x = 0;
14155 copy_region.srcOffset.y = 0;
14156 copy_region.srcOffset.z = 0;
14157 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14158 copy_region.dstSubresource.mipLevel = 0;
14159 copy_region.dstSubresource.baseArrayLayer = 0;
14160 copy_region.dstSubresource.layerCount = 0;
14161 copy_region.dstOffset.x = 0;
14162 copy_region.dstOffset.y = 0;
14163 copy_region.dstOffset.z = 0;
14164 copy_region.extent.width = 64;
14165 copy_region.extent.height = 64;
14166 copy_region.extent.depth = 1;
14167 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14168 &copy_region);
14169 EndCommandBuffer();
14170
14171 m_errorMonitor->VerifyFound();
14172}
14173
14174TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14175
14176 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014178
14179 ASSERT_NO_FATAL_FAILURE(InitState());
14180
14181 VkImageObj src_image(m_device);
14182 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14183 VkImageObj dst_image(m_device);
14184 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14185
14186 BeginCommandBuffer();
14187 VkImageCopy copy_region;
14188 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14189 copy_region.srcSubresource.mipLevel = 0;
14190 copy_region.srcSubresource.baseArrayLayer = 0;
14191 copy_region.srcSubresource.layerCount = 0;
14192 copy_region.srcOffset.x = 0;
14193 copy_region.srcOffset.y = 0;
14194 copy_region.srcOffset.z = 0;
14195 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14196 copy_region.dstSubresource.mipLevel = 0;
14197 copy_region.dstSubresource.baseArrayLayer = 0;
14198 copy_region.dstSubresource.layerCount = 0;
14199 copy_region.dstOffset.x = 0;
14200 copy_region.dstOffset.y = 0;
14201 copy_region.dstOffset.z = 0;
14202 copy_region.extent.width = 64;
14203 copy_region.extent.height = 64;
14204 copy_region.extent.depth = 1;
14205 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14206 &copy_region);
14207 EndCommandBuffer();
14208
14209 m_errorMonitor->VerifyFound();
14210}
14211
Karl Schultz6addd812016-02-02 17:17:23 -070014212TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014213 VkResult err;
14214 bool pass;
14215
14216 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14218 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014219
14220 ASSERT_NO_FATAL_FAILURE(InitState());
14221
14222 // Create two images of different types and try to copy between them
14223 VkImage srcImage;
14224 VkImage dstImage;
14225 VkDeviceMemory srcMem;
14226 VkDeviceMemory destMem;
14227 VkMemoryRequirements memReqs;
14228
14229 VkImageCreateInfo image_create_info = {};
14230 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14231 image_create_info.pNext = NULL;
14232 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14233 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14234 image_create_info.extent.width = 32;
14235 image_create_info.extent.height = 32;
14236 image_create_info.extent.depth = 1;
14237 image_create_info.mipLevels = 1;
14238 image_create_info.arrayLayers = 1;
14239 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14240 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14241 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14242 image_create_info.flags = 0;
14243
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014244 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014245 ASSERT_VK_SUCCESS(err);
14246
14247 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14248 // Introduce failure by creating second image with a different-sized format.
14249 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14250
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014251 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014252 ASSERT_VK_SUCCESS(err);
14253
14254 // Allocate memory
14255 VkMemoryAllocateInfo memAlloc = {};
14256 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14257 memAlloc.pNext = NULL;
14258 memAlloc.allocationSize = 0;
14259 memAlloc.memoryTypeIndex = 0;
14260
14261 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14262 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014263 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014264 ASSERT_TRUE(pass);
14265 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14266 ASSERT_VK_SUCCESS(err);
14267
14268 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14269 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014270 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014271 ASSERT_TRUE(pass);
14272 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14273 ASSERT_VK_SUCCESS(err);
14274
14275 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14276 ASSERT_VK_SUCCESS(err);
14277 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14278 ASSERT_VK_SUCCESS(err);
14279
14280 BeginCommandBuffer();
14281 VkImageCopy copyRegion;
14282 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14283 copyRegion.srcSubresource.mipLevel = 0;
14284 copyRegion.srcSubresource.baseArrayLayer = 0;
14285 copyRegion.srcSubresource.layerCount = 0;
14286 copyRegion.srcOffset.x = 0;
14287 copyRegion.srcOffset.y = 0;
14288 copyRegion.srcOffset.z = 0;
14289 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14290 copyRegion.dstSubresource.mipLevel = 0;
14291 copyRegion.dstSubresource.baseArrayLayer = 0;
14292 copyRegion.dstSubresource.layerCount = 0;
14293 copyRegion.dstOffset.x = 0;
14294 copyRegion.dstOffset.y = 0;
14295 copyRegion.dstOffset.z = 0;
14296 copyRegion.extent.width = 1;
14297 copyRegion.extent.height = 1;
14298 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014299 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014300 EndCommandBuffer();
14301
14302 m_errorMonitor->VerifyFound();
14303
14304 vkDestroyImage(m_device->device(), srcImage, NULL);
14305 vkDestroyImage(m_device->device(), dstImage, NULL);
14306 vkFreeMemory(m_device->device(), srcMem, NULL);
14307 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014308}
14309
Karl Schultz6addd812016-02-02 17:17:23 -070014310TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14311 VkResult err;
14312 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014313
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014314 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14316 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014317
Mike Stroyana3082432015-09-25 13:39:21 -060014318 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014319
14320 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014321 VkImage srcImage;
14322 VkImage dstImage;
14323 VkDeviceMemory srcMem;
14324 VkDeviceMemory destMem;
14325 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014326
14327 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014328 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14329 image_create_info.pNext = NULL;
14330 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14331 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14332 image_create_info.extent.width = 32;
14333 image_create_info.extent.height = 32;
14334 image_create_info.extent.depth = 1;
14335 image_create_info.mipLevels = 1;
14336 image_create_info.arrayLayers = 1;
14337 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14338 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14339 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14340 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014341
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014342 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014343 ASSERT_VK_SUCCESS(err);
14344
Karl Schultzbdb75952016-04-19 11:36:49 -060014345 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14346
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014347 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014348 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014349 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014350 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014351
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014352 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014353 ASSERT_VK_SUCCESS(err);
14354
14355 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014356 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014357 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14358 memAlloc.pNext = NULL;
14359 memAlloc.allocationSize = 0;
14360 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014361
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014362 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014363 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014364 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014365 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014366 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014367 ASSERT_VK_SUCCESS(err);
14368
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014369 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014370 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014371 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014372 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014373 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014374 ASSERT_VK_SUCCESS(err);
14375
14376 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14377 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014378 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014379 ASSERT_VK_SUCCESS(err);
14380
14381 BeginCommandBuffer();
14382 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014383 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014384 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014385 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014386 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014387 copyRegion.srcOffset.x = 0;
14388 copyRegion.srcOffset.y = 0;
14389 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014390 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014391 copyRegion.dstSubresource.mipLevel = 0;
14392 copyRegion.dstSubresource.baseArrayLayer = 0;
14393 copyRegion.dstSubresource.layerCount = 0;
14394 copyRegion.dstOffset.x = 0;
14395 copyRegion.dstOffset.y = 0;
14396 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014397 copyRegion.extent.width = 1;
14398 copyRegion.extent.height = 1;
14399 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014400 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014401 EndCommandBuffer();
14402
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014403 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014404
Chia-I Wuf7458c52015-10-26 21:10:41 +080014405 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014406 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014407 vkFreeMemory(m_device->device(), srcMem, NULL);
14408 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014409}
14410
Karl Schultz6addd812016-02-02 17:17:23 -070014411TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14412 VkResult err;
14413 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014414
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14416 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014417
Mike Stroyana3082432015-09-25 13:39:21 -060014418 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014419
14420 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014421 VkImage srcImage;
14422 VkImage dstImage;
14423 VkDeviceMemory srcMem;
14424 VkDeviceMemory destMem;
14425 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014426
14427 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014428 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14429 image_create_info.pNext = NULL;
14430 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14431 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14432 image_create_info.extent.width = 32;
14433 image_create_info.extent.height = 1;
14434 image_create_info.extent.depth = 1;
14435 image_create_info.mipLevels = 1;
14436 image_create_info.arrayLayers = 1;
14437 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14438 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14439 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14440 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014441
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014442 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014443 ASSERT_VK_SUCCESS(err);
14444
Karl Schultz6addd812016-02-02 17:17:23 -070014445 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014447 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014448 ASSERT_VK_SUCCESS(err);
14449
14450 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014451 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014452 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14453 memAlloc.pNext = NULL;
14454 memAlloc.allocationSize = 0;
14455 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014456
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014457 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014458 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014459 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014460 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014461 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014462 ASSERT_VK_SUCCESS(err);
14463
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014464 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014465 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014466 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014467 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014468 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014469 ASSERT_VK_SUCCESS(err);
14470
14471 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14472 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014473 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014474 ASSERT_VK_SUCCESS(err);
14475
14476 BeginCommandBuffer();
14477 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014478 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14479 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014480 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014481 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014482 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014483 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014484 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014485 resolveRegion.srcOffset.x = 0;
14486 resolveRegion.srcOffset.y = 0;
14487 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014488 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014489 resolveRegion.dstSubresource.mipLevel = 0;
14490 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014491 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014492 resolveRegion.dstOffset.x = 0;
14493 resolveRegion.dstOffset.y = 0;
14494 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014495 resolveRegion.extent.width = 1;
14496 resolveRegion.extent.height = 1;
14497 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014498 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014499 EndCommandBuffer();
14500
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014501 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014502
Chia-I Wuf7458c52015-10-26 21:10:41 +080014503 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014504 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014505 vkFreeMemory(m_device->device(), srcMem, NULL);
14506 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014507}
14508
Karl Schultz6addd812016-02-02 17:17:23 -070014509TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14510 VkResult err;
14511 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014512
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14514 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014515
Mike Stroyana3082432015-09-25 13:39:21 -060014516 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014517
Chris Forbesa7530692016-05-08 12:35:39 +120014518 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014519 VkImage srcImage;
14520 VkImage dstImage;
14521 VkDeviceMemory srcMem;
14522 VkDeviceMemory destMem;
14523 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014524
14525 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014526 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14527 image_create_info.pNext = NULL;
14528 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14529 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14530 image_create_info.extent.width = 32;
14531 image_create_info.extent.height = 1;
14532 image_create_info.extent.depth = 1;
14533 image_create_info.mipLevels = 1;
14534 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014535 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014536 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14537 // Note: Some implementations expect color attachment usage for any
14538 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014539 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014540 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014541
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014542 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014543 ASSERT_VK_SUCCESS(err);
14544
Karl Schultz6addd812016-02-02 17:17:23 -070014545 // Note: Some implementations expect color attachment usage for any
14546 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014547 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014548
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014549 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014550 ASSERT_VK_SUCCESS(err);
14551
14552 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014553 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014554 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14555 memAlloc.pNext = NULL;
14556 memAlloc.allocationSize = 0;
14557 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014558
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014559 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014560 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014561 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014562 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014563 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014564 ASSERT_VK_SUCCESS(err);
14565
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014566 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014567 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014568 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014569 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014570 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014571 ASSERT_VK_SUCCESS(err);
14572
14573 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14574 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014575 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014576 ASSERT_VK_SUCCESS(err);
14577
14578 BeginCommandBuffer();
14579 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014580 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14581 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014582 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014583 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014584 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014585 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014586 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014587 resolveRegion.srcOffset.x = 0;
14588 resolveRegion.srcOffset.y = 0;
14589 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014590 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014591 resolveRegion.dstSubresource.mipLevel = 0;
14592 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014593 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014594 resolveRegion.dstOffset.x = 0;
14595 resolveRegion.dstOffset.y = 0;
14596 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014597 resolveRegion.extent.width = 1;
14598 resolveRegion.extent.height = 1;
14599 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014600 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014601 EndCommandBuffer();
14602
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014603 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014604
Chia-I Wuf7458c52015-10-26 21:10:41 +080014605 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014606 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014607 vkFreeMemory(m_device->device(), srcMem, NULL);
14608 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014609}
14610
Karl Schultz6addd812016-02-02 17:17:23 -070014611TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14612 VkResult err;
14613 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014614
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14616 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014617
Mike Stroyana3082432015-09-25 13:39:21 -060014618 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014619
14620 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014621 VkImage srcImage;
14622 VkImage dstImage;
14623 VkDeviceMemory srcMem;
14624 VkDeviceMemory destMem;
14625 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014626
14627 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014628 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14629 image_create_info.pNext = NULL;
14630 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14631 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14632 image_create_info.extent.width = 32;
14633 image_create_info.extent.height = 1;
14634 image_create_info.extent.depth = 1;
14635 image_create_info.mipLevels = 1;
14636 image_create_info.arrayLayers = 1;
14637 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14638 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14639 // Note: Some implementations expect color attachment usage for any
14640 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014641 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014642 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014644 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014645 ASSERT_VK_SUCCESS(err);
14646
Karl Schultz6addd812016-02-02 17:17:23 -070014647 // Set format to something other than source image
14648 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14649 // Note: Some implementations expect color attachment usage for any
14650 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014651 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014652 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014654 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014655 ASSERT_VK_SUCCESS(err);
14656
14657 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014658 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014659 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14660 memAlloc.pNext = NULL;
14661 memAlloc.allocationSize = 0;
14662 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014663
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014664 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014665 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014666 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014667 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014668 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014669 ASSERT_VK_SUCCESS(err);
14670
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014671 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014672 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014673 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014674 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014675 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014676 ASSERT_VK_SUCCESS(err);
14677
14678 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14679 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014680 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014681 ASSERT_VK_SUCCESS(err);
14682
14683 BeginCommandBuffer();
14684 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014685 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14686 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014687 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014688 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014689 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014690 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014691 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014692 resolveRegion.srcOffset.x = 0;
14693 resolveRegion.srcOffset.y = 0;
14694 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014695 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014696 resolveRegion.dstSubresource.mipLevel = 0;
14697 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014698 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014699 resolveRegion.dstOffset.x = 0;
14700 resolveRegion.dstOffset.y = 0;
14701 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014702 resolveRegion.extent.width = 1;
14703 resolveRegion.extent.height = 1;
14704 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014705 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014706 EndCommandBuffer();
14707
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014708 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014709
Chia-I Wuf7458c52015-10-26 21:10:41 +080014710 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014711 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014712 vkFreeMemory(m_device->device(), srcMem, NULL);
14713 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014714}
14715
Karl Schultz6addd812016-02-02 17:17:23 -070014716TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14717 VkResult err;
14718 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014719
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14721 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014722
Mike Stroyana3082432015-09-25 13:39:21 -060014723 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014724
14725 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014726 VkImage srcImage;
14727 VkImage dstImage;
14728 VkDeviceMemory srcMem;
14729 VkDeviceMemory destMem;
14730 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014731
14732 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014733 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14734 image_create_info.pNext = NULL;
14735 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14736 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14737 image_create_info.extent.width = 32;
14738 image_create_info.extent.height = 1;
14739 image_create_info.extent.depth = 1;
14740 image_create_info.mipLevels = 1;
14741 image_create_info.arrayLayers = 1;
14742 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14743 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14744 // Note: Some implementations expect color attachment usage for any
14745 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014746 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014747 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014749 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014750 ASSERT_VK_SUCCESS(err);
14751
Karl Schultz6addd812016-02-02 17:17:23 -070014752 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14753 // Note: Some implementations expect color attachment usage for any
14754 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014755 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014756 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014757
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014758 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014759 ASSERT_VK_SUCCESS(err);
14760
14761 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014762 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014763 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14764 memAlloc.pNext = NULL;
14765 memAlloc.allocationSize = 0;
14766 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014767
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014768 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014769 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014770 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014771 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014772 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014773 ASSERT_VK_SUCCESS(err);
14774
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014775 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014776 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014777 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014778 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014779 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014780 ASSERT_VK_SUCCESS(err);
14781
14782 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14783 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014784 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014785 ASSERT_VK_SUCCESS(err);
14786
14787 BeginCommandBuffer();
14788 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014789 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14790 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014791 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014792 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014793 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014794 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014795 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014796 resolveRegion.srcOffset.x = 0;
14797 resolveRegion.srcOffset.y = 0;
14798 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014799 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014800 resolveRegion.dstSubresource.mipLevel = 0;
14801 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014802 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014803 resolveRegion.dstOffset.x = 0;
14804 resolveRegion.dstOffset.y = 0;
14805 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014806 resolveRegion.extent.width = 1;
14807 resolveRegion.extent.height = 1;
14808 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014809 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014810 EndCommandBuffer();
14811
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014812 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014813
Chia-I Wuf7458c52015-10-26 21:10:41 +080014814 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014815 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014816 vkFreeMemory(m_device->device(), srcMem, NULL);
14817 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014818}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014819
Karl Schultz6addd812016-02-02 17:17:23 -070014820TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014821 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014822 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14823 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014824 // The image format check comes 2nd in validation so we trigger it first,
14825 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014826 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014827
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14829 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014830
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014831 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014832
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014833 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014834 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14835 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014836
14837 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014838 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14839 ds_pool_ci.pNext = NULL;
14840 ds_pool_ci.maxSets = 1;
14841 ds_pool_ci.poolSizeCount = 1;
14842 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014843
14844 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014845 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014846 ASSERT_VK_SUCCESS(err);
14847
14848 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014849 dsl_binding.binding = 0;
14850 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14851 dsl_binding.descriptorCount = 1;
14852 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14853 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014854
14855 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014856 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14857 ds_layout_ci.pNext = NULL;
14858 ds_layout_ci.bindingCount = 1;
14859 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014860 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014862 ASSERT_VK_SUCCESS(err);
14863
14864 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014865 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080014866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070014867 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014868 alloc_info.descriptorPool = ds_pool;
14869 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014871 ASSERT_VK_SUCCESS(err);
14872
Karl Schultz6addd812016-02-02 17:17:23 -070014873 VkImage image_bad;
14874 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014875 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060014876 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014877 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070014878 const int32_t tex_width = 32;
14879 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014880
14881 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014882 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14883 image_create_info.pNext = NULL;
14884 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14885 image_create_info.format = tex_format_bad;
14886 image_create_info.extent.width = tex_width;
14887 image_create_info.extent.height = tex_height;
14888 image_create_info.extent.depth = 1;
14889 image_create_info.mipLevels = 1;
14890 image_create_info.arrayLayers = 1;
14891 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14892 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014893 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014894 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014895
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014896 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014897 ASSERT_VK_SUCCESS(err);
14898 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014899 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14900 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014901 ASSERT_VK_SUCCESS(err);
14902
14903 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014904 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14905 image_view_create_info.image = image_bad;
14906 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14907 image_view_create_info.format = tex_format_bad;
14908 image_view_create_info.subresourceRange.baseArrayLayer = 0;
14909 image_view_create_info.subresourceRange.baseMipLevel = 0;
14910 image_view_create_info.subresourceRange.layerCount = 1;
14911 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014912 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014913
14914 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014915 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014916
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014917 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014918
Chia-I Wuf7458c52015-10-26 21:10:41 +080014919 vkDestroyImage(m_device->device(), image_bad, NULL);
14920 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014921 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
14922 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014923}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014924
14925TEST_F(VkLayerTest, ClearImageErrors) {
14926 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
14927 "ClearDepthStencilImage with a color image.");
14928
14929 ASSERT_NO_FATAL_FAILURE(InitState());
14930 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14931
14932 // Renderpass is started here so end it as Clear cmds can't be in renderpass
14933 BeginCommandBuffer();
14934 m_commandBuffer->EndRenderPass();
14935
14936 // Color image
14937 VkClearColorValue clear_color;
14938 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
14939 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
14940 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
14941 const int32_t img_width = 32;
14942 const int32_t img_height = 32;
14943 VkImageCreateInfo image_create_info = {};
14944 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14945 image_create_info.pNext = NULL;
14946 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14947 image_create_info.format = color_format;
14948 image_create_info.extent.width = img_width;
14949 image_create_info.extent.height = img_height;
14950 image_create_info.extent.depth = 1;
14951 image_create_info.mipLevels = 1;
14952 image_create_info.arrayLayers = 1;
14953 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14954 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14955 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14956
14957 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014958 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014960 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014961
14962 // Depth/Stencil image
14963 VkClearDepthStencilValue clear_value = {0};
14964 reqs = 0; // don't need HOST_VISIBLE DS image
14965 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
14966 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
14967 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
14968 ds_image_create_info.extent.width = 64;
14969 ds_image_create_info.extent.height = 64;
14970 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14971 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
14972
14973 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014974 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014976 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 -060014977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014980 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014981 &color_range);
14982
14983 m_errorMonitor->VerifyFound();
14984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
14986 "image created without "
14987 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060014988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014989 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060014990 &color_range);
14991
14992 m_errorMonitor->VerifyFound();
14993
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014994 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14996 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014997
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014998 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
14999 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015000
15001 m_errorMonitor->VerifyFound();
15002}
Tobin Ehliscde08892015-09-22 10:11:37 -060015003#endif // IMAGE_TESTS
15004
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015005
15006// WSI Enabled Tests
15007//
15008TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15009
15010#if defined(VK_USE_PLATFORM_XCB_KHR)
15011 VkSurfaceKHR surface = VK_NULL_HANDLE;
15012
15013 VkResult err;
15014 bool pass;
15015 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15016 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15017 // uint32_t swapchain_image_count = 0;
15018 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15019 // uint32_t image_index = 0;
15020 // VkPresentInfoKHR present_info = {};
15021
15022 ASSERT_NO_FATAL_FAILURE(InitState());
15023
15024 // Use the create function from one of the VK_KHR_*_surface extension in
15025 // order to create a surface, testing all known errors in the process,
15026 // before successfully creating a surface:
15027 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15029 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15030 pass = (err != VK_SUCCESS);
15031 ASSERT_TRUE(pass);
15032 m_errorMonitor->VerifyFound();
15033
15034 // Next, try to create a surface with the wrong
15035 // VkXcbSurfaceCreateInfoKHR::sType:
15036 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15037 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15039 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15040 pass = (err != VK_SUCCESS);
15041 ASSERT_TRUE(pass);
15042 m_errorMonitor->VerifyFound();
15043
15044 // Create a native window, and then correctly create a surface:
15045 xcb_connection_t *connection;
15046 xcb_screen_t *screen;
15047 xcb_window_t xcb_window;
15048 xcb_intern_atom_reply_t *atom_wm_delete_window;
15049
15050 const xcb_setup_t *setup;
15051 xcb_screen_iterator_t iter;
15052 int scr;
15053 uint32_t value_mask, value_list[32];
15054 int width = 1;
15055 int height = 1;
15056
15057 connection = xcb_connect(NULL, &scr);
15058 ASSERT_TRUE(connection != NULL);
15059 setup = xcb_get_setup(connection);
15060 iter = xcb_setup_roots_iterator(setup);
15061 while (scr-- > 0)
15062 xcb_screen_next(&iter);
15063 screen = iter.data;
15064
15065 xcb_window = xcb_generate_id(connection);
15066
15067 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15068 value_list[0] = screen->black_pixel;
15069 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15070
15071 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15072 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15073
15074 /* Magic code that will send notification when window is destroyed */
15075 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15076 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15077
15078 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15079 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15080 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15081 free(reply);
15082
15083 xcb_map_window(connection, xcb_window);
15084
15085 // Force the x/y coordinates to 100,100 results are identical in consecutive
15086 // runs
15087 const uint32_t coords[] = { 100, 100 };
15088 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15089
15090 // Finally, try to correctly create a surface:
15091 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15092 xcb_create_info.pNext = NULL;
15093 xcb_create_info.flags = 0;
15094 xcb_create_info.connection = connection;
15095 xcb_create_info.window = xcb_window;
15096 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15097 pass = (err == VK_SUCCESS);
15098 ASSERT_TRUE(pass);
15099
15100 // Check if surface supports presentation:
15101
15102 // 1st, do so without having queried the queue families:
15103 VkBool32 supported = false;
15104 // TODO: Get the following error to come out:
15105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15106 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15107 "function");
15108 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15109 pass = (err != VK_SUCCESS);
15110 // ASSERT_TRUE(pass);
15111 // m_errorMonitor->VerifyFound();
15112
15113 // Next, query a queue family index that's too large:
15114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15115 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15116 pass = (err != VK_SUCCESS);
15117 ASSERT_TRUE(pass);
15118 m_errorMonitor->VerifyFound();
15119
15120 // Finally, do so correctly:
15121 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15122 // SUPPORTED
15123 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15124 pass = (err == VK_SUCCESS);
15125 ASSERT_TRUE(pass);
15126
15127 // Before proceeding, try to create a swapchain without having called
15128 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15129 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15130 swapchain_create_info.pNext = NULL;
15131 swapchain_create_info.flags = 0;
15132 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15133 swapchain_create_info.surface = surface;
15134 swapchain_create_info.imageArrayLayers = 1;
15135 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15136 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15138 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15139 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15140 pass = (err != VK_SUCCESS);
15141 ASSERT_TRUE(pass);
15142 m_errorMonitor->VerifyFound();
15143
15144 // Get the surface capabilities:
15145 VkSurfaceCapabilitiesKHR surface_capabilities;
15146
15147 // Do so correctly (only error logged by this entrypoint is if the
15148 // extension isn't enabled):
15149 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15150 pass = (err == VK_SUCCESS);
15151 ASSERT_TRUE(pass);
15152
15153 // Get the surface formats:
15154 uint32_t surface_format_count;
15155
15156 // First, try without a pointer to surface_format_count:
15157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15158 "specified as NULL");
15159 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15160 pass = (err == VK_SUCCESS);
15161 ASSERT_TRUE(pass);
15162 m_errorMonitor->VerifyFound();
15163
15164 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15165 // correctly done a 1st try (to get the count):
15166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15167 surface_format_count = 0;
15168 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15169 pass = (err == VK_SUCCESS);
15170 ASSERT_TRUE(pass);
15171 m_errorMonitor->VerifyFound();
15172
15173 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15174 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15175 pass = (err == VK_SUCCESS);
15176 ASSERT_TRUE(pass);
15177
15178 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15179 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15180
15181 // Next, do a 2nd try with surface_format_count being set too high:
15182 surface_format_count += 5;
15183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15184 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15185 pass = (err == VK_SUCCESS);
15186 ASSERT_TRUE(pass);
15187 m_errorMonitor->VerifyFound();
15188
15189 // Finally, do a correct 1st and 2nd try:
15190 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15191 pass = (err == VK_SUCCESS);
15192 ASSERT_TRUE(pass);
15193 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15194 pass = (err == VK_SUCCESS);
15195 ASSERT_TRUE(pass);
15196
15197 // Get the surface present modes:
15198 uint32_t surface_present_mode_count;
15199
15200 // First, try without a pointer to surface_format_count:
15201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15202 "specified as NULL");
15203
15204 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15205 pass = (err == VK_SUCCESS);
15206 ASSERT_TRUE(pass);
15207 m_errorMonitor->VerifyFound();
15208
15209 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15210 // correctly done a 1st try (to get the count):
15211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15212 surface_present_mode_count = 0;
15213 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15214 (VkPresentModeKHR *)&surface_present_mode_count);
15215 pass = (err == VK_SUCCESS);
15216 ASSERT_TRUE(pass);
15217 m_errorMonitor->VerifyFound();
15218
15219 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15220 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15221 pass = (err == VK_SUCCESS);
15222 ASSERT_TRUE(pass);
15223
15224 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15225 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15226
15227 // Next, do a 2nd try with surface_format_count being set too high:
15228 surface_present_mode_count += 5;
15229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15230 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15231 pass = (err == VK_SUCCESS);
15232 ASSERT_TRUE(pass);
15233 m_errorMonitor->VerifyFound();
15234
15235 // Finally, do a correct 1st and 2nd try:
15236 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15237 pass = (err == VK_SUCCESS);
15238 ASSERT_TRUE(pass);
15239 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15240 pass = (err == VK_SUCCESS);
15241 ASSERT_TRUE(pass);
15242
15243 // Create a swapchain:
15244
15245 // First, try without a pointer to swapchain_create_info:
15246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15247 "specified as NULL");
15248
15249 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15250 pass = (err != VK_SUCCESS);
15251 ASSERT_TRUE(pass);
15252 m_errorMonitor->VerifyFound();
15253
15254 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15255 // sType:
15256 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15258
15259 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15260 pass = (err != VK_SUCCESS);
15261 ASSERT_TRUE(pass);
15262 m_errorMonitor->VerifyFound();
15263
15264 // Next, call with a NULL swapchain pointer:
15265 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15266 swapchain_create_info.pNext = NULL;
15267 swapchain_create_info.flags = 0;
15268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15269 "specified as NULL");
15270
15271 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15272 pass = (err != VK_SUCCESS);
15273 ASSERT_TRUE(pass);
15274 m_errorMonitor->VerifyFound();
15275
15276 // TODO: Enhance swapchain layer so that
15277 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15278
15279 // Next, call with a queue family index that's too large:
15280 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15281 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15282 swapchain_create_info.queueFamilyIndexCount = 2;
15283 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15285 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15286 pass = (err != VK_SUCCESS);
15287 ASSERT_TRUE(pass);
15288 m_errorMonitor->VerifyFound();
15289
15290 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15291 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15292 swapchain_create_info.queueFamilyIndexCount = 1;
15293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15294 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15295 "pCreateInfo->pQueueFamilyIndices).");
15296 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15297 pass = (err != VK_SUCCESS);
15298 ASSERT_TRUE(pass);
15299 m_errorMonitor->VerifyFound();
15300
15301 // Next, call with an invalid imageSharingMode:
15302 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15303 swapchain_create_info.queueFamilyIndexCount = 1;
15304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15305 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15306 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15307 pass = (err != VK_SUCCESS);
15308 ASSERT_TRUE(pass);
15309 m_errorMonitor->VerifyFound();
15310 // Fix for the future:
15311 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15312 // SUPPORTED
15313 swapchain_create_info.queueFamilyIndexCount = 0;
15314 queueFamilyIndex[0] = 0;
15315 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15316
15317 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15318 // Get the images from a swapchain:
15319 // Acquire an image from a swapchain:
15320 // Present an image to a swapchain:
15321 // Destroy the swapchain:
15322
15323 // TODOs:
15324 //
15325 // - Try destroying the device without first destroying the swapchain
15326 //
15327 // - Try destroying the device without first destroying the surface
15328 //
15329 // - Try destroying the surface without first destroying the swapchain
15330
15331 // Destroy the surface:
15332 vkDestroySurfaceKHR(instance(), surface, NULL);
15333
15334 // Tear down the window:
15335 xcb_destroy_window(connection, xcb_window);
15336 xcb_disconnect(connection);
15337
15338#else // VK_USE_PLATFORM_XCB_KHR
15339 return;
15340#endif // VK_USE_PLATFORM_XCB_KHR
15341}
15342
15343//
15344// POSITIVE VALIDATION TESTS
15345//
15346// These tests do not expect to encounter ANY validation errors pass only if this is true
15347
15348// This is a positive test. No failures are expected.
15349TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15350 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15351 "is ignoring VkWriteDescriptorSet members that are not "
15352 "related to the descriptor type specified by "
15353 "VkWriteDescriptorSet::descriptorType. Correct "
15354 "validation behavior will result in the test running to "
15355 "completion without validation errors.");
15356
15357 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15358
15359 ASSERT_NO_FATAL_FAILURE(InitState());
15360
15361 // Image Case
15362 {
15363 m_errorMonitor->ExpectSuccess();
15364
15365 VkImage image;
15366 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15367 const int32_t tex_width = 32;
15368 const int32_t tex_height = 32;
15369 VkImageCreateInfo image_create_info = {};
15370 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15371 image_create_info.pNext = NULL;
15372 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15373 image_create_info.format = tex_format;
15374 image_create_info.extent.width = tex_width;
15375 image_create_info.extent.height = tex_height;
15376 image_create_info.extent.depth = 1;
15377 image_create_info.mipLevels = 1;
15378 image_create_info.arrayLayers = 1;
15379 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15380 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15381 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15382 image_create_info.flags = 0;
15383 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15384 ASSERT_VK_SUCCESS(err);
15385
15386 VkMemoryRequirements memory_reqs;
15387 VkDeviceMemory image_memory;
15388 bool pass;
15389 VkMemoryAllocateInfo memory_info = {};
15390 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15391 memory_info.pNext = NULL;
15392 memory_info.allocationSize = 0;
15393 memory_info.memoryTypeIndex = 0;
15394 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15395 memory_info.allocationSize = memory_reqs.size;
15396 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15397 ASSERT_TRUE(pass);
15398 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15399 ASSERT_VK_SUCCESS(err);
15400 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15401 ASSERT_VK_SUCCESS(err);
15402
15403 VkImageViewCreateInfo image_view_create_info = {};
15404 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15405 image_view_create_info.image = image;
15406 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15407 image_view_create_info.format = tex_format;
15408 image_view_create_info.subresourceRange.layerCount = 1;
15409 image_view_create_info.subresourceRange.baseMipLevel = 0;
15410 image_view_create_info.subresourceRange.levelCount = 1;
15411 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15412
15413 VkImageView view;
15414 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15415 ASSERT_VK_SUCCESS(err);
15416
15417 VkDescriptorPoolSize ds_type_count = {};
15418 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15419 ds_type_count.descriptorCount = 1;
15420
15421 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15422 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15423 ds_pool_ci.pNext = NULL;
15424 ds_pool_ci.maxSets = 1;
15425 ds_pool_ci.poolSizeCount = 1;
15426 ds_pool_ci.pPoolSizes = &ds_type_count;
15427
15428 VkDescriptorPool ds_pool;
15429 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15430 ASSERT_VK_SUCCESS(err);
15431
15432 VkDescriptorSetLayoutBinding dsl_binding = {};
15433 dsl_binding.binding = 0;
15434 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15435 dsl_binding.descriptorCount = 1;
15436 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15437 dsl_binding.pImmutableSamplers = NULL;
15438
15439 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15440 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15441 ds_layout_ci.pNext = NULL;
15442 ds_layout_ci.bindingCount = 1;
15443 ds_layout_ci.pBindings = &dsl_binding;
15444 VkDescriptorSetLayout ds_layout;
15445 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15446 ASSERT_VK_SUCCESS(err);
15447
15448 VkDescriptorSet descriptor_set;
15449 VkDescriptorSetAllocateInfo alloc_info = {};
15450 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15451 alloc_info.descriptorSetCount = 1;
15452 alloc_info.descriptorPool = ds_pool;
15453 alloc_info.pSetLayouts = &ds_layout;
15454 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15455 ASSERT_VK_SUCCESS(err);
15456
15457 VkDescriptorImageInfo image_info = {};
15458 image_info.imageView = view;
15459 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15460
15461 VkWriteDescriptorSet descriptor_write;
15462 memset(&descriptor_write, 0, sizeof(descriptor_write));
15463 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15464 descriptor_write.dstSet = descriptor_set;
15465 descriptor_write.dstBinding = 0;
15466 descriptor_write.descriptorCount = 1;
15467 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15468 descriptor_write.pImageInfo = &image_info;
15469
15470 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15471 // be
15472 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15473 // This will most likely produce a crash if the parameter_validation
15474 // layer
15475 // does not correctly ignore pBufferInfo.
15476 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15477 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15478
15479 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15480
15481 m_errorMonitor->VerifyNotFound();
15482
15483 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15484 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15485 vkDestroyImageView(m_device->device(), view, NULL);
15486 vkDestroyImage(m_device->device(), image, NULL);
15487 vkFreeMemory(m_device->device(), image_memory, NULL);
15488 }
15489
15490 // Buffer Case
15491 {
15492 m_errorMonitor->ExpectSuccess();
15493
15494 VkBuffer buffer;
15495 uint32_t queue_family_index = 0;
15496 VkBufferCreateInfo buffer_create_info = {};
15497 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15498 buffer_create_info.size = 1024;
15499 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15500 buffer_create_info.queueFamilyIndexCount = 1;
15501 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15502
15503 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15504 ASSERT_VK_SUCCESS(err);
15505
15506 VkMemoryRequirements memory_reqs;
15507 VkDeviceMemory buffer_memory;
15508 bool pass;
15509 VkMemoryAllocateInfo memory_info = {};
15510 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15511 memory_info.pNext = NULL;
15512 memory_info.allocationSize = 0;
15513 memory_info.memoryTypeIndex = 0;
15514
15515 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15516 memory_info.allocationSize = memory_reqs.size;
15517 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15518 ASSERT_TRUE(pass);
15519
15520 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15521 ASSERT_VK_SUCCESS(err);
15522 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15523 ASSERT_VK_SUCCESS(err);
15524
15525 VkDescriptorPoolSize ds_type_count = {};
15526 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_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_UNIFORM_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 VkDescriptorBufferInfo buffer_info = {};
15566 buffer_info.buffer = buffer;
15567 buffer_info.offset = 0;
15568 buffer_info.range = 1024;
15569
15570 VkWriteDescriptorSet descriptor_write;
15571 memset(&descriptor_write, 0, sizeof(descriptor_write));
15572 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15573 descriptor_write.dstSet = descriptor_set;
15574 descriptor_write.dstBinding = 0;
15575 descriptor_write.descriptorCount = 1;
15576 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15577 descriptor_write.pBufferInfo = &buffer_info;
15578
15579 // Set pImageInfo and pTexelBufferView to invalid values, which should
15580 // be
15581 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15582 // This will most likely produce a crash if the parameter_validation
15583 // layer
15584 // does not correctly ignore pImageInfo.
15585 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15586 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15587
15588 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15589
15590 m_errorMonitor->VerifyNotFound();
15591
15592 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15593 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15594 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15595 vkDestroyBuffer(m_device->device(), buffer, NULL);
15596 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15597 }
15598
15599 // Texel Buffer Case
15600 {
15601 m_errorMonitor->ExpectSuccess();
15602
15603 VkBuffer buffer;
15604 uint32_t queue_family_index = 0;
15605 VkBufferCreateInfo buffer_create_info = {};
15606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15607 buffer_create_info.size = 1024;
15608 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15609 buffer_create_info.queueFamilyIndexCount = 1;
15610 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15611
15612 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15613 ASSERT_VK_SUCCESS(err);
15614
15615 VkMemoryRequirements memory_reqs;
15616 VkDeviceMemory buffer_memory;
15617 bool pass;
15618 VkMemoryAllocateInfo memory_info = {};
15619 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15620 memory_info.pNext = NULL;
15621 memory_info.allocationSize = 0;
15622 memory_info.memoryTypeIndex = 0;
15623
15624 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15625 memory_info.allocationSize = memory_reqs.size;
15626 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15627 ASSERT_TRUE(pass);
15628
15629 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15630 ASSERT_VK_SUCCESS(err);
15631 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15632 ASSERT_VK_SUCCESS(err);
15633
15634 VkBufferViewCreateInfo buff_view_ci = {};
15635 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15636 buff_view_ci.buffer = buffer;
15637 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15638 buff_view_ci.range = VK_WHOLE_SIZE;
15639 VkBufferView buffer_view;
15640 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15641
15642 VkDescriptorPoolSize ds_type_count = {};
15643 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15644 ds_type_count.descriptorCount = 1;
15645
15646 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15647 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15648 ds_pool_ci.pNext = NULL;
15649 ds_pool_ci.maxSets = 1;
15650 ds_pool_ci.poolSizeCount = 1;
15651 ds_pool_ci.pPoolSizes = &ds_type_count;
15652
15653 VkDescriptorPool ds_pool;
15654 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15655 ASSERT_VK_SUCCESS(err);
15656
15657 VkDescriptorSetLayoutBinding dsl_binding = {};
15658 dsl_binding.binding = 0;
15659 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15660 dsl_binding.descriptorCount = 1;
15661 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15662 dsl_binding.pImmutableSamplers = NULL;
15663
15664 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15665 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15666 ds_layout_ci.pNext = NULL;
15667 ds_layout_ci.bindingCount = 1;
15668 ds_layout_ci.pBindings = &dsl_binding;
15669 VkDescriptorSetLayout ds_layout;
15670 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15671 ASSERT_VK_SUCCESS(err);
15672
15673 VkDescriptorSet descriptor_set;
15674 VkDescriptorSetAllocateInfo alloc_info = {};
15675 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15676 alloc_info.descriptorSetCount = 1;
15677 alloc_info.descriptorPool = ds_pool;
15678 alloc_info.pSetLayouts = &ds_layout;
15679 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15680 ASSERT_VK_SUCCESS(err);
15681
15682 VkWriteDescriptorSet descriptor_write;
15683 memset(&descriptor_write, 0, sizeof(descriptor_write));
15684 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15685 descriptor_write.dstSet = descriptor_set;
15686 descriptor_write.dstBinding = 0;
15687 descriptor_write.descriptorCount = 1;
15688 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15689 descriptor_write.pTexelBufferView = &buffer_view;
15690
15691 // Set pImageInfo and pBufferInfo to invalid values, which should be
15692 // ignored for descriptorType ==
15693 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15694 // This will most likely produce a crash if the parameter_validation
15695 // layer
15696 // does not correctly ignore pImageInfo and pBufferInfo.
15697 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15698 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15699
15700 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15701
15702 m_errorMonitor->VerifyNotFound();
15703
15704 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15705 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15706 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15707 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15708 vkDestroyBuffer(m_device->device(), buffer, NULL);
15709 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15710 }
15711}
15712
Tobin Ehlisf7428442016-10-25 07:58:24 -060015713TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
15714 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
15715
15716 ASSERT_NO_FATAL_FAILURE(InitState());
15717 // Create layout where two binding #s are "1"
15718 static const uint32_t NUM_BINDINGS = 3;
15719 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15720 dsl_binding[0].binding = 1;
15721 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15722 dsl_binding[0].descriptorCount = 1;
15723 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15724 dsl_binding[0].pImmutableSamplers = NULL;
15725 dsl_binding[1].binding = 0;
15726 dsl_binding[1].descriptorCount = 1;
15727 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15728 dsl_binding[1].descriptorCount = 1;
15729 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15730 dsl_binding[1].pImmutableSamplers = NULL;
15731 dsl_binding[2].binding = 1; // Duplicate binding should cause error
15732 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15733 dsl_binding[2].descriptorCount = 1;
15734 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15735 dsl_binding[2].pImmutableSamplers = NULL;
15736
15737 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15738 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15739 ds_layout_ci.pNext = NULL;
15740 ds_layout_ci.bindingCount = NUM_BINDINGS;
15741 ds_layout_ci.pBindings = dsl_binding;
15742 VkDescriptorSetLayout ds_layout;
15743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
15744 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15745 m_errorMonitor->VerifyFound();
15746}
15747
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015748// This is a positive test. No failures are expected.
15749TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
15750 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
15751 VkResult err;
15752
15753 ASSERT_NO_FATAL_FAILURE(InitState());
15754 m_errorMonitor->ExpectSuccess();
15755 VkDescriptorPoolSize ds_type_count = {};
15756 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15757 ds_type_count.descriptorCount = 2;
15758
15759 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15760 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15761 ds_pool_ci.pNext = NULL;
15762 ds_pool_ci.maxSets = 1;
15763 ds_pool_ci.poolSizeCount = 1;
15764 ds_pool_ci.pPoolSizes = &ds_type_count;
15765
15766 VkDescriptorPool ds_pool;
15767 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15768 ASSERT_VK_SUCCESS(err);
15769
15770 // Create layout with two uniform buffer descriptors w/ empty binding between them
15771 static const uint32_t NUM_BINDINGS = 3;
15772 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15773 dsl_binding[0].binding = 0;
15774 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15775 dsl_binding[0].descriptorCount = 1;
15776 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
15777 dsl_binding[0].pImmutableSamplers = NULL;
15778 dsl_binding[1].binding = 1;
15779 dsl_binding[1].descriptorCount = 0; // empty binding
15780 dsl_binding[2].binding = 2;
15781 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15782 dsl_binding[2].descriptorCount = 1;
15783 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
15784 dsl_binding[2].pImmutableSamplers = NULL;
15785
15786 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15787 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15788 ds_layout_ci.pNext = NULL;
15789 ds_layout_ci.bindingCount = NUM_BINDINGS;
15790 ds_layout_ci.pBindings = dsl_binding;
15791 VkDescriptorSetLayout ds_layout;
15792 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15793 ASSERT_VK_SUCCESS(err);
15794
15795 VkDescriptorSet descriptor_set = {};
15796 VkDescriptorSetAllocateInfo alloc_info = {};
15797 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15798 alloc_info.descriptorSetCount = 1;
15799 alloc_info.descriptorPool = ds_pool;
15800 alloc_info.pSetLayouts = &ds_layout;
15801 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15802 ASSERT_VK_SUCCESS(err);
15803
15804 // Create a buffer to be used for update
15805 VkBufferCreateInfo buff_ci = {};
15806 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15807 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15808 buff_ci.size = 256;
15809 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15810 VkBuffer buffer;
15811 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
15812 ASSERT_VK_SUCCESS(err);
15813 // Have to bind memory to buffer before descriptor update
15814 VkMemoryAllocateInfo mem_alloc = {};
15815 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15816 mem_alloc.pNext = NULL;
15817 mem_alloc.allocationSize = 512; // one allocation for both buffers
15818 mem_alloc.memoryTypeIndex = 0;
15819
15820 VkMemoryRequirements mem_reqs;
15821 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
15822 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
15823 if (!pass) {
15824 vkDestroyBuffer(m_device->device(), buffer, NULL);
15825 return;
15826 }
15827
15828 VkDeviceMemory mem;
15829 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
15830 ASSERT_VK_SUCCESS(err);
15831 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
15832 ASSERT_VK_SUCCESS(err);
15833
15834 // Only update the descriptor at binding 2
15835 VkDescriptorBufferInfo buff_info = {};
15836 buff_info.buffer = buffer;
15837 buff_info.offset = 0;
15838 buff_info.range = VK_WHOLE_SIZE;
15839 VkWriteDescriptorSet descriptor_write = {};
15840 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15841 descriptor_write.dstBinding = 2;
15842 descriptor_write.descriptorCount = 1;
15843 descriptor_write.pTexelBufferView = nullptr;
15844 descriptor_write.pBufferInfo = &buff_info;
15845 descriptor_write.pImageInfo = nullptr;
15846 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15847 descriptor_write.dstSet = descriptor_set;
15848
15849 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15850
15851 m_errorMonitor->VerifyNotFound();
15852 // Cleanup
15853 vkFreeMemory(m_device->device(), mem, NULL);
15854 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15855 vkDestroyBuffer(m_device->device(), buffer, NULL);
15856 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15857}
15858
15859// This is a positive test. No failures are expected.
15860TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
15861 VkResult err;
15862 bool pass;
15863
15864 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
15865 "the buffer, create an image, and bind the same memory to "
15866 "it");
15867
15868 m_errorMonitor->ExpectSuccess();
15869
15870 ASSERT_NO_FATAL_FAILURE(InitState());
15871
15872 VkBuffer buffer;
15873 VkImage image;
15874 VkDeviceMemory mem;
15875 VkMemoryRequirements mem_reqs;
15876
15877 VkBufferCreateInfo buf_info = {};
15878 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15879 buf_info.pNext = NULL;
15880 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15881 buf_info.size = 256;
15882 buf_info.queueFamilyIndexCount = 0;
15883 buf_info.pQueueFamilyIndices = NULL;
15884 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15885 buf_info.flags = 0;
15886 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
15887 ASSERT_VK_SUCCESS(err);
15888
15889 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
15890
15891 VkMemoryAllocateInfo alloc_info = {};
15892 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15893 alloc_info.pNext = NULL;
15894 alloc_info.memoryTypeIndex = 0;
15895
15896 // Ensure memory is big enough for both bindings
15897 alloc_info.allocationSize = 0x10000;
15898
15899 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
15900 if (!pass) {
15901 vkDestroyBuffer(m_device->device(), buffer, NULL);
15902 return;
15903 }
15904
15905 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
15906 ASSERT_VK_SUCCESS(err);
15907
15908 uint8_t *pData;
15909 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
15910 ASSERT_VK_SUCCESS(err);
15911
15912 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
15913
15914 vkUnmapMemory(m_device->device(), mem);
15915
15916 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
15917 ASSERT_VK_SUCCESS(err);
15918
15919 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
15920 // memory. In fact, it was never used by the GPU.
15921 // Just be be sure, wait for idle.
15922 vkDestroyBuffer(m_device->device(), buffer, NULL);
15923 vkDeviceWaitIdle(m_device->device());
15924
15925 VkImageCreateInfo image_create_info = {};
15926 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15927 image_create_info.pNext = NULL;
15928 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15929 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
15930 image_create_info.extent.width = 64;
15931 image_create_info.extent.height = 64;
15932 image_create_info.extent.depth = 1;
15933 image_create_info.mipLevels = 1;
15934 image_create_info.arrayLayers = 1;
15935 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15936 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15937 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
15938 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15939 image_create_info.queueFamilyIndexCount = 0;
15940 image_create_info.pQueueFamilyIndices = NULL;
15941 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15942 image_create_info.flags = 0;
15943
15944 VkMemoryAllocateInfo mem_alloc = {};
15945 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15946 mem_alloc.pNext = NULL;
15947 mem_alloc.allocationSize = 0;
15948 mem_alloc.memoryTypeIndex = 0;
15949
15950 /* Create a mappable image. It will be the texture if linear images are ok
15951 * to be textures or it will be the staging image if they are not.
15952 */
15953 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15954 ASSERT_VK_SUCCESS(err);
15955
15956 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
15957
15958 mem_alloc.allocationSize = mem_reqs.size;
15959
15960 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
15961 if (!pass) {
15962 vkDestroyImage(m_device->device(), image, NULL);
15963 return;
15964 }
15965
15966 // VALIDATION FAILURE:
15967 err = vkBindImageMemory(m_device->device(), image, mem, 0);
15968 ASSERT_VK_SUCCESS(err);
15969
15970 m_errorMonitor->VerifyNotFound();
15971
15972 vkFreeMemory(m_device->device(), mem, NULL);
15973 vkDestroyBuffer(m_device->device(), buffer, NULL);
15974 vkDestroyImage(m_device->device(), image, NULL);
15975}
15976
15977TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
15978
15979 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
15980 "mapping while using VK_WHOLE_SIZE does not cause access "
15981 "violations");
15982 VkResult err;
15983 uint8_t *pData;
15984 ASSERT_NO_FATAL_FAILURE(InitState());
15985
15986 VkDeviceMemory mem;
15987 VkMemoryRequirements mem_reqs;
15988 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
15989 VkMemoryAllocateInfo alloc_info = {};
15990 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15991 alloc_info.pNext = NULL;
15992 alloc_info.memoryTypeIndex = 0;
15993
15994 static const VkDeviceSize allocation_size = 0x1000;
15995 alloc_info.allocationSize = allocation_size;
15996
15997 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
15998 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
15999 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16000 if (!pass) {
16001 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16002 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16003 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16004 if (!pass) {
16005 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16006 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16007 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16008 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16009 if (!pass) {
16010 return;
16011 }
16012 }
16013 }
16014
16015 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16016 ASSERT_VK_SUCCESS(err);
16017
16018 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16019 // mapped range
16020 m_errorMonitor->ExpectSuccess();
16021 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16022 ASSERT_VK_SUCCESS(err);
16023 VkMappedMemoryRange mmr = {};
16024 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16025 mmr.memory = mem;
16026 mmr.offset = 0;
16027 mmr.size = VK_WHOLE_SIZE;
16028 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16029 ASSERT_VK_SUCCESS(err);
16030 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16031 ASSERT_VK_SUCCESS(err);
16032 m_errorMonitor->VerifyNotFound();
16033 vkUnmapMemory(m_device->device(), mem);
16034
16035 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16036 // mapped range
16037 m_errorMonitor->ExpectSuccess();
16038 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16039 ASSERT_VK_SUCCESS(err);
16040 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16041 mmr.memory = mem;
16042 mmr.offset = 13;
16043 mmr.size = VK_WHOLE_SIZE;
16044 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16045 ASSERT_VK_SUCCESS(err);
16046 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16047 ASSERT_VK_SUCCESS(err);
16048 m_errorMonitor->VerifyNotFound();
16049 vkUnmapMemory(m_device->device(), mem);
16050
16051 // Map with prime offset and size
16052 // Flush/Invalidate subrange of mapped area with prime offset and size
16053 m_errorMonitor->ExpectSuccess();
16054 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16055 ASSERT_VK_SUCCESS(err);
16056 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16057 mmr.memory = mem;
16058 mmr.offset = allocation_size - 107;
16059 mmr.size = 61;
16060 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16061 ASSERT_VK_SUCCESS(err);
16062 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16063 ASSERT_VK_SUCCESS(err);
16064 m_errorMonitor->VerifyNotFound();
16065 vkUnmapMemory(m_device->device(), mem);
16066
16067 // Map without offset and flush WHOLE_SIZE with two separate offsets
16068 m_errorMonitor->ExpectSuccess();
16069 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16070 ASSERT_VK_SUCCESS(err);
16071 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16072 mmr.memory = mem;
16073 mmr.offset = allocation_size - 100;
16074 mmr.size = VK_WHOLE_SIZE;
16075 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16076 ASSERT_VK_SUCCESS(err);
16077 mmr.offset = allocation_size - 200;
16078 mmr.size = VK_WHOLE_SIZE;
16079 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16080 ASSERT_VK_SUCCESS(err);
16081 m_errorMonitor->VerifyNotFound();
16082 vkUnmapMemory(m_device->device(), mem);
16083
16084 vkFreeMemory(m_device->device(), mem, NULL);
16085}
16086
16087// This is a positive test. We used to expect error in this case but spec now allows it
16088TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16089 m_errorMonitor->ExpectSuccess();
16090 vk_testing::Fence testFence;
16091 VkFenceCreateInfo fenceInfo = {};
16092 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16093 fenceInfo.pNext = NULL;
16094
16095 ASSERT_NO_FATAL_FAILURE(InitState());
16096 testFence.init(*m_device, fenceInfo);
16097 VkFence fences[1] = { testFence.handle() };
16098 VkResult result = vkResetFences(m_device->device(), 1, fences);
16099 ASSERT_VK_SUCCESS(result);
16100
16101 m_errorMonitor->VerifyNotFound();
16102}
16103
16104TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16105 m_errorMonitor->ExpectSuccess();
16106
16107 ASSERT_NO_FATAL_FAILURE(InitState());
16108 VkResult err;
16109
16110 // Record (empty!) command buffer that can be submitted multiple times
16111 // simultaneously.
16112 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16113 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16114 m_commandBuffer->BeginCommandBuffer(&cbbi);
16115 m_commandBuffer->EndCommandBuffer();
16116
16117 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16118 VkFence fence;
16119 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16120 ASSERT_VK_SUCCESS(err);
16121
16122 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16123 VkSemaphore s1, s2;
16124 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16125 ASSERT_VK_SUCCESS(err);
16126 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16127 ASSERT_VK_SUCCESS(err);
16128
16129 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16130 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16131 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16132 ASSERT_VK_SUCCESS(err);
16133
16134 // Submit CB again, signaling s2.
16135 si.pSignalSemaphores = &s2;
16136 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16137 ASSERT_VK_SUCCESS(err);
16138
16139 // Wait for fence.
16140 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16141 ASSERT_VK_SUCCESS(err);
16142
16143 // CB is still in flight from second submission, but semaphore s1 is no
16144 // longer in flight. delete it.
16145 vkDestroySemaphore(m_device->device(), s1, nullptr);
16146
16147 m_errorMonitor->VerifyNotFound();
16148
16149 // Force device idle and clean up remaining objects
16150 vkDeviceWaitIdle(m_device->device());
16151 vkDestroySemaphore(m_device->device(), s2, nullptr);
16152 vkDestroyFence(m_device->device(), fence, nullptr);
16153}
16154
16155TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16156 m_errorMonitor->ExpectSuccess();
16157
16158 ASSERT_NO_FATAL_FAILURE(InitState());
16159 VkResult err;
16160
16161 // A fence created signaled
16162 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16163 VkFence f1;
16164 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16165 ASSERT_VK_SUCCESS(err);
16166
16167 // A fence created not
16168 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16169 VkFence f2;
16170 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16171 ASSERT_VK_SUCCESS(err);
16172
16173 // Submit the unsignaled fence
16174 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16175 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16176
16177 // Wait on both fences, with signaled first.
16178 VkFence fences[] = { f1, f2 };
16179 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16180
16181 // Should have both retired!
16182 vkDestroyFence(m_device->device(), f1, nullptr);
16183 vkDestroyFence(m_device->device(), f2, nullptr);
16184
16185 m_errorMonitor->VerifyNotFound();
16186}
16187
16188TEST_F(VkPositiveLayerTest, ValidUsage) {
16189 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16190 "doesn't generate validation errors");
16191
16192 ASSERT_NO_FATAL_FAILURE(InitState());
16193
16194 m_errorMonitor->ExpectSuccess();
16195 // Verify that we can create a view with usage INPUT_ATTACHMENT
16196 VkImageObj image(m_device);
16197 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16198 ASSERT_TRUE(image.initialized());
16199 VkImageView imageView;
16200 VkImageViewCreateInfo ivci = {};
16201 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16202 ivci.image = image.handle();
16203 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16204 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16205 ivci.subresourceRange.layerCount = 1;
16206 ivci.subresourceRange.baseMipLevel = 0;
16207 ivci.subresourceRange.levelCount = 1;
16208 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16209
16210 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16211 m_errorMonitor->VerifyNotFound();
16212 vkDestroyImageView(m_device->device(), imageView, NULL);
16213}
16214
16215// This is a positive test. No failures are expected.
16216TEST_F(VkPositiveLayerTest, BindSparse) {
16217 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16218 "and then free the memory");
16219
16220 ASSERT_NO_FATAL_FAILURE(InitState());
16221
16222 auto index = m_device->graphics_queue_node_index_;
16223 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16224 return;
16225
16226 m_errorMonitor->ExpectSuccess();
16227
16228 VkImage image;
16229 VkImageCreateInfo image_create_info = {};
16230 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16231 image_create_info.pNext = NULL;
16232 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16233 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16234 image_create_info.extent.width = 64;
16235 image_create_info.extent.height = 64;
16236 image_create_info.extent.depth = 1;
16237 image_create_info.mipLevels = 1;
16238 image_create_info.arrayLayers = 1;
16239 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16240 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16241 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16242 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16243 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16244 ASSERT_VK_SUCCESS(err);
16245
16246 VkMemoryRequirements memory_reqs;
16247 VkDeviceMemory memory_one, memory_two;
16248 bool pass;
16249 VkMemoryAllocateInfo memory_info = {};
16250 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16251 memory_info.pNext = NULL;
16252 memory_info.allocationSize = 0;
16253 memory_info.memoryTypeIndex = 0;
16254 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16255 // Find an image big enough to allow sparse mapping of 2 memory regions
16256 // Increase the image size until it is at least twice the
16257 // size of the required alignment, to ensure we can bind both
16258 // allocated memory blocks to the image on aligned offsets.
16259 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16260 vkDestroyImage(m_device->device(), image, nullptr);
16261 image_create_info.extent.width *= 2;
16262 image_create_info.extent.height *= 2;
16263 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16264 ASSERT_VK_SUCCESS(err);
16265 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16266 }
16267 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16268 // at the end of the first
16269 memory_info.allocationSize = memory_reqs.alignment;
16270 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16271 ASSERT_TRUE(pass);
16272 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16273 ASSERT_VK_SUCCESS(err);
16274 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16275 ASSERT_VK_SUCCESS(err);
16276 VkSparseMemoryBind binds[2];
16277 binds[0].flags = 0;
16278 binds[0].memory = memory_one;
16279 binds[0].memoryOffset = 0;
16280 binds[0].resourceOffset = 0;
16281 binds[0].size = memory_info.allocationSize;
16282 binds[1].flags = 0;
16283 binds[1].memory = memory_two;
16284 binds[1].memoryOffset = 0;
16285 binds[1].resourceOffset = memory_info.allocationSize;
16286 binds[1].size = memory_info.allocationSize;
16287
16288 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16289 opaqueBindInfo.image = image;
16290 opaqueBindInfo.bindCount = 2;
16291 opaqueBindInfo.pBinds = binds;
16292
16293 VkFence fence = VK_NULL_HANDLE;
16294 VkBindSparseInfo bindSparseInfo = {};
16295 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16296 bindSparseInfo.imageOpaqueBindCount = 1;
16297 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16298
16299 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16300 vkQueueWaitIdle(m_device->m_queue);
16301 vkDestroyImage(m_device->device(), image, NULL);
16302 vkFreeMemory(m_device->device(), memory_one, NULL);
16303 vkFreeMemory(m_device->device(), memory_two, NULL);
16304 m_errorMonitor->VerifyNotFound();
16305}
16306
16307TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16308 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16309 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16310 "the command buffer has prior knowledge of that "
16311 "attachment's layout.");
16312
16313 m_errorMonitor->ExpectSuccess();
16314
16315 ASSERT_NO_FATAL_FAILURE(InitState());
16316
16317 // A renderpass with one color attachment.
16318 VkAttachmentDescription attachment = { 0,
16319 VK_FORMAT_R8G8B8A8_UNORM,
16320 VK_SAMPLE_COUNT_1_BIT,
16321 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16322 VK_ATTACHMENT_STORE_OP_STORE,
16323 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16324 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16325 VK_IMAGE_LAYOUT_UNDEFINED,
16326 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16327
16328 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16329
16330 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16331
16332 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16333
16334 VkRenderPass rp;
16335 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16336 ASSERT_VK_SUCCESS(err);
16337
16338 // A compatible framebuffer.
16339 VkImageObj image(m_device);
16340 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16341 ASSERT_TRUE(image.initialized());
16342
16343 VkImageViewCreateInfo ivci = {
16344 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16345 nullptr,
16346 0,
16347 image.handle(),
16348 VK_IMAGE_VIEW_TYPE_2D,
16349 VK_FORMAT_R8G8B8A8_UNORM,
16350 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16351 VK_COMPONENT_SWIZZLE_IDENTITY },
16352 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16353 };
16354 VkImageView view;
16355 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16356 ASSERT_VK_SUCCESS(err);
16357
16358 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16359 VkFramebuffer fb;
16360 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16361 ASSERT_VK_SUCCESS(err);
16362
16363 // Record a single command buffer which uses this renderpass twice. The
16364 // bug is triggered at the beginning of the second renderpass, when the
16365 // command buffer already has a layout recorded for the attachment.
16366 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16367 BeginCommandBuffer();
16368 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16369 vkCmdEndRenderPass(m_commandBuffer->handle());
16370 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16371
16372 m_errorMonitor->VerifyNotFound();
16373
16374 vkCmdEndRenderPass(m_commandBuffer->handle());
16375 EndCommandBuffer();
16376
16377 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16378 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16379 vkDestroyImageView(m_device->device(), view, nullptr);
16380}
16381
16382TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16383 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16384 "command buffer, bind them together, then destroy "
16385 "command pool and framebuffer and verify there are no "
16386 "errors.");
16387
16388 m_errorMonitor->ExpectSuccess();
16389
16390 ASSERT_NO_FATAL_FAILURE(InitState());
16391
16392 // A renderpass with one color attachment.
16393 VkAttachmentDescription attachment = { 0,
16394 VK_FORMAT_R8G8B8A8_UNORM,
16395 VK_SAMPLE_COUNT_1_BIT,
16396 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16397 VK_ATTACHMENT_STORE_OP_STORE,
16398 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16399 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16400 VK_IMAGE_LAYOUT_UNDEFINED,
16401 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16402
16403 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16404
16405 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16406
16407 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16408
16409 VkRenderPass rp;
16410 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16411 ASSERT_VK_SUCCESS(err);
16412
16413 // A compatible framebuffer.
16414 VkImageObj image(m_device);
16415 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16416 ASSERT_TRUE(image.initialized());
16417
16418 VkImageViewCreateInfo ivci = {
16419 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16420 nullptr,
16421 0,
16422 image.handle(),
16423 VK_IMAGE_VIEW_TYPE_2D,
16424 VK_FORMAT_R8G8B8A8_UNORM,
16425 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16426 VK_COMPONENT_SWIZZLE_IDENTITY },
16427 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16428 };
16429 VkImageView view;
16430 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16431 ASSERT_VK_SUCCESS(err);
16432
16433 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16434 VkFramebuffer fb;
16435 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16436 ASSERT_VK_SUCCESS(err);
16437
16438 // Explicitly create a command buffer to bind the FB to so that we can then
16439 // destroy the command pool in order to implicitly free command buffer
16440 VkCommandPool command_pool;
16441 VkCommandPoolCreateInfo pool_create_info{};
16442 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16443 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16444 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16445 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16446
16447 VkCommandBuffer command_buffer;
16448 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16449 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16450 command_buffer_allocate_info.commandPool = command_pool;
16451 command_buffer_allocate_info.commandBufferCount = 1;
16452 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16453 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16454
16455 // Begin our cmd buffer with renderpass using our framebuffer
16456 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16457 VkCommandBufferBeginInfo begin_info{};
16458 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16459 vkBeginCommandBuffer(command_buffer, &begin_info);
16460
16461 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16462 vkCmdEndRenderPass(command_buffer);
16463 vkEndCommandBuffer(command_buffer);
16464 vkDestroyImageView(m_device->device(), view, nullptr);
16465 // Destroy command pool to implicitly free command buffer
16466 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16467 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16468 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16469 m_errorMonitor->VerifyNotFound();
16470}
16471
16472TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16473 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16474 "transitions for the first subpass");
16475
16476 m_errorMonitor->ExpectSuccess();
16477
16478 ASSERT_NO_FATAL_FAILURE(InitState());
16479
16480 // A renderpass with one color attachment.
16481 VkAttachmentDescription attachment = { 0,
16482 VK_FORMAT_R8G8B8A8_UNORM,
16483 VK_SAMPLE_COUNT_1_BIT,
16484 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16485 VK_ATTACHMENT_STORE_OP_STORE,
16486 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16487 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16488 VK_IMAGE_LAYOUT_UNDEFINED,
16489 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16490
16491 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16492
16493 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16494
16495 VkSubpassDependency dep = { 0,
16496 0,
16497 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16498 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16499 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16500 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16501 VK_DEPENDENCY_BY_REGION_BIT };
16502
16503 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16504
16505 VkResult err;
16506 VkRenderPass rp;
16507 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16508 ASSERT_VK_SUCCESS(err);
16509
16510 // A compatible framebuffer.
16511 VkImageObj image(m_device);
16512 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16513 ASSERT_TRUE(image.initialized());
16514
16515 VkImageViewCreateInfo ivci = {
16516 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16517 nullptr,
16518 0,
16519 image.handle(),
16520 VK_IMAGE_VIEW_TYPE_2D,
16521 VK_FORMAT_R8G8B8A8_UNORM,
16522 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16523 VK_COMPONENT_SWIZZLE_IDENTITY },
16524 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16525 };
16526 VkImageView view;
16527 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16528 ASSERT_VK_SUCCESS(err);
16529
16530 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16531 VkFramebuffer fb;
16532 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16533 ASSERT_VK_SUCCESS(err);
16534
16535 // Record a single command buffer which issues a pipeline barrier w/
16536 // image memory barrier for the attachment. This detects the previously
16537 // missing tracking of the subpass layout by throwing a validation error
16538 // if it doesn't occur.
16539 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16540 BeginCommandBuffer();
16541 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16542
16543 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
16544 nullptr,
16545 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16546 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16547 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16548 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16549 VK_QUEUE_FAMILY_IGNORED,
16550 VK_QUEUE_FAMILY_IGNORED,
16551 image.handle(),
16552 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
16553 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16554 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16555 &imb);
16556
16557 vkCmdEndRenderPass(m_commandBuffer->handle());
16558 m_errorMonitor->VerifyNotFound();
16559 EndCommandBuffer();
16560
16561 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16562 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16563 vkDestroyImageView(m_device->device(), view, nullptr);
16564}
16565
16566TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
16567 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
16568 "is used as a depth/stencil framebuffer attachment, the "
16569 "aspectMask is ignored and both depth and stencil image "
16570 "subresources are used.");
16571
16572 VkFormatProperties format_properties;
16573 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
16574 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
16575 return;
16576 }
16577
16578 m_errorMonitor->ExpectSuccess();
16579
16580 ASSERT_NO_FATAL_FAILURE(InitState());
16581
16582 VkAttachmentDescription attachment = { 0,
16583 VK_FORMAT_D32_SFLOAT_S8_UINT,
16584 VK_SAMPLE_COUNT_1_BIT,
16585 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16586 VK_ATTACHMENT_STORE_OP_STORE,
16587 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16588 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16589 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
16590 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16591
16592 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16593
16594 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
16595
16596 VkSubpassDependency dep = { 0,
16597 0,
16598 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16599 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16600 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16601 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16602 VK_DEPENDENCY_BY_REGION_BIT};
16603
16604 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16605
16606 VkResult err;
16607 VkRenderPass rp;
16608 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16609 ASSERT_VK_SUCCESS(err);
16610
16611 VkImageObj image(m_device);
16612 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
16613 0x26, // usage
16614 VK_IMAGE_TILING_OPTIMAL, 0);
16615 ASSERT_TRUE(image.initialized());
16616 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
16617
16618 VkImageViewCreateInfo ivci = {
16619 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16620 nullptr,
16621 0,
16622 image.handle(),
16623 VK_IMAGE_VIEW_TYPE_2D,
16624 VK_FORMAT_D32_SFLOAT_S8_UINT,
16625 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
16626 { 0x2, 0, 1, 0, 1 },
16627 };
16628 VkImageView view;
16629 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16630 ASSERT_VK_SUCCESS(err);
16631
16632 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16633 VkFramebuffer fb;
16634 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16635 ASSERT_VK_SUCCESS(err);
16636
16637 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16638 BeginCommandBuffer();
16639 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16640
16641 VkImageMemoryBarrier imb = {};
16642 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16643 imb.pNext = nullptr;
16644 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16645 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16646 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16647 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16648 imb.srcQueueFamilyIndex = 0;
16649 imb.dstQueueFamilyIndex = 0;
16650 imb.image = image.handle();
16651 imb.subresourceRange.aspectMask = 0x6;
16652 imb.subresourceRange.baseMipLevel = 0;
16653 imb.subresourceRange.levelCount = 0x1;
16654 imb.subresourceRange.baseArrayLayer = 0;
16655 imb.subresourceRange.layerCount = 0x1;
16656
16657 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16658 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16659 &imb);
16660
16661 vkCmdEndRenderPass(m_commandBuffer->handle());
16662 EndCommandBuffer();
16663 QueueCommandBuffer(false);
16664 m_errorMonitor->VerifyNotFound();
16665
16666 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16667 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16668 vkDestroyImageView(m_device->device(), view, nullptr);
16669}
16670
16671TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
16672 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
16673 "errors, when an attachment reference is "
16674 "VK_ATTACHMENT_UNUSED");
16675
16676 m_errorMonitor->ExpectSuccess();
16677
16678 ASSERT_NO_FATAL_FAILURE(InitState());
16679
16680 // A renderpass with no attachments
16681 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16682
16683 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16684
16685 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
16686
16687 VkRenderPass rp;
16688 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16689 ASSERT_VK_SUCCESS(err);
16690
16691 // A compatible framebuffer.
16692 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
16693 VkFramebuffer fb;
16694 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16695 ASSERT_VK_SUCCESS(err);
16696
16697 // Record a command buffer which just begins and ends the renderpass. The
16698 // bug manifests in BeginRenderPass.
16699 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16700 BeginCommandBuffer();
16701 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16702 vkCmdEndRenderPass(m_commandBuffer->handle());
16703 m_errorMonitor->VerifyNotFound();
16704 EndCommandBuffer();
16705
16706 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16707 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16708}
16709
16710// This is a positive test. No errors are expected.
16711TEST_F(VkPositiveLayerTest, StencilLoadOp) {
16712 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
16713 "CLEAR. stencil[Load|Store]Op used to be ignored.");
16714 VkResult result = VK_SUCCESS;
16715 VkImageFormatProperties formatProps;
16716 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
16717 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
16718 &formatProps);
16719 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
16720 return;
16721 }
16722
16723 ASSERT_NO_FATAL_FAILURE(InitState());
16724 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
16725 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
16726 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
16727 VkAttachmentDescription att = {};
16728 VkAttachmentReference ref = {};
16729 att.format = depth_stencil_fmt;
16730 att.samples = VK_SAMPLE_COUNT_1_BIT;
16731 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
16732 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
16733 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
16734 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
16735 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16736 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16737
16738 VkClearValue clear;
16739 clear.depthStencil.depth = 1.0;
16740 clear.depthStencil.stencil = 0;
16741 ref.attachment = 0;
16742 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16743
16744 VkSubpassDescription subpass = {};
16745 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
16746 subpass.flags = 0;
16747 subpass.inputAttachmentCount = 0;
16748 subpass.pInputAttachments = NULL;
16749 subpass.colorAttachmentCount = 0;
16750 subpass.pColorAttachments = NULL;
16751 subpass.pResolveAttachments = NULL;
16752 subpass.pDepthStencilAttachment = &ref;
16753 subpass.preserveAttachmentCount = 0;
16754 subpass.pPreserveAttachments = NULL;
16755
16756 VkRenderPass rp;
16757 VkRenderPassCreateInfo rp_info = {};
16758 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16759 rp_info.attachmentCount = 1;
16760 rp_info.pAttachments = &att;
16761 rp_info.subpassCount = 1;
16762 rp_info.pSubpasses = &subpass;
16763 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
16764 ASSERT_VK_SUCCESS(result);
16765
16766 VkImageView *depthView = m_depthStencil->BindInfo();
16767 VkFramebufferCreateInfo fb_info = {};
16768 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
16769 fb_info.pNext = NULL;
16770 fb_info.renderPass = rp;
16771 fb_info.attachmentCount = 1;
16772 fb_info.pAttachments = depthView;
16773 fb_info.width = 100;
16774 fb_info.height = 100;
16775 fb_info.layers = 1;
16776 VkFramebuffer fb;
16777 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
16778 ASSERT_VK_SUCCESS(result);
16779
16780 VkRenderPassBeginInfo rpbinfo = {};
16781 rpbinfo.clearValueCount = 1;
16782 rpbinfo.pClearValues = &clear;
16783 rpbinfo.pNext = NULL;
16784 rpbinfo.renderPass = rp;
16785 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
16786 rpbinfo.renderArea.extent.width = 100;
16787 rpbinfo.renderArea.extent.height = 100;
16788 rpbinfo.renderArea.offset.x = 0;
16789 rpbinfo.renderArea.offset.y = 0;
16790 rpbinfo.framebuffer = fb;
16791
16792 VkFence fence = {};
16793 VkFenceCreateInfo fence_ci = {};
16794 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16795 fence_ci.pNext = nullptr;
16796 fence_ci.flags = 0;
16797 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
16798 ASSERT_VK_SUCCESS(result);
16799
16800 m_commandBuffer->BeginCommandBuffer();
16801 m_commandBuffer->BeginRenderPass(rpbinfo);
16802 m_commandBuffer->EndRenderPass();
16803 m_commandBuffer->EndCommandBuffer();
16804 m_commandBuffer->QueueCommandBuffer(fence);
16805
16806 VkImageObj destImage(m_device);
16807 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16808 VK_IMAGE_TILING_OPTIMAL, 0);
16809 VkImageMemoryBarrier barrier = {};
16810 VkImageSubresourceRange range;
16811 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16812 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16813 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
16814 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16815 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
16816 barrier.image = m_depthStencil->handle();
16817 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16818 range.baseMipLevel = 0;
16819 range.levelCount = 1;
16820 range.baseArrayLayer = 0;
16821 range.layerCount = 1;
16822 barrier.subresourceRange = range;
16823 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16824 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
16825 cmdbuf.BeginCommandBuffer();
16826 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
16827 &barrier);
16828 barrier.srcAccessMask = 0;
16829 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16830 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
16831 barrier.image = destImage.handle();
16832 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16833 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
16834 &barrier);
16835 VkImageCopy cregion;
16836 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16837 cregion.srcSubresource.mipLevel = 0;
16838 cregion.srcSubresource.baseArrayLayer = 0;
16839 cregion.srcSubresource.layerCount = 1;
16840 cregion.srcOffset.x = 0;
16841 cregion.srcOffset.y = 0;
16842 cregion.srcOffset.z = 0;
16843 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16844 cregion.dstSubresource.mipLevel = 0;
16845 cregion.dstSubresource.baseArrayLayer = 0;
16846 cregion.dstSubresource.layerCount = 1;
16847 cregion.dstOffset.x = 0;
16848 cregion.dstOffset.y = 0;
16849 cregion.dstOffset.z = 0;
16850 cregion.extent.width = 100;
16851 cregion.extent.height = 100;
16852 cregion.extent.depth = 1;
16853 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
16854 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
16855 cmdbuf.EndCommandBuffer();
16856
16857 VkSubmitInfo submit_info;
16858 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16859 submit_info.pNext = NULL;
16860 submit_info.waitSemaphoreCount = 0;
16861 submit_info.pWaitSemaphores = NULL;
16862 submit_info.pWaitDstStageMask = NULL;
16863 submit_info.commandBufferCount = 1;
16864 submit_info.pCommandBuffers = &cmdbuf.handle();
16865 submit_info.signalSemaphoreCount = 0;
16866 submit_info.pSignalSemaphores = NULL;
16867
16868 m_errorMonitor->ExpectSuccess();
16869 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16870 m_errorMonitor->VerifyNotFound();
16871
16872 vkQueueWaitIdle(m_device->m_queue);
16873 vkDestroyFence(m_device->device(), fence, nullptr);
16874 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16875 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16876}
16877
16878// This is a positive test. No errors should be generated.
16879TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
16880 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
16881
16882 m_errorMonitor->ExpectSuccess();
16883 ASSERT_NO_FATAL_FAILURE(InitState());
16884
16885 VkEvent event;
16886 VkEventCreateInfo event_create_info{};
16887 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
16888 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
16889
16890 VkCommandPool command_pool;
16891 VkCommandPoolCreateInfo pool_create_info{};
16892 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16893 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16894 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16895 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16896
16897 VkCommandBuffer command_buffer;
16898 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16899 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16900 command_buffer_allocate_info.commandPool = command_pool;
16901 command_buffer_allocate_info.commandBufferCount = 1;
16902 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16903 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16904
16905 VkQueue queue = VK_NULL_HANDLE;
16906 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
16907
16908 {
16909 VkCommandBufferBeginInfo begin_info{};
16910 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16911 vkBeginCommandBuffer(command_buffer, &begin_info);
16912
16913 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
16914 nullptr, 0, nullptr);
16915 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
16916 vkEndCommandBuffer(command_buffer);
16917 }
16918 {
16919 VkSubmitInfo submit_info{};
16920 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16921 submit_info.commandBufferCount = 1;
16922 submit_info.pCommandBuffers = &command_buffer;
16923 submit_info.signalSemaphoreCount = 0;
16924 submit_info.pSignalSemaphores = nullptr;
16925 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
16926 }
16927 { vkSetEvent(m_device->device(), event); }
16928
16929 vkQueueWaitIdle(queue);
16930
16931 vkDestroyEvent(m_device->device(), event, nullptr);
16932 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
16933 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16934
16935 m_errorMonitor->VerifyNotFound();
16936}
16937// This is a positive test. No errors should be generated.
16938TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
16939 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
16940
16941 ASSERT_NO_FATAL_FAILURE(InitState());
16942 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
16943 return;
16944
16945 m_errorMonitor->ExpectSuccess();
16946
16947 VkQueryPool query_pool;
16948 VkQueryPoolCreateInfo query_pool_create_info{};
16949 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
16950 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
16951 query_pool_create_info.queryCount = 1;
16952 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
16953
16954 VkCommandPool command_pool;
16955 VkCommandPoolCreateInfo pool_create_info{};
16956 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16957 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16958 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16959 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16960
16961 VkCommandBuffer command_buffer;
16962 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16963 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16964 command_buffer_allocate_info.commandPool = command_pool;
16965 command_buffer_allocate_info.commandBufferCount = 1;
16966 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16967 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16968
16969 VkCommandBuffer secondary_command_buffer;
16970 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16971 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_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 VkCommandBufferInheritanceInfo hinfo = {};
17009 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17010 hinfo.renderPass = VK_NULL_HANDLE;
17011 hinfo.subpass = 0;
17012 hinfo.framebuffer = VK_NULL_HANDLE;
17013 hinfo.occlusionQueryEnable = VK_FALSE;
17014 hinfo.queryFlags = 0;
17015 hinfo.pipelineStatistics = 0;
17016
17017 {
17018 VkCommandBufferBeginInfo begin_info{};
17019 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17020 begin_info.pInheritanceInfo = &hinfo;
17021 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17022
17023 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17024 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17025
17026 vkEndCommandBuffer(secondary_command_buffer);
17027
17028 begin_info.pInheritanceInfo = nullptr;
17029 vkBeginCommandBuffer(command_buffer, &begin_info);
17030
17031 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17032 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17033
17034 vkEndCommandBuffer(command_buffer);
17035 }
17036 {
17037 VkSubmitInfo submit_info{};
17038 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17039 submit_info.commandBufferCount = 1;
17040 submit_info.pCommandBuffers = &command_buffer;
17041 submit_info.signalSemaphoreCount = 0;
17042 submit_info.pSignalSemaphores = nullptr;
17043 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17044 }
17045
17046 vkQueueWaitIdle(queue);
17047
17048 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17049 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17050 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17051 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17052 vkDestroyBuffer(m_device->device(), buffer, NULL);
17053 vkFreeMemory(m_device->device(), mem, NULL);
17054
17055 m_errorMonitor->VerifyNotFound();
17056}
17057
17058// This is a positive test. No errors should be generated.
17059TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17060 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17061
17062 ASSERT_NO_FATAL_FAILURE(InitState());
17063 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17064 return;
17065
17066 m_errorMonitor->ExpectSuccess();
17067
17068 VkQueryPool query_pool;
17069 VkQueryPoolCreateInfo query_pool_create_info{};
17070 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17071 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17072 query_pool_create_info.queryCount = 1;
17073 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17074
17075 VkCommandPool command_pool;
17076 VkCommandPoolCreateInfo pool_create_info{};
17077 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17078 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17079 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17080 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17081
17082 VkCommandBuffer command_buffer[2];
17083 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17084 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17085 command_buffer_allocate_info.commandPool = command_pool;
17086 command_buffer_allocate_info.commandBufferCount = 2;
17087 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17088 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17089
17090 VkQueue queue = VK_NULL_HANDLE;
17091 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17092
17093 uint32_t qfi = 0;
17094 VkBufferCreateInfo buff_create_info = {};
17095 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17096 buff_create_info.size = 1024;
17097 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17098 buff_create_info.queueFamilyIndexCount = 1;
17099 buff_create_info.pQueueFamilyIndices = &qfi;
17100
17101 VkResult err;
17102 VkBuffer buffer;
17103 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17104 ASSERT_VK_SUCCESS(err);
17105 VkMemoryAllocateInfo mem_alloc = {};
17106 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17107 mem_alloc.pNext = NULL;
17108 mem_alloc.allocationSize = 1024;
17109 mem_alloc.memoryTypeIndex = 0;
17110
17111 VkMemoryRequirements memReqs;
17112 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17113 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17114 if (!pass) {
17115 vkDestroyBuffer(m_device->device(), buffer, NULL);
17116 return;
17117 }
17118
17119 VkDeviceMemory mem;
17120 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17121 ASSERT_VK_SUCCESS(err);
17122 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17123 ASSERT_VK_SUCCESS(err);
17124
17125 {
17126 VkCommandBufferBeginInfo begin_info{};
17127 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17128 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17129
17130 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17131 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17132
17133 vkEndCommandBuffer(command_buffer[0]);
17134
17135 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17136
17137 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17138
17139 vkEndCommandBuffer(command_buffer[1]);
17140 }
17141 {
17142 VkSubmitInfo submit_info{};
17143 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17144 submit_info.commandBufferCount = 2;
17145 submit_info.pCommandBuffers = command_buffer;
17146 submit_info.signalSemaphoreCount = 0;
17147 submit_info.pSignalSemaphores = nullptr;
17148 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17149 }
17150
17151 vkQueueWaitIdle(queue);
17152
17153 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17154 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17155 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17156 vkDestroyBuffer(m_device->device(), buffer, NULL);
17157 vkFreeMemory(m_device->device(), mem, NULL);
17158
17159 m_errorMonitor->VerifyNotFound();
17160}
17161
17162TEST_F(VkPositiveLayerTest, ResetEventThenSet) {
17163 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17164
17165 m_errorMonitor->ExpectSuccess();
17166
17167 ASSERT_NO_FATAL_FAILURE(InitState());
17168 VkEvent event;
17169 VkEventCreateInfo event_create_info{};
17170 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17171 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17172
17173 VkCommandPool command_pool;
17174 VkCommandPoolCreateInfo pool_create_info{};
17175 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17176 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17177 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17178 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17179
17180 VkCommandBuffer command_buffer;
17181 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17182 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17183 command_buffer_allocate_info.commandPool = command_pool;
17184 command_buffer_allocate_info.commandBufferCount = 1;
17185 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17186 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17187
17188 VkQueue queue = VK_NULL_HANDLE;
17189 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17190
17191 {
17192 VkCommandBufferBeginInfo begin_info{};
17193 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17194 vkBeginCommandBuffer(command_buffer, &begin_info);
17195
17196 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17197 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
17198 nullptr, 0, nullptr, 0, nullptr);
17199 vkEndCommandBuffer(command_buffer);
17200 }
17201 {
17202 VkSubmitInfo submit_info{};
17203 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17204 submit_info.commandBufferCount = 1;
17205 submit_info.pCommandBuffers = &command_buffer;
17206 submit_info.signalSemaphoreCount = 0;
17207 submit_info.pSignalSemaphores = nullptr;
17208 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17209 }
17210 {
17211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17212 "command buffer.");
17213 vkSetEvent(m_device->device(), event);
17214 m_errorMonitor->VerifyFound();
17215 }
17216
17217 vkQueueWaitIdle(queue);
17218
17219 vkDestroyEvent(m_device->device(), event, nullptr);
17220 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17221 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17222}
17223
17224// This is a positive test. No errors should be generated.
17225TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17226 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17227 "run through a Submit & WaitForFences cycle 3 times. This "
17228 "previously revealed a bug so running this positive test "
17229 "to prevent a regression.");
17230 m_errorMonitor->ExpectSuccess();
17231
17232 ASSERT_NO_FATAL_FAILURE(InitState());
17233 VkQueue queue = VK_NULL_HANDLE;
17234 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17235
17236 static const uint32_t NUM_OBJECTS = 2;
17237 static const uint32_t NUM_FRAMES = 3;
17238 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17239 VkFence fences[NUM_OBJECTS] = {};
17240
17241 VkCommandPool cmd_pool;
17242 VkCommandPoolCreateInfo cmd_pool_ci = {};
17243 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17244 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17245 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17246 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17247 ASSERT_VK_SUCCESS(err);
17248
17249 VkCommandBufferAllocateInfo cmd_buf_info = {};
17250 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17251 cmd_buf_info.commandPool = cmd_pool;
17252 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17253 cmd_buf_info.commandBufferCount = 1;
17254
17255 VkFenceCreateInfo fence_ci = {};
17256 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17257 fence_ci.pNext = nullptr;
17258 fence_ci.flags = 0;
17259
17260 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17261 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17262 ASSERT_VK_SUCCESS(err);
17263 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17264 ASSERT_VK_SUCCESS(err);
17265 }
17266
17267 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17268 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17269 // Create empty cmd buffer
17270 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17271 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17272
17273 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17274 ASSERT_VK_SUCCESS(err);
17275 err = vkEndCommandBuffer(cmd_buffers[obj]);
17276 ASSERT_VK_SUCCESS(err);
17277
17278 VkSubmitInfo submit_info = {};
17279 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17280 submit_info.commandBufferCount = 1;
17281 submit_info.pCommandBuffers = &cmd_buffers[obj];
17282 // Submit cmd buffer and wait for fence
17283 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17284 ASSERT_VK_SUCCESS(err);
17285 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17286 ASSERT_VK_SUCCESS(err);
17287 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17288 ASSERT_VK_SUCCESS(err);
17289 }
17290 }
17291 m_errorMonitor->VerifyNotFound();
17292 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17293 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17294 vkDestroyFence(m_device->device(), fences[i], nullptr);
17295 }
17296}
17297// This is a positive test. No errors should be generated.
17298TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17299
17300 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17301 "submitted on separate queues followed by a QueueWaitIdle.");
17302
17303 ASSERT_NO_FATAL_FAILURE(InitState());
17304 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17305 return;
17306
17307 m_errorMonitor->ExpectSuccess();
17308
17309 VkSemaphore semaphore;
17310 VkSemaphoreCreateInfo semaphore_create_info{};
17311 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17312 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17313
17314 VkCommandPool command_pool;
17315 VkCommandPoolCreateInfo pool_create_info{};
17316 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17317 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17318 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17319 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17320
17321 VkCommandBuffer command_buffer[2];
17322 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17323 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17324 command_buffer_allocate_info.commandPool = command_pool;
17325 command_buffer_allocate_info.commandBufferCount = 2;
17326 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17327 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17328
17329 VkQueue queue = VK_NULL_HANDLE;
17330 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17331
17332 {
17333 VkCommandBufferBeginInfo begin_info{};
17334 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17335 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17336
17337 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17338 nullptr, 0, nullptr, 0, nullptr);
17339
17340 VkViewport viewport{};
17341 viewport.maxDepth = 1.0f;
17342 viewport.minDepth = 0.0f;
17343 viewport.width = 512;
17344 viewport.height = 512;
17345 viewport.x = 0;
17346 viewport.y = 0;
17347 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17348 vkEndCommandBuffer(command_buffer[0]);
17349 }
17350 {
17351 VkCommandBufferBeginInfo begin_info{};
17352 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17353 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17354
17355 VkViewport viewport{};
17356 viewport.maxDepth = 1.0f;
17357 viewport.minDepth = 0.0f;
17358 viewport.width = 512;
17359 viewport.height = 512;
17360 viewport.x = 0;
17361 viewport.y = 0;
17362 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17363 vkEndCommandBuffer(command_buffer[1]);
17364 }
17365 {
17366 VkSubmitInfo submit_info{};
17367 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17368 submit_info.commandBufferCount = 1;
17369 submit_info.pCommandBuffers = &command_buffer[0];
17370 submit_info.signalSemaphoreCount = 1;
17371 submit_info.pSignalSemaphores = &semaphore;
17372 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17373 }
17374 {
17375 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17376 VkSubmitInfo submit_info{};
17377 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17378 submit_info.commandBufferCount = 1;
17379 submit_info.pCommandBuffers = &command_buffer[1];
17380 submit_info.waitSemaphoreCount = 1;
17381 submit_info.pWaitSemaphores = &semaphore;
17382 submit_info.pWaitDstStageMask = flags;
17383 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17384 }
17385
17386 vkQueueWaitIdle(m_device->m_queue);
17387
17388 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17389 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17390 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17391
17392 m_errorMonitor->VerifyNotFound();
17393}
17394
17395// This is a positive test. No errors should be generated.
17396TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17397
17398 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17399 "submitted on separate queues, the second having a fence"
17400 "followed by a QueueWaitIdle.");
17401
17402 ASSERT_NO_FATAL_FAILURE(InitState());
17403 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17404 return;
17405
17406 m_errorMonitor->ExpectSuccess();
17407
17408 VkFence fence;
17409 VkFenceCreateInfo fence_create_info{};
17410 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17411 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17412
17413 VkSemaphore semaphore;
17414 VkSemaphoreCreateInfo semaphore_create_info{};
17415 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17416 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17417
17418 VkCommandPool command_pool;
17419 VkCommandPoolCreateInfo pool_create_info{};
17420 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17421 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17422 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17423 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17424
17425 VkCommandBuffer command_buffer[2];
17426 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17427 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17428 command_buffer_allocate_info.commandPool = command_pool;
17429 command_buffer_allocate_info.commandBufferCount = 2;
17430 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17431 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17432
17433 VkQueue queue = VK_NULL_HANDLE;
17434 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17435
17436 {
17437 VkCommandBufferBeginInfo begin_info{};
17438 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17439 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17440
17441 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17442 nullptr, 0, nullptr, 0, nullptr);
17443
17444 VkViewport viewport{};
17445 viewport.maxDepth = 1.0f;
17446 viewport.minDepth = 0.0f;
17447 viewport.width = 512;
17448 viewport.height = 512;
17449 viewport.x = 0;
17450 viewport.y = 0;
17451 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17452 vkEndCommandBuffer(command_buffer[0]);
17453 }
17454 {
17455 VkCommandBufferBeginInfo begin_info{};
17456 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17457 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17458
17459 VkViewport viewport{};
17460 viewport.maxDepth = 1.0f;
17461 viewport.minDepth = 0.0f;
17462 viewport.width = 512;
17463 viewport.height = 512;
17464 viewport.x = 0;
17465 viewport.y = 0;
17466 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17467 vkEndCommandBuffer(command_buffer[1]);
17468 }
17469 {
17470 VkSubmitInfo submit_info{};
17471 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17472 submit_info.commandBufferCount = 1;
17473 submit_info.pCommandBuffers = &command_buffer[0];
17474 submit_info.signalSemaphoreCount = 1;
17475 submit_info.pSignalSemaphores = &semaphore;
17476 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17477 }
17478 {
17479 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17480 VkSubmitInfo submit_info{};
17481 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17482 submit_info.commandBufferCount = 1;
17483 submit_info.pCommandBuffers = &command_buffer[1];
17484 submit_info.waitSemaphoreCount = 1;
17485 submit_info.pWaitSemaphores = &semaphore;
17486 submit_info.pWaitDstStageMask = flags;
17487 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17488 }
17489
17490 vkQueueWaitIdle(m_device->m_queue);
17491
17492 vkDestroyFence(m_device->device(), fence, nullptr);
17493 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17494 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17495 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17496
17497 m_errorMonitor->VerifyNotFound();
17498}
17499
17500// This is a positive test. No errors should be generated.
17501TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17502
17503 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17504 "submitted on separate queues, the second having a fence"
17505 "followed by two consecutive WaitForFences calls on the same fence.");
17506
17507 ASSERT_NO_FATAL_FAILURE(InitState());
17508 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17509 return;
17510
17511 m_errorMonitor->ExpectSuccess();
17512
17513 VkFence fence;
17514 VkFenceCreateInfo fence_create_info{};
17515 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17516 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17517
17518 VkSemaphore semaphore;
17519 VkSemaphoreCreateInfo semaphore_create_info{};
17520 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17521 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17522
17523 VkCommandPool command_pool;
17524 VkCommandPoolCreateInfo pool_create_info{};
17525 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17526 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17527 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17528 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17529
17530 VkCommandBuffer command_buffer[2];
17531 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17532 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17533 command_buffer_allocate_info.commandPool = command_pool;
17534 command_buffer_allocate_info.commandBufferCount = 2;
17535 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17536 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17537
17538 VkQueue queue = VK_NULL_HANDLE;
17539 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17540
17541 {
17542 VkCommandBufferBeginInfo begin_info{};
17543 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17544 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17545
17546 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17547 nullptr, 0, nullptr, 0, nullptr);
17548
17549 VkViewport viewport{};
17550 viewport.maxDepth = 1.0f;
17551 viewport.minDepth = 0.0f;
17552 viewport.width = 512;
17553 viewport.height = 512;
17554 viewport.x = 0;
17555 viewport.y = 0;
17556 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17557 vkEndCommandBuffer(command_buffer[0]);
17558 }
17559 {
17560 VkCommandBufferBeginInfo begin_info{};
17561 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17562 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17563
17564 VkViewport viewport{};
17565 viewport.maxDepth = 1.0f;
17566 viewport.minDepth = 0.0f;
17567 viewport.width = 512;
17568 viewport.height = 512;
17569 viewport.x = 0;
17570 viewport.y = 0;
17571 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17572 vkEndCommandBuffer(command_buffer[1]);
17573 }
17574 {
17575 VkSubmitInfo submit_info{};
17576 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17577 submit_info.commandBufferCount = 1;
17578 submit_info.pCommandBuffers = &command_buffer[0];
17579 submit_info.signalSemaphoreCount = 1;
17580 submit_info.pSignalSemaphores = &semaphore;
17581 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17582 }
17583 {
17584 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17585 VkSubmitInfo submit_info{};
17586 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17587 submit_info.commandBufferCount = 1;
17588 submit_info.pCommandBuffers = &command_buffer[1];
17589 submit_info.waitSemaphoreCount = 1;
17590 submit_info.pWaitSemaphores = &semaphore;
17591 submit_info.pWaitDstStageMask = flags;
17592 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17593 }
17594
17595 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17596 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17597
17598 vkDestroyFence(m_device->device(), fence, nullptr);
17599 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17600 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17601 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17602
17603 m_errorMonitor->VerifyNotFound();
17604}
17605
17606TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
17607
17608 ASSERT_NO_FATAL_FAILURE(InitState());
17609 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
17610 printf("Test requires two queues, skipping\n");
17611 return;
17612 }
17613
17614 VkResult err;
17615
17616 m_errorMonitor->ExpectSuccess();
17617
17618 VkQueue q0 = m_device->m_queue;
17619 VkQueue q1 = nullptr;
17620 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
17621 ASSERT_NE(q1, nullptr);
17622
17623 // An (empty) command buffer. We must have work in the first submission --
17624 // the layer treats unfenced work differently from fenced work.
17625 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
17626 VkCommandPool pool;
17627 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
17628 ASSERT_VK_SUCCESS(err);
17629 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
17630 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
17631 VkCommandBuffer cb;
17632 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
17633 ASSERT_VK_SUCCESS(err);
17634 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
17635 err = vkBeginCommandBuffer(cb, &cbbi);
17636 ASSERT_VK_SUCCESS(err);
17637 err = vkEndCommandBuffer(cb);
17638 ASSERT_VK_SUCCESS(err);
17639
17640 // A semaphore
17641 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17642 VkSemaphore s;
17643 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
17644 ASSERT_VK_SUCCESS(err);
17645
17646 // First submission, to q0
17647 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
17648
17649 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
17650 ASSERT_VK_SUCCESS(err);
17651
17652 // Second submission, to q1, waiting on s
17653 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
17654 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
17655
17656 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
17657 ASSERT_VK_SUCCESS(err);
17658
17659 // Wait for q0 idle
17660 err = vkQueueWaitIdle(q0);
17661 ASSERT_VK_SUCCESS(err);
17662
17663 // Command buffer should have been completed (it was on q0); reset the pool.
17664 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
17665
17666 m_errorMonitor->VerifyNotFound();
17667
17668 // Force device completely idle and clean up resources
17669 vkDeviceWaitIdle(m_device->device());
17670 vkDestroyCommandPool(m_device->device(), pool, nullptr);
17671 vkDestroySemaphore(m_device->device(), s, nullptr);
17672}
17673
17674// This is a positive test. No errors should be generated.
17675TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
17676
17677 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17678 "submitted on separate queues, the second having a fence, "
17679 "followed by a WaitForFences call.");
17680
17681 ASSERT_NO_FATAL_FAILURE(InitState());
17682 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17683 return;
17684
17685 m_errorMonitor->ExpectSuccess();
17686
17687 ASSERT_NO_FATAL_FAILURE(InitState());
17688 VkFence fence;
17689 VkFenceCreateInfo fence_create_info{};
17690 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17691 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17692
17693 VkSemaphore semaphore;
17694 VkSemaphoreCreateInfo semaphore_create_info{};
17695 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17696 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17697
17698 VkCommandPool command_pool;
17699 VkCommandPoolCreateInfo pool_create_info{};
17700 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17701 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17702 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17703 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17704
17705 VkCommandBuffer command_buffer[2];
17706 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17707 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17708 command_buffer_allocate_info.commandPool = command_pool;
17709 command_buffer_allocate_info.commandBufferCount = 2;
17710 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17711 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17712
17713 VkQueue queue = VK_NULL_HANDLE;
17714 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17715
17716 {
17717 VkCommandBufferBeginInfo begin_info{};
17718 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17719 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17720
17721 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17722 nullptr, 0, nullptr, 0, nullptr);
17723
17724 VkViewport viewport{};
17725 viewport.maxDepth = 1.0f;
17726 viewport.minDepth = 0.0f;
17727 viewport.width = 512;
17728 viewport.height = 512;
17729 viewport.x = 0;
17730 viewport.y = 0;
17731 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17732 vkEndCommandBuffer(command_buffer[0]);
17733 }
17734 {
17735 VkCommandBufferBeginInfo begin_info{};
17736 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17737 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17738
17739 VkViewport viewport{};
17740 viewport.maxDepth = 1.0f;
17741 viewport.minDepth = 0.0f;
17742 viewport.width = 512;
17743 viewport.height = 512;
17744 viewport.x = 0;
17745 viewport.y = 0;
17746 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17747 vkEndCommandBuffer(command_buffer[1]);
17748 }
17749 {
17750 VkSubmitInfo submit_info{};
17751 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17752 submit_info.commandBufferCount = 1;
17753 submit_info.pCommandBuffers = &command_buffer[0];
17754 submit_info.signalSemaphoreCount = 1;
17755 submit_info.pSignalSemaphores = &semaphore;
17756 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17757 }
17758 {
17759 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17760 VkSubmitInfo submit_info{};
17761 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17762 submit_info.commandBufferCount = 1;
17763 submit_info.pCommandBuffers = &command_buffer[1];
17764 submit_info.waitSemaphoreCount = 1;
17765 submit_info.pWaitSemaphores = &semaphore;
17766 submit_info.pWaitDstStageMask = flags;
17767 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17768 }
17769
17770 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17771
17772 vkDestroyFence(m_device->device(), fence, nullptr);
17773 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17774 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17775 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17776
17777 m_errorMonitor->VerifyNotFound();
17778}
17779
17780// This is a positive test. No errors should be generated.
17781TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
17782
17783 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17784 "on the same queue, sharing a signal/wait semaphore, the "
17785 "second having a fence, "
17786 "followed by a WaitForFences call.");
17787
17788 m_errorMonitor->ExpectSuccess();
17789
17790 ASSERT_NO_FATAL_FAILURE(InitState());
17791 VkFence fence;
17792 VkFenceCreateInfo fence_create_info{};
17793 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17794 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17795
17796 VkSemaphore semaphore;
17797 VkSemaphoreCreateInfo semaphore_create_info{};
17798 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17799 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17800
17801 VkCommandPool command_pool;
17802 VkCommandPoolCreateInfo pool_create_info{};
17803 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17804 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17805 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17806 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17807
17808 VkCommandBuffer command_buffer[2];
17809 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17810 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17811 command_buffer_allocate_info.commandPool = command_pool;
17812 command_buffer_allocate_info.commandBufferCount = 2;
17813 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17814 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17815
17816 {
17817 VkCommandBufferBeginInfo begin_info{};
17818 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17819 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17820
17821 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17822 nullptr, 0, nullptr, 0, nullptr);
17823
17824 VkViewport viewport{};
17825 viewport.maxDepth = 1.0f;
17826 viewport.minDepth = 0.0f;
17827 viewport.width = 512;
17828 viewport.height = 512;
17829 viewport.x = 0;
17830 viewport.y = 0;
17831 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17832 vkEndCommandBuffer(command_buffer[0]);
17833 }
17834 {
17835 VkCommandBufferBeginInfo begin_info{};
17836 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17837 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17838
17839 VkViewport viewport{};
17840 viewport.maxDepth = 1.0f;
17841 viewport.minDepth = 0.0f;
17842 viewport.width = 512;
17843 viewport.height = 512;
17844 viewport.x = 0;
17845 viewport.y = 0;
17846 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17847 vkEndCommandBuffer(command_buffer[1]);
17848 }
17849 {
17850 VkSubmitInfo submit_info{};
17851 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17852 submit_info.commandBufferCount = 1;
17853 submit_info.pCommandBuffers = &command_buffer[0];
17854 submit_info.signalSemaphoreCount = 1;
17855 submit_info.pSignalSemaphores = &semaphore;
17856 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17857 }
17858 {
17859 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17860 VkSubmitInfo submit_info{};
17861 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17862 submit_info.commandBufferCount = 1;
17863 submit_info.pCommandBuffers = &command_buffer[1];
17864 submit_info.waitSemaphoreCount = 1;
17865 submit_info.pWaitSemaphores = &semaphore;
17866 submit_info.pWaitDstStageMask = flags;
17867 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17868 }
17869
17870 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17871
17872 vkDestroyFence(m_device->device(), fence, nullptr);
17873 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17874 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17875 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17876
17877 m_errorMonitor->VerifyNotFound();
17878}
17879
17880// This is a positive test. No errors should be generated.
17881TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
17882
17883 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17884 "on the same queue, no fences, followed by a third QueueSubmit with NO "
17885 "SubmitInfos but with a fence, followed by a WaitForFences call.");
17886
17887 m_errorMonitor->ExpectSuccess();
17888
17889 ASSERT_NO_FATAL_FAILURE(InitState());
17890 VkFence fence;
17891 VkFenceCreateInfo fence_create_info{};
17892 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17893 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17894
17895 VkCommandPool command_pool;
17896 VkCommandPoolCreateInfo pool_create_info{};
17897 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17898 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17899 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17900 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17901
17902 VkCommandBuffer command_buffer[2];
17903 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17904 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17905 command_buffer_allocate_info.commandPool = command_pool;
17906 command_buffer_allocate_info.commandBufferCount = 2;
17907 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17908 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17909
17910 {
17911 VkCommandBufferBeginInfo begin_info{};
17912 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17913 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17914
17915 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17916 nullptr, 0, nullptr, 0, nullptr);
17917
17918 VkViewport viewport{};
17919 viewport.maxDepth = 1.0f;
17920 viewport.minDepth = 0.0f;
17921 viewport.width = 512;
17922 viewport.height = 512;
17923 viewport.x = 0;
17924 viewport.y = 0;
17925 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17926 vkEndCommandBuffer(command_buffer[0]);
17927 }
17928 {
17929 VkCommandBufferBeginInfo begin_info{};
17930 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17931 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17932
17933 VkViewport viewport{};
17934 viewport.maxDepth = 1.0f;
17935 viewport.minDepth = 0.0f;
17936 viewport.width = 512;
17937 viewport.height = 512;
17938 viewport.x = 0;
17939 viewport.y = 0;
17940 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17941 vkEndCommandBuffer(command_buffer[1]);
17942 }
17943 {
17944 VkSubmitInfo submit_info{};
17945 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17946 submit_info.commandBufferCount = 1;
17947 submit_info.pCommandBuffers = &command_buffer[0];
17948 submit_info.signalSemaphoreCount = 0;
17949 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
17950 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17951 }
17952 {
17953 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17954 VkSubmitInfo submit_info{};
17955 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17956 submit_info.commandBufferCount = 1;
17957 submit_info.pCommandBuffers = &command_buffer[1];
17958 submit_info.waitSemaphoreCount = 0;
17959 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
17960 submit_info.pWaitDstStageMask = flags;
17961 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17962 }
17963
17964 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
17965
17966 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17967 ASSERT_VK_SUCCESS(err);
17968
17969 vkDestroyFence(m_device->device(), fence, nullptr);
17970 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17971 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17972
17973 m_errorMonitor->VerifyNotFound();
17974}
17975
17976// This is a positive test. No errors should be generated.
17977TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
17978
17979 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17980 "on the same queue, the second having a fence, followed "
17981 "by a WaitForFences call.");
17982
17983 m_errorMonitor->ExpectSuccess();
17984
17985 ASSERT_NO_FATAL_FAILURE(InitState());
17986 VkFence fence;
17987 VkFenceCreateInfo fence_create_info{};
17988 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17989 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17990
17991 VkCommandPool command_pool;
17992 VkCommandPoolCreateInfo pool_create_info{};
17993 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17994 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17995 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17996 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17997
17998 VkCommandBuffer command_buffer[2];
17999 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18000 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18001 command_buffer_allocate_info.commandPool = command_pool;
18002 command_buffer_allocate_info.commandBufferCount = 2;
18003 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18004 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18005
18006 {
18007 VkCommandBufferBeginInfo begin_info{};
18008 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18009 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18010
18011 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18012 nullptr, 0, nullptr, 0, nullptr);
18013
18014 VkViewport viewport{};
18015 viewport.maxDepth = 1.0f;
18016 viewport.minDepth = 0.0f;
18017 viewport.width = 512;
18018 viewport.height = 512;
18019 viewport.x = 0;
18020 viewport.y = 0;
18021 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18022 vkEndCommandBuffer(command_buffer[0]);
18023 }
18024 {
18025 VkCommandBufferBeginInfo begin_info{};
18026 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18027 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18028
18029 VkViewport viewport{};
18030 viewport.maxDepth = 1.0f;
18031 viewport.minDepth = 0.0f;
18032 viewport.width = 512;
18033 viewport.height = 512;
18034 viewport.x = 0;
18035 viewport.y = 0;
18036 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18037 vkEndCommandBuffer(command_buffer[1]);
18038 }
18039 {
18040 VkSubmitInfo submit_info{};
18041 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18042 submit_info.commandBufferCount = 1;
18043 submit_info.pCommandBuffers = &command_buffer[0];
18044 submit_info.signalSemaphoreCount = 0;
18045 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18046 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18047 }
18048 {
18049 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18050 VkSubmitInfo submit_info{};
18051 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18052 submit_info.commandBufferCount = 1;
18053 submit_info.pCommandBuffers = &command_buffer[1];
18054 submit_info.waitSemaphoreCount = 0;
18055 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18056 submit_info.pWaitDstStageMask = flags;
18057 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18058 }
18059
18060 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18061
18062 vkDestroyFence(m_device->device(), fence, nullptr);
18063 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18064 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18065
18066 m_errorMonitor->VerifyNotFound();
18067}
18068
18069// This is a positive test. No errors should be generated.
18070TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18071
18072 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18073 "QueueSubmit call followed by a WaitForFences call.");
18074 ASSERT_NO_FATAL_FAILURE(InitState());
18075
18076 m_errorMonitor->ExpectSuccess();
18077
18078 VkFence fence;
18079 VkFenceCreateInfo fence_create_info{};
18080 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18081 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18082
18083 VkSemaphore semaphore;
18084 VkSemaphoreCreateInfo semaphore_create_info{};
18085 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18086 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18087
18088 VkCommandPool command_pool;
18089 VkCommandPoolCreateInfo pool_create_info{};
18090 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18091 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18092 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18093 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18094
18095 VkCommandBuffer command_buffer[2];
18096 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18097 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18098 command_buffer_allocate_info.commandPool = command_pool;
18099 command_buffer_allocate_info.commandBufferCount = 2;
18100 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18101 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18102
18103 {
18104 VkCommandBufferBeginInfo begin_info{};
18105 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18106 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18107
18108 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18109 nullptr, 0, nullptr, 0, nullptr);
18110
18111 VkViewport viewport{};
18112 viewport.maxDepth = 1.0f;
18113 viewport.minDepth = 0.0f;
18114 viewport.width = 512;
18115 viewport.height = 512;
18116 viewport.x = 0;
18117 viewport.y = 0;
18118 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18119 vkEndCommandBuffer(command_buffer[0]);
18120 }
18121 {
18122 VkCommandBufferBeginInfo begin_info{};
18123 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18124 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18125
18126 VkViewport viewport{};
18127 viewport.maxDepth = 1.0f;
18128 viewport.minDepth = 0.0f;
18129 viewport.width = 512;
18130 viewport.height = 512;
18131 viewport.x = 0;
18132 viewport.y = 0;
18133 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18134 vkEndCommandBuffer(command_buffer[1]);
18135 }
18136 {
18137 VkSubmitInfo submit_info[2];
18138 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18139
18140 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18141 submit_info[0].pNext = NULL;
18142 submit_info[0].commandBufferCount = 1;
18143 submit_info[0].pCommandBuffers = &command_buffer[0];
18144 submit_info[0].signalSemaphoreCount = 1;
18145 submit_info[0].pSignalSemaphores = &semaphore;
18146 submit_info[0].waitSemaphoreCount = 0;
18147 submit_info[0].pWaitSemaphores = NULL;
18148 submit_info[0].pWaitDstStageMask = 0;
18149
18150 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18151 submit_info[1].pNext = NULL;
18152 submit_info[1].commandBufferCount = 1;
18153 submit_info[1].pCommandBuffers = &command_buffer[1];
18154 submit_info[1].waitSemaphoreCount = 1;
18155 submit_info[1].pWaitSemaphores = &semaphore;
18156 submit_info[1].pWaitDstStageMask = flags;
18157 submit_info[1].signalSemaphoreCount = 0;
18158 submit_info[1].pSignalSemaphores = NULL;
18159 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18160 }
18161
18162 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18163
18164 vkDestroyFence(m_device->device(), fence, nullptr);
18165 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18166 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18167 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18168
18169 m_errorMonitor->VerifyNotFound();
18170}
18171
18172TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18173 m_errorMonitor->ExpectSuccess();
18174
18175 ASSERT_NO_FATAL_FAILURE(InitState());
18176 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18177
18178 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18179 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18180
18181 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18182 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18183 m_errorMonitor->VerifyNotFound();
18184 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18185 m_errorMonitor->VerifyNotFound();
18186 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18187 m_errorMonitor->VerifyNotFound();
18188
18189 m_commandBuffer->EndCommandBuffer();
18190 m_errorMonitor->VerifyNotFound();
18191}
18192
18193TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18194 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18195 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18196 "has a valid layout, and a second subpass then uses a "
18197 "valid *READ_ONLY* layout.");
18198 m_errorMonitor->ExpectSuccess();
18199 ASSERT_NO_FATAL_FAILURE(InitState());
18200
18201 VkAttachmentReference attach[2] = {};
18202 attach[0].attachment = 0;
18203 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18204 attach[1].attachment = 0;
18205 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18206 VkSubpassDescription subpasses[2] = {};
18207 // First subpass clears DS attach on load
18208 subpasses[0].pDepthStencilAttachment = &attach[0];
18209 // 2nd subpass reads in DS as input attachment
18210 subpasses[1].inputAttachmentCount = 1;
18211 subpasses[1].pInputAttachments = &attach[1];
18212 VkAttachmentDescription attach_desc = {};
18213 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18214 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18215 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18216 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18217 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18218 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18219 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18220 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18221 VkRenderPassCreateInfo rpci = {};
18222 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18223 rpci.attachmentCount = 1;
18224 rpci.pAttachments = &attach_desc;
18225 rpci.subpassCount = 2;
18226 rpci.pSubpasses = subpasses;
18227
18228 // Now create RenderPass and verify no errors
18229 VkRenderPass rp;
18230 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18231 m_errorMonitor->VerifyNotFound();
18232
18233 vkDestroyRenderPass(m_device->device(), rp, NULL);
18234}
18235
18236TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18237 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18238 "as vertex attributes");
18239 m_errorMonitor->ExpectSuccess();
18240
18241 ASSERT_NO_FATAL_FAILURE(InitState());
18242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18243
18244 VkVertexInputBindingDescription input_binding;
18245 memset(&input_binding, 0, sizeof(input_binding));
18246
18247 VkVertexInputAttributeDescription input_attribs[2];
18248 memset(input_attribs, 0, sizeof(input_attribs));
18249
18250 for (int i = 0; i < 2; i++) {
18251 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18252 input_attribs[i].location = i;
18253 }
18254
18255 char const *vsSource = "#version 450\n"
18256 "\n"
18257 "layout(location=0) in mat2x4 x;\n"
18258 "out gl_PerVertex {\n"
18259 " vec4 gl_Position;\n"
18260 "};\n"
18261 "void main(){\n"
18262 " gl_Position = x[0] + x[1];\n"
18263 "}\n";
18264 char const *fsSource = "#version 450\n"
18265 "\n"
18266 "layout(location=0) out vec4 color;\n"
18267 "void main(){\n"
18268 " color = vec4(1);\n"
18269 "}\n";
18270
18271 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18272 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18273
18274 VkPipelineObj pipe(m_device);
18275 pipe.AddColorAttachment();
18276 pipe.AddShader(&vs);
18277 pipe.AddShader(&fs);
18278
18279 pipe.AddVertexInputBindings(&input_binding, 1);
18280 pipe.AddVertexInputAttribs(input_attribs, 2);
18281
18282 VkDescriptorSetObj descriptorSet(m_device);
18283 descriptorSet.AppendDummy();
18284 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18285
18286 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18287
18288 /* expect success */
18289 m_errorMonitor->VerifyNotFound();
18290}
18291
18292TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18293 m_errorMonitor->ExpectSuccess();
18294
18295 ASSERT_NO_FATAL_FAILURE(InitState());
18296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18297
18298 VkVertexInputBindingDescription input_binding;
18299 memset(&input_binding, 0, sizeof(input_binding));
18300
18301 VkVertexInputAttributeDescription input_attribs[2];
18302 memset(input_attribs, 0, sizeof(input_attribs));
18303
18304 for (int i = 0; i < 2; i++) {
18305 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18306 input_attribs[i].location = i;
18307 }
18308
18309 char const *vsSource = "#version 450\n"
18310 "\n"
18311 "layout(location=0) in vec4 x[2];\n"
18312 "out gl_PerVertex {\n"
18313 " vec4 gl_Position;\n"
18314 "};\n"
18315 "void main(){\n"
18316 " gl_Position = x[0] + x[1];\n"
18317 "}\n";
18318 char const *fsSource = "#version 450\n"
18319 "\n"
18320 "layout(location=0) out vec4 color;\n"
18321 "void main(){\n"
18322 " color = vec4(1);\n"
18323 "}\n";
18324
18325 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18326 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18327
18328 VkPipelineObj pipe(m_device);
18329 pipe.AddColorAttachment();
18330 pipe.AddShader(&vs);
18331 pipe.AddShader(&fs);
18332
18333 pipe.AddVertexInputBindings(&input_binding, 1);
18334 pipe.AddVertexInputAttribs(input_attribs, 2);
18335
18336 VkDescriptorSetObj descriptorSet(m_device);
18337 descriptorSet.AppendDummy();
18338 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18339
18340 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18341
18342 m_errorMonitor->VerifyNotFound();
18343}
18344
18345TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18346 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18347 "through multiple vertex shader inputs, each consuming a different "
18348 "subset of the components.");
18349 m_errorMonitor->ExpectSuccess();
18350
18351 ASSERT_NO_FATAL_FAILURE(InitState());
18352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18353
18354 VkVertexInputBindingDescription input_binding;
18355 memset(&input_binding, 0, sizeof(input_binding));
18356
18357 VkVertexInputAttributeDescription input_attribs[3];
18358 memset(input_attribs, 0, sizeof(input_attribs));
18359
18360 for (int i = 0; i < 3; i++) {
18361 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18362 input_attribs[i].location = i;
18363 }
18364
18365 char const *vsSource = "#version 450\n"
18366 "\n"
18367 "layout(location=0) in vec4 x;\n"
18368 "layout(location=1) in vec3 y1;\n"
18369 "layout(location=1, component=3) in float y2;\n"
18370 "layout(location=2) in vec4 z;\n"
18371 "out gl_PerVertex {\n"
18372 " vec4 gl_Position;\n"
18373 "};\n"
18374 "void main(){\n"
18375 " gl_Position = x + vec4(y1, y2) + z;\n"
18376 "}\n";
18377 char const *fsSource = "#version 450\n"
18378 "\n"
18379 "layout(location=0) out vec4 color;\n"
18380 "void main(){\n"
18381 " color = vec4(1);\n"
18382 "}\n";
18383
18384 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18385 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18386
18387 VkPipelineObj pipe(m_device);
18388 pipe.AddColorAttachment();
18389 pipe.AddShader(&vs);
18390 pipe.AddShader(&fs);
18391
18392 pipe.AddVertexInputBindings(&input_binding, 1);
18393 pipe.AddVertexInputAttribs(input_attribs, 3);
18394
18395 VkDescriptorSetObj descriptorSet(m_device);
18396 descriptorSet.AppendDummy();
18397 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18398
18399 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18400
18401 m_errorMonitor->VerifyNotFound();
18402}
18403
18404TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18405 m_errorMonitor->ExpectSuccess();
18406
18407 ASSERT_NO_FATAL_FAILURE(InitState());
18408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18409
18410 char const *vsSource = "#version 450\n"
18411 "out gl_PerVertex {\n"
18412 " vec4 gl_Position;\n"
18413 "};\n"
18414 "void main(){\n"
18415 " gl_Position = vec4(0);\n"
18416 "}\n";
18417 char const *fsSource = "#version 450\n"
18418 "\n"
18419 "layout(location=0) out vec4 color;\n"
18420 "void main(){\n"
18421 " color = vec4(1);\n"
18422 "}\n";
18423
18424 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18425 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18426
18427 VkPipelineObj pipe(m_device);
18428 pipe.AddColorAttachment();
18429 pipe.AddShader(&vs);
18430 pipe.AddShader(&fs);
18431
18432 VkDescriptorSetObj descriptorSet(m_device);
18433 descriptorSet.AppendDummy();
18434 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18435
18436 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18437
18438 m_errorMonitor->VerifyNotFound();
18439}
18440
18441TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18442 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18443 "set out in 14.1.3: fundamental type must match, and producer side must "
18444 "have at least as many components");
18445 m_errorMonitor->ExpectSuccess();
18446
18447 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18448
18449 ASSERT_NO_FATAL_FAILURE(InitState());
18450 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18451
18452 char const *vsSource = "#version 450\n"
18453 "out gl_PerVertex {\n"
18454 " vec4 gl_Position;\n"
18455 "};\n"
18456 "layout(location=0) out vec3 x;\n"
18457 "layout(location=1) out ivec3 y;\n"
18458 "layout(location=2) out vec3 z;\n"
18459 "void main(){\n"
18460 " gl_Position = vec4(0);\n"
18461 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18462 "}\n";
18463 char const *fsSource = "#version 450\n"
18464 "\n"
18465 "layout(location=0) out vec4 color;\n"
18466 "layout(location=0) in float x;\n"
18467 "layout(location=1) flat in int y;\n"
18468 "layout(location=2) in vec2 z;\n"
18469 "void main(){\n"
18470 " color = vec4(1 + x + y + z.x);\n"
18471 "}\n";
18472
18473 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18474 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18475
18476 VkPipelineObj pipe(m_device);
18477 pipe.AddColorAttachment();
18478 pipe.AddShader(&vs);
18479 pipe.AddShader(&fs);
18480
18481 VkDescriptorSetObj descriptorSet(m_device);
18482 descriptorSet.AppendDummy();
18483 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18484
18485 VkResult err = VK_SUCCESS;
18486 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18487 ASSERT_VK_SUCCESS(err);
18488
18489 m_errorMonitor->VerifyNotFound();
18490}
18491
18492TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18493 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18494 "passed between the TCS and TES stages");
18495 m_errorMonitor->ExpectSuccess();
18496
18497 ASSERT_NO_FATAL_FAILURE(InitState());
18498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18499
18500 if (!m_device->phy().features().tessellationShader) {
18501 printf("Device does not support tessellation shaders; skipped.\n");
18502 return;
18503 }
18504
18505 char const *vsSource = "#version 450\n"
18506 "void main(){}\n";
18507 char const *tcsSource = "#version 450\n"
18508 "layout(location=0) out int x[];\n"
18509 "layout(vertices=3) out;\n"
18510 "void main(){\n"
18511 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
18512 " gl_TessLevelInner[0] = 1;\n"
18513 " x[gl_InvocationID] = gl_InvocationID;\n"
18514 "}\n";
18515 char const *tesSource = "#version 450\n"
18516 "layout(triangles, equal_spacing, cw) in;\n"
18517 "layout(location=0) in int x[];\n"
18518 "out gl_PerVertex { vec4 gl_Position; };\n"
18519 "void main(){\n"
18520 " gl_Position.xyz = gl_TessCoord;\n"
18521 " gl_Position.w = x[0] + x[1] + x[2];\n"
18522 "}\n";
18523 char const *fsSource = "#version 450\n"
18524 "layout(location=0) out vec4 color;\n"
18525 "void main(){\n"
18526 " color = vec4(1);\n"
18527 "}\n";
18528
18529 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18530 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
18531 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
18532 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18533
18534 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
18535 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
18536
18537 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
18538
18539 VkPipelineObj pipe(m_device);
18540 pipe.SetInputAssembly(&iasci);
18541 pipe.SetTessellation(&tsci);
18542 pipe.AddColorAttachment();
18543 pipe.AddShader(&vs);
18544 pipe.AddShader(&tcs);
18545 pipe.AddShader(&tes);
18546 pipe.AddShader(&fs);
18547
18548 VkDescriptorSetObj descriptorSet(m_device);
18549 descriptorSet.AppendDummy();
18550 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18551
18552 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18553
18554 m_errorMonitor->VerifyNotFound();
18555}
18556
18557TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
18558 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
18559 "interface block passed into the geometry shader. This "
18560 "is interesting because the 'extra' array level is not "
18561 "present on the member type, but on the block instance.");
18562 m_errorMonitor->ExpectSuccess();
18563
18564 ASSERT_NO_FATAL_FAILURE(InitState());
18565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18566
18567 if (!m_device->phy().features().geometryShader) {
18568 printf("Device does not support geometry shaders; skipped.\n");
18569 return;
18570 }
18571
18572 char const *vsSource = "#version 450\n"
18573 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
18574 "void main(){\n"
18575 " vs_out.x = vec4(1);\n"
18576 "}\n";
18577 char const *gsSource = "#version 450\n"
18578 "layout(triangles) in;\n"
18579 "layout(triangle_strip, max_vertices=3) out;\n"
18580 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
18581 "out gl_PerVertex { vec4 gl_Position; };\n"
18582 "void main() {\n"
18583 " gl_Position = gs_in[0].x;\n"
18584 " EmitVertex();\n"
18585 "}\n";
18586 char const *fsSource = "#version 450\n"
18587 "layout(location=0) out vec4 color;\n"
18588 "void main(){\n"
18589 " color = vec4(1);\n"
18590 "}\n";
18591
18592 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18593 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
18594 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18595
18596 VkPipelineObj pipe(m_device);
18597 pipe.AddColorAttachment();
18598 pipe.AddShader(&vs);
18599 pipe.AddShader(&gs);
18600 pipe.AddShader(&fs);
18601
18602 VkDescriptorSetObj descriptorSet(m_device);
18603 descriptorSet.AppendDummy();
18604 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18605
18606 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18607
18608 m_errorMonitor->VerifyNotFound();
18609}
18610
18611TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
18612 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
18613 "attributes. This is interesting because they consume multiple "
18614 "locations.");
18615 m_errorMonitor->ExpectSuccess();
18616
18617 ASSERT_NO_FATAL_FAILURE(InitState());
18618 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18619
18620 if (!m_device->phy().features().shaderFloat64) {
18621 printf("Device does not support 64bit vertex attributes; skipped.\n");
18622 return;
18623 }
18624
18625 VkVertexInputBindingDescription input_bindings[1];
18626 memset(input_bindings, 0, sizeof(input_bindings));
18627
18628 VkVertexInputAttributeDescription input_attribs[4];
18629 memset(input_attribs, 0, sizeof(input_attribs));
18630 input_attribs[0].location = 0;
18631 input_attribs[0].offset = 0;
18632 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18633 input_attribs[1].location = 2;
18634 input_attribs[1].offset = 32;
18635 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18636 input_attribs[2].location = 4;
18637 input_attribs[2].offset = 64;
18638 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18639 input_attribs[3].location = 6;
18640 input_attribs[3].offset = 96;
18641 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18642
18643 char const *vsSource = "#version 450\n"
18644 "\n"
18645 "layout(location=0) in dmat4 x;\n"
18646 "out gl_PerVertex {\n"
18647 " vec4 gl_Position;\n"
18648 "};\n"
18649 "void main(){\n"
18650 " gl_Position = vec4(x[0][0]);\n"
18651 "}\n";
18652 char const *fsSource = "#version 450\n"
18653 "\n"
18654 "layout(location=0) out vec4 color;\n"
18655 "void main(){\n"
18656 " color = vec4(1);\n"
18657 "}\n";
18658
18659 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18660 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18661
18662 VkPipelineObj pipe(m_device);
18663 pipe.AddColorAttachment();
18664 pipe.AddShader(&vs);
18665 pipe.AddShader(&fs);
18666
18667 pipe.AddVertexInputBindings(input_bindings, 1);
18668 pipe.AddVertexInputAttribs(input_attribs, 4);
18669
18670 VkDescriptorSetObj descriptorSet(m_device);
18671 descriptorSet.AppendDummy();
18672 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18673
18674 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18675
18676 m_errorMonitor->VerifyNotFound();
18677}
18678
18679TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
18680 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
18681 m_errorMonitor->ExpectSuccess();
18682
18683 ASSERT_NO_FATAL_FAILURE(InitState());
18684
18685 char const *vsSource = "#version 450\n"
18686 "\n"
18687 "out gl_PerVertex {\n"
18688 " vec4 gl_Position;\n"
18689 "};\n"
18690 "void main(){\n"
18691 " gl_Position = vec4(1);\n"
18692 "}\n";
18693 char const *fsSource = "#version 450\n"
18694 "\n"
18695 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
18696 "layout(location=0) out vec4 color;\n"
18697 "void main() {\n"
18698 " color = subpassLoad(x);\n"
18699 "}\n";
18700
18701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18703
18704 VkPipelineObj pipe(m_device);
18705 pipe.AddShader(&vs);
18706 pipe.AddShader(&fs);
18707 pipe.AddColorAttachment();
18708 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18709
18710 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
18711 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
18712 VkDescriptorSetLayout dsl;
18713 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18714 ASSERT_VK_SUCCESS(err);
18715
18716 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18717 VkPipelineLayout pl;
18718 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18719 ASSERT_VK_SUCCESS(err);
18720
18721 VkAttachmentDescription descs[2] = {
18722 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18723 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18724 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
18725 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18726 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
18727 };
18728 VkAttachmentReference color = {
18729 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18730 };
18731 VkAttachmentReference input = {
18732 1, VK_IMAGE_LAYOUT_GENERAL,
18733 };
18734
18735 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
18736
18737 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
18738 VkRenderPass rp;
18739 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18740 ASSERT_VK_SUCCESS(err);
18741
18742 // should be OK. would go wrong here if it's going to...
18743 pipe.CreateVKPipeline(pl, rp);
18744
18745 m_errorMonitor->VerifyNotFound();
18746
18747 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18748 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18749 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18750}
18751
18752TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
18753 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
18754 "descriptor-backed resource which is not provided, but the shader does not "
18755 "statically use it. This is interesting because it requires compute pipelines "
18756 "to have a proper descriptor use walk, which they didn't for some time.");
18757 m_errorMonitor->ExpectSuccess();
18758
18759 ASSERT_NO_FATAL_FAILURE(InitState());
18760
18761 char const *csSource = "#version 450\n"
18762 "\n"
18763 "layout(local_size_x=1) in;\n"
18764 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
18765 "void main(){\n"
18766 " // x is not used.\n"
18767 "}\n";
18768
18769 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18770
18771 VkDescriptorSetObj descriptorSet(m_device);
18772 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18773
18774 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18775 nullptr,
18776 0,
18777 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18778 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18779 descriptorSet.GetPipelineLayout(),
18780 VK_NULL_HANDLE,
18781 -1 };
18782
18783 VkPipeline pipe;
18784 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18785
18786 m_errorMonitor->VerifyNotFound();
18787
18788 if (err == VK_SUCCESS) {
18789 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18790 }
18791}
18792
18793TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
18794 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
18795 "sampler portion of a combined image + sampler");
18796 m_errorMonitor->ExpectSuccess();
18797
18798 ASSERT_NO_FATAL_FAILURE(InitState());
18799
18800 VkDescriptorSetLayoutBinding bindings[] = {
18801 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18802 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18803 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18804 };
18805 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
18806 VkDescriptorSetLayout dsl;
18807 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18808 ASSERT_VK_SUCCESS(err);
18809
18810 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18811 VkPipelineLayout pl;
18812 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18813 ASSERT_VK_SUCCESS(err);
18814
18815 char const *csSource = "#version 450\n"
18816 "\n"
18817 "layout(local_size_x=1) in;\n"
18818 "layout(set=0, binding=0) uniform sampler s;\n"
18819 "layout(set=0, binding=1) uniform texture2D t;\n"
18820 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
18821 "void main() {\n"
18822 " x = texture(sampler2D(t, s), vec2(0));\n"
18823 "}\n";
18824 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18825
18826 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18827 nullptr,
18828 0,
18829 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18830 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18831 pl,
18832 VK_NULL_HANDLE,
18833 -1 };
18834
18835 VkPipeline pipe;
18836 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18837
18838 m_errorMonitor->VerifyNotFound();
18839
18840 if (err == VK_SUCCESS) {
18841 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18842 }
18843
18844 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18845 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18846}
18847
18848TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
18849 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
18850 "image portion of a combined image + sampler");
18851 m_errorMonitor->ExpectSuccess();
18852
18853 ASSERT_NO_FATAL_FAILURE(InitState());
18854
18855 VkDescriptorSetLayoutBinding bindings[] = {
18856 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18857 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18858 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18859 };
18860 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
18861 VkDescriptorSetLayout dsl;
18862 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18863 ASSERT_VK_SUCCESS(err);
18864
18865 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18866 VkPipelineLayout pl;
18867 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18868 ASSERT_VK_SUCCESS(err);
18869
18870 char const *csSource = "#version 450\n"
18871 "\n"
18872 "layout(local_size_x=1) in;\n"
18873 "layout(set=0, binding=0) uniform texture2D t;\n"
18874 "layout(set=0, binding=1) uniform sampler s;\n"
18875 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
18876 "void main() {\n"
18877 " x = texture(sampler2D(t, s), vec2(0));\n"
18878 "}\n";
18879 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18880
18881 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18882 nullptr,
18883 0,
18884 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18885 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18886 pl,
18887 VK_NULL_HANDLE,
18888 -1 };
18889
18890 VkPipeline pipe;
18891 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18892
18893 m_errorMonitor->VerifyNotFound();
18894
18895 if (err == VK_SUCCESS) {
18896 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18897 }
18898
18899 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18900 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18901}
18902
18903TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
18904 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
18905 "both the sampler and the image of a combined image+sampler "
18906 "but via separate variables");
18907 m_errorMonitor->ExpectSuccess();
18908
18909 ASSERT_NO_FATAL_FAILURE(InitState());
18910
18911 VkDescriptorSetLayoutBinding bindings[] = {
18912 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18913 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18914 };
18915 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
18916 VkDescriptorSetLayout dsl;
18917 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18918 ASSERT_VK_SUCCESS(err);
18919
18920 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18921 VkPipelineLayout pl;
18922 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18923 ASSERT_VK_SUCCESS(err);
18924
18925 char const *csSource = "#version 450\n"
18926 "\n"
18927 "layout(local_size_x=1) in;\n"
18928 "layout(set=0, binding=0) uniform texture2D t;\n"
18929 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
18930 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
18931 "void main() {\n"
18932 " x = texture(sampler2D(t, s), vec2(0));\n"
18933 "}\n";
18934 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18935
18936 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18937 nullptr,
18938 0,
18939 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18940 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18941 pl,
18942 VK_NULL_HANDLE,
18943 -1 };
18944
18945 VkPipeline pipe;
18946 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18947
18948 m_errorMonitor->VerifyNotFound();
18949
18950 if (err == VK_SUCCESS) {
18951 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18952 }
18953
18954 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18955 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18956}
18957
18958TEST_F(VkPositiveLayerTest, ValidStructPNext) {
18959 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
18960
18961 ASSERT_NO_FATAL_FAILURE(InitState());
18962
18963 // Positive test to check parameter_validation and unique_objects support
18964 // for NV_dedicated_allocation
18965 uint32_t extension_count = 0;
18966 bool supports_nv_dedicated_allocation = false;
18967 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
18968 ASSERT_VK_SUCCESS(err);
18969
18970 if (extension_count > 0) {
18971 std::vector<VkExtensionProperties> available_extensions(extension_count);
18972
18973 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
18974 ASSERT_VK_SUCCESS(err);
18975
18976 for (const auto &extension_props : available_extensions) {
18977 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
18978 supports_nv_dedicated_allocation = true;
18979 }
18980 }
18981 }
18982
18983 if (supports_nv_dedicated_allocation) {
18984 m_errorMonitor->ExpectSuccess();
18985
18986 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
18987 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
18988 dedicated_buffer_create_info.pNext = nullptr;
18989 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
18990
18991 uint32_t queue_family_index = 0;
18992 VkBufferCreateInfo buffer_create_info = {};
18993 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18994 buffer_create_info.pNext = &dedicated_buffer_create_info;
18995 buffer_create_info.size = 1024;
18996 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18997 buffer_create_info.queueFamilyIndexCount = 1;
18998 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18999
19000 VkBuffer buffer;
19001 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19002 ASSERT_VK_SUCCESS(err);
19003
19004 VkMemoryRequirements memory_reqs;
19005 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19006
19007 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19008 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19009 dedicated_memory_info.pNext = nullptr;
19010 dedicated_memory_info.buffer = buffer;
19011 dedicated_memory_info.image = VK_NULL_HANDLE;
19012
19013 VkMemoryAllocateInfo memory_info = {};
19014 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19015 memory_info.pNext = &dedicated_memory_info;
19016 memory_info.allocationSize = memory_reqs.size;
19017
19018 bool pass;
19019 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19020 ASSERT_TRUE(pass);
19021
19022 VkDeviceMemory buffer_memory;
19023 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19024 ASSERT_VK_SUCCESS(err);
19025
19026 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19027 ASSERT_VK_SUCCESS(err);
19028
19029 vkDestroyBuffer(m_device->device(), buffer, NULL);
19030 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19031
19032 m_errorMonitor->VerifyNotFound();
19033 }
19034}
19035
19036TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19037 VkResult err;
19038
19039 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19040
19041 ASSERT_NO_FATAL_FAILURE(InitState());
19042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19043
19044 std::vector<const char *> device_extension_names;
19045 auto features = m_device->phy().features();
19046 // Artificially disable support for non-solid fill modes
19047 features.fillModeNonSolid = false;
19048 // The sacrificial device object
19049 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19050
19051 VkRenderpassObj render_pass(&test_device);
19052
19053 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19054 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19055 pipeline_layout_ci.setLayoutCount = 0;
19056 pipeline_layout_ci.pSetLayouts = NULL;
19057
19058 VkPipelineLayout pipeline_layout;
19059 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19060 ASSERT_VK_SUCCESS(err);
19061
19062 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19063 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19064 rs_ci.pNext = nullptr;
19065 rs_ci.lineWidth = 1.0f;
19066 rs_ci.rasterizerDiscardEnable = true;
19067
19068 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19069 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19070
19071 // Set polygonMode=FILL. No error is expected
19072 m_errorMonitor->ExpectSuccess();
19073 {
19074 VkPipelineObj pipe(&test_device);
19075 pipe.AddShader(&vs);
19076 pipe.AddShader(&fs);
19077 pipe.AddColorAttachment();
19078 // Set polygonMode to a good value
19079 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19080 pipe.SetRasterization(&rs_ci);
19081 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19082 }
19083 m_errorMonitor->VerifyNotFound();
19084
19085 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19086}
19087
19088TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19089 VkResult err;
19090 ASSERT_NO_FATAL_FAILURE(InitState());
19091 ASSERT_NO_FATAL_FAILURE(InitViewport());
19092 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19093
19094 VkPipelineLayout pipeline_layout;
19095 VkPushConstantRange pc_range = {};
19096 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19097 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19098 pipeline_layout_ci.pushConstantRangeCount = 1;
19099 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19100
19101 //
19102 // Check for invalid push constant ranges in pipeline layouts.
19103 //
19104 struct PipelineLayoutTestCase {
19105 VkPushConstantRange const range;
19106 char const *msg;
19107 };
19108
19109 // Check for overlapping ranges
19110 const uint32_t ranges_per_test = 5;
19111 struct OverlappingRangeTestCase {
19112 VkPushConstantRange const ranges[ranges_per_test];
19113 char const *msg;
19114 };
19115
19116 // Run some positive tests to make sure overlap checking in the layer is OK
19117 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19118 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19119 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19120 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19121 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19122 "" },
19123 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19124 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19125 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19126 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19127 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19128 "" } } };
19129 for (const auto &iter : overlapping_range_tests_pos) {
19130 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19131 m_errorMonitor->ExpectSuccess();
19132 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19133 m_errorMonitor->VerifyNotFound();
19134 if (VK_SUCCESS == err) {
19135 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19136 }
19137 }
19138
19139 //
19140 // CmdPushConstants tests
19141 //
19142 const uint8_t dummy_values[100] = {};
19143
19144 BeginCommandBuffer();
19145
19146 // positive overlapping range tests with cmd
19147 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19148 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19149 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19150 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19151 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19152 } };
19153
19154 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19155 const VkPushConstantRange pc_range4[] = {
19156 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19157 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19158 };
19159
19160 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19161 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19162 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19163 ASSERT_VK_SUCCESS(err);
19164 for (const auto &iter : cmd_overlap_tests_pos) {
19165 m_errorMonitor->ExpectSuccess();
19166 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19167 iter.range.size, dummy_values);
19168 m_errorMonitor->VerifyNotFound();
19169 }
19170 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19171
19172 EndCommandBuffer();
19173}
19174
19175
19176
19177
19178
19179
19180
19181#if 0 // A few devices have issues with this test so disabling for now
19182TEST_F(VkPositiveLayerTest, LongFenceChain)
19183{
19184 m_errorMonitor->ExpectSuccess();
19185
19186 ASSERT_NO_FATAL_FAILURE(InitState());
19187 VkResult err;
19188
19189 std::vector<VkFence> fences;
19190
19191 const int chainLength = 32768;
19192
19193 for (int i = 0; i < chainLength; i++) {
19194 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19195 VkFence fence;
19196 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19197 ASSERT_VK_SUCCESS(err);
19198
19199 fences.push_back(fence);
19200
19201 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19202 0, nullptr, 0, nullptr };
19203 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19204 ASSERT_VK_SUCCESS(err);
19205
19206 }
19207
19208 // BOOM, stack overflow.
19209 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19210
19211 for (auto fence : fences)
19212 vkDestroyFence(m_device->device(), fence, nullptr);
19213
19214 m_errorMonitor->VerifyNotFound();
19215}
19216#endif
19217
19218
Cody Northrop1242dfd2016-07-13 17:24:59 -060019219#if defined(ANDROID) && defined(VALIDATION_APK)
19220static bool initialized = false;
19221static bool active = false;
19222
19223// Convert Intents to argv
19224// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019225std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019226 std::vector<std::string> args;
19227 JavaVM &vm = *app.activity->vm;
19228 JNIEnv *p_env;
19229 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19230 return args;
19231
19232 JNIEnv &env = *p_env;
19233 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019234 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019235 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019236 jmethodID get_string_extra_method =
19237 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019238 jvalue get_string_extra_args;
19239 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019240 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019241
19242 std::string args_str;
19243 if (extra_str) {
19244 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19245 args_str = extra_utf;
19246 env.ReleaseStringUTFChars(extra_str, extra_utf);
19247 env.DeleteLocalRef(extra_str);
19248 }
19249
19250 env.DeleteLocalRef(get_string_extra_args.l);
19251 env.DeleteLocalRef(intent);
19252 vm.DetachCurrentThread();
19253
19254 // split args_str
19255 std::stringstream ss(args_str);
19256 std::string arg;
19257 while (std::getline(ss, arg, ' ')) {
19258 if (!arg.empty())
19259 args.push_back(arg);
19260 }
19261
19262 return args;
19263}
19264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019265static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019267static void processCommand(struct android_app *app, int32_t cmd) {
19268 switch (cmd) {
19269 case APP_CMD_INIT_WINDOW: {
19270 if (app->window) {
19271 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019272 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019273 break;
19274 }
19275 case APP_CMD_GAINED_FOCUS: {
19276 active = true;
19277 break;
19278 }
19279 case APP_CMD_LOST_FOCUS: {
19280 active = false;
19281 break;
19282 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019283 }
19284}
19285
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019286void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019287 app_dummy();
19288
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019289 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019290
19291 int vulkanSupport = InitVulkan();
19292 if (vulkanSupport == 0) {
19293 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19294 return;
19295 }
19296
19297 app->onAppCmd = processCommand;
19298 app->onInputEvent = processInput;
19299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019300 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019301 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019302 struct android_poll_source *source;
19303 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019304 if (source) {
19305 source->process(app, source);
19306 }
19307
19308 if (app->destroyRequested != 0) {
19309 VkTestFramework::Finish();
19310 return;
19311 }
19312 }
19313
19314 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019315 // Use the following key to send arguments to gtest, i.e.
19316 // --es args "--gtest_filter=-VkLayerTest.foo"
19317 const char key[] = "args";
19318 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019320 std::string filter = "";
19321 if (args.size() > 0) {
19322 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19323 filter += args[0];
19324 } else {
19325 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19326 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019328 int argc = 2;
19329 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19330 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019332 // Route output to files until we can override the gtest output
19333 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19334 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019336 ::testing::InitGoogleTest(&argc, argv);
19337 VkTestFramework::InitArgs(&argc, argv);
19338 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019340 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019341
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019342 if (result != 0) {
19343 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19344 } else {
19345 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19346 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019348 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019350 fclose(stdout);
19351 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019353 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019354
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019355 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019356 }
19357 }
19358}
19359#endif
19360
Tony Barbour300a6082015-04-07 13:44:53 -060019361int main(int argc, char **argv) {
19362 int result;
19363
Cody Northrop8e54a402016-03-08 22:25:52 -070019364#ifdef ANDROID
19365 int vulkanSupport = InitVulkan();
19366 if (vulkanSupport == 0)
19367 return 1;
19368#endif
19369
Tony Barbour300a6082015-04-07 13:44:53 -060019370 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019371 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019372
19373 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19374
19375 result = RUN_ALL_TESTS();
19376
Tony Barbour6918cd52015-04-09 12:58:51 -060019377 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019378 return result;
19379}